- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
253
scanvar.c
253
scanvar.c
@ -16,96 +16,104 @@
|
||||
#include "lld.h"
|
||||
#include "devexec.h"
|
||||
/*----------------------------------------------------------------------*/
|
||||
pVarEntry MakeScanVar(SicsInterp *pSics, SConnection *pCon, char
|
||||
*name, float start, float step){
|
||||
pVarEntry MakeScanVar(SicsInterp * pSics, SConnection * pCon, char
|
||||
*name, float start, float step)
|
||||
{
|
||||
CommandList *pCom = NULL;
|
||||
pIDrivable pDriv = NULL;
|
||||
pDummy pData = NULL;
|
||||
pVarEntry pVar = NULL;
|
||||
pIDrivable pDriv = NULL;
|
||||
pDummy pData = NULL;
|
||||
pVarEntry pVar = NULL;
|
||||
char pBueffel[512];
|
||||
|
||||
/*
|
||||
allocate space
|
||||
*/
|
||||
pVar = (pVarEntry)malloc(sizeof(VarEntry));
|
||||
if(pVar == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory allocating scan variable",eError);
|
||||
allocate space
|
||||
*/
|
||||
pVar = (pVarEntry) malloc(sizeof(VarEntry));
|
||||
if (pVar == NULL) {
|
||||
SCWrite(pCon, "ERROR: out of memory allocating scan variable", eError);
|
||||
return NULL;
|
||||
}
|
||||
memset(pVar,0,sizeof(VarEntry));
|
||||
memset(pVar, 0, sizeof(VarEntry));
|
||||
|
||||
/* find the thing */
|
||||
pCom = FindCommand(pSics,name);
|
||||
if(!pCom){
|
||||
snprintf(pBueffel,511,"ERROR: Cannot find variable %s to scan",name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
pCom = FindCommand(pSics, name);
|
||||
if (!pCom) {
|
||||
snprintf(pBueffel, 511, "ERROR: Cannot find variable %s to scan",
|
||||
name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return NULL;
|
||||
}
|
||||
pData = (pDummy)pCom->pData;
|
||||
if(!pData){
|
||||
snprintf(pBueffel,511,"ERROR: Cannot find data for variable %s",name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
pData = (pDummy) pCom->pData;
|
||||
if (!pData) {
|
||||
snprintf(pBueffel, 511, "ERROR: Cannot find data for variable %s",
|
||||
name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return NULL;
|
||||
}
|
||||
pDriv = pData->pDescriptor->GetInterface(pData,DRIVEID);
|
||||
if(!pDriv){
|
||||
snprintf(pBueffel,511,
|
||||
"ERROR: variable %s is NOT driveable and cannot be scanned",name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
pDriv = pData->pDescriptor->GetInterface(pData, DRIVEID);
|
||||
if (!pDriv) {
|
||||
snprintf(pBueffel, 511,
|
||||
"ERROR: variable %s is NOT driveable and cannot be scanned",
|
||||
name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* got everything, fill in the VarEntry structure */
|
||||
strcpy(pVar->Name,name);
|
||||
strcpy(pVar->Name, name);
|
||||
pVar->pInter = pDriv;
|
||||
pVar->pObject = pData;
|
||||
pVar->fStart = start;
|
||||
pVar->fStep = step;
|
||||
pVar->fStep = step;
|
||||
pVar->dataList = LLDcreate(sizeof(float));
|
||||
|
||||
return pVar;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
pVarEntry MakeLogVar(SicsInterp *pSics, SConnection *pCon, char *name){
|
||||
pVarEntry MakeLogVar(SicsInterp * pSics, SConnection * pCon, char *name)
|
||||
{
|
||||
CommandList *pCom = NULL;
|
||||
pIDrivable pDriv = NULL;
|
||||
pDummy pData = NULL;
|
||||
pVarEntry pVar = NULL;
|
||||
pIDrivable pDriv = NULL;
|
||||
pDummy pData = NULL;
|
||||
pVarEntry pVar = NULL;
|
||||
char pBueffel[512];
|
||||
|
||||
/*
|
||||
allocate space
|
||||
*/
|
||||
pVar = (pVarEntry)malloc(sizeof(VarEntry));
|
||||
if(pVar == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory allocating scan variable",eError);
|
||||
allocate space
|
||||
*/
|
||||
pVar = (pVarEntry) malloc(sizeof(VarEntry));
|
||||
if (pVar == NULL) {
|
||||
SCWrite(pCon, "ERROR: out of memory allocating scan variable", eError);
|
||||
return NULL;
|
||||
}
|
||||
memset(pVar,0,sizeof(VarEntry));
|
||||
memset(pVar, 0, sizeof(VarEntry));
|
||||
|
||||
/* find the thing */
|
||||
pCom = FindCommand(pSics,name);
|
||||
if(!pCom){
|
||||
snprintf(pBueffel,511,"ERROR: Cannot find variable %s to log",name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
pCom = FindCommand(pSics, name);
|
||||
if (!pCom) {
|
||||
snprintf(pBueffel, 511, "ERROR: Cannot find variable %s to log", name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return NULL;
|
||||
}
|
||||
pData = (pDummy)pCom->pData;
|
||||
if(!pData){
|
||||
snprintf(pBueffel,511,"ERROR: Cannot find data for variable %s",name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
pData = (pDummy) pCom->pData;
|
||||
if (!pData) {
|
||||
snprintf(pBueffel, 511, "ERROR: Cannot find data for variable %s",
|
||||
name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return NULL;
|
||||
}
|
||||
pDriv = pData->pDescriptor->GetInterface(pData,DRIVEID);
|
||||
if(!pDriv){
|
||||
snprintf(pBueffel,511,
|
||||
"ERROR: variable %s is NOT driveable and cannot be logged",name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return NULL;
|
||||
pDriv = pData->pDescriptor->GetInterface(pData, DRIVEID);
|
||||
if (!pDriv) {
|
||||
snprintf(pBueffel, 511,
|
||||
"ERROR: variable %s is NOT driveable and cannot be logged",
|
||||
name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* got everything, fill in the VarEntry structure */
|
||||
strcpy(pVar->Name,name);
|
||||
strcpy(pVar->Name, name);
|
||||
pVar->pInter = pDriv;
|
||||
pVar->pObject = pData;
|
||||
pVar->logVar = 1;
|
||||
@ -115,40 +123,51 @@ pVarEntry MakeLogVar(SicsInterp *pSics, SConnection *pCon, char *name){
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
void InitScanVar(pVarEntry pVar){
|
||||
void InitScanVar(pVarEntry pVar)
|
||||
{
|
||||
LLDdelete(pVar->dataList);
|
||||
pVar->dataList = LLDcreate(sizeof(float));
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
void DeleteVarEntry(void *pData){
|
||||
void DeleteVarEntry(void *pData)
|
||||
{
|
||||
pVarEntry pVar = NULL;
|
||||
|
||||
pVar = (pVarEntry)pData;
|
||||
|
||||
if(pVar == NULL){
|
||||
|
||||
pVar = (pVarEntry) pData;
|
||||
|
||||
if (pVar == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(pVar->fData){
|
||||
|
||||
if (pVar->fData) {
|
||||
free(pVar->fData);
|
||||
}
|
||||
LLDdelete(pVar->dataList);
|
||||
free(pVar);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
char *ScanVarName(pVarEntry pVar){
|
||||
char *ScanVarName(pVarEntry pVar)
|
||||
{
|
||||
return pVar->Name;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
float ScanVarStart(pVarEntry pVar){
|
||||
float ScanVarStart(pVarEntry pVar)
|
||||
{
|
||||
return pVar->fStart;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
float ScanVarStep(pVarEntry pVar){
|
||||
float ScanVarStep(pVarEntry pVar)
|
||||
{
|
||||
return pVar->fStep;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
int StartScanVar(pVarEntry pVar, SConnection *pCon, int i){
|
||||
int StartScanVar(pVarEntry pVar, SConnection * pCon, int i)
|
||||
{
|
||||
float fVal;
|
||||
pDummy pDum;
|
||||
char pBueffel[512];
|
||||
@ -157,84 +176,90 @@ int StartScanVar(pVarEntry pVar, SConnection *pCon, int i){
|
||||
/**
|
||||
* logged variables are not started
|
||||
*/
|
||||
if(pVar->logVar == 1){
|
||||
if (pVar->logVar == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
pDum = (pDummy)pVar->pObject;
|
||||
fVal = pVar->fStart + i * pVar->fStep;
|
||||
status = StartDevice(pServ->pExecutor,
|
||||
pVar->Name,
|
||||
pDum->pDescriptor,
|
||||
pVar->pObject,
|
||||
pCon,
|
||||
fVal);
|
||||
if(!status){
|
||||
snprintf(pBueffel,511,"ERROR: Failed to start %s",pVar->Name);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
pDum = (pDummy) pVar->pObject;
|
||||
fVal = pVar->fStart + i * pVar->fStep;
|
||||
status = StartDevice(pServ->pExecutor,
|
||||
pVar->Name,
|
||||
pDum->pDescriptor, pVar->pObject, pCon, fVal);
|
||||
if (!status) {
|
||||
snprintf(pBueffel, 511, "ERROR: Failed to start %s", pVar->Name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int CheckScanVar(pVarEntry pVar, SConnection *pCon, int np){
|
||||
int status;
|
||||
char pError[132], pBueffel[512];
|
||||
|
||||
if(pVar->logVar == 1){
|
||||
return 1;
|
||||
}
|
||||
|
||||
status = pVar->pInter->CheckLimits(pVar->pObject,
|
||||
pVar->fStart,pError,131);
|
||||
if(status != 1){
|
||||
snprintf(pBueffel,511,"ERROR: %s, scan aborted",pError);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = pVar->pInter->CheckLimits(pVar->pObject,
|
||||
pVar->fStart + np * pVar->fStep,
|
||||
pError,131);
|
||||
if(status != 1){
|
||||
snprintf(pBueffel,511,"ERROR: %s, scan aborted",pError);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void AppendScanVar(pVarEntry pVar, float pos){
|
||||
float fVal = pos;
|
||||
LLDnodeAppendFrom(pVar->dataList,&fVal);
|
||||
int CheckScanVar(pVarEntry pVar, SConnection * pCon, int np)
|
||||
{
|
||||
int status;
|
||||
char pError[132], pBueffel[512];
|
||||
|
||||
if (pVar->logVar == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
status = pVar->pInter->CheckLimits(pVar->pObject,
|
||||
pVar->fStart, pError, 131);
|
||||
if (status != 1) {
|
||||
snprintf(pBueffel, 511, "ERROR: %s, scan aborted", pError);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
status = pVar->pInter->CheckLimits(pVar->pObject,
|
||||
pVar->fStart + np * pVar->fStep,
|
||||
pError, 131);
|
||||
if (status != 1) {
|
||||
snprintf(pBueffel, 511, "ERROR: %s, scan aborted", pError);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void AppendScanVar(pVarEntry pVar, float pos)
|
||||
{
|
||||
float fVal = pos;
|
||||
LLDnodeAppendFrom(pVar->dataList, &fVal);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
float GetScanVarPos(pVarEntry pVar, int i){
|
||||
float GetScanVarPos(pVarEntry pVar, int i)
|
||||
{
|
||||
int count = 0, status;
|
||||
|
||||
status = LLDnodePtr2First(pVar->dataList);
|
||||
while(count < i && (status = LLDnodePtr2Next(pVar->dataList)) != 0){
|
||||
while (count < i && (status = LLDnodePtr2Next(pVar->dataList)) != 0) {
|
||||
count++;
|
||||
}
|
||||
if(count == i){
|
||||
if (count == i) {
|
||||
return LLDnodeFloat(pVar->dataList);
|
||||
} else {
|
||||
return -99999.99;
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
void CopyScanVar(pVarEntry pVar, float *fData, int np){
|
||||
void CopyScanVar(pVarEntry pVar, float *fData, int np)
|
||||
{
|
||||
int i, count = 0, status;
|
||||
|
||||
status = LLDnodePtr2First(pVar->dataList);
|
||||
while(status > 0 && count < np){
|
||||
while (status > 0 && count < np) {
|
||||
fData[count] = LLDnodeFloat(pVar->dataList);
|
||||
count++;
|
||||
status = LLDnodePtr2Next(pVar->dataList);
|
||||
}
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int isLogVar(pVarEntry pVar){
|
||||
return pVar->logVar;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int isLogVar(pVarEntry pVar)
|
||||
{
|
||||
return pVar->logVar;
|
||||
}
|
||||
|
Reference in New Issue
Block a user