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