|
rllib
1
|
#include <rl3964r.h>

Public Types | |
| enum | priorityEnum { highPriority = 0, lowPriority } |
Public Member Functions | |
| rl3964R (int _priority=highPriority) | |
| virtual | ~rl3964R () |
| int | open (const char *devicename, int _baudrate=B9600) |
| int | close () |
| int | setReadCallback (void(*_readCallback)(const unsigned char *buf, int len)) |
| int | write (const unsigned char *buf, int len) |
| int | send () |
| int | receive () |
| int | dprintf (const char *format,...) |
Public Attributes | |
| rlThread | receiver |
| rlSerial | tty |
| int | state |
| int | priority |
| int | run |
| int | debug |
Private Attributes | |
| void(* | readCallback )(const unsigned char *buf, int len) |
| unsigned char | tel_send [512] |
| unsigned char | tel_receive [512] |
| int | tel_send_length |
| int | tel_receive_length |
| int | isOpen |
| int | send_result |
This class implements the siemens 3964R dust protocol. The read messages must be handled within the callback routine.
Definition at line 30 of file rl3964r.h.
{
highPriority = 0,
lowPriority
};
| rl3964R::rl3964R | ( | int | _priority = highPriority | ) |
Definition at line 124 of file rl3964r.cpp.
{
priority = _priority;
readCallback = NULL;
debug = 0;
isOpen = 0;
state = IDLE;
send_result = 0;
tel_receive_length = tel_send_length = -1;
}
| rl3964R::~rl3964R | ( | ) | [virtual] |
Definition at line 135 of file rl3964r.cpp.
{
close();
}
| int rl3964R::close | ( | ) |
| int rl3964R::dprintf | ( | const char * | format, |
| ... | |||
| ) |
Definition at line 310 of file rl3964r.cpp.
{
char message[rl_PRINTF_LENGTH]; // should be big enough
int ret;
if(debug != 1) return 0;
va_list ap;
va_start(ap,format);
ret = rlvsnprintf(message, rl_PRINTF_LENGTH - 1, format, ap);
va_end(ap);
printf("%s",message);
return ret;
}
| int rl3964R::open | ( | const char * | devicename, |
| int | _baudrate = B9600 |
||
| ) |
Definition at line 140 of file rl3964r.cpp.
{
int ret;
if(isOpen == 0)
{
//int openDevice(const char *devicename, int speed=B9600, int block=1, int rtscts=1, int bits=8, int stopbits=1, int parity=NONE);
ret = tty.openDevice(devicename,_baudrate,1,0,8,1,rlSerial::EVEN);
if(ret >= 0)
{
isOpen = 1;
run = 1;
receiver.create(receiverThread,this);
}
return ret;
}
return -1;
}
| int rl3964R::receive | ( | ) |
Definition at line 248 of file rl3964r.cpp.
{
int i,c,c2,bcc,received_bcc,ret;
dprintf("receive()\n");
//bcc = STX;
bcc = 0;
i = received_bcc = 0;
tel_receive[i++] = c = STX;
while(c > 0 && i < (int) sizeof(tel_receive))
{
ret = tty.select(1000);
if(ret == 1) c = tty.readChar();
else
{
dprintf("receive(): partner was sending nothing\n");
return -1;
}
dprintf(" %x\n",c);
switch(c)
{
case -1:
case -2:
return -1;
case DLE:
bcc = bcc ^ c;
c2 = tty.readChar();
dprintf(" %x\n",c2);
bcc = bcc ^ c2;
if(c2 < 0) return -1;
tel_receive[i++] = c2;
if(c2 == ETX)
{
c2 = tty.readChar();
dprintf(" %x\n",c2);
if(c2 < 0) return -1;
tel_receive[i++] = c2; // bcc
received_bcc = c2;
dprintf(" bcc=%d received_bcc=%d\n",bcc,received_bcc);
c = -1;
}
break;
default:
bcc = bcc ^ c;
tel_receive[i++] = c;
break;
}
}
tel_receive_length = i;
if(bcc == received_bcc)
{
tty.writeChar(DLE);
dprintf(" success\n");
if(readCallback != NULL) (readCallback)(&tel_receive[1],tel_receive_length-3);
return tel_receive_length-3;
}
tty.writeChar(NAK);
dprintf(" failure\n");
return -1;
}
| int rl3964R::send | ( | ) |
Definition at line 201 of file rl3964r.cpp.
{
int i,bcc,c,ret;
dprintf("send()");
//bcc = STX;
bcc = 0;
for(i=0; i<tel_send_length; i++)
{
switch(tel_send[i])
{
case DLE:
tty.writeChar(DLE);
tty.writeChar(DLE);
bcc = bcc ^ DLE;
bcc = bcc ^ DLE;
break;
default:
tty.writeChar(tel_send[i]);
bcc = bcc ^ tel_send[i];
break;
}
}
tty.writeChar(DLE);
bcc = bcc ^ DLE;
tty.writeChar(ETX);
bcc = bcc ^ ETX;
tty.writeChar(bcc);
ret = tty.select(1000);
if(ret == 1) c = tty.readChar();
else
{
send_result = -1;
dprintf("send(): partner was sending nothing\n");
return -1;
}
if(c == DLE)
{
send_result = 0;
dprintf(" success\n");
return tel_send_length;
}
send_result = -1;
dprintf(" failure\n");
return -1;
}
| int rl3964R::setReadCallback | ( | void(*)(const unsigned char *buf, int len) | _readCallback | ) |
Definition at line 176 of file rl3964r.cpp.
{
readCallback = _readCallback;
return 0;
}
| int rl3964R::write | ( | const unsigned char * | buf, |
| int | len | ||
| ) |
Definition at line 182 of file rl3964r.cpp.
{
dprintf("write() len=%d\n",len);
if(len >= (int) sizeof(tel_send)) return -1;
receiver.lock();
tel_send_length = len;
memcpy(tel_send,buf,len);
state = WANT_TO_SEND;
dprintf("write() STX\n");
tty.writeChar(STX);
dprintf("write() unlock\n");
receiver.unlock();
dprintf("write() waitSemaphore\n");
receiver.waitSemaphore();
dprintf("write() return len=%d\n",len);
if(send_result < 0) return -1;
return len;
}
| int rl3964R::debug |
int rl3964R::isOpen [private] |
void(* rl3964R::readCallback)(const unsigned char *buf, int len) [private] |
| int rl3964R::run |
int rl3964R::send_result [private] |
| int rl3964R::state |
unsigned char rl3964R::tel_receive[512] [private] |
int rl3964R::tel_receive_length [private] |
unsigned char rl3964R::tel_send[512] [private] |
int rl3964R::tel_send_length [private] |
1.7.5.1