rllib  1
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

◆ ACK

#define ACK   6

Definition at line 28 of file rl3964r.cpp.

◆ DLE

#define DLE   16

Definition at line 26 of file rl3964r.cpp.

◆ ENQ

#define ENQ   5

Definition at line 23 of file rl3964r.cpp.

◆ EOT

#define EOT   4

Definition at line 24 of file rl3964r.cpp.

◆ ETB

#define ETB   23

Definition at line 25 of file rl3964r.cpp.

◆ ETX

#define ETX   3

Definition at line 22 of file rl3964r.cpp.

◆ NAK

#define NAK   21

Definition at line 27 of file rl3964r.cpp.

◆ STX

#define STX   2

Definition at line 21 of file rl3964r.cpp.

Enumeration Type Documentation

◆ State

enum State
Enumerator
IDLE 
SENDING 
RECEIVING 
WANT_TO_SEND 
WANT_TO_RECEIVE 

Definition at line 30 of file rl3964r.cpp.

31 {
32  IDLE = 0,
33  SENDING = 1,
34  RECEIVING = 2,
35  WANT_TO_SEND = 3,
36  WANT_TO_RECEIVE = 4
37 };
Definition: rl3964r.cpp:32

Function Documentation

◆ receiverThread()

static void* receiverThread ( void *  arg)
static

Definition at line 41 of file rl3964r.cpp.

42 {
43  THREAD_PARAM *p = (THREAD_PARAM *) arg;
44  rl3964R *d = (rl3964R *) p->user;
45  unsigned char c;
46  int ret,send_retry;
47 
48  send_retry = 0;
49  while(d->run)
50  {
51  c = 0x0ff;
52  ret = d->tty.select(1000);
53  if(ret == 1) c = d->tty.readChar();
54  p->thread->lock();
55 
56  d->dprintf("receiverThread: c=%d state=%s\n",c,statestr[d->state]);
57  if(c==STX && d->state==IDLE)
58  {
59  d->dprintf("STX IDLE\n");
60  d->state = RECEIVING;
61  d->dprintf("write DLE\n");
62  d->tty.writeChar(DLE);
63  d->dprintf("call receive\n");
64  d->receive();
65  d->dprintf("after receive\n");
66  d->state = IDLE;
67  }
68  else if(c==STX && d->state==WANT_TO_SEND && d->priority==rl3964R::lowPriority)
69  {
70  d->dprintf("receiverThread: STX WANT_TO_SEND lowPriority\n");
71  d->state = RECEIVING;
72  d->tty.writeChar(DLE);
73  d->receive();
74  d->state = WANT_TO_SEND;
75  }
76  else if(c==STX && d->state==WANT_TO_SEND && d->priority==rl3964R::highPriority)
77  {
78  d->dprintf("receiverThread: STX WANT_TO_SEND highPriority\n");
79  d->tty.writeChar(NAK);
80  d->tty.writeChar(STX);
81  }
82  else if(c==DLE && d->state==WANT_TO_SEND)
83  {
84  d->dprintf("receiverThread: DLE WANT_TO_SEND\n");
85  d->send();
86  d->state = IDLE;
88  }
89  else if(c==NAK)
90  {
91  d->dprintf("receiverThread: NAK\n");
92  }
93  else if(d->state==WANT_TO_SEND)
94  {
95  if(send_retry < 1)
96  {
97  }
98  else if(send_retry < 3)
99  {
100  d->tty.writeChar(STX);
101  send_retry++;
102  d->dprintf("receiverThread: WANT_TO_SEND send=STX retry=%d\n",send_retry+1);
103  }
104  else
105  {
106  send_retry = 0;
107  d->dprintf("receiverThread: WANT_TO_SEND failed after 3 retries\n");
108  d->state = IDLE;
110  }
111  }
112  else
113  {
114  d->dprintf("receiverThread: IDLE\n");
115  d->state = IDLE;
116  }
117 
118  p->thread->unlock();
119  }
120 
121  return NULL;
122 }
static const char * statestr[]
Definition: rl3964r.cpp:39
int receive()
Definition: rl3964r.cpp:248
void * user
Definition: rlthread.h:30
int send()
Definition: rl3964r.cpp:201
rlThread * thread
Definition: rlthread.h:29
int unlock()
Definition: rlthread.cpp:52
rlSerial tty
Definition: rl3964r.h:46
#define STX
Definition: rl3964r.cpp:21
Definition: rl3964r.cpp:32
rlThread receiver
Definition: rl3964r.h:45
int writeChar(unsigned char uchar)
Definition: rlserial.cpp:454
#define DLE
Definition: rl3964r.cpp:26
int select(int timeout=500)
Definition: rlserial.cpp:719
int dprintf(const char *format,...)
Definition: rl3964r.cpp:310
int run
Definition: rl3964r.h:49
int readChar()
Definition: rlserial.cpp:405
#define NAK
Definition: rl3964r.cpp:27
int incrementSemaphore()
Definition: rlthread.cpp:62
int state
Definition: rl3964r.h:47
int priority
Definition: rl3964r.h:48
int lock()
Definition: rlthread.cpp:47

Variable Documentation

◆ statestr

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

Definition at line 39 of file rl3964r.cpp.