Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/QNX4/SerialPort.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__SerialPort_CPP__
00002 #define __J2K__SerialPort_CPP__
00003 
00004 #include <j2k/Fred/QNX/SerialPort.hpp>
00005 
00006 // Default Constructor
00007 SerialPort::SerialPort() {
00008   // Elan-104 on QNX-2 COM1
00009   modem = open( "//2/dev/ser1", O_RDWR );
00010   Task  = new SerialTask_t[ MAX_SERIAL_TASK ];
00011 
00012   for( int i = 0; i < MAX_SERIAL_TASK; i++ ) {
00013     Task[i].cmd   = 0;
00014     Task[i].id    = 0;
00015     Task[i].valid = 0;
00016   }
00017 
00018   bottom  = 0;
00019   Waiting = 0;
00020 
00021   curr.cmd   = 0;
00022   curr.id    = 0;
00023   curr.valid = 0;
00024 
00025   TrainCmd( 96, -1 );   // Activate Serial Controller
00026 }
00027 
00028 // Destructor
00029 SerialPort::~SerialPort() {
00030   delete [] Task;
00031   TrainCmd( 97, -1 );   // Deactivate Serial Controller
00032 }
00033 
00034 void SerialPort::TrainCmd( int cmd, int id ) {
00035   buf[0] = cmd;
00036 
00037   if ( id > 0 ) {
00038     buf[1] = id;
00039     write( modem, &buf, 2 );    // Send TrainID
00040   } else {
00041     write( modem, &buf, 1 );    // Don't Send TrainID
00042   }
00043 
00044   Waiting = 1;
00045   delay( MODEM_DELAY );
00046 
00047   Waiting = 0;
00048 }
00049 
00050 void SerialPort::AddTask( int cmd, int id ) {
00051   if ( Waiting == 0 ) {
00052 
00053     TrainCmd( cmd, id );
00054 
00055   } else if ( bottom >= MAX_SERIAL_TASK ) {
00056 
00057     printf("\n*** Error: Reach the end of the array  ***  ");
00058     printf("\n***        Can't Add more Serial Task ! ***\n"); 
00059     return;        
00060 
00061   } else {
00062     ++bottom;
00063     Task[ bottom ].cmd   = cmd;
00064     Task[ bottom ].id    = id;
00065     Task[ bottom ].valid = 1;
00066   }
00067 }
00068 
00069 void SerialPort::ExecuteTask() {
00070   if ( bottom < 1 ) return;
00071   if ( Task[0].valid == 0 ) return;
00072 
00073   curr.cmd = Task[0].cmd;
00074   curr.id  = Task[0].id;
00075 
00076   for( int k = 0; k < bottom; k++ ) {
00077     Task[k].cmd   = Task[k+1].cmd;
00078     Task[k].id    = Task[k+1].id;
00079     Task[k].valid = Task[k+1].valid;
00080   }
00081 
00082   Task[bottom].cmd   = 0;
00083   Task[bottom].id    = 0;
00084   Task[botton].valid = 0;
00085 
00086   bottom--;
00087   curr.valid = 0;
00088   TrainCmd( curr.cmd, curr.id );
00089 }
00090 
00091 #endif

Generated on Sun Oct 14 18:46:42 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001