rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
rl3964R Class Reference

#include <rl3964r.h>

Collaboration diagram for rl3964R:
Collaboration graph
[legend]

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
 

Detailed Description

This class implements the siemens 3964R dust protocol.
The read messages must be handled within the callback routine.

Definition at line 27 of file rl3964r.h.

Member Enumeration Documentation

Enumerator:
highPriority 
lowPriority 

Definition at line 30 of file rl3964r.h.

Constructor & Destructor Documentation

rl3964R::rl3964R ( int  _priority = highPriority)

Definition at line 124 of file rl3964r.cpp.

{
priority = _priority;
readCallback = NULL;
debug = 0;
isOpen = 0;
}
rl3964R::~rl3964R ( )
virtual

Definition at line 135 of file rl3964r.cpp.

{
close();
}

Member Function Documentation

int rl3964R::close ( )

Definition at line 159 of file rl3964r.cpp.

{
if(isOpen == 1)
{
isOpen = 0;
run = 0;
dprintf("close(): cancel\n");
dprintf("close(): closeDevice\n");
dprintf("close(): return\n");
return 0;
}
isOpen = 0;
return -1;
}
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;
}
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;
}
}
if(bcc == received_bcc)
{
dprintf(" success\n");
}
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:
bcc = bcc ^ DLE;
bcc = bcc ^ DLE;
break;
default:
bcc = bcc ^ tel_send[i];
break;
}
}
bcc = bcc ^ DLE;
bcc = bcc ^ ETX;
tty.writeChar(bcc);
ret = tty.select(1000);
if(ret == 1) c = tty.readChar();
else
{
dprintf("send(): partner was sending nothing\n");
return -1;
}
if(c == DLE)
{
dprintf(" success\n");
}
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;
memcpy(tel_send,buf,len);
dprintf("write() STX\n");
dprintf("write() unlock\n");
dprintf("write() waitSemaphore\n");
dprintf("write() return len=%d\n",len);
if(send_result < 0) return -1;
return len;
}

Member Data Documentation

int rl3964R::debug

Definition at line 50 of file rl3964r.h.

int rl3964R::isOpen
private

Definition at line 58 of file rl3964r.h.

int rl3964R::priority

Definition at line 48 of file rl3964r.h.

void(* rl3964R::readCallback)(const unsigned char *buf, int len)
private

Definition at line 53 of file rl3964r.h.

rlThread rl3964R::receiver

Definition at line 45 of file rl3964r.h.

int rl3964R::run

Definition at line 49 of file rl3964r.h.

int rl3964R::send_result
private

Definition at line 59 of file rl3964r.h.

int rl3964R::state

Definition at line 47 of file rl3964r.h.

unsigned char rl3964R::tel_receive[512]
private

Definition at line 55 of file rl3964r.h.

int rl3964R::tel_receive_length
private

Definition at line 57 of file rl3964r.h.

unsigned char rl3964R::tel_send[512]
private

Definition at line 54 of file rl3964r.h.

int rl3964R::tel_send_length
private

Definition at line 56 of file rl3964r.h.

rlSerial rl3964R::tty

Definition at line 46 of file rl3964r.h.


The documentation for this class was generated from the following files: