Align nhq200.c and orhvps.c to be more alike (and more diffable)
r2629 | dcl | 2008-06-12 17:23:40 +1000 (Thu, 12 Jun 2008) | 2 lines
This commit is contained in:
@@ -8,35 +8,8 @@
|
||||
|
||||
Douglas Clowes, December 2007
|
||||
|
||||
Copyright:
|
||||
Copyright: site_ansto/doc/Copyright.txt
|
||||
|
||||
Labor fuer Neutronenstreuung
|
||||
Paul Scherrer Institut
|
||||
CH-5423 Villigen-PSI
|
||||
|
||||
|
||||
The authors hereby grant permission to use, copy, modify, distribute,
|
||||
and license this software and its documentation for any purpose, provided
|
||||
that existing copyright notices are retained in all copies and that this
|
||||
notice is included verbatim in any distributions. No written agreement,
|
||||
license, or royalty fee is required for any of the authorized uses.
|
||||
Modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided that
|
||||
the new terms are clearly indicated on the first page of each file where
|
||||
they apply.
|
||||
|
||||
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
||||
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
||||
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
|
||||
IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
|
||||
NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -54,29 +27,38 @@
|
||||
#include <math.h>
|
||||
|
||||
#define CMDLEN 132
|
||||
#define MY_ABSOLUTE_MAXIMUM (2600.0)
|
||||
#define MY_MINIMUM_RATE (1.0)
|
||||
#define MY_MAXIMUM_RATE (40.0)
|
||||
/* ERROR CODES */
|
||||
#define ORHVPS_ERR_NONE (0)
|
||||
#define ORHVPS_ERR_LOCKED (-1)
|
||||
#define ORHVPS_ERR_RANGE (-2)
|
||||
|
||||
typedef struct orhvps_s {
|
||||
/* Device Driver Control Structure */
|
||||
struct orhvps_s {
|
||||
pEVControl controller;
|
||||
int iValue; /* integer value from controller (0..63) */
|
||||
int iPeriod; /* integer step-rate period in milliseconds */
|
||||
int iError; /* error code */
|
||||
int iErrorCode; /* error code */
|
||||
float fTarget; /* requested target voltage in volts */
|
||||
float fValue; /* current voltage in volts */
|
||||
float fMax; /* maximum voltage in volts at iValue=63 */
|
||||
float fMax; /* maximum voltage in volts */
|
||||
float fRate; /* voltage slew rate in volts per second */
|
||||
float fTarget; /* requested target voltage */
|
||||
float fUpper; /* Normal Operating Voltage */
|
||||
float fLower; /* Normal Moving Voltage */
|
||||
bool isLocked; /* changes no longer permitted */
|
||||
bool isLocked; /* changes no longer permitted */
|
||||
bool bRunFlag; /* set by the run command */
|
||||
bool bInternal; /* Flags an internal run request */
|
||||
char* name;
|
||||
pAsyncUnit asyncUnit;
|
||||
StateMachine fsm;
|
||||
pNWTimer state_timer; /**< state timer */
|
||||
} ORHVPSDriv, *pORHVPSDriv;
|
||||
int iValue; /* integer value from controller (0..63) */
|
||||
int iPeriod; /* integer step-rate period in milliseconds */
|
||||
};
|
||||
|
||||
typedef struct orhvps_s ORHVPSDriv, *pORHVPSDriv;
|
||||
|
||||
/* Functions */
|
||||
static int ORHVPSGetValue( pEVDriver self, float* fPos);
|
||||
static int ORHVPSSetValue( pEVDriver self, float fPos);
|
||||
static int ORHVPSSend(pEVDriver self, char *pCommand, char *pReply, int iLen);
|
||||
@@ -87,13 +69,25 @@ static int ORHVPSClose(pEVDriver self);
|
||||
static void ORHVPSKillPrivate(void *pData);
|
||||
static void ORHVPSNotify(void* context, int event);
|
||||
|
||||
static int ORHV_SendCmd(pORHVPSDriv self,
|
||||
static int get_period(float max, float rate) {
|
||||
return (int) roundf(1000 * (max / 63.0) / rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Sends a command and set up for a response event
|
||||
*
|
||||
* \param self motor data
|
||||
* \param cmd command to send
|
||||
* \param reply space to return response
|
||||
* \return
|
||||
*/
|
||||
static int ORHV_SendCmd(pORHVPSDriv priv,
|
||||
char* command,
|
||||
int cmd_len,
|
||||
AsyncTxnHandler callback)
|
||||
{
|
||||
pStateMachine sm = &self->fsm;
|
||||
return AsyncUnitSendTxn(self->asyncUnit,
|
||||
pStateMachine sm = &priv->fsm;
|
||||
return AsyncUnitSendTxn(priv->asyncUnit,
|
||||
command, cmd_len,
|
||||
callback, sm, CMDLEN);
|
||||
}
|
||||
@@ -101,19 +95,19 @@ static int ORHV_SendCmd(pORHVPSDriv self,
|
||||
/**
|
||||
* \brief Sends a command and waits for a response
|
||||
*
|
||||
* \param self motor data
|
||||
* \param priv motor data
|
||||
* \param cmd command to send
|
||||
* \param reply space to return response
|
||||
* \return
|
||||
*/
|
||||
static int ORHV_SendReceive(pORHVPSDriv self,
|
||||
static int ORHV_SendReceive(pORHVPSDriv priv,
|
||||
char *cmd,
|
||||
int cmd_len,
|
||||
char* reply,
|
||||
int *rep_len) {
|
||||
int status;
|
||||
|
||||
status = AsyncUnitTransact(self->asyncUnit, cmd, cmd_len, reply, rep_len);
|
||||
status = AsyncUnitTransact(priv->asyncUnit, cmd, cmd_len, reply, rep_len);
|
||||
|
||||
if (status != 1) {
|
||||
return FAILURE;
|
||||
@@ -122,6 +116,7 @@ static int ORHV_SendReceive(pORHVPSDriv self,
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
/* State Functions */
|
||||
static void ORHVState_Unknown(pStateMachine sm, pEvtEvent event);
|
||||
static void ORHVState_Idle(pStateMachine sm, pEvtEvent event);
|
||||
static void ORHVState_Raising(pStateMachine sm, pEvtEvent event);
|
||||
@@ -147,7 +142,7 @@ static void str_n_cat(char* s1, int len, const char* s2) {
|
||||
s1[i] = '\0';
|
||||
}
|
||||
|
||||
const char* state_name(StateFunc func)
|
||||
static const char* state_name(StateFunc func)
|
||||
{
|
||||
if (func == NULL) return "<null_state>";
|
||||
if (func == ORHVState_Unknown) return "ORHVState_Unknown";
|
||||
@@ -157,7 +152,7 @@ const char* state_name(StateFunc func)
|
||||
return "<unknown_state>";
|
||||
}
|
||||
|
||||
const char* event_name(pEvtEvent event, char* text, int length)
|
||||
static const char* event_name(pEvtEvent event, char* text, int length)
|
||||
{
|
||||
char line[1024];
|
||||
if (event == NULL)
|
||||
@@ -252,6 +247,13 @@ static int getProcess(pStateMachine sm, pAsyncTxn pCmd, int bot, int top) {
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/* State Functions */
|
||||
|
||||
/*
|
||||
* Unknown State
|
||||
*
|
||||
* Handle initialisation and reset operations
|
||||
*/
|
||||
static void ORHVState_Unknown(pStateMachine sm, pEvtEvent event) {
|
||||
pEVDriver driv = (pEVDriver) sm->context;
|
||||
pORHVPSDriv priv = (pORHVPSDriv) driv->pPrivate;
|
||||
@@ -308,6 +310,12 @@ static void ORHVState_Unknown(pStateMachine sm, pEvtEvent event) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Idle State
|
||||
*
|
||||
* Just monitoring what's going on
|
||||
* and waiting to be told to run somewhere
|
||||
*/
|
||||
static void ORHVState_Idle(pStateMachine sm, pEvtEvent event){
|
||||
pEVDriver driv = (pEVDriver) sm->context;
|
||||
pORHVPSDriv priv = (pORHVPSDriv) driv->pPrivate;
|
||||
@@ -384,6 +392,10 @@ static void ORHVState_Idle(pStateMachine sm, pEvtEvent event){
|
||||
return;
|
||||
}
|
||||
|
||||
/* Raising State
|
||||
*
|
||||
* Increasing controlled value
|
||||
*/
|
||||
static void ORHVState_Raising(pStateMachine sm, pEvtEvent event){
|
||||
pEVDriver driv = (pEVDriver) sm->context;
|
||||
pORHVPSDriv priv = (pORHVPSDriv) driv->pPrivate;
|
||||
@@ -484,6 +496,10 @@ static void ORHVState_Raising(pStateMachine sm, pEvtEvent event){
|
||||
return;
|
||||
}
|
||||
|
||||
/* Lowering State
|
||||
*
|
||||
* Decreasing controlled value
|
||||
*/
|
||||
static void ORHVState_Lowering(pStateMachine sm, pEvtEvent event){
|
||||
pEVDriver driv = (pEVDriver) sm->context;
|
||||
pORHVPSDriv priv = (pORHVPSDriv) driv->pPrivate;
|
||||
@@ -585,32 +601,47 @@ static void ORHVState_Lowering(pStateMachine sm, pEvtEvent event){
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return the current value to SICS
|
||||
*/
|
||||
static int ORHVPSGetValue( pEVDriver self, float* fPos) {
|
||||
pORHVPSDriv me = NULL;
|
||||
pORHVPSDriv priv = NULL;
|
||||
int newVal;
|
||||
assert(self);
|
||||
assert(self->pPrivate);
|
||||
me = (pORHVPSDriv) self->pPrivate;
|
||||
newVal = roundf(me->fTarget / (me->fMax / 63.0));
|
||||
if (newVal == me->iValue)
|
||||
*fPos = me->fTarget;
|
||||
priv = (pORHVPSDriv) self->pPrivate;
|
||||
newVal = roundf(priv->fTarget / (priv->fMax / 63.0));
|
||||
if (newVal == priv->iValue)
|
||||
*fPos = priv->fTarget;
|
||||
else
|
||||
*fPos = me->fValue;
|
||||
*fPos = priv->fValue;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the current value from SICS
|
||||
*/
|
||||
static int ORHVPSSetValue( pEVDriver self, float fPos) {
|
||||
pORHVPSDriv me = NULL;
|
||||
pORHVPSDriv priv = NULL;
|
||||
assert(self);
|
||||
assert(self->pPrivate);
|
||||
me = (pORHVPSDriv) self->pPrivate;
|
||||
if (fPos < 0.0 || fPos > me->fMax) {
|
||||
me->iError = ORHVPS_ERR_RANGE;
|
||||
priv = (pORHVPSDriv) self->pPrivate;
|
||||
if (priv->isLocked && !priv->bInternal) {
|
||||
priv->iErrorCode = ORHVPS_ERR_LOCKED;
|
||||
return 0;
|
||||
}
|
||||
me->fTarget = fPos;
|
||||
me->bRunFlag = true;
|
||||
if (fPos < 0.0 || fPos > priv->fMax) {
|
||||
priv->iErrorCode = ORHVPS_ERR_RANGE;
|
||||
return 0;
|
||||
}
|
||||
priv->fTarget = fPos;
|
||||
priv->bRunFlag = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a command from SICS
|
||||
*/
|
||||
static int ORHVPSSend(pEVDriver self, char *pCommand, char *pReply, int iLen) {
|
||||
char cmd[CMDLEN];
|
||||
int cmd_len;
|
||||
@@ -664,10 +695,14 @@ static int ORHVPSSend(pEVDriver self, char *pCommand, char *pReply, int iLen) {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* SICS error handler
|
||||
*/
|
||||
static int ORHVPSError(pEVDriver self, int *iCode, char *error, int iErrLen) {
|
||||
pORHVPSDriv priv = (pORHVPSDriv) self->pPrivate;
|
||||
*iCode = priv->iError;
|
||||
switch (priv->iError) {
|
||||
*iCode = priv->iErrorCode;
|
||||
switch (priv->iErrorCode) {
|
||||
case ORHVPS_ERR_RANGE:
|
||||
strncpy(error,"Value out of range",iErrLen);
|
||||
break;
|
||||
@@ -680,6 +715,10 @@ static int ORHVPSError(pEVDriver self, int *iCode, char *error, int iErrLen) {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* SICS fix handler
|
||||
*/
|
||||
static int ORHVPSFix(pEVDriver self, int iError) {
|
||||
/* TODO */
|
||||
return DEVFAULT;
|
||||
@@ -710,46 +749,12 @@ static void ORHVPSKillPrivate(void *pData) {
|
||||
}
|
||||
}
|
||||
|
||||
static void ORHVPSNotify(void* context, int event)
|
||||
{
|
||||
/* TODO */
|
||||
#if 0
|
||||
pEVDriver self = (pEVDriver) context;
|
||||
char line[132];
|
||||
|
||||
switch (event) {
|
||||
case AQU_DISCONNECT:
|
||||
snprintf(line, 132, "Disconnect on Device '%s'", self->name);
|
||||
SICSLogWrite(line, eStatus);
|
||||
/* TODO: disconnect */
|
||||
break;
|
||||
case AQU_RECONNECT:
|
||||
snprintf(line, 132, "Reconnect on Device '%s'", self->name);
|
||||
SICSLogWrite(line, eStatus);
|
||||
/* TODO: reconnect */
|
||||
if (self->has_fsm) {
|
||||
/* Reset the state machine */
|
||||
if (self->state_timer)
|
||||
NetWatchRemoveTimer(self->state_timer);
|
||||
self->state_timer = 0;
|
||||
change_state(self, DMCState_Unknown);
|
||||
/* Schedule a timer event as soon as possible */
|
||||
NetWatchRegisterTimer(&self->state_timer,
|
||||
0,
|
||||
state_tmr_callback, self);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
static pAsyncProtocol ORHVPS_Protocol = NULL;
|
||||
|
||||
static int ORHVPS_Tx(pAsyncProtocol p, pAsyncTxn ctx)
|
||||
{
|
||||
/*
|
||||
* Protocol transmit function
|
||||
* Called by AsyncQueue to transmit a line
|
||||
*/
|
||||
static int ORHVPS_Tx(pAsyncProtocol p, pAsyncTxn myCmd) {
|
||||
int iRet = 1;
|
||||
pAsyncTxn myCmd = (pAsyncTxn) ctx;
|
||||
|
||||
if (myCmd) {
|
||||
myCmd->txn_status = ATX_ACTIVE;
|
||||
@@ -766,6 +771,9 @@ static int ORHVPS_Tx(pAsyncProtocol p, pAsyncTxn ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Protocol receive character - characater by character
|
||||
*/
|
||||
static int ORHVPS_Rx(pAsyncProtocol p, pAsyncTxn ctx, int rxchar) {
|
||||
int iRet = 1;
|
||||
pAsyncTxn myCmd = (pAsyncTxn) ctx;
|
||||
@@ -802,6 +810,46 @@ static int ORHVPS_Rx(pAsyncProtocol p, pAsyncTxn ctx, int rxchar) {
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/*
|
||||
* AsyncUnit Notify Callback
|
||||
*/
|
||||
static void ORHVPSNotify(void* context, int event)
|
||||
{
|
||||
/* TODO */
|
||||
#if 0
|
||||
pEVDriver self = (pEVDriver) context;
|
||||
char line[132];
|
||||
|
||||
switch (event) {
|
||||
case AQU_DISCONNECT:
|
||||
snprintf(line, 132, "Disconnect on Device '%s'", self->name);
|
||||
SICSLogWrite(line, eStatus);
|
||||
/* TODO: disconnect */
|
||||
break;
|
||||
case AQU_RECONNECT:
|
||||
snprintf(line, 132, "Reconnect on Device '%s'", self->name);
|
||||
SICSLogWrite(line, eStatus);
|
||||
/* TODO: reconnect */
|
||||
if (self->has_fsm) {
|
||||
/* Reset the state machine */
|
||||
if (self->state_timer)
|
||||
NetWatchRemoveTimer(self->state_timer);
|
||||
self->state_timer = 0;
|
||||
change_state(self, DMCState_Unknown);
|
||||
/* Schedule a timer event as soon as possible */
|
||||
NetWatchRegisterTimer(&self->state_timer,
|
||||
0,
|
||||
state_tmr_callback, self);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* AsyncProtocol Event callback
|
||||
*/
|
||||
static int ORHVPS_Ev(pAsyncProtocol p, pAsyncTxn pTxn, int event) {
|
||||
if (event == AQU_TIMEOUT) {
|
||||
/* handle command timeout */
|
||||
@@ -822,6 +870,11 @@ static int ORHVPS_PrepareTxn(pAsyncProtocol p, pAsyncTxn txn, const char* cmd, i
|
||||
return 1;
|
||||
}
|
||||
|
||||
static pAsyncProtocol ORHVPS_Protocol = NULL;
|
||||
|
||||
/*
|
||||
* Protocol Initialisation
|
||||
*/
|
||||
void ORHVPSInitProtocol(SicsInterp *pSics) {
|
||||
if (ORHVPS_Protocol == NULL) {
|
||||
ORHVPS_Protocol = AsyncProtocolCreate(pSics, "ORHVPS", NULL, NULL);
|
||||
@@ -833,11 +886,9 @@ void ORHVPSInitProtocol(SicsInterp *pSics) {
|
||||
}
|
||||
}
|
||||
|
||||
static int get_period(float max, float rate) {
|
||||
return (int) roundf(1000 * (max / 63.0) / rate);
|
||||
//return (int) roundf((rate * 60 * 1000) / 63.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Device Factory
|
||||
*/
|
||||
pEVDriver CreateORHVPSDriver(int argc, char *argv[])
|
||||
{
|
||||
pEVDriver self = NULL;
|
||||
@@ -860,6 +911,7 @@ pEVDriver CreateORHVPSDriver(int argc, char *argv[])
|
||||
if (!AsyncUnitCreate(argv[0], &priv->asyncUnit)) {
|
||||
char line[132];
|
||||
snprintf(line, 132, "Error: did not find AsyncQueue %s for Device %s", argv[1], argv[0]);
|
||||
SICSLogWrite(line, eError);
|
||||
DeleteEVDriver(self);
|
||||
free(priv);
|
||||
return NULL;
|
||||
@@ -889,11 +941,13 @@ pEVDriver CreateORHVPSDriver(int argc, char *argv[])
|
||||
priv->iPeriod = get_period(priv->fMax, priv->fRate);
|
||||
priv->bRunFlag = false;
|
||||
|
||||
fsm_change_state(&priv->fsm, ORHVState_Unknown);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register the controller with the driver
|
||||
*/
|
||||
void ORHVPSRegister(pEVControl self, pEVDriver driv)
|
||||
{
|
||||
pORHVPSDriv priv = (pORHVPSDriv) driv->pPrivate;
|
||||
@@ -904,8 +958,20 @@ void ORHVPSRegister(pEVControl self, pEVDriver driv)
|
||||
priv->name = strdup(self->pName);
|
||||
priv->fsm.name = priv->name;
|
||||
}
|
||||
|
||||
fsm_change_state(&priv->fsm, ORHVState_Unknown);
|
||||
|
||||
while (priv->fsm.myState == ORHVState_Unknown) {
|
||||
pTaskMan pTasker = GetTasker();
|
||||
TaskYield(pTasker);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Action Wrapper routine
|
||||
*/
|
||||
int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
@@ -990,7 +1056,9 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
priv->fTarget = priv->fMax;
|
||||
if (priv->fTarget < 0)
|
||||
priv->fTarget = 0.0;
|
||||
priv->bInternal = true;
|
||||
iRet = EVCDrive(priv->controller, pCon, priv->fTarget);
|
||||
priv->bInternal = false;
|
||||
if(iRet)
|
||||
SCSendOK(pCon);
|
||||
return iRet;
|
||||
@@ -1000,7 +1068,9 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
if(!SCMatchRights(pCon,usUser))
|
||||
return 0;
|
||||
priv->fTarget = 0.0;
|
||||
priv->bInternal = true;
|
||||
iRet = EVCDrive(priv->controller, pCon, priv->fTarget);
|
||||
priv->bInternal = false;
|
||||
if(iRet)
|
||||
SCSendOK(pCon);
|
||||
return iRet;
|
||||
@@ -1016,11 +1086,11 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
else {
|
||||
float value = atof(argv[2]);
|
||||
if (value >= priv->fLower && value <= priv->fMax) {
|
||||
if (value >= 0.0 && value <= priv->fMax) {
|
||||
priv->fUpper = value;
|
||||
}
|
||||
else {
|
||||
SCWrite(pCon, "upper value must be between <lower> and <max>", eError);
|
||||
SCWrite(pCon, "upper value must be between 0.0 and <maximum>", eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1040,11 +1110,11 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
else {
|
||||
float value = atof(argv[2]);
|
||||
if (value >= 0.0 && value <= priv->fUpper) {
|
||||
if (value >= 0.0 && value <= priv->fMax) {
|
||||
priv->fLower = value;
|
||||
}
|
||||
else {
|
||||
SCWrite(pCon, "lower value must be between 0.0 and <upper>", eError);
|
||||
SCWrite(pCon, "lower value must be between 0.0 and <maximum>", eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1064,12 +1134,14 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
else {
|
||||
float value = atof(argv[2]);
|
||||
if (value >= 0.0 && value <= 2600.0) {
|
||||
if (value >= 0.0 && value <= MY_ABSOLUTE_MAXIMUM) {
|
||||
priv->fMax = value;
|
||||
priv->iPeriod = get_period(priv->fMax, priv->fRate);
|
||||
}
|
||||
else {
|
||||
SCWrite(pCon, "max must be between 0.0 and 2600.0", eError);
|
||||
char line[CMDLEN];
|
||||
snprintf(line, CMDLEN, "max must be between 0.0 and %.0f", MY_ABSOLUTE_MAXIMUM);
|
||||
SCWrite(pCon, line, eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1102,12 +1174,14 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
else {
|
||||
float value = atof(argv[2]);
|
||||
if (value >= 1.0 && value <= 40.0) {
|
||||
if (value >= MY_MINIMUM_RATE && value <= MY_MAXIMUM_RATE) {
|
||||
priv->fRate = value;
|
||||
priv->iPeriod = get_period(priv->fMax, priv->fRate);
|
||||
}
|
||||
else {
|
||||
SCWrite(pCon, "rate must be between 1.0 and 40.0", eError);
|
||||
char line[CMDLEN];
|
||||
snprintf(line, CMDLEN, "rate must be between %.0f and %.0f", MY_MINIMUM_RATE, MY_MAXIMUM_RATE);
|
||||
SCWrite(pCon, line, eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1116,31 +1190,25 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
SCWrite(pCon, rsp, eValue);
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp("period", argv[1]) == 0) {
|
||||
char rsp[CMDLEN];
|
||||
if (argc > 2) {
|
||||
if (!SCMatchRights(pCon, usUser))
|
||||
return 0;
|
||||
SCWrite(pCon, "cannot set period, set max and rate instead", eError);
|
||||
return 0;
|
||||
}
|
||||
snprintf(rsp, CMDLEN, "%s.period = %6d", priv->name, priv->iPeriod);
|
||||
SCWrite(pCon, rsp, eValue);
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp("reset", argv[1]) == 0) {
|
||||
char rsp[CMDLEN];
|
||||
char line[CMDLEN];
|
||||
if (!SCMatchRights(pCon, usUser))
|
||||
return 0;
|
||||
/* restart state machine */
|
||||
fsm_change_state(&priv->fsm, ORHVState_Unknown);
|
||||
snprintf(rsp, CMDLEN, "%s.reset = 1", priv->name);
|
||||
SCWrite(pCon, rsp, eValue);
|
||||
while (priv->fsm.myState == ORHVState_Unknown) {
|
||||
pTaskMan pTasker = GetTasker();
|
||||
TaskYield(pTasker);
|
||||
}
|
||||
/* give feedback */
|
||||
snprintf(line, CMDLEN, "%s.reset = 1", priv->name);
|
||||
SCWrite(pCon, line, eValue);
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp("lock", argv[1]) == 0) {
|
||||
char rsp[CMDLEN];
|
||||
if (!SCMatchRights(pCon, usUser))
|
||||
return 0;
|
||||
if (!SCMatchRights(pCon, usUser))
|
||||
return 0;
|
||||
priv->isLocked = 1;
|
||||
snprintf(rsp, CMDLEN, "%s.lock = %d", priv->name, priv->isLocked);
|
||||
SCWrite(pCon, rsp, eValue);
|
||||
@@ -1173,6 +1241,19 @@ int ORHVPSWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
if (strcasecmp("period", argv[1]) == 0) {
|
||||
char line[CMDLEN];
|
||||
if (argc > 2) {
|
||||
if (!SCMatchRights(pCon, usUser))
|
||||
return 0;
|
||||
SCWrite(pCon, "cannot set period, set rate instead", eError);
|
||||
return 0;
|
||||
}
|
||||
snprintf(line, CMDLEN, "%s.period = %6d", priv->name, priv->iPeriod);
|
||||
SCWrite(pCon, line, eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return EVControlWrapper(pCon,pSics,pData,argc,argv);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user