Change some names for consistency
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
#include "sics.h"
|
||||
#include "huber_asyncprotocol.h"
|
||||
#include "asyncprotocol.h"
|
||||
#include "asyncqueue.h"
|
||||
|
||||
@ -10,16 +10,16 @@
|
||||
* Protocol transmit function
|
||||
* Called by AsyncQueue to transmit a line
|
||||
*/
|
||||
static int HUBER_Tx(pAsyncProtocol p, pAsyncTxn myCmd) {
|
||||
static int HUBER_Tx(pAsyncProtocol p, pAsyncTxn pTxn) {
|
||||
int iRet = 1;
|
||||
|
||||
if (myCmd) {
|
||||
myCmd->txn_status = ATX_ACTIVE;
|
||||
iRet = AsyncUnitWrite(myCmd->unit, myCmd->out_buf, myCmd->out_len);
|
||||
if (pTxn) {
|
||||
pTxn->txn_status = ATX_ACTIVE;
|
||||
iRet = AsyncUnitWrite(pTxn->unit, pTxn->out_buf, pTxn->out_len);
|
||||
/* TODO handle errors */
|
||||
if (iRet < 0) { /* TODO: EOF */
|
||||
/*
|
||||
iRet = AsyncUnitReconnect(myCmd->unit);
|
||||
iRet = AsyncUnitReconnect(pTxn->unit);
|
||||
if (iRet == 0)
|
||||
*/
|
||||
return 0;
|
||||
@ -31,39 +31,38 @@ static int HUBER_Tx(pAsyncProtocol p, pAsyncTxn myCmd) {
|
||||
/*
|
||||
* Protocol receive character - characater by character
|
||||
*/
|
||||
static int HUBER_Rx(pAsyncProtocol p, pAsyncTxn ctx, int rxchar) {
|
||||
static int HUBER_Rx(pAsyncProtocol p, pAsyncTxn pTxn, int rxchar) {
|
||||
int iRet = 1;
|
||||
pAsyncTxn myCmd = (pAsyncTxn) ctx;
|
||||
|
||||
switch (myCmd->txn_state) {
|
||||
switch (pTxn->txn_state) {
|
||||
case 0: /* first character */
|
||||
if (rxchar != LBRACE) {
|
||||
/* TODO: error */
|
||||
myCmd->txn_state = 99;
|
||||
myCmd->txn_status = ATX_COMPLETE;
|
||||
pTxn->txn_state = 99;
|
||||
pTxn->txn_status = ATX_COMPLETE;
|
||||
break;
|
||||
}
|
||||
/* normal data */
|
||||
myCmd->txn_state = 1;
|
||||
pTxn->txn_state = 1;
|
||||
/* note fallthrough */
|
||||
case 1: /* receiving reply */
|
||||
if (myCmd->inp_idx < myCmd->inp_len)
|
||||
myCmd->inp_buf[myCmd->inp_idx++] = rxchar;
|
||||
if (pTxn->inp_idx < pTxn->inp_len)
|
||||
pTxn->inp_buf[pTxn->inp_idx++] = rxchar;
|
||||
if (rxchar == CR)
|
||||
myCmd->txn_state = 2;
|
||||
pTxn->txn_state = 2;
|
||||
break;
|
||||
case 2: /* receiving LF */
|
||||
if (myCmd->inp_idx < myCmd->inp_len)
|
||||
myCmd->inp_buf[myCmd->inp_idx++] = rxchar;
|
||||
if (pTxn->inp_idx < pTxn->inp_len)
|
||||
pTxn->inp_buf[pTxn->inp_idx++] = rxchar;
|
||||
if (rxchar != LF) {
|
||||
/* TODO: error */
|
||||
}
|
||||
myCmd->txn_state = 99;
|
||||
myCmd->inp_idx -= 3;
|
||||
memmove(myCmd->inp_buf, myCmd->inp_buf + 1, myCmd->inp_idx);
|
||||
pTxn->txn_state = 99;
|
||||
pTxn->inp_idx -= 3;
|
||||
memmove(pTxn->inp_buf, pTxn->inp_buf + 1, pTxn->inp_idx);
|
||||
break;
|
||||
}
|
||||
if (myCmd->txn_state == 99) {
|
||||
if (pTxn->txn_state == 99) {
|
||||
iRet = 0;
|
||||
}
|
||||
if (iRet == 0) { /* end of command */
|
||||
@ -84,18 +83,18 @@ static int HUBER_Ev(pAsyncProtocol p, pAsyncTxn pTxn, int event) {
|
||||
return AQU_POP_CMD;
|
||||
}
|
||||
|
||||
static int HUBER_PrepareTxn(pAsyncProtocol p, pAsyncTxn txn, const char* cmd, int cmd_len, int rsp_len) {
|
||||
static int HUBER_PrepareTxn(pAsyncProtocol p, pAsyncTxn pTxn, const char* cmd, int cmd_len, int rsp_len) {
|
||||
int i, bcc;
|
||||
txn->out_buf = (char*) malloc(cmd_len + 3);
|
||||
if (txn->out_buf == NULL) {
|
||||
pTxn->out_buf = (char*) malloc(cmd_len + 3);
|
||||
if (pTxn->out_buf == NULL) {
|
||||
SICSLogWrite("ERROR: Out of memory in HUBER_PrepareTxn", eError);
|
||||
return 0;
|
||||
}
|
||||
memcpy(txn->out_buf + 1, cmd, cmd_len);
|
||||
txn->out_buf[0] = LBRACE;
|
||||
txn->out_buf[cmd_len + 1] = CR;
|
||||
txn->out_buf[cmd_len + 2] = LF;
|
||||
txn->out_len = cmd_len + 3;
|
||||
memcpy(pTxn->out_buf + 1, cmd, cmd_len);
|
||||
pTxn->out_buf[0] = LBRACE;
|
||||
pTxn->out_buf[cmd_len + 1] = CR;
|
||||
pTxn->out_buf[cmd_len + 2] = LF;
|
||||
pTxn->out_len = cmd_len + 3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#ifndef HUBER_ASYNCPROTOCOL_H
|
||||
#define HUBER_ASYNCPROTOCOL_H
|
||||
#include "sics.h"
|
||||
void HUBERInitProtocol(SicsInterp *pSics);
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "sics.h"
|
||||
#include "omron_asyncprotocol.h"
|
||||
#include "asyncprotocol.h"
|
||||
#include "asyncqueue.h"
|
||||
|
||||
@ -30,16 +30,16 @@ static int calc_bcc(const char* text)
|
||||
* Protocol transmit function
|
||||
* Called by AsyncQueue to transmit a line
|
||||
*/
|
||||
static int OMRON_Tx(pAsyncProtocol p, pAsyncTxn myCmd) {
|
||||
static int OMRON_Tx(pAsyncProtocol p, pAsyncTxn pTxn) {
|
||||
int iRet = 1;
|
||||
|
||||
if (myCmd) {
|
||||
myCmd->txn_status = ATX_ACTIVE;
|
||||
iRet = AsyncUnitWrite(myCmd->unit, myCmd->out_buf, myCmd->out_len);
|
||||
if (pTxn) {
|
||||
pTxn->txn_status = ATX_ACTIVE;
|
||||
iRet = AsyncUnitWrite(pTxn->unit, pTxn->out_buf, pTxn->out_len);
|
||||
/* TODO handle errors */
|
||||
if (iRet < 0) { /* TODO: EOF */
|
||||
/*
|
||||
iRet = AsyncUnitReconnect(myCmd->unit);
|
||||
iRet = AsyncUnitReconnect(pTxn->unit);
|
||||
if (iRet == 0)
|
||||
*/
|
||||
return 0;
|
||||
@ -51,44 +51,43 @@ static int OMRON_Tx(pAsyncProtocol p, pAsyncTxn myCmd) {
|
||||
/*
|
||||
* Protocol receive character - characater by character
|
||||
*/
|
||||
static int OMRON_Rx(pAsyncProtocol p, pAsyncTxn ctx, int rxchar) {
|
||||
static int OMRON_Rx(pAsyncProtocol p, pAsyncTxn pTxn, int rxchar) {
|
||||
int iRet = 1;
|
||||
pAsyncTxn myCmd = (pAsyncTxn) ctx;
|
||||
|
||||
switch (myCmd->txn_state) {
|
||||
switch (pTxn->txn_state) {
|
||||
case 0: /* first character */
|
||||
if (rxchar != STX) { /* STX */
|
||||
/* TODO: error */
|
||||
myCmd->txn_state = 99;
|
||||
myCmd->txn_status = ATX_COMPLETE;
|
||||
pTxn->txn_state = 99;
|
||||
pTxn->txn_status = ATX_COMPLETE;
|
||||
break;
|
||||
}
|
||||
/* normal data */
|
||||
myCmd->txn_state = 1;
|
||||
pTxn->txn_state = 1;
|
||||
/* note fallthrough */
|
||||
case 1: /* receiving reply */
|
||||
if (myCmd->inp_idx < myCmd->inp_len)
|
||||
myCmd->inp_buf[myCmd->inp_idx++] = rxchar;
|
||||
if (pTxn->inp_idx < pTxn->inp_len)
|
||||
pTxn->inp_buf[pTxn->inp_idx++] = rxchar;
|
||||
if (rxchar == ETX)
|
||||
myCmd->txn_state = 2;
|
||||
pTxn->txn_state = 2;
|
||||
break;
|
||||
case 2: /* receiving bcc */
|
||||
if (myCmd->inp_idx < myCmd->inp_len)
|
||||
myCmd->inp_buf[myCmd->inp_idx++] = rxchar;
|
||||
if (calc_bcc(myCmd->inp_buf) != rxchar) {
|
||||
if (pTxn->inp_idx < pTxn->inp_len)
|
||||
pTxn->inp_buf[pTxn->inp_idx++] = rxchar;
|
||||
if (calc_bcc(pTxn->inp_buf) != rxchar) {
|
||||
/* TODO: fail bcc */
|
||||
int bcc = calc_bcc(myCmd->inp_buf);
|
||||
int bcc = calc_bcc(pTxn->inp_buf);
|
||||
SICSLogPrintf(eError,
|
||||
"Omron BCC mismatch, expected %02X but received %02X on message:",
|
||||
bcc, rxchar);
|
||||
SICSLogWriteHex(myCmd->inp_buf, myCmd->inp_idx, eError);
|
||||
SICSLogWriteHex(pTxn->inp_buf, pTxn->inp_idx, eError);
|
||||
}
|
||||
myCmd->txn_state = 99;
|
||||
myCmd->inp_idx -= 3;
|
||||
memmove(myCmd->inp_buf, myCmd->inp_buf + 1, myCmd->inp_idx);
|
||||
pTxn->txn_state = 99;
|
||||
pTxn->inp_idx -= 3;
|
||||
memmove(pTxn->inp_buf, pTxn->inp_buf + 1, pTxn->inp_idx);
|
||||
break;
|
||||
}
|
||||
if (myCmd->txn_state == 99) {
|
||||
if (pTxn->txn_state == 99) {
|
||||
iRet = 0;
|
||||
}
|
||||
if (iRet == 0) { /* end of command */
|
||||
@ -109,18 +108,18 @@ static int OMRON_Ev(pAsyncProtocol p, pAsyncTxn pTxn, int event) {
|
||||
return AQU_POP_CMD;
|
||||
}
|
||||
|
||||
static int OMRON_PrepareTxn(pAsyncProtocol p, pAsyncTxn txn, const char* cmd, int cmd_len, int rsp_len) {
|
||||
static int OMRON_PrepareTxn(pAsyncProtocol p, pAsyncTxn pTxn, const char* cmd, int cmd_len, int rsp_len) {
|
||||
int i, bcc;
|
||||
txn->out_buf = (char*) malloc(cmd_len + 3);
|
||||
if (txn->out_buf == NULL) {
|
||||
pTxn->out_buf = (char*) malloc(cmd_len + 3);
|
||||
if (pTxn->out_buf == NULL) {
|
||||
SICSLogWrite("ERROR: Out of memory in OMRON_PrepareTxn", eError);
|
||||
return 0;
|
||||
}
|
||||
memcpy(txn->out_buf + 1, cmd, cmd_len);
|
||||
txn->out_buf[0] = STX;
|
||||
txn->out_buf[cmd_len + 1] = ETX;
|
||||
txn->out_buf[cmd_len + 2] = calc_bcc(txn->out_buf);
|
||||
txn->out_len = cmd_len + 3;
|
||||
memcpy(pTxn->out_buf + 1, cmd, cmd_len);
|
||||
pTxn->out_buf[0] = STX;
|
||||
pTxn->out_buf[cmd_len + 1] = ETX;
|
||||
pTxn->out_buf[cmd_len + 2] = calc_bcc(pTxn->out_buf);
|
||||
pTxn->out_len = cmd_len + 3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#ifndef OMRON_ASYNCPROTOCOL_H
|
||||
#define OMRON_ASYNCPROTOCOL_H
|
||||
#include "sics.h"
|
||||
void OMRONInitProtocol(SicsInterp *pSics);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user