- Added Sycamore protocol and command context to SICS
- Added sinfo to SICS - Added driver for TCP/IP Astrium velocity selector - Added driver for TCP/IP Astrium chopper controller SKIPPED: psi/amor2t.c psi/amorstat.c psi/dornier2.c psi/ecb.c psi/el734hp.c psi/fowrite.c psi/libpsi.a psi/make_gen psi/nextrics.c psi/pardef.c psi/pimotor.c psi/pipiezo.c psi/polterwrite.c psi/psi.c psi/scontroller.c psi/serial.c psi/tasinit.c psi/tasscan.c psi/tcpdocho.c psi/tcpdornier.c psi/tricssupport.c psi/velodornier.c
This commit is contained in:
305
SCinter.c
305
SCinter.c
@ -2,8 +2,6 @@
|
||||
|
||||
Implementation file for the SICS-interpreter.
|
||||
|
||||
|
||||
|
||||
Mark Koennecke, November 1996
|
||||
|
||||
Made ListObjects more intelligent: list objects according to interface etc.
|
||||
@ -42,6 +40,16 @@
|
||||
M. Zolliker, Sept 2000, introduced formal aliases, modifications marked M.Z
|
||||
Mark Koennecke, August 2001, modified SicsWriteStatus to write motor
|
||||
positions on demand.
|
||||
|
||||
Made ListObjects moe intelligent: list objects according to interface etc.
|
||||
Mark Koennecke, December 2003
|
||||
|
||||
Extended 'dir' command (function ListObjects) to list via typename from
|
||||
object descriptor. For completeness, added function PrintAllTypes.
|
||||
Paul Hathaway, May 2004
|
||||
|
||||
Modified printXXX functions to fix duplicate write of last buffer line.
|
||||
Paul Hathaway, May 2004
|
||||
---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -61,6 +69,15 @@
|
||||
/* M.Z. */
|
||||
#include "definealias.h"
|
||||
|
||||
/* pvh */
|
||||
#include "lld_str.h"
|
||||
static void printList(SConnection *pCon, int listID);
|
||||
static void freeList(int listID);
|
||||
int compareStringNode(void *pStr1, void **ppStr2);
|
||||
|
||||
#define MAXLEN 256
|
||||
#define MAXPAR 100
|
||||
#define MAXBUF 128
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
SicsInterp *InitInterp(void)
|
||||
@ -219,22 +236,11 @@
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
void RemoveStartupCommands(void)
|
||||
{
|
||||
CommandList *pCurrent, *pNext;
|
||||
pCurrent = pServ->pSics->pCList;
|
||||
while(pCurrent)
|
||||
{
|
||||
pNext = pCurrent->pNext;
|
||||
if (pCurrent->startupOnly) {
|
||||
RemoveCommand(pServ->pSics, pCurrent->pName);
|
||||
}
|
||||
pCurrent = pNext;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
#define MAXLEN 256
|
||||
#define MAXCOM 50
|
||||
extern char *stptok(char *s, char *tok, unsigned int toklen, char *brk);
|
||||
extern char *SkipSpace(char *pPtr);
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int InterpExecute(SicsInterp *self,SConnection *pCon, char *pText)
|
||||
{
|
||||
int iCount = 0;
|
||||
@ -275,6 +281,7 @@
|
||||
iRet = 1;
|
||||
goto deleteArgv;
|
||||
}
|
||||
|
||||
if(argv[0] == NULL)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: failed to parse command",eError);
|
||||
@ -298,7 +305,13 @@
|
||||
self->eOut = eStatus;
|
||||
Tcl_ResetResult((Tcl_Interp *)self->pTcl);
|
||||
MacroPush(pCon);
|
||||
SCWrite(pCon, "", eStart);
|
||||
pCon->conStatus = 0;
|
||||
iRet = pCommand->OFunc(pCon, self, pCommand->pData, argc, argv);
|
||||
/* If a task is registered with the dev exec then conStatus is HWBusy*/
|
||||
if (pCon->conStatus != HWBusy) {
|
||||
SCWrite(pCon,"",eFinish);
|
||||
}
|
||||
MacroPop();
|
||||
|
||||
deleteArgv:
|
||||
@ -519,6 +532,74 @@ static void printAll(SicsInterp *pSics, SConnection *pCon)
|
||||
SCWrite(pCon,pBueffel,eStatus);
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
printAllTypes prints the list of types of objects instantiated on the
|
||||
CommandList.
|
||||
iFiltered=0 gives all objects including interpreter command objects
|
||||
iFiltered=1 gives types where object name is not the same as its type
|
||||
-------------------------------------------------------------------------*/
|
||||
static void printAllTypes(SicsInterp *pSics, SConnection *pCon, int iFiltered)
|
||||
{
|
||||
CommandList *pCurrent = NULL;
|
||||
char pBueffel[256];
|
||||
char pName_lc[256];
|
||||
char pType_lc[256];
|
||||
char *pType;
|
||||
Dummy *pTest;
|
||||
int typeListID;
|
||||
|
||||
assert(pSics);
|
||||
assert(pCon);
|
||||
|
||||
pBueffel[0] = '\0';
|
||||
|
||||
typeListID = LLDstringCreate();
|
||||
if(-1==typeListID)
|
||||
{
|
||||
strcpy(pBueffel,"ERROR: Cannot generate list of object types\r\n");
|
||||
SCWrite(pCon,pBueffel,eStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
pCurrent = pSics->pCList;
|
||||
while(pCurrent)
|
||||
{
|
||||
if(NULL != pCurrent->pData)
|
||||
{
|
||||
pTest = (pDummy)pCurrent->pData;
|
||||
if(NULL != pTest->pDescriptor)
|
||||
{
|
||||
pType = pTest->pDescriptor->name;
|
||||
strcpy(pType_lc,pType);
|
||||
strtolower(pType_lc);
|
||||
|
||||
LLDnodePtr2First(typeListID);
|
||||
|
||||
/* int LLDnodeFind( int List, CompFunPtr Compare, void * DataPtr ); */
|
||||
/* */
|
||||
/* Find *DataPtr in the List using the *Compare function. */
|
||||
/* Returns the return value of *Compare. */
|
||||
/* 0 == equal == found. */
|
||||
/* non-zero == not found. Current node is set to found node. */
|
||||
/* Returns 2 for an empty list. */
|
||||
/* NB: First checked node is current node, then search to end of list*/
|
||||
|
||||
if(0!=LLDnodeFind(typeListID,compareStringNode,(void *)pType))
|
||||
{ /* empty list or 'typename' not found */
|
||||
strcpy(pName_lc, pCurrent->pName);
|
||||
strtolower(pName_lc);
|
||||
if((0==iFiltered)||((1==iFiltered)&&(0!=strcmp(pType_lc,pName_lc))))
|
||||
{ /*ie Add if unfiltered or pass filter(name!=typename) */
|
||||
LLDstringAdd(typeListID,pType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
printList(pCon,typeListID);
|
||||
freeList(typeListID);
|
||||
}
|
||||
/*-----------------------------------------------------------------------
|
||||
printInterface prints only those objects which implement an interface
|
||||
as specified bi the id given
|
||||
@ -625,9 +706,9 @@ static void printMatch(SicsInterp *pSics, SConnection *pCon, char *mask)
|
||||
SCWrite(pCon,pBueffel,eStatus);
|
||||
}
|
||||
/*-----------------------------------------------------------------------
|
||||
printType prints only those objects which match the type given
|
||||
printType prints only those objects whose descriptor match the type given
|
||||
-------------------------------------------------------------------------*/
|
||||
static void printType(SicsInterp *pSics, SConnection *pCon, char *type)
|
||||
static void printType(SicsInterp *pSics, SConnection *pCon, char *typeName)
|
||||
{
|
||||
CommandList *pCurrent;
|
||||
Tcl_DString txt;
|
||||
@ -644,7 +725,7 @@ static void printType(SicsInterp *pSics, SConnection *pCon, char *type)
|
||||
{
|
||||
if(pCurrent->pData != NULL)
|
||||
{
|
||||
if(iHasType(pCurrent->pData,type))
|
||||
if(iHasType(pCurrent->pData,typeName))
|
||||
{
|
||||
if(iNum == 0)
|
||||
{
|
||||
@ -680,6 +761,8 @@ static void printType(SicsInterp *pSics, SConnection *pCon, char *type)
|
||||
int ListObjects(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char pType[256];
|
||||
int i;
|
||||
|
||||
if(argc < 2)
|
||||
{
|
||||
@ -701,6 +784,13 @@ static void printType(SicsInterp *pSics, SConnection *pCon, char *type)
|
||||
printType(pSics,pCon,"Motor");
|
||||
return 1;
|
||||
}
|
||||
/* Start Mod by Paul Hathaway May 2004 */
|
||||
if(0 == strcmp(argv[1],"types"))
|
||||
{
|
||||
printAllTypes(pSics,pCon,1);
|
||||
return 1;
|
||||
}
|
||||
/* End Mod by Paul Hathaway May 2004*/
|
||||
|
||||
|
||||
/*
|
||||
@ -745,6 +835,33 @@ static void printType(SicsInterp *pSics, SConnection *pCon, char *type)
|
||||
printMatch(pSics,pCon,argv[2]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Start Mod by Paul Hathaway May 2004 */
|
||||
/*
|
||||
* type-based dir
|
||||
*/
|
||||
if(0 == strcmp(argv[1],"type"))
|
||||
{
|
||||
if(0==strcmp(argv[2],"*"))
|
||||
{
|
||||
printAllTypes(pSics,pCon,0);
|
||||
return 1;
|
||||
}
|
||||
strcpy(pType,argv[2]);
|
||||
/* Cater for multi-word types eg 'Environment Monitor' */
|
||||
if(argc > 3)
|
||||
{
|
||||
for(i=3;i<argc;i++)
|
||||
{
|
||||
strcat(pType," ");
|
||||
strcat(pType,argv[i]);
|
||||
}
|
||||
}
|
||||
printType(pSics,pCon,pType);
|
||||
return 1;
|
||||
}
|
||||
/* End Mod by Paul Hathaway May 2004*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -848,3 +965,149 @@ void *FindDrivable(SicsInterp *pSics, char *name){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* printList: Print contents of an LLDstring list
|
||||
* Envisaged to be used by other extensions/refactoring utilising dynamic
|
||||
* linked list module. May extend toallow different output formats
|
||||
* (eg multi/single column) via switches
|
||||
*/
|
||||
static void printList(SConnection *pCon, int listID)
|
||||
{
|
||||
char pBueffel[MAXBUF];
|
||||
int retCode;
|
||||
|
||||
if(0!=LLDnodePtr2First(listID))
|
||||
{
|
||||
do
|
||||
{
|
||||
retCode = LLDstringData(listID,NULL);
|
||||
if ((MAXBUF-3) > retCode) {
|
||||
retCode = LLDstringData(listID,pBueffel);
|
||||
strcat(pBueffel,"\r\n");
|
||||
SCWrite(pCon,pBueffel,eStatus);
|
||||
}
|
||||
} while(0!=LLDnodePtr2Next(listID));
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static void freeList(int listID)
|
||||
{
|
||||
do {
|
||||
LLDstringDelete(listID);
|
||||
} while(0!=LLDnodePtr2First(listID));
|
||||
LLDdelete(listID);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* compareStringNode wraps strcmp for use in findNode(LLD module) calls */
|
||||
int compareStringNode(void *pStr1, void **ppStr2)
|
||||
{
|
||||
return strcmp((char *)pStr1,(char *)(*ppStr2));
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
void RemoveStartupCommands(void)
|
||||
{
|
||||
CommandList *pCurrent, *pNext;
|
||||
pCurrent = pServ->pSics->pCList;
|
||||
while(pCurrent)
|
||||
{
|
||||
pNext = pCurrent->pNext;
|
||||
if (pCurrent->startupOnly) {
|
||||
RemoveCommand(pServ->pSics, pCurrent->pName);
|
||||
}
|
||||
pCurrent = pNext;
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static int handleGet(SConnection *pCon,SicsInterp *pSics, int argc,
|
||||
char *argv[]){
|
||||
CommandList *obj = NULL;
|
||||
pDummy pDum = NULL;
|
||||
char pBueffel[512];
|
||||
char *pPtr = NULL;
|
||||
|
||||
if(argc < 4){
|
||||
SCWrite(pCon,"ERROR: Insufficient number of arguments to SicsAtt get",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
obj = FindCommand(pSics,argv[2]);
|
||||
if(obj == NULL){
|
||||
snprintf(pBueffel,511,"ERROR: object %s not found",argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
pDum = obj->pData;
|
||||
if(pDum == NULL){
|
||||
snprintf(pBueffel,511,"%s has no data, is command", argv[2]);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
strtolower(argv[3]);
|
||||
if(strcmp(argv[3],"type") == 0){
|
||||
snprintf(pBueffel,511, "%s.type = %s", argv[2], pDum->pDescriptor->name);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
} else {
|
||||
pPtr = GetDescriptorKey(pDum->pDescriptor, argv[3]);
|
||||
if(pPtr == NULL){
|
||||
snprintf(pBueffel,511,"%s.%s = Undefined", argv[0], argv[3]);
|
||||
} else {
|
||||
snprintf(pBueffel,511,"%s.%s = %s", argv[0], argv[3], pPtr);
|
||||
}
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static int handleSet(SConnection *pCon,SicsInterp *pSics, int argc,
|
||||
char *argv[]){
|
||||
CommandList *obj = NULL;
|
||||
pDummy pDum = NULL;
|
||||
char pBueffel[512];
|
||||
char *pPtr = NULL;
|
||||
|
||||
if(argc < 5){
|
||||
SCWrite(pCon,"ERROR: Insufficient number of arguments to SicsAtt set",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
obj = FindCommand(pSics,argv[2]);
|
||||
if(obj == NULL){
|
||||
snprintf(pBueffel,511,"ERROR: object %s not found",argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
pDum = obj->pData;
|
||||
if(pDum == NULL){
|
||||
snprintf(pBueffel,511,"%s has no data, is command", argv[2]);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
strtolower(argv[3]);
|
||||
pDum->pDescriptor->pKeys = IFSetOption(pDum->pDescriptor->pKeys, argv[3], argv[4]);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int SicsAtt(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
CommandList *current = NULL;
|
||||
pDummy pDum = NULL;
|
||||
|
||||
if(argc < 2){
|
||||
SCWrite(pCon,"ERROR: insufficient number of argumens to SicsAtt",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strtolower(argv[1]);
|
||||
if(strcmp(argv[1],"get") == 0) {
|
||||
return handleGet(pCon, pSics, argc, argv);
|
||||
} else if(strcmp(argv[1],"set") == 0){
|
||||
return handleSet(pCon,pSics,argc, argv);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user