39 #define DBGPRINTF(x...) {printf(x);fflush(stdout);} 41 #define DBGPRINTF(x...) 60 unsigned int write(
unsigned char c);
61 unsigned int writeDLE(
unsigned char c);
68 dat =
new unsigned char[_maxsize];
103 printf(
"*** rlBuffer read error! Pos:%u Len:%u\n", pos,
len);
110 printf(
"Buffer [%d]:",
len);
112 for(
int i=0; i<(int)
len; i++) printf(
" %02X", (
unsigned int)
dat[i]);
118 static unsigned short calcCRC (
unsigned short crc,
unsigned short buffer)
120 unsigned short temp1, y;
121 temp1 = crc ^ buffer;
122 crc = (crc & 0xff00) | (temp1 & 0xff);
123 for (y = 0; y < 8; y++) {
133 static unsigned short computeCRC (
const unsigned char *buffer,
int len)
135 unsigned short crc = 0;
136 for (
int x=0; x<len; x++) {
137 crc =
calcCRC(crc, (
unsigned short)buffer[x] );
153 tns = (
unsigned short) time((time_t *)0);
213 static unsigned char buf[2];
222 static unsigned char buf[2];
231 static unsigned char buf[2];
243 unsigned char cdat[256];
246 int ret =
sendCommand( destination, 0x0F, 0x00, cdat, 2);
248 unsigned char dest,cmd,sts,len;
251 printf(
"\nSet CPU Mode Execution Error! STS:%02X",sts);
259 unsigned char cdat[256];
261 int ret =
sendCommand( destination, 0x06, 0x00, cdat, 1);
263 unsigned char dest,cmd,sts,len;
266 for (
int i=0;i<len;i++) buffer[i]=cdat[i];
273 int rlDF1::cmdLogicalRead(
unsigned char destination,
unsigned char nsize,
unsigned char filetype,
unsigned char filenum,
unsigned char adr,
unsigned char sadr,
unsigned char *buffer)
275 unsigned char cdat[256];
282 int ret =
sendCommand( destination , 0x0F, 0x00, cdat, 6);
284 unsigned char dest,cmd,sts,len;
287 for (
int i=0;i<len;i++) buffer[i]=cdat[i];
294 int rlDF1::cmdLogicalWrite(
unsigned char destination,
unsigned char nsize,
unsigned char filetype,
unsigned char filenum,
unsigned char adr,
unsigned char sadr,
unsigned char *buffer)
296 unsigned char cdat[256];
303 for (
int i=0;i<nsize;i++) cdat[6+i] = buffer[i];
304 int ret =
sendCommand( destination, 0x0F, 0x00, cdat, 6+nsize);
306 unsigned char dest,cmd,sts,len;
309 for (
int i=0;i<len;i++) buffer[i] = cdat[i];
319 int rlDF1::sendCommand(
unsigned char destination,
unsigned char cmd,
unsigned char sts,
unsigned char *cdata,
unsigned char len)
333 for (
int i=0; i<len; i++) {
DBGPRINTF(
"[%02X] ",cdata[i]); }
334 msg.
write( destination );
338 msg.
write( (
unsigned char)(
tns&0x00FF) );
339 msg.
write( (
unsigned char)(
tns>>8) );
340 for(
int i=0; i<len; i++) msg.
write( cdata[i] );
349 fullmsg.
write( (
unsigned char)(crc&0x00FF) );
350 fullmsg.
write( (
unsigned char)(crc>>8) );
386 int rlDF1::receiveAnswer(
unsigned char &destination,
unsigned char &cmd,
unsigned char &sts,
unsigned char *cdata,
unsigned char &len)
389 static unsigned char response=
NAC;
398 DBGPRINTF(
"\nreceiveAnswer() Timeout....");
424 unsigned short crc = (
unsigned short)rxc;
432 crc += ( (
unsigned short)rxc )<<8;
439 unsigned short tns_ = (
unsigned short)msg[
POS_TNSL];
440 tns_ += ( (
unsigned short)msg[
POS_TNSH] )<<8;
462 for (
int i=0; i<len; i++) cdata[i] = msg[i +
POS_DATA];
int readBlock(unsigned char *buf, int len, int timeout=-1)
unsigned int writeDLE(unsigned char c)
df1Buffer(unsigned int maxsize=256)
int writeBuffer(unsigned char *buffer, int len)
void registerSerial(rlSerial *serial)
rlDF1(unsigned char src=0, int timeout=1000)
unsigned char & operator[](unsigned int pos)
int sendCommand(unsigned char destination, unsigned char cmd, unsigned char sts, unsigned char *cdata, unsigned char len)
static unsigned short calcCRC(unsigned short crc, unsigned short buffer)
int cmdLogicalWrite(unsigned char destination, unsigned char nsize, unsigned char filetype, unsigned char filenum, unsigned char adr, unsigned char sadr, unsigned char *buffer)
int get(unsigned char *c)
int cmdSetCPUMode(unsigned char destination, unsigned char mode)
unsigned int write(unsigned char c)
int getSymbol(unsigned char *c)
int cmdDiagnosticStatus(unsigned char destination, unsigned char *data)
static unsigned short computeCRC(const unsigned char *buffer, int len)
int cmdLogicalRead(unsigned char destination, unsigned char nsize, unsigned char filetype, unsigned char filenum, unsigned char adr, unsigned char sadr, unsigned char *buffer)
int writeBlock(const unsigned char *buf, int len)
int receiveAnswer(unsigned char &destination, unsigned char &cmd, unsigned char &sts, unsigned char *cdata, unsigned char &len)