rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Enumerations | Functions | Variables
rl3964r.cpp File Reference
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "rlcutil.h"
#include "rl3964r.h"
Include dependency graph for rl3964r.cpp:

Go to the source code of this file.

Macros

#define STX   2
 
#define ETX   3
 
#define ENQ   5
 
#define EOT   4
 
#define ETB   23
 
#define DLE   16
 
#define NAK   21
 
#define ACK   6
 

Enumerations

enum  State {
  IDLE = 0, SENDING = 1, RECEIVING = 2, WANT_TO_SEND = 3,
  WANT_TO_RECEIVE = 4
}
 

Functions

static void * receiverThread (void *arg)
 

Variables

static const char * statestr [] = {"idle","sending","receiving","want_to_send","want_to_receive"}
 

Macro Definition Documentation

#define ACK   6

Definition at line 28 of file rl3964r.cpp.

#define DLE   16

Definition at line 26 of file rl3964r.cpp.

#define ENQ   5

Definition at line 23 of file rl3964r.cpp.

#define EOT   4

Definition at line 24 of file rl3964r.cpp.

#define ETB   23

Definition at line 25 of file rl3964r.cpp.

#define ETX   3

Definition at line 22 of file rl3964r.cpp.

#define NAK   21

Definition at line 27 of file rl3964r.cpp.

#define STX   2

Definition at line 21 of file rl3964r.cpp.

Enumeration Type Documentation

enum State
Enumerator:
IDLE 
SENDING 
RECEIVING 
WANT_TO_SEND 
WANT_TO_RECEIVE 

Definition at line 30 of file rl3964r.cpp.

{
IDLE = 0,
SENDING = 1,
RECEIVING = 2,
};

Function Documentation

static void* receiverThread ( void *  arg)
static

Definition at line 41 of file rl3964r.cpp.

{
THREAD_PARAM *p = (THREAD_PARAM *) arg;
rl3964R *d = (rl3964R *) p->user;
unsigned char c;
int ret,send_retry;
send_retry = 0;
while(d->run)
{
c = 0x0ff;
ret = d->tty.select(1000);
if(ret == 1) c = d->tty.readChar();
p->thread->lock();
d->dprintf("receiverThread: c=%d state=%s\n",c,statestr[d->state]);
if(c==STX && d->state==IDLE)
{
d->dprintf("STX IDLE\n");
d->dprintf("write DLE\n");
d->dprintf("call receive\n");
d->receive();
d->dprintf("after receive\n");
d->state = IDLE;
}
{
d->dprintf("receiverThread: STX WANT_TO_SEND lowPriority\n");
d->receive();
}
{
d->dprintf("receiverThread: STX WANT_TO_SEND highPriority\n");
}
else if(c==DLE && d->state==WANT_TO_SEND)
{
d->dprintf("receiverThread: DLE WANT_TO_SEND\n");
d->send();
d->state = IDLE;
}
else if(c==NAK)
{
d->dprintf("receiverThread: NAK\n");
}
else if(d->state==WANT_TO_SEND)
{
if(send_retry < 1)
{
}
else if(send_retry < 3)
{
send_retry++;
d->dprintf("receiverThread: WANT_TO_SEND send=STX retry=%d\n",send_retry+1);
}
else
{
send_retry = 0;
d->dprintf("receiverThread: WANT_TO_SEND failed after 3 retries\n");
d->state = IDLE;
}
}
else
{
d->dprintf("receiverThread: IDLE\n");
d->state = IDLE;
}
p->thread->unlock();
}
return NULL;
}

Variable Documentation

const char* statestr[] = {"idle","sending","receiving","want_to_send","want_to_receive"}
static

Definition at line 39 of file rl3964r.cpp.