Clean up the space/tab mess and trailing whitespace
This commit is contained in:
@ -1,18 +1,18 @@
|
|||||||
/**
|
/**
|
||||||
* This is an adapter to a node under the control of the new
|
* This is an adapter to a node under the control of the new
|
||||||
* scriptcontext generic device model. This is a wrapper around
|
* scriptcontext generic device model. This is a wrapper around
|
||||||
* such a node which implements the drivable interface.
|
* such a node which implements the drivable interface.
|
||||||
*
|
*
|
||||||
* Some cooperation from the node is required: It has to provide
|
* Some cooperation from the node is required: It has to provide
|
||||||
* certain properties the value of which define scripts which
|
* certain properties the value of which define scripts which
|
||||||
* have to be called at various stages. These are:
|
* have to be called at various stages. These are:
|
||||||
*
|
*
|
||||||
* checklimits, for limits checking
|
* checklimits, for limits checking
|
||||||
* checkstatus, for evaluating progress
|
* checkstatus, for evaluating progress
|
||||||
* halt , for halting things
|
* halt , for halting things
|
||||||
*
|
*
|
||||||
* copyright: see file COPYRIGHT
|
* copyright: see file COPYRIGHT
|
||||||
*
|
*
|
||||||
* Mark Koennecke, June 2008
|
* Mark Koennecke, June 2008
|
||||||
* --------------------------------------------------------------*/
|
* --------------------------------------------------------------*/
|
||||||
#include <sics.h>
|
#include <sics.h>
|
||||||
@ -24,16 +24,16 @@
|
|||||||
#include "scriptcontext.h"
|
#include "scriptcontext.h"
|
||||||
/*---------------------------------------------------------------*/
|
/*---------------------------------------------------------------*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pObjectDescriptor pDes;
|
pObjectDescriptor pDes;
|
||||||
pIDrivable pDriv;
|
pIDrivable pDriv;
|
||||||
pHdb write_node;
|
pHdb write_node;
|
||||||
pHdb read_node;
|
pHdb read_node;
|
||||||
SctController *c;
|
SctController *c;
|
||||||
}SctDrive, *pSctDrive;
|
}SctDrive, *pSctDrive;
|
||||||
/*---------------------------------------------------------------*/
|
/*---------------------------------------------------------------*/
|
||||||
static void *SCTDRIVGetInterface(void *data, int iD){
|
static void *SCTDRIVGetInterface(void *data, int iD){
|
||||||
pSctDrive self = NULL;
|
pSctDrive self = NULL;
|
||||||
|
|
||||||
self = (pSctDrive)data;
|
self = (pSctDrive)data;
|
||||||
if(self != NULL && iD == DRIVEID){
|
if(self != NULL && iD == DRIVEID){
|
||||||
if (self->write_node == NULL) return NULL;
|
if (self->write_node == NULL) return NULL;
|
||||||
@ -48,51 +48,51 @@ static void *SCTDRIVGetInterface(void *data, int iD){
|
|||||||
go wrong. However, the return value of Halt is usually ignored!
|
go wrong. However, the return value of Halt is usually ignored!
|
||||||
------------------------------------------------------------------*/
|
------------------------------------------------------------------*/
|
||||||
static int SCTDRIVHalt(void *data) {
|
static int SCTDRIVHalt(void *data) {
|
||||||
pSctDrive self = NULL;
|
pSctDrive self = NULL;
|
||||||
char dummy[16];
|
char dummy[16];
|
||||||
|
|
||||||
self = (pSctDrive)data;
|
self = (pSctDrive)data;
|
||||||
if (GetHdbProperty(self->write_node,"halt", dummy, sizeof dummy)) {
|
if (GetHdbProperty(self->write_node,"halt", dummy, sizeof dummy)) {
|
||||||
SctQueueNode(self->c, self->write_node, HaltPRIO, "halt", NULL);
|
SctQueueNode(self->c, self->write_node, HaltPRIO, "halt", NULL);
|
||||||
} else if (GetHdbProperty(self->write_node, "status", dummy, sizeof dummy)) {
|
} else if (GetHdbProperty(self->write_node, "status", dummy, sizeof dummy)) {
|
||||||
SetHdbProperty(self->write_node, "status", "idle");
|
SetHdbProperty(self->write_node, "status", "idle");
|
||||||
}
|
}
|
||||||
return OKOK;
|
return OKOK;
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------
|
/*----------------------------------------------------------------
|
||||||
This routine can return either 1 or 0. 1 means the position can
|
This routine can return either 1 or 0. 1 means the position can
|
||||||
be reached, 0 NOT
|
be reached, 0 NOT
|
||||||
If 0, error shall contain up to errlen characters of information
|
If 0, error shall contain up to errlen characters of information
|
||||||
about which limit was violated
|
about which limit was violated
|
||||||
------------------------------------------------------------------*/
|
------------------------------------------------------------------*/
|
||||||
static int SCTDRIVCheckLimits(void *data, float val,
|
static int SCTDRIVCheckLimits(void *data, float val,
|
||||||
char *error, int errlen){
|
char *error, int errlen){
|
||||||
pSctDrive self = NULL;
|
pSctDrive self = NULL;
|
||||||
char script[1024];
|
char script[1024];
|
||||||
int status;
|
int status;
|
||||||
Tcl_Interp *pTcl = NULL;
|
Tcl_Interp *pTcl = NULL;
|
||||||
char *result;
|
char *result;
|
||||||
|
|
||||||
self = (pSctDrive)data;
|
self = (pSctDrive)data;
|
||||||
snprintf(script,1024,"%f", val);
|
snprintf(script,1024,"%f", val);
|
||||||
SetHdbProperty(self->write_node,"target", script);
|
SetHdbProperty(self->write_node,"target", script);
|
||||||
if(GetHdbProperty(self->write_node,"checklimits",script,1024)){
|
if(GetHdbProperty(self->write_node,"checklimits",script,1024)){
|
||||||
status = SctCallInContext(pServ->dummyCon, script,
|
status = SctCallInContext(pServ->dummyCon, script,
|
||||||
self->write_node, self->c, &result);
|
self->write_node, self->c, &result);
|
||||||
if(SctVerbose(self->c)){
|
if(SctVerbose(self->c)){
|
||||||
SCPrintf(pServ->dummyCon, eWarning, "script %s called with result %s\n ",
|
SCPrintf(pServ->dummyCon, eWarning, "script %s called with result %s\n ",
|
||||||
script, result);
|
script, result);
|
||||||
}
|
}
|
||||||
if(status == 0){
|
if(status == 0){
|
||||||
strncpy(error,result,errlen);
|
strncpy(error,result,errlen);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------
|
/*----------------------------------------------------------------
|
||||||
This routine can return 0 when a limit problem occurred
|
This routine can return 0 when a limit problem occurred
|
||||||
OKOK when the motor was successfully started
|
OKOK when the motor was successfully started
|
||||||
HWFault when a problem occured starting the device
|
HWFault when a problem occured starting the device
|
||||||
Possible errors shall be printed to pCon
|
Possible errors shall be printed to pCon
|
||||||
For real motors, this is supposed to try at least three times
|
For real motors, this is supposed to try at least three times
|
||||||
@ -100,19 +100,19 @@ static int SCTDRIVCheckLimits(void *data, float val,
|
|||||||
val is the value to drive the motor too
|
val is the value to drive the motor too
|
||||||
------------------------------------------------------------------*/
|
------------------------------------------------------------------*/
|
||||||
static long SCTDRIVSetValue(void *data, SConnection *pCon, float val){
|
static long SCTDRIVSetValue(void *data, SConnection *pCon, float val){
|
||||||
pSctDrive self = NULL;
|
pSctDrive self = NULL;
|
||||||
int status;
|
int status;
|
||||||
hdbValue v;
|
hdbValue v;
|
||||||
|
|
||||||
self = (pSctDrive)data;
|
self = (pSctDrive)data;
|
||||||
v.dataType = HIPFLOAT;
|
v.dataType = HIPFLOAT;
|
||||||
v.v.doubleValue = (double)val;
|
v.v.doubleValue = (double)val;
|
||||||
SetHdbProperty(self->write_node,"writestatus", "start");
|
SetHdbProperty(self->write_node,"writestatus", "start");
|
||||||
status = SetHipadabaPar(self->write_node, v, pCon);
|
status = SetHipadabaPar(self->write_node, v, pCon);
|
||||||
if(status == 1){
|
if(status == 1){
|
||||||
return OKOK;
|
return OKOK;
|
||||||
} else {
|
} else {
|
||||||
return HWFault;
|
return HWFault;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------
|
/*----------------------------------------------------------------
|
||||||
@ -122,28 +122,28 @@ static long SCTDRIVSetValue(void *data, SConnection *pCon, float val){
|
|||||||
HWFault when a hardware problem ocurred
|
HWFault when a hardware problem ocurred
|
||||||
HWPosFault when the hardware cannot reach a position
|
HWPosFault when the hardware cannot reach a position
|
||||||
Errors are duly to be printed to pCon
|
Errors are duly to be printed to pCon
|
||||||
For real motors CheckStatus again shall try hard to fix any
|
For real motors CheckStatus again shall try hard to fix any
|
||||||
issues with the motor
|
issues with the motor
|
||||||
------------------------------------------------------------------*/
|
------------------------------------------------------------------*/
|
||||||
static int SCTDRIVCheckStatus(void *data, SConnection *pCon){
|
static int SCTDRIVCheckStatus(void *data, SConnection *pCon){
|
||||||
pSctDrive self = NULL;
|
pSctDrive self = NULL;
|
||||||
char script[1024];
|
char script[1024];
|
||||||
int status;
|
int status;
|
||||||
Tcl_Interp *pTcl = NULL;
|
Tcl_Interp *pTcl = NULL;
|
||||||
char *result;
|
char *result;
|
||||||
SConnection *con;
|
SConnection *con;
|
||||||
|
|
||||||
self = (pSctDrive)data;
|
self = (pSctDrive)data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check if the write command has gone through
|
* check if the write command has gone through
|
||||||
*/
|
*/
|
||||||
if(GetHdbProperty(self->write_node,"writestatus", script,1024)){
|
if(GetHdbProperty(self->write_node,"writestatus", script,1024)){
|
||||||
if(strcmp(script,"start") == 0){
|
if(strcmp(script,"start") == 0){
|
||||||
return HWBusy;
|
return HWBusy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* run the checkstatus script
|
* run the checkstatus script
|
||||||
*/
|
*/
|
||||||
@ -155,16 +155,16 @@ static int SCTDRIVCheckStatus(void *data, SConnection *pCon){
|
|||||||
}
|
}
|
||||||
result = script;
|
result = script;
|
||||||
} else {
|
} else {
|
||||||
status = SctCallInContext(pCon,script, self->write_node,
|
status = SctCallInContext(pCon,script, self->write_node,
|
||||||
self->c, &result);
|
self->c, &result);
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
SCPrintf(pCon,eError," script %s returned %s",
|
SCPrintf(pCon,eError," script %s returned %s",
|
||||||
script, result);
|
script, result);
|
||||||
return HWFault;
|
return HWFault;
|
||||||
}
|
}
|
||||||
if(SctVerbose(self->c)){
|
if(SctVerbose(self->c)){
|
||||||
SCPrintf(pCon,eError," script %s returned %s",
|
SCPrintf(pCon,eError," script %s returned %s",
|
||||||
script, result);
|
script, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strstr(result,"busy") != NULL){
|
if(strstr(result,"busy") != NULL){
|
||||||
@ -188,16 +188,16 @@ static int SCTDRIVCheckStatus(void *data, SConnection *pCon){
|
|||||||
On errors, -99999999.99 is returned and messages printed to pCon
|
On errors, -99999999.99 is returned and messages printed to pCon
|
||||||
------------------------------------------------------------------*/
|
------------------------------------------------------------------*/
|
||||||
static float SCTDRIVGetValue(void *data, SConnection *pCon){
|
static float SCTDRIVGetValue(void *data, SConnection *pCon){
|
||||||
pSctDrive self = NULL;
|
pSctDrive self = NULL;
|
||||||
float val = -99999999.99;
|
float val = -99999999.99;
|
||||||
int status;
|
int status;
|
||||||
char error[256];
|
char error[256];
|
||||||
hdbValue v;
|
hdbValue v;
|
||||||
|
|
||||||
self = (pSctDrive)data;
|
self = (pSctDrive)data;
|
||||||
if(GetHdbProperty(self->read_node,"geterror", error, 256)){
|
if(GetHdbProperty(self->read_node,"geterror", error, 256)){
|
||||||
SCWrite(pCon,error, eError);
|
SCWrite(pCon,error, eError);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
return (float)self->read_node->value.v.doubleValue;
|
return (float)self->read_node->value.v.doubleValue;
|
||||||
}
|
}
|
||||||
@ -205,19 +205,19 @@ static float SCTDRIVGetValue(void *data, SConnection *pCon){
|
|||||||
returns NULL on failure, a new datastructure else
|
returns NULL on failure, a new datastructure else
|
||||||
------------------------------------------------------------------*/
|
------------------------------------------------------------------*/
|
||||||
static pSctDrive SCTDRIVMakeObject(){
|
static pSctDrive SCTDRIVMakeObject(){
|
||||||
pSctDrive self = NULL;
|
pSctDrive self = NULL;
|
||||||
|
|
||||||
self = calloc(sizeof(SctDrive),1);
|
self = calloc(sizeof(SctDrive),1);
|
||||||
if(self == NULL){
|
if(self == NULL){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
self->pDes = CreateDescriptor("SctDriveAdapter");
|
self->pDes = CreateDescriptor("SctDriveAdapter");
|
||||||
self->pDriv = CreateDrivableInterface();
|
self->pDriv = CreateDrivableInterface();
|
||||||
if(self->pDes == NULL || self->pDriv == NULL){
|
if(self->pDes == NULL || self->pDriv == NULL){
|
||||||
free(self);
|
free(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->pDes->GetInterface = SCTDRIVGetInterface;
|
self->pDes->GetInterface = SCTDRIVGetInterface;
|
||||||
self->pDriv->Halt = SCTDRIVHalt;
|
self->pDriv->Halt = SCTDRIVHalt;
|
||||||
self->pDriv->CheckLimits = SCTDRIVCheckLimits;
|
self->pDriv->CheckLimits = SCTDRIVCheckLimits;
|
||||||
@ -230,36 +230,36 @@ static pSctDrive SCTDRIVMakeObject(){
|
|||||||
/*-----------------------------------------------------------------*/
|
/*-----------------------------------------------------------------*/
|
||||||
static int SctDriveCommand(SConnection *pCon, SicsInterp *sics, void *object,
|
static int SctDriveCommand(SConnection *pCon, SicsInterp *sics, void *object,
|
||||||
int argc, char *argv[]) {
|
int argc, char *argv[]) {
|
||||||
pSctDrive self = (pSctDrive)object;
|
pSctDrive self = (pSctDrive)object;
|
||||||
float val;
|
float val;
|
||||||
|
|
||||||
assert(self != NULL);
|
assert(self != NULL);
|
||||||
|
|
||||||
if (self->write_node == NULL) {
|
if (self->write_node == NULL) {
|
||||||
SCWrite(pCon, "ERROR: defunct object", eError);
|
SCWrite(pCon, "ERROR: defunct object", eError);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* only action: print value
|
* only action: print value
|
||||||
*/
|
*/
|
||||||
val = self->pDriv->GetValue(self,pCon);
|
val = self->pDriv->GetValue(self,pCon);
|
||||||
SCPrintf(pCon,eValue,"%s = %f", argv[0], val);
|
SCPrintf(pCon,eValue,"%s = %f", argv[0], val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------*/
|
/*----------------------------------------------------------------*/
|
||||||
static void SctDriveKill(void *data){
|
static void SctDriveKill(void *data){
|
||||||
pSctDrive self = (pSctDrive)data;
|
pSctDrive self = (pSctDrive)data;
|
||||||
|
|
||||||
if(self == NULL){
|
if(self == NULL){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(self->pDriv != NULL){
|
if(self->pDriv != NULL){
|
||||||
free(self->pDriv);
|
free(self->pDriv);
|
||||||
}
|
}
|
||||||
if(self->pDes != NULL){
|
if(self->pDes != NULL){
|
||||||
DeleteDescriptor(self->pDes);
|
DeleteDescriptor(self->pDes);
|
||||||
}
|
}
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------*/
|
/*----------------------------------------------------------------*/
|
||||||
static hdbCallbackReturn SctDummyCallback(Hdb *node, void *userData,
|
static hdbCallbackReturn SctDummyCallback(Hdb *node, void *userData,
|
||||||
@ -274,44 +274,44 @@ static void SctDriveDeleteNode(void *data) {
|
|||||||
/*---------------------------------------------------------------*/
|
/*---------------------------------------------------------------*/
|
||||||
int ANSTO_SctMakeDriveAdapter(SConnection *pCon, SicsInterp *pSics, void *object,
|
int ANSTO_SctMakeDriveAdapter(SConnection *pCon, SicsInterp *pSics, void *object,
|
||||||
int argc, char *argv[]) {
|
int argc, char *argv[]) {
|
||||||
pSctDrive pNew = NULL;
|
pSctDrive pNew = NULL;
|
||||||
pSICSOBJ obj = NULL;
|
pSICSOBJ obj = NULL;
|
||||||
hdbCallback *cb;
|
hdbCallback *cb;
|
||||||
|
|
||||||
pNew = SCTDRIVMakeObject();
|
pNew = SCTDRIVMakeObject();
|
||||||
if(pNew == NULL){
|
if(pNew == NULL){
|
||||||
SCWrite(pCon,"ERROR: out of memory in ANSTO_SctMakeDriveAdapter",
|
SCWrite(pCon,"ERROR: out of memory in ANSTO_SctMakeDriveAdapter",
|
||||||
eError);
|
eError);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(argc < 4){
|
if(argc < 4){
|
||||||
SCWrite(pCon,"ERROR: not enough arguments for ANSTO_SctMakeDriveAdapter", eError);
|
SCWrite(pCon,"ERROR: not enough arguments for ANSTO_SctMakeDriveAdapter", eError);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNew->write_node = FindHdbNode(NULL,argv[2], pCon);
|
pNew->write_node = FindHdbNode(NULL,argv[2], pCon);
|
||||||
pNew->read_node = FindHdbNode(NULL,argv[3], pCon);
|
pNew->read_node = FindHdbNode(NULL,argv[3], pCon);
|
||||||
obj = FindCommandData(pSics,argv[4], "SctController");
|
obj = FindCommandData(pSics,argv[4], "SctController");
|
||||||
if(pNew->write_node == NULL || obj == NULL){
|
if(pNew->write_node == NULL || obj == NULL){
|
||||||
SCWrite(pCon,"ERROR: node or controller not found", eError);
|
SCWrite(pCon,"ERROR: node or controller not found", eError);
|
||||||
SctDriveKill(pNew);
|
SctDriveKill(pNew);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pNew->c =(SctController *)obj->pPrivate;
|
pNew->c =(SctController *)obj->pPrivate;
|
||||||
|
|
||||||
if (strcasecmp(argv[0],"dynsctdrive") == 0) {
|
if (strcasecmp(argv[0],"dynsctdrive") == 0) {
|
||||||
/* make object dynamic by defining a descriptor command */
|
/* make object dynamic by defining a descriptor command */
|
||||||
SetDescriptorKey(pNew->pDes, "creationCommand", "0");
|
SetDescriptorKey(pNew->pDes, "creationCommand", "0");
|
||||||
}
|
}
|
||||||
AddCommand(pSics, argv[1], SctDriveCommand, SctDriveKill, pNew);
|
AddCommand(pSics, argv[1], SctDriveCommand, SctDriveKill, pNew);
|
||||||
SetHdbProperty(pNew->write_node,"sicsdev",argv[1]);
|
SetHdbProperty(pNew->write_node,"sicsdev",argv[1]);
|
||||||
|
|
||||||
cb = MakeHipadabaCallback(SctDummyCallback, pNew, SctDriveDeleteNode);
|
cb = MakeHipadabaCallback(SctDummyCallback, pNew, SctDriveDeleteNode);
|
||||||
assert(cb);
|
assert(cb);
|
||||||
AppendHipadabaCallback(pNew->write_node, cb);
|
AppendHipadabaCallback(pNew->write_node, cb);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------*/
|
/*---------------------------------------------------------------*/
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user