- Some fixes to the hipadaba code.
SKIPPED: psi/libpsi.a psi/hardsup/libhlib.a psi/tecs/libtecsl.a
This commit is contained in:
Binary file not shown.
@ -1,3 +1,5 @@
|
||||
exe batchpath ./
|
||||
exe syspath ./
|
||||
# Motor omegam
|
||||
omegam sign 1.000000
|
||||
omegam SoftZero 0.000000
|
||||
@ -98,7 +100,7 @@ twothetad ignorefault 0.000000
|
||||
twothetad AccessCode 2.000000
|
||||
twothetad movecount 10.000000
|
||||
# Counter counter
|
||||
counter SetPreset 60000000.000000
|
||||
counter SetPreset 600000000.000000
|
||||
counter SetMode Monitor
|
||||
banana CountMode monitor
|
||||
banana preset 60000.000000
|
||||
@ -227,5 +229,5 @@ email UNKNOWN
|
||||
email setAccess 2
|
||||
sample_mur 0.000000
|
||||
sample_mur setAccess 2
|
||||
exe batchpath ./
|
||||
exe syspath ./
|
||||
lastdatafile UNKNOWN
|
||||
lastdatafile setAccess 2
|
||||
|
@ -20,6 +20,8 @@
|
||||
"event",
|
||||
"warning",
|
||||
"error",
|
||||
"hdbvalue",
|
||||
"hdbevent",
|
||||
NULL };
|
||||
static int iNoCodes = 10;
|
||||
#endif
|
||||
|
110
sicshipadaba.c
110
sicshipadaba.c
@ -29,6 +29,11 @@
|
||||
/*== there can be only hipadaba in SICS, some globals to care for that == */
|
||||
static pHdb root = NULL;
|
||||
static pSicsPoll poller = NULL;
|
||||
typedef enum {
|
||||
normal_protocol,
|
||||
json_protocol,
|
||||
} Protocol;
|
||||
char *trim(char *str);
|
||||
/*=============== common callback functions used for SICS ===========================*/
|
||||
static int SICSCheckPermissionCallback(void *userData, void *callData, pHdb node,
|
||||
hdbValue v){
|
||||
@ -150,50 +155,70 @@ typedef struct {
|
||||
commandContext context;
|
||||
}HdbCBInfo;
|
||||
|
||||
static int isJSON(SConnection *pCon) {
|
||||
static Protocol isJSON(SConnection *pCon) {
|
||||
char proName[128];
|
||||
void *pData;
|
||||
|
||||
if(SCinMacro(pCon)){
|
||||
return 0;
|
||||
return normal_protocol;
|
||||
}
|
||||
pData = FindCommandData(pServ->pSics, "protocol","Protocol");
|
||||
ProtocolGet(pCon, pData, proName, 128);
|
||||
if (strcmp(proName, "json") == 0)
|
||||
return 1;
|
||||
return json_protocol;
|
||||
else
|
||||
return 0;
|
||||
return normal_protocol;
|
||||
}
|
||||
|
||||
int formatNameValue(int jsonSet, char *name, char *value, pDynString result) {
|
||||
if (name == NULL) {
|
||||
if (jsonSet) {
|
||||
} else {
|
||||
}
|
||||
} else if (value == NULL) {
|
||||
if (jsonSet) {
|
||||
DynStringInsert(result,"\": ", 0);
|
||||
DynStringInsert(result,name,0);
|
||||
DynStringInsert(result,"{\"", 0);
|
||||
DynStringConcat(result,"}");
|
||||
} else {
|
||||
DynStringInsert(result," =",0);
|
||||
DynStringInsert(result,name,0);
|
||||
}
|
||||
} else {
|
||||
if (jsonSet) {
|
||||
DynStringCopy(result,"{\"");
|
||||
DynStringConcat(result,name);
|
||||
DynStringConcat(result,"\": ");
|
||||
DynStringConcat(result,value);
|
||||
DynStringConcat(result,"}");
|
||||
} else {
|
||||
/* Format a name,value pair according to the given protocol */
|
||||
int formatNameValue(Protocol protocol, char *name, char *value, pDynString result, int hdtype) {
|
||||
char *char_arr, *ptr;
|
||||
|
||||
switch(protocol) {
|
||||
case normal_protocol:
|
||||
DynStringCopy(result,name);
|
||||
DynStringConcat(result," = ");
|
||||
DynStringConcat(result,value);
|
||||
break;
|
||||
case json_protocol:
|
||||
switch(hdtype){
|
||||
case HIPNONE:
|
||||
break;
|
||||
case HIPINT:
|
||||
case HIPFLOAT:
|
||||
DynStringCopy(result,"{\"");
|
||||
DynStringConcat(result,name);
|
||||
DynStringConcat(result,"\": ");
|
||||
DynStringConcat(result,value);
|
||||
DynStringConcat(result,"}");
|
||||
break;
|
||||
case HIPTEXT:
|
||||
DynStringCopy(result,"{\"");
|
||||
DynStringConcat(result,name);
|
||||
DynStringConcat(result,"\": \"");
|
||||
DynStringConcat(result,value);
|
||||
DynStringConcat(result,"\"}");
|
||||
break;
|
||||
case HIPINTAR:
|
||||
case HIPINTVARAR:
|
||||
case HIPFLOATAR:
|
||||
case HIPFLOATVARAR:
|
||||
char_arr = ptr = strdup(trim(value));
|
||||
while(*ptr != '\0') {
|
||||
if (isspace(*ptr))
|
||||
*ptr=',';
|
||||
ptr++;
|
||||
}
|
||||
DynStringCopy(result,"{\"");
|
||||
DynStringConcat(result,name);
|
||||
DynStringConcat(result,"\": [ ");
|
||||
DynStringConcat(result,char_arr);
|
||||
DynStringConcat(result," ]}");
|
||||
if (char_arr != NULL ) free(char_arr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return jsonSet;
|
||||
return protocol;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------------------*/
|
||||
@ -203,7 +228,8 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
|
||||
pDynString printedData = NULL;
|
||||
pDynString result = NULL;
|
||||
char *pPath = NULL;
|
||||
int protocol = 0, outCode;
|
||||
Protocol protocol = normal_protocol;
|
||||
int outCode;
|
||||
|
||||
cbInfo = (HdbCBInfo *)userData;
|
||||
pPath = GetHipadabaPath(node);
|
||||
@ -224,12 +250,12 @@ static int SICSNotifyCallback(void *userData, void *callData, pHdb node,
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
formatNameValue(protocol, pPath, GetCharArray(printedData), result);
|
||||
formatNameValue(protocol, pPath, GetCharArray(printedData), result, v.dataType);
|
||||
SCWriteInContext(cbInfo->pCon,GetCharArray(result),
|
||||
outCode,cbInfo->context);
|
||||
DeleteDynString(printedData);
|
||||
} else {
|
||||
formatNameValue(protocol,"!!datachange!!", pPath, result);
|
||||
formatNameValue(protocol, pPath,"!!datachange!!", result, HIPTEXT);
|
||||
SCWriteInContext(cbInfo->pCon,GetCharArray(result),
|
||||
outCode,cbInfo->context);
|
||||
}
|
||||
@ -256,7 +282,8 @@ static int TreeChangeCallback(void *userData, void *callData, pHdb node,
|
||||
char *path = NULL;
|
||||
char buffer[1024];
|
||||
pDynString result = NULL;
|
||||
int protocol = 0, outCode;
|
||||
Protocol protocol = normal_protocol;
|
||||
int outCode;
|
||||
|
||||
result = CreateDynString(128,128);
|
||||
HdbCBInfo *cbInfo = (HdbCBInfo *)userData;
|
||||
@ -267,7 +294,7 @@ static int TreeChangeCallback(void *userData, void *callData, pHdb node,
|
||||
outCode = eHdbEvent;
|
||||
else
|
||||
outCode = eEvent;
|
||||
formatNameValue(protocol, "treechange", path, result);
|
||||
formatNameValue(protocol, "treechange", path, result, v.dataType);
|
||||
SCWriteInContext(cbInfo->pCon,GetCharArray(result),outCode,cbInfo->context);
|
||||
DeleteDynString(result);
|
||||
free(path);
|
||||
@ -1152,7 +1179,6 @@ void SaveSICSHipadaba(FILE *fd, pHdb node, char *prefix){
|
||||
currentChild = node->child;
|
||||
while(currentChild != NULL){
|
||||
if(currentChild->value.dataType != HIPNONE && !isSICSHdbRO(currentChild)){
|
||||
GetHipadabaPar(currentChild,&v,NULL);
|
||||
data = formatValue(currentChild->value);
|
||||
if(data != NULL){
|
||||
fprintf(fd,"%s%s %s\n", prefix, currentChild->name, GetCharArray(data));
|
||||
@ -1742,10 +1768,11 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pHdb targetNode = NULL;
|
||||
hdbValue newValue;
|
||||
pDynString parData = NULL;
|
||||
pDynString parData = NULL, result = NULL;
|
||||
char error[512], oriPath[512];;
|
||||
int i, status;
|
||||
int protocol = 0, outCode;
|
||||
Protocol protocol = normal_protocol;
|
||||
int outCode;
|
||||
|
||||
if(argc < 2) {
|
||||
SCWrite(pCon,"ERROR: need path to node to print",eError);
|
||||
@ -1769,9 +1796,11 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
else
|
||||
outCode = eEvent;
|
||||
|
||||
formatNameValue(protocol, oriPath, NULL, parData);
|
||||
SCWrite(pCon,GetCharArray(parData),outCode);
|
||||
result = CreateDynString(128,128);
|
||||
formatNameValue(protocol, oriPath, GetCharArray(parData), result, newValue.dataType);
|
||||
SCWrite(pCon,GetCharArray(result),outCode);
|
||||
DeleteDynString(parData);
|
||||
DeleteDynString(result);
|
||||
ReleaseHdbValue(&newValue);
|
||||
|
||||
return 1;
|
||||
@ -2075,7 +2104,8 @@ static int ListHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
pHdb node = NULL;
|
||||
int pathArg = 1;
|
||||
pDynString listData = NULL;
|
||||
int protocol = 0, outCode;
|
||||
Protocol protocol = normal_protocol;
|
||||
int outCode;
|
||||
|
||||
if(argc < 2) {
|
||||
SCWrite(pCon,"ERROR: need path to node to print",eError);
|
||||
|
Reference in New Issue
Block a user