Histmem now only calls TaskYield after SICS has finished initalising, this stops the statusfile task from being called early and overwriting the status file. Created ANSTO_MakeHistMemory command to install ANSTO_HistAction Added veto functions. Mapped the HistDriver interface Pause() and Continue() commands to AnstoHttpVeto and AnstoHttpNoVeto. Implemented an ANSTO_Histaction to call AnstoHttpPause when sent a "pause" subcommand. hmcontrol_ansto.c Call AnstoHttpPause() directly when Pause_HM_After_Count is set to preserver current behaviour. counterdriv.c Now sends the correct "SICS RESUME" command to resume a paused count. ansto_sctdriveadapter.c NEW This lets you create driveable objects from script-context controllers which have one node for setting a parameter and another node for reading the parameter (eg temperature controllers, choppers, velocity selectors) sctemonadapter.c NEW This generates an environment monitor interface for script-context controllers so that the emon object in SICS will be able to pause counters if the controller goes out of tolerance. sct_usbtmcprot.c, usbtmc.h NEW First attempt at a protocol handler for USB Test and Measurement Class devices sct_julabo_lh45.tcl NEW Implements script-context controller for the Julabo LH45 temperature controller. Makefile Added ansto_sctdriveadapter and sctemonadapter hardsup/makefile Added velocity selector and usbtmc protocol handlers hardsup/sct_velselprot.c Simplified, don't worry about trying to implement a login handler for now, just implement a "Reading" handler. site_ansto.c Add the velocity selector and USBTMC protocol handlers. Added the ANSTO_MakeHM command instrument/config/hipadaba/common_instrument_dictionary.tcl Added support for auxiliary data, ie extra meta-data entries in the "data" group of the nexus file. Add new NXvelocity_selector object under /instrument. instrument/config/hipadaba/hipadaba_configuration_common.tcl Add the new "sct_object" script-context controller objects to the hdb tree. instrument/config/hipadaba/instdict_specification.tcl Define the new sct_object controllers. instrument/config/hmm/hmm_configuration_common_1.tcl Use the new ANSTO_MakeHM command to create histmem drivers which support veto. Define allowed attributes and elements for the BAT_TABLE and FAT_TABLE Stop between counts instead of pausing because setting pause now sends a veto. instrument/config/motors/sct_jogmotor_common.tcl You now need to specify klass when creating a jogmotor. instrument/config/motors/sct_positmotor_common.tcl You can now specify an optional function which calculates the instrument parameter (eg attenuation) from a posit table entry when defining a posit motor. instrument/config/nexus/nxscripts_common_1.tcl Report file status info in the /experiment section of the hdb tree. Add auxiliary data to data file. Handle saving data from script-context controller objects. instrument/util/script_context_util.tcl Added procedure to set required properties for saving script-context object data. instrument/util/utility.tcl Added set_sct_object_attributes proc to automatically set required attributes on SCT_OBJECTs Fixed hlistplainprop to deal with empty property fields on hdb nodes. instrument/server_config.tcl Call the new nexus initialisation command and set attributes on sct objects. hrpd/config/motors/motor_configuration.tcl New absenc home readings for mchi and mphi. New absenc home and range for mf1 hipd/config/commands/commands.tcl Exported and published the new ajscmds so that they can be used in batch files. hipd/config/motors/motor_configuration.tcl New mchi absenc home rsd/config/hmm/hmm_configuration.tcl Provide support for saving corrected hmm data rsd/config/motors/motor_configuration.tcl Use simple names for motors. SICS-329 sans/config/INSTCFCOMMON.TXT Added julabo and lakeshore configuration files to list. sans/config/optics/guide_configuration.tcl Added entrance aperture positions to the configuration table and the cn_maps which map the index to the component ID. sans/commands/commands.tcl The "guide" command now set EApPosYmm after driving the guides in place. The indexed position to component maps (cn_map) have been moved to the guide_configuration.tcl file. sans/motors/motor_configuration.tcl Set samy home to 56.1mm sans/config/velsel/sct_velsel.tc NEW Implements script-context controller object for the NVS40 velocity selector. TODO tilt-angle control, driveable interface. sans/config/hmm/hmm_configuration.tcl Set 5.08mm spacing on detector width. Use pixel-offset for vertical and horizontal detector axes. sans/config/motors/motor_configuration.tcl Swap directions of beamstops 4 and 5 (the two smallest) New config parameters for samx, samthet, apx, det, detoff, bsz, sans/config/motors/positmotor_configuration.tcl Added descriptive headers to positmotor configuration tables and new synstax for the make positmotor command. sans/config/nexus/nxscripts.tcl Implemented initialisation command. sans/config/parameters/parameters.tcl Added SampleThickness and TransmissionFlag. Calculate SamplePosYmm from samy and SamyOffsetmm. Added beamstops to hdb tree. reflectometer/config/nexus/nxscripts.tcl Implement the initialisation procedure. r2767 | ffr | 2009-03-31 10:16:54 +1100 (Tue, 31 Mar 2009) | 123 lines
321 lines
10 KiB
C
321 lines
10 KiB
C
/**
|
|
* This is an adapter to a node under the control of the new
|
|
* scriptcontext generic device model. This is a wrapper around
|
|
* such a node which implements the drivable interface.
|
|
*
|
|
* Some cooperation from the node is required: It has to provide
|
|
* certain properties the value of which define scripts which
|
|
* have to be called at various stages. These are:
|
|
*
|
|
* checklimits, for limits checking
|
|
* checkstatus, for evaluating progress
|
|
* halt , for halting things
|
|
*
|
|
* copyright: see file COPYRIGHT
|
|
*
|
|
* Mark Koennecke, June 2008
|
|
* --------------------------------------------------------------*/
|
|
#include <sics.h>
|
|
#include <sicshipadaba.h>
|
|
#include <devser.h>
|
|
#include <tcl.h>
|
|
#include <macro.h>
|
|
#include <sicsobj.h>
|
|
#include "scriptcontext.h"
|
|
/*---------------------------------------------------------------*/
|
|
typedef struct {
|
|
pObjectDescriptor pDes;
|
|
pIDrivable pDriv;
|
|
pHdb write_node;
|
|
pHdb read_node;
|
|
SctController *c;
|
|
}SctDrive, *pSctDrive;
|
|
/*---------------------------------------------------------------*/
|
|
static void *SCTDRIVGetInterface(void *data, int iD){
|
|
pSctDrive self = NULL;
|
|
|
|
self = (pSctDrive)data;
|
|
if(self != NULL && iD == DRIVEID){
|
|
if (self->write_node == NULL) return NULL;
|
|
return self->pDriv;
|
|
} else {
|
|
return NULL;
|
|
}
|
|
return NULL;
|
|
}
|
|
/*----------------------------------------------------------------
|
|
This routine can return either OKOK or HWFault when thing
|
|
go wrong. However, the return value of Halt is usually ignored!
|
|
------------------------------------------------------------------*/
|
|
static int SCTDRIVHalt(void *data) {
|
|
pSctDrive self = NULL;
|
|
char dummy[16];
|
|
|
|
self = (pSctDrive)data;
|
|
if (GetHdbProperty(self->write_node,"halt", dummy, sizeof dummy)) {
|
|
SctQueueNode(self->c, self->write_node, HaltPRIO, "halt", NULL);
|
|
} else if (GetHdbProperty(self->write_node, "status", dummy, sizeof dummy)) {
|
|
SetHdbProperty(self->write_node, "status", "idle");
|
|
}
|
|
return OKOK;
|
|
}
|
|
/*----------------------------------------------------------------
|
|
This routine can return either 1 or 0. 1 means the position can
|
|
be reached, 0 NOT
|
|
If 0, error shall contain up to errlen characters of information
|
|
about which limit was violated
|
|
------------------------------------------------------------------*/
|
|
static int SCTDRIVCheckLimits(void *data, float val,
|
|
char *error, int errlen){
|
|
pSctDrive self = NULL;
|
|
char script[1024];
|
|
int status;
|
|
Tcl_Interp *pTcl = NULL;
|
|
char *result;
|
|
|
|
self = (pSctDrive)data;
|
|
snprintf(script,1024,"%f", val);
|
|
SetHdbProperty(self->write_node,"target", script);
|
|
if(GetHdbProperty(self->write_node,"checklimits",script,1024)){
|
|
status = SctCallInContext(pServ->dummyCon, script,
|
|
self->write_node, self->c, &result);
|
|
if(SctVerbose(self->c)){
|
|
SCPrintf(pServ->dummyCon, eWarning, "script %s called with result %s\n ",
|
|
script, result);
|
|
}
|
|
if(status == 0){
|
|
strncpy(error,result,errlen);
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
/*----------------------------------------------------------------
|
|
This routine can return 0 when a limit problem occurred
|
|
OKOK when the motor was successfully started
|
|
HWFault when a problem occured starting the device
|
|
Possible errors shall be printed to pCon
|
|
For real motors, this is supposed to try at least three times
|
|
to start the motor in question
|
|
val is the value to drive the motor too
|
|
------------------------------------------------------------------*/
|
|
static long SCTDRIVSetValue(void *data, SConnection *pCon, float val){
|
|
pSctDrive self = NULL;
|
|
int status;
|
|
hdbValue v;
|
|
|
|
self = (pSctDrive)data;
|
|
v.dataType = HIPFLOAT;
|
|
v.v.doubleValue = (double)val;
|
|
SetHdbProperty(self->write_node,"writestatus", "start");
|
|
status = SetHipadabaPar(self->write_node, v, pCon);
|
|
if(status == 1){
|
|
return OKOK;
|
|
} else {
|
|
return HWFault;
|
|
}
|
|
}
|
|
/*----------------------------------------------------------------
|
|
Checks the status of a running motor. Possible return values
|
|
HWBusy The motor is still running
|
|
OKOK or HWIdle when the motor finished driving
|
|
HWFault when a hardware problem ocurred
|
|
HWPosFault when the hardware cannot reach a position
|
|
Errors are duly to be printed to pCon
|
|
For real motors CheckStatus again shall try hard to fix any
|
|
issues with the motor
|
|
------------------------------------------------------------------*/
|
|
static int SCTDRIVCheckStatus(void *data, SConnection *pCon){
|
|
pSctDrive self = NULL;
|
|
char script[1024];
|
|
int status;
|
|
Tcl_Interp *pTcl = NULL;
|
|
char *result;
|
|
SConnection *con;
|
|
|
|
self = (pSctDrive)data;
|
|
|
|
/*
|
|
* check if the write command has gone through
|
|
*/
|
|
if(GetHdbProperty(self->write_node,"writestatus", script,1024)){
|
|
if(strcmp(script,"start") == 0){
|
|
return HWBusy;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* run the checkstatus script
|
|
*/
|
|
if(!GetHdbProperty(self->write_node,"checkstatus",script,1024)){
|
|
if (!GetHdbProperty(self->write_node,"status",script,1024)){
|
|
SCWrite(pCon,
|
|
"ERROR: configuration problem: no checkstatus script!", eError);
|
|
return HWFault;
|
|
}
|
|
result = script;
|
|
} else {
|
|
status = SctCallInContext(pCon,script, self->write_node,
|
|
self->c, &result);
|
|
if (status == 0) {
|
|
SCPrintf(pCon,eError," script %s returned %s",
|
|
script, result);
|
|
return HWFault;
|
|
}
|
|
if(SctVerbose(self->c)){
|
|
SCPrintf(pCon,eError," script %s returned %s",
|
|
script, result);
|
|
}
|
|
}
|
|
if(strstr(result,"busy") != NULL){
|
|
return HWBusy;
|
|
} else if(strstr(result,"posfault") != NULL){
|
|
return HWPosFault;
|
|
} else if(strstr(result,"fault") != NULL){
|
|
return HWFault;
|
|
} else if(strstr(result,"idle") != NULL){
|
|
return HWIdle;
|
|
} else {
|
|
SCPrintf(pCon,eError,
|
|
"ERROR: invalid status code %s returned from checkstatus script",
|
|
result);
|
|
return HWFault;
|
|
}
|
|
return HWFault;
|
|
}
|
|
/*----------------------------------------------------------------
|
|
GetValue is supposed to read a motor position
|
|
On errors, -99999999.99 is returned and messages printed to pCon
|
|
------------------------------------------------------------------*/
|
|
static float SCTDRIVGetValue(void *data, SConnection *pCon){
|
|
pSctDrive self = NULL;
|
|
float val = -99999999.99;
|
|
int status;
|
|
char error[256];
|
|
hdbValue v;
|
|
|
|
self = (pSctDrive)data;
|
|
if(GetHdbProperty(self->read_node,"geterror", error, 256)){
|
|
SCWrite(pCon,error, eError);
|
|
return val;
|
|
}
|
|
return (float)self->read_node->value.v.doubleValue;
|
|
}
|
|
/*----------------------------------------------------------------
|
|
returns NULL on failure, a new datastructure else
|
|
------------------------------------------------------------------*/
|
|
static pSctDrive SCTDRIVMakeObject(){
|
|
pSctDrive self = NULL;
|
|
|
|
self = calloc(sizeof(SctDrive),1);
|
|
if(self == NULL){
|
|
return NULL;
|
|
}
|
|
self->pDes = CreateDescriptor("SctDriveAdapter");
|
|
self->pDriv = CreateDrivableInterface();
|
|
if(self->pDes == NULL || self->pDriv == NULL){
|
|
free(self);
|
|
return NULL;
|
|
}
|
|
|
|
self->pDes->GetInterface = SCTDRIVGetInterface;
|
|
self->pDriv->Halt = SCTDRIVHalt;
|
|
self->pDriv->CheckLimits = SCTDRIVCheckLimits;
|
|
self->pDriv->SetValue = SCTDRIVSetValue;
|
|
self->pDriv->CheckStatus = SCTDRIVCheckStatus;
|
|
self->pDriv->GetValue = SCTDRIVGetValue;
|
|
|
|
return self;
|
|
}
|
|
/*-----------------------------------------------------------------*/
|
|
static int SctDriveCommand(SConnection *pCon, SicsInterp *sics, void *object,
|
|
int argc, char *argv[]) {
|
|
pSctDrive self = (pSctDrive)object;
|
|
float val;
|
|
|
|
assert(self != NULL);
|
|
|
|
if (self->write_node == NULL) {
|
|
SCWrite(pCon, "ERROR: defunct object", eError);
|
|
return 0;
|
|
}
|
|
/*
|
|
* only action: print value
|
|
*/
|
|
val = self->pDriv->GetValue(self,pCon);
|
|
SCPrintf(pCon,eValue,"%s = %f", argv[0], val);
|
|
return 1;
|
|
}
|
|
/*----------------------------------------------------------------*/
|
|
static void SctDriveKill(void *data){
|
|
pSctDrive self = (pSctDrive)data;
|
|
|
|
if(self == NULL){
|
|
return;
|
|
}
|
|
if(self->pDriv != NULL){
|
|
free(self->pDriv);
|
|
}
|
|
if(self->pDes != NULL){
|
|
DeleteDescriptor(self->pDes);
|
|
}
|
|
free(self);
|
|
}
|
|
/*----------------------------------------------------------------*/
|
|
static hdbCallbackReturn SctDummyCallback(Hdb *node, void *userData,
|
|
hdbMessage *msg) {
|
|
return hdbContinue;
|
|
}
|
|
/*----------------------------------------------------------------*/
|
|
static void SctDriveDeleteNode(void *data) {
|
|
pSctDrive self = (pSctDrive)data;
|
|
self->write_node = NULL;
|
|
}
|
|
/*---------------------------------------------------------------*/
|
|
int ANSTO_SctMakeDriveAdapter(SConnection *pCon, SicsInterp *pSics, void *object,
|
|
int argc, char *argv[]) {
|
|
pSctDrive pNew = NULL;
|
|
pSICSOBJ obj = NULL;
|
|
hdbCallback *cb;
|
|
|
|
pNew = SCTDRIVMakeObject();
|
|
if(pNew == NULL){
|
|
SCWrite(pCon,"ERROR: out of memory in ANSTO_SctMakeDriveAdapter",
|
|
eError);
|
|
return 0;
|
|
}
|
|
|
|
if(argc < 4){
|
|
SCWrite(pCon,"ERROR: not enough arguments for ANSTO_SctMakeDriveAdapter", eError);
|
|
return 0;
|
|
}
|
|
|
|
pNew->write_node = FindHdbNode(NULL,argv[2], pCon);
|
|
pNew->read_node = FindHdbNode(NULL,argv[3], pCon);
|
|
obj = FindCommandData(pSics,argv[4], "SctController");
|
|
if(pNew->write_node == NULL || obj == NULL){
|
|
SCWrite(pCon,"ERROR: node or controller not found", eError);
|
|
SctDriveKill(pNew);
|
|
return 0;
|
|
}
|
|
pNew->c =(SctController *)obj->pPrivate;
|
|
|
|
if (strcasecmp(argv[0],"dynsctdrive") == 0) {
|
|
/* make object dynamic by defining a descriptor command */
|
|
SetDescriptorKey(pNew->pDes, "creationCommand", "0");
|
|
}
|
|
AddCommand(pSics, argv[1], SctDriveCommand, SctDriveKill, pNew);
|
|
SetHdbProperty(pNew->write_node,"sicsdev",argv[1]);
|
|
|
|
cb = MakeHipadabaCallback(SctDummyCallback, pNew, SctDriveDeleteNode);
|
|
assert(cb);
|
|
AppendHipadabaCallback(pNew->write_node, cb);
|
|
|
|
return 1;
|
|
}
|
|
/*---------------------------------------------------------------*/
|
|
|
|
void ANSTO_SctDriveInit(void) {
|
|
AddCmd("ansto_makesctdrive", ANSTO_SctMakeDriveAdapter);
|
|
}
|