Add huber asyncprotocol and make huber_ap and omron_ap to remove name conflicts
This commit is contained in:
117
site_ansto/hardsup/huber_asyncprotocol.c
Normal file
117
site_ansto/hardsup/huber_asyncprotocol.c
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#include "sics.h"
|
||||||
|
#include "asyncprotocol.h"
|
||||||
|
#include "asyncqueue.h"
|
||||||
|
|
||||||
|
#define LBRACE '{'
|
||||||
|
#define CR '\r'
|
||||||
|
#define LF '\n'
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Protocol transmit function
|
||||||
|
* Called by AsyncQueue to transmit a line
|
||||||
|
*/
|
||||||
|
static int HUBER_Tx(pAsyncProtocol p, pAsyncTxn myCmd) {
|
||||||
|
int iRet = 1;
|
||||||
|
|
||||||
|
if (myCmd) {
|
||||||
|
myCmd->txn_status = ATX_ACTIVE;
|
||||||
|
iRet = AsyncUnitWrite(myCmd->unit, myCmd->out_buf, myCmd->out_len);
|
||||||
|
/* TODO handle errors */
|
||||||
|
if (iRet < 0) { /* TODO: EOF */
|
||||||
|
/*
|
||||||
|
iRet = AsyncUnitReconnect(myCmd->unit);
|
||||||
|
if (iRet == 0)
|
||||||
|
*/
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Protocol receive character - characater by character
|
||||||
|
*/
|
||||||
|
static int HUBER_Rx(pAsyncProtocol p, pAsyncTxn ctx, int rxchar) {
|
||||||
|
int iRet = 1;
|
||||||
|
pAsyncTxn myCmd = (pAsyncTxn) ctx;
|
||||||
|
|
||||||
|
switch (myCmd->txn_state) {
|
||||||
|
case 0: /* first character */
|
||||||
|
if (rxchar != LBRACE) {
|
||||||
|
/* TODO: error */
|
||||||
|
myCmd->txn_state = 99;
|
||||||
|
myCmd->txn_status = ATX_COMPLETE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* normal data */
|
||||||
|
myCmd->txn_state = 1;
|
||||||
|
/* note fallthrough */
|
||||||
|
case 1: /* receiving reply */
|
||||||
|
if (myCmd->inp_idx < myCmd->inp_len)
|
||||||
|
myCmd->inp_buf[myCmd->inp_idx++] = rxchar;
|
||||||
|
if (rxchar == CR)
|
||||||
|
myCmd->txn_state = 2;
|
||||||
|
break;
|
||||||
|
case 2: /* receiving LF */
|
||||||
|
if (myCmd->inp_idx < myCmd->inp_len)
|
||||||
|
myCmd->inp_buf[myCmd->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);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (myCmd->txn_state == 99) {
|
||||||
|
iRet = 0;
|
||||||
|
}
|
||||||
|
if (iRet == 0) { /* end of command */
|
||||||
|
return AQU_POP_CMD;
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* AsyncProtocol Event callback
|
||||||
|
*/
|
||||||
|
static int HUBER_Ev(pAsyncProtocol p, pAsyncTxn pTxn, int event) {
|
||||||
|
if (event == AQU_TIMEOUT) {
|
||||||
|
/* handle command timeout */
|
||||||
|
pTxn->txn_status = ATX_TIMEOUT;
|
||||||
|
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) {
|
||||||
|
int i, bcc;
|
||||||
|
txn->out_buf = (char*) malloc(cmd_len + 3);
|
||||||
|
if (txn->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;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static pAsyncProtocol HUBER_Protocol = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Protocol Initialisation
|
||||||
|
*/
|
||||||
|
void HUBERInitProtocol(SicsInterp *pSics) {
|
||||||
|
if (HUBER_Protocol == NULL) {
|
||||||
|
HUBER_Protocol = AsyncProtocolCreate(pSics, "HUBER_AP", NULL, NULL);
|
||||||
|
HUBER_Protocol->sendCommand = HUBER_Tx;
|
||||||
|
HUBER_Protocol->handleInput = HUBER_Rx;
|
||||||
|
HUBER_Protocol->handleEvent = HUBER_Ev;
|
||||||
|
HUBER_Protocol->prepareTxn = HUBER_PrepareTxn;
|
||||||
|
HUBER_Protocol->killPrivate = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
4
site_ansto/hardsup/huber_asyncprotocol.h
Normal file
4
site_ansto/hardsup/huber_asyncprotocol.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#ifndef HUBER_ASYNCPROTOCOL_H
|
||||||
|
#define HUBER_ASYNCPROTOCOL_H
|
||||||
|
void HUBERInitProtocol(SicsInterp *pSics);
|
||||||
|
#endif
|
@ -36,6 +36,7 @@ HOBJ += cameradriver.o
|
|||||||
HOBJ += sct_asyncqueue.o
|
HOBJ += sct_asyncqueue.o
|
||||||
HOBJ += aqp_opalstatus.o
|
HOBJ += aqp_opalstatus.o
|
||||||
HOBJ += omron_asyncprotocol.o
|
HOBJ += omron_asyncprotocol.o
|
||||||
|
HOBJ += huber_asyncprotocol.o
|
||||||
|
|
||||||
libhlib.a: $(HOBJ)
|
libhlib.a: $(HOBJ)
|
||||||
rm -f libhlib.a
|
rm -f libhlib.a
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include <sics.h>
|
#include "sics.h"
|
||||||
#include <asyncprotocol.h>
|
#include "asyncprotocol.h"
|
||||||
#include <asyncqueue.h>
|
#include "asyncqueue.h"
|
||||||
|
|
||||||
#define STX 2
|
#define STX 2
|
||||||
#define ETX 3
|
#define ETX 3
|
||||||
@ -131,7 +131,7 @@ static pAsyncProtocol OMRON_Protocol = NULL;
|
|||||||
*/
|
*/
|
||||||
void OMRONInitProtocol(SicsInterp *pSics) {
|
void OMRONInitProtocol(SicsInterp *pSics) {
|
||||||
if (OMRON_Protocol == NULL) {
|
if (OMRON_Protocol == NULL) {
|
||||||
OMRON_Protocol = AsyncProtocolCreate(pSics, "OMRON", NULL, NULL);
|
OMRON_Protocol = AsyncProtocolCreate(pSics, "OMRON_AP", NULL, NULL);
|
||||||
OMRON_Protocol->sendCommand = OMRON_Tx;
|
OMRON_Protocol->sendCommand = OMRON_Tx;
|
||||||
OMRON_Protocol->handleInput = OMRON_Rx;
|
OMRON_Protocol->handleInput = OMRON_Rx;
|
||||||
OMRON_Protocol->handleEvent = OMRON_Ev;
|
OMRON_Protocol->handleEvent = OMRON_Ev;
|
||||||
|
@ -53,16 +53,16 @@ driver huber_pilot = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
code getValue = {%%
|
code getValue = {%%
|
||||||
set cmd "\{M${cmd_str}****"
|
set cmd "M${cmd_str}****"
|
||||||
%%}
|
%%}
|
||||||
|
|
||||||
code rdStatus = {%%
|
code rdStatus = {%%
|
||||||
if {[string length ${data}] < 8} {
|
if {[string length ${data}] < 7} {
|
||||||
sct geterror "rdValue short response ${data}"
|
sct geterror "rdValue short response ${data}"
|
||||||
} elseif { ![string equal -nocase [string range ${data} 1 1] "S"] } {
|
} elseif { ![string equal -nocase [string range ${data} 0 0] "S"] } {
|
||||||
sct geterror "rdValue syntax error ${data}"
|
sct geterror "rdValue syntax error ${data}"
|
||||||
} else {
|
} else {
|
||||||
set resp [scan [string range ${data} 4 end] "%x" val]
|
set resp [scan [string range ${data} 3 end] "%x" val]
|
||||||
if { ${resp} < 1 } {
|
if { ${resp} < 1 } {
|
||||||
sct geterror "rdValue scan error ${data}"
|
sct geterror "rdValue scan error ${data}"
|
||||||
} else {
|
} else {
|
||||||
@ -72,12 +72,12 @@ driver huber_pilot = {
|
|||||||
%%}
|
%%}
|
||||||
|
|
||||||
code rdTemp = {%%
|
code rdTemp = {%%
|
||||||
if {[string length ${data}] < 8} {
|
if {[string length ${data}] < 7} {
|
||||||
sct geterror "rdValue short response ${data}"
|
sct geterror "rdValue short response ${data}"
|
||||||
} elseif { ![string equal -nocase [string range ${data} 1 1] "S"] } {
|
} elseif { ![string equal -nocase [string range ${data} 0 0] "S"] } {
|
||||||
sct geterror "rdValue syntax error ${data}"
|
sct geterror "rdValue syntax error ${data}"
|
||||||
} else {
|
} else {
|
||||||
set resp [scan [string range ${data} 4 end] "%x" val]
|
set resp [scan [string range ${data} 3 end] "%x" val]
|
||||||
if { ${resp} < 1 } {
|
if { ${resp} < 1 } {
|
||||||
sct geterror "rdValue scan error ${data}"
|
sct geterror "rdValue scan error ${data}"
|
||||||
} else {
|
} else {
|
||||||
@ -95,7 +95,7 @@ driver huber_pilot = {
|
|||||||
code setValue = {%%
|
code setValue = {%%
|
||||||
set param [expr { round(100.0 * [sct target]) }]
|
set param [expr { round(100.0 * [sct target]) }]
|
||||||
set param [string range [format "%04X" ${param}] end-3 end]
|
set param [string range [format "%04X" ${param}] end-3 end]
|
||||||
set cmd "\{M${cmd_str}${param}"
|
set cmd "M${cmd_str}${param}"
|
||||||
%%}
|
%%}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ proc ::scobj::huber_pilot::getValue {tc_root nextState cmd_str} {
|
|||||||
}
|
}
|
||||||
set cmd "${cmd_str}"
|
set cmd "${cmd_str}"
|
||||||
# getValue hook code starts
|
# getValue hook code starts
|
||||||
set cmd "\{M${cmd_str}****"
|
set cmd "M${cmd_str}****"
|
||||||
# getValue hook code ends
|
# getValue hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
|
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
|
||||||
@ -178,12 +178,12 @@ proc ::scobj::huber_pilot::rdStatus {tc_root} {
|
|||||||
error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
}
|
||||||
# rdStatus hook code starts
|
# rdStatus hook code starts
|
||||||
if {[string length ${data}] < 8} {
|
if {[string length ${data}] < 7} {
|
||||||
sct geterror "rdValue short response ${data}"
|
sct geterror "rdValue short response ${data}"
|
||||||
} elseif { ![string equal -nocase [string range ${data} 1 1] "S"] } {
|
} elseif { ![string equal -nocase [string range ${data} 0 0] "S"] } {
|
||||||
sct geterror "rdValue syntax error ${data}"
|
sct geterror "rdValue syntax error ${data}"
|
||||||
} else {
|
} else {
|
||||||
set resp [scan [string range ${data} 4 end] "%x" val]
|
set resp [scan [string range ${data} 3 end] "%x" val]
|
||||||
if { ${resp} < 1 } {
|
if { ${resp} < 1 } {
|
||||||
sct geterror "rdValue scan error ${data}"
|
sct geterror "rdValue scan error ${data}"
|
||||||
} else {
|
} else {
|
||||||
@ -221,12 +221,12 @@ proc ::scobj::huber_pilot::rdTemp {tc_root} {
|
|||||||
error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
}
|
||||||
# rdTemp hook code starts
|
# rdTemp hook code starts
|
||||||
if {[string length ${data}] < 8} {
|
if {[string length ${data}] < 7} {
|
||||||
sct geterror "rdValue short response ${data}"
|
sct geterror "rdValue short response ${data}"
|
||||||
} elseif { ![string equal -nocase [string range ${data} 1 1] "S"] } {
|
} elseif { ![string equal -nocase [string range ${data} 0 0] "S"] } {
|
||||||
sct geterror "rdValue syntax error ${data}"
|
sct geterror "rdValue syntax error ${data}"
|
||||||
} else {
|
} else {
|
||||||
set resp [scan [string range ${data} 4 end] "%x" val]
|
set resp [scan [string range ${data} 3 end] "%x" val]
|
||||||
if { ${resp} < 1 } {
|
if { ${resp} < 1 } {
|
||||||
sct geterror "rdValue scan error ${data}"
|
sct geterror "rdValue scan error ${data}"
|
||||||
} else {
|
} else {
|
||||||
@ -267,7 +267,7 @@ proc ::scobj::huber_pilot::setValue {tc_root nextState cmd_str} {
|
|||||||
# setValue hook code starts
|
# setValue hook code starts
|
||||||
set param [expr { round(100.0 * [sct target]) }]
|
set param [expr { round(100.0 * [sct target]) }]
|
||||||
set param [string range [format "%04X" ${param}] end-3 end]
|
set param [string range [format "%04X" ${param}] end-3 end]
|
||||||
set cmd "\{M${cmd_str}${param}"
|
set cmd "M${cmd_str}${param}"
|
||||||
# setValue hook code ends
|
# setValue hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
|
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
#include "cameradriver.h"
|
#include "cameradriver.h"
|
||||||
#include "aqp_opalstatus.h"
|
#include "aqp_opalstatus.h"
|
||||||
#include "omron_asyncprotocol.h"
|
#include "omron_asyncprotocol.h"
|
||||||
|
#include "huber_asyncprotocol.h"
|
||||||
|
|
||||||
/*@observer@*//*@null@*/ pCounterDriver CreateMonCounter(/*@observer@*/SConnection *pCon, /*@observer@*/char *name, char *params);
|
/*@observer@*//*@null@*/ pCounterDriver CreateMonCounter(/*@observer@*/SConnection *pCon, /*@observer@*/char *name, char *params);
|
||||||
|
|
||||||
@ -75,7 +76,6 @@ extern void AddRFAmpProtocol();
|
|||||||
extern void AddTCPMBProtocol ();
|
extern void AddTCPMBProtocol ();
|
||||||
extern void AddLFGenProtocol();
|
extern void AddLFGenProtocol();
|
||||||
extern void AddSCAQAProtocol();
|
extern void AddSCAQAProtocol();
|
||||||
extern void OMRONInitProtocol(pInter);
|
|
||||||
extern int ANSTO_MakeHistMemory(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]);
|
extern int ANSTO_MakeHistMemory(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]);
|
||||||
extern int testLogCmd(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]);
|
extern int testLogCmd(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]);
|
||||||
extern pCounterDriver CreateCam(SConnection *pCon, char *name, char *asynq);
|
extern pCounterDriver CreateCam(SConnection *pCon, char *name, char *asynq);
|
||||||
@ -356,6 +356,7 @@ static void AddCommands(SicsInterp *pInter)
|
|||||||
CameraInitProtocol(pInter);
|
CameraInitProtocol(pInter);
|
||||||
OpalStatusInitProtocol(pInter);
|
OpalStatusInitProtocol(pInter);
|
||||||
OMRONInitProtocol(pInter);
|
OMRONInitProtocol(pInter);
|
||||||
|
HUBERInitProtocol(pInter);
|
||||||
AddCommand(pInter,"InstallProtocolHandler", InstallProtocol,NULL,NULL);
|
AddCommand(pInter,"InstallProtocolHandler", InstallProtocol,NULL,NULL);
|
||||||
AddCommand(pInter,"hostnam",hostNamCmd,NULL,NULL);
|
AddCommand(pInter,"hostnam",hostNamCmd,NULL,NULL);
|
||||||
AddCommand(pInter,"portnum",portNumCmd,NULL,NULL);
|
AddCommand(pInter,"portnum",portNumCmd,NULL,NULL);
|
||||||
|
Reference in New Issue
Block a user