OpenQNX :: The QNX Community Portal

May 13, 2008 - 02:20 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 69 unlogged users and 2 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
deadcafe
22 Post subject: terminal functions (cursor position)  PostPosted: Jan 17, 2008 - 08:21 PM
New Member


Joined: Jan 17, 2008
Posts: 3

Hi there,

I have recently suffered the lack of the function changing cursor position to the specified coordinates (QNX 4.25)

Finally I've found term_cur() function which uses one of the global terminal strucutres (don't remember the name now). Anyway it does not work as I was expecting... Maybe it's because I use standard printf function to print the text... these two functionalities are the only one I need: moving cursor somewhere and printing the string.

Do you folks know how to solve this problem? Maybe other functions?
 
 View user's profile Send private message  
Reply with quote Back to top
kwschumm
Post subject: RE: terminal functions (cursor position)  PostPosted: Jan 18, 2008 - 03:06 AM
Senior Member


Joined: Sep 17, 2004
Posts: 172

IIRC, term_cur was supplied in a supplemental library with QNX4 to provide compatibility with the old QNX2 term style functions. You are correct, if you expect it to work you need to use term_printf to print and you generally can't mix and match functions. term_printf takes row and column arguments as a starting position. IIRC, you need to do a term_load to initialize the library before using any of them.
 
 View user's profile Send private message  
Reply with quote Back to top
AlexZ
Post subject: RE: terminal functions (cursor position)  PostPosted: Jan 18, 2008 - 01:49 PM
New Member


Joined: Aug 18, 2006
Posts: 8

Sample code

#include <sys/types.h>
#include <sys/qnxterm.h>
#include <sys/vc.h>
#include <sys/psinfo.h>
#include <sys/kernel.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <signal.h>

#define MAX_NET 4

#define N_ATTR TERM_NORMAL|TERM_FLUSH|TERM_WHITE|TERM_BLUE_BG

#define ERR_ATTR TERM_NORMAL|TERM_FLUSH|TERM_WHITE|TERM_RED_BG

void sigAlrm (int s_num) {
s_num = s_num;
}

static timer_t idt;
static int pr_idt;
static struct itimerspec timer;

short diaginfo (nid_t node,short net, short *buf) {

short c,p;
pid_t pid;

if (pr_idt==0) {
if ((idt=timer_create (CLOCK_REALTIME,NULL))==-1)
return (Cool;
pr_idt++;
// qnx_pflags (~0L,_PPF_SIGCATCH,NULL,NULL);
signal( SIGALRM, sigAlrm );
timer.it_value.tv_sec = 0L;
timer.it_value.tv_nsec = 0L;
timer.it_interval.tv_sec = 0L;
timer.it_interval.tv_nsec = 0L;
}
timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
pid=qnx_vc_name_attach (node,100,"qnx/net");
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
if (pid==-1)
return (1);

buf[0] = 0x438;

timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
p = Send (pid,(void far *)buf,(void far *)buf,2,8+12*MAX_NET);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
qnx_vc_detach (pid);
if (p)
return (2);

if (buf[0])
return (3);

for (c=0; c<buf[2]; c++)

if (buf[4+c*6]==net) {

pid = buf[4+c*6+4];

timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
pid=qnx_vc_attach (node,pid,512,0);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
if (pid==-1)
return (4);

buf[0] = 0x477;

timer.it_value.tv_sec = 1L;
timer_settime (idt,0,&timer,NULL);
p = Send (pid,(void far *)buf,(void far *)buf,2,32);
timer.it_value.tv_sec = 0L;
timer_settime (idt,0,&timer,NULL);
qnx_vc_detach (pid);
if (p)
return (5);

if (buf[0])
return (6);

return (0);
}

return (7);
}

int main (int argc, char *argv[]) {

short i,j,k,km,max_node,buf[75],i1;

if (argc<2) {

printf ("Use diaginfo <max_nodes>\n");
return (1);
}

max_node = atoi (argv[1]);

if (max_node<1 || max_node>31)
max_node = 31;

if (term_load ()) {

printf ("_иЁЎЄ  term_load Errno=%d\n",errno);
return (1);
}

term_fill (TERM_BLUE_BG);

term_clear (TERM_CLS_SCR);

term_type (0,3,"Net 1",0,N_ATTR);

term_type (1,19,"node's",0,N_ATTR);

for (i=1; i<=max_node; i++)
term_printf (1,20+i*6,N_ATTR,"%d",i);

term_type (13,3,"Net 2",0,N_ATTR);

term_type (14,19,"node's",0,N_ATTR);

for (i=1; i<=max_node; i++)
term_printf (14,20+i*6,N_ATTR,"%d",i);

term_type (2,0,"Pkt read error format",0,N_ATTR);
term_type (15,0,"Pkt read error format",0,N_ATTR);

term_type (3,0,"Retry tx msg",0,N_ATTR);
term_type (16,0,"Retry tx msg",0,N_ATTR);

term_type (4,0,"Receive busy",0,N_ATTR);
term_type (17,0,"Receive busy",0,N_ATTR);

term_type (5,0,"Send busy",0,N_ATTR);
term_type (18,0,"Send busy",0,N_ATTR);

term_type (6,0,"T-out send marker",0,N_ATTR);
term_type (19,0,"T-out send marker",0,N_ATTR);

term_type (7,0,"Retry tx marker",0,N_ATTR);
term_type (20,0,"Retry tx marker",0,N_ATTR);

term_type (8,0,"Restore marker",0,N_ATTR);
term_type (21,0,"Restore marker",0,N_ATTR);

term_type (9,0,"Max size queue",0,N_ATTR);
term_type (22,0,"Max size queue",0,N_ATTR);

term_type (10,0,"T-out rx ask",0,N_ATTR);
term_type (23,0,"T-out rx ask",0,N_ATTR);

term_type (11,0,"Error rx ask",0,N_ATTR);
term_type (24,0,"Error rx ask",0,N_ATTR);

for (;Wink {

sleep (1);

for (j=1; j<=2; j++)
for (i=1; i<=max_node; i++) {
if (i<=9) i1 = 1;
else i1 = 2;
if (diaginfo (i,j,buf))
term_printf ((j-1)*13+1,20+i*6,ERR_ATTR,"%d",i);
else {

term_printf ((j-1)*13+1,20+i*6,N_ATTR,"%d",i);
if (buf[1]==2)
term_type ((j-1)*13+1,20+i*6+i1,"(ksv)",0,N_ATTR);
else
term_type ((j-1)*13+1,20+i*6+i1,"(bpr)",0,N_ATTR);
memmove (&buf[11],(char *)buf+21,11);
buf[10]&=0xFF;
memmove (&buf[11],&buf[14],4);
memmove (&buf[9],&buf[10],6);
for (k=2,km=9+(buf[1]-1)*2; k<=km; k++)
term_printf ((j-1)*13+k,20+i*6,N_ATTR,"%-5u",buf[k]);
}
}
}
}
 
 View user's profile Send private message  
Reply with quote Back to top
deadcafe
Post subject:   PostPosted: Jan 18, 2008 - 04:48 PM
New Member


Joined: Jan 17, 2008
Posts: 3

thanks guys, of course I do use term_load() function but never used #define N_ATTR with the term_printf function. Anyway I will try to check it. the other reason may be that I am referring to the wrong library as a compilation parameter (without one library i couldn't compile it at all, although i included <sys/qnxterm.h> )

second issue: i suppose gets() also won't work properly, is there any other terminal function to read the string (with spaces) from the console?

and at last: do you know how to run qnx 4.25 from windows platform? E.g using virtual machine? And I am not thinking of QNX Neutrino... just old 4.25
 
 View user's profile Send private message  
Reply with quote Back to top
micro
Post subject:   PostPosted: Jan 21, 2008 - 04:19 PM
Senior Member


Joined: Jul 22, 2004
Posts: 315

Actually if you run your console in ANSI-mode you can use ANSI-Style to move the cursor.
It was something like:

In Shell do (for ANSIable Shell):
Code:

export TERM=ansi
stty protocol=1 term=$TERM


For xy coordinates use:
Code:

void gotoxy (int x, int y) {
   char c[7];
   c[0] = 0x9b;
   c[1] = 0x30+y/10;
   c[2] = 0x30+y%10;
   c[3] = 0x3b;
   c[4] = 0x30+x/10;
   c[5] = 0x30+x%10;
   c[6] = 0x48;
   printf(c);
return;
}
 
 View user's profile Send private message  
Reply with quote Back to top
micro
Post subject:   PostPosted: Jan 21, 2008 - 04:20 PM
Senior Member


Joined: Jul 22, 2004
Posts: 315

http://www.qnx.com/developers/docs/qnx_4.25_docs/qnx4/utils/d/devansi.html

;P
 
 View user's profile Send private message  
Reply with quote Back to top
AlexZ
Post subject:   PostPosted: Jan 23, 2008 - 01:21 PM
New Member


Joined: Aug 18, 2006
Posts: 8

cc -l termlib
 
 View user's profile Send private message  
Reply with quote Back to top
deadcafe
Post subject:   PostPosted: Jan 25, 2008 - 10:55 PM
New Member


Joined: Jan 17, 2008
Posts: 3

thx a lot. the library was: termlib3r
and it was okay, but I did have to switch between terminal functions and others standard input/output. So I used term_load and term_restore functions to enable/disable terminal couple times in the code.

Anyway big thanks, application works really well... and fast Smile

cheers,
dc.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.