From c277681fa1cd5a6c37e49ba5efa3f4bf2b6a8ed3 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 28 Nov 2012 15:20:29 +1100 Subject: [PATCH] SICS-195 --- counter.c | 61 +++++++++++++++++++++++++++++++++++++++++-------------- counter.h | 2 ++ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/counter.c b/counter.c index c6b6ab5b..0c820901 100644 --- a/counter.c +++ b/counter.c @@ -536,7 +536,7 @@ static int SetCounterModeImpl(pCounter self, CounterMode eNew) /*-------------------------------------------------------------------------*/ CounterMode GetCounterMode(pCounter self) { - return self->getMode(self); + return self->getMode(self); } /*--------------------------------------------------------------------------*/ static CounterMode GetCounterModeImpl(pCounter self) @@ -547,7 +547,7 @@ static CounterMode GetCounterModeImpl(pCounter self) /*------------------------------------------------------------------------*/ int GetNMonitor(pCounter self) { - return self->getNMonitor(self); + return self->getNMonitor(self); } /*------------------------------------------------------------------------*/ static int GetNMonitorImpl(pCounter self) @@ -556,13 +556,28 @@ static int GetNMonitorImpl(pCounter self) return self->pDriv->iNoOfMonitors; } +int GetControlMonitor(pCounter self) +{ + return self->pDriv->iControlMonitor; +} + +int SetControlMonitor(pCounter self, int channel) +{ + int maxchan = self->pDriv->iNoOfMonitors - 1; + if (channel < 0 || channel > maxchan) { + return 0; + } + self->pDriv->iControlMonitor = channel; + return 1; +} + #ifdef NONINTF extern float nintf(float f); #endif /*------------------------------------------------------------------------*/ int SetCounterPreset(pCounter self, float fVal) { - return self->setPreset(self,fVal); + return self->setPreset(self,fVal); } /*------------------------------------------------------------------------*/ static int SetCounterPresetImpl(pCounter self, float fVal) @@ -588,17 +603,17 @@ static int SetCounterPresetImpl(pCounter self, float fVal) /*------------------------------------------------------------------------*/ float GetCounterPreset(pCounter self) { - return self->getPreset(self); + return self->getPreset(self); } /*------------------------------------------------------------------------*/ float GetControlValue(pCounter self) { - return self->getControlValue(self); + return self->getControlValue(self); } /*------------------------------------------------------------------------*/ static float GetControlValueImpl(pCounter self) { - return self->pDriv->fLastCurrent; + return self->pDriv->fLastCurrent; } /*------------------------------------------------------------------------*/ static float GetCounterPresetImpl(pCounter self) @@ -619,7 +634,7 @@ static float GetCounterPresetImpl(pCounter self) /*-----------------------------------------------------------------------*/ long GetCounts(pCounter self, SConnection * pCon) { - return self->getCounts(self, pCon); + return self->getCounts(self, pCon); } /*-----------------------------------------------------------------------*/ static long GetCountsImpl(pCounter self, SConnection * pCon) @@ -628,12 +643,12 @@ static long GetCountsImpl(pCounter self, SConnection * pCon) if (!self->isUpToDate) { self->pCountInt->TransferData(self, pCon); } - return self->pDriv->lCounts[0]; + return self->pDriv->lCounts[self->pDriv->iControlMonitor]; } /*------------------------------------------------------------------------*/ long GetMonitor(pCounter self, int iNum, SConnection * pCon) { - return self->getMonitor(self, iNum, pCon); + return self->getMonitor(self, iNum, pCon); } /*------------------------------------------------------------------------*/ static long GetMonitorImpl(pCounter self, int iNum, SConnection * pCon) @@ -643,7 +658,7 @@ static long GetMonitorImpl(pCounter self, int iNum, SConnection * pCon) if (!self->isUpToDate) { self->pCountInt->TransferData(self, pCon); } - if ((iNum < 0) || (iNum > self->pDriv->iNoOfMonitors)) { + if ((iNum < 0) || (iNum >= self->pDriv->iNoOfMonitors)) { return -1L; } else { return self->pDriv->lCounts[iNum]; @@ -652,7 +667,7 @@ static long GetMonitorImpl(pCounter self, int iNum, SConnection * pCon) /*-----------------------------------------------------------------------*/ void SetMonitorValue(pCounter self, int index, long value) { - return self->setMonitor(self, index, value); + return self->setMonitor(self, index, value); } /*-----------------------------------------------------------------------*/ static void SetMonitorValueImpl(pCounter self, int index, long value) @@ -666,7 +681,7 @@ static void SetMonitorValueImpl(pCounter self, int index, long value) /*------------------------------------------------------------------------*/ float GetCountTime(pCounter self, SConnection * pCon) { - return self->getTime(self, pCon); + return self->getTime(self, pCon); } /*------------------------------------------------------------------------*/ static float GetCountTimeImpl(pCounter self, SConnection * pCon) @@ -814,7 +829,9 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, {"send", 0, {0, 0}}, {"setpar", 3, {FUPATEXT, FUPAINT, FUPAFLOAT}}, {"getpar", 2, {FUPATEXT, FUPAOPT}}, - {"getnmon", 0, {0, 0}} + {"getnmon",0,{0,0}}, + {"getchannel",0,{0}}, + {"setchannel",1,{FUPAINT}} }; char *pMode[] = { "timer", @@ -831,7 +848,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, argtolower(argc, argv); argx = &argv[1]; iRet = - EvaluateFuPa((pFuncTemplate) & ActionTemplate, 23, argc - 1, argx, + EvaluateFuPa((pFuncTemplate) & ActionTemplate, 25, argc - 1, argx, &PaRes); if (iRet < 0) { snprintf(pBueffel, 255,"%s", PaRes.pError); @@ -1126,7 +1143,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, PaRes.Arg[1].iVal, &fVal); if (iRet == 1) { snprintf(pBueffel,255, "%s.%s %d = %f", argv[0], PaRes.Arg[0].text, - PaRes.Arg[1].iVal, fVal); + PaRes.Arg[1].text, fVal); SCWrite(pCon, pBueffel, eValue); return 1; } else { @@ -1138,6 +1155,20 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData, case 22: /* getnmon */ snprintf(pBueffel, 131, "%s.getnmon = %d", argv[0], GetNMonitor(self)); SCWrite(pCon, pBueffel, eValue); + return 1; + break; + case 23: /* getchannel */ + snprintf(pBueffel,131,"%s.getchannel = %d", argv[0], GetControlMonitor(self)); + SCWrite(pCon,pBueffel,eValue); + return 1; + break; + case 24: /* setchannel */ + if (SetControlMonitor(self, PaRes.Arg[0].iVal)) { + return 1; + } else { + SCWrite(pCon,"ERROR: Invalid channel id",eError); + return 0; + } break; default: assert(0); /* internal error */ diff --git a/counter.h b/counter.h index b69573ca..55264363 100644 --- a/counter.h +++ b/counter.h @@ -63,6 +63,8 @@ float GetControlValue(pCounter self); long GetCounts(pCounter self, SConnection * pCon); long GetMonitor(pCounter self, int iNum, SConnection * pCon); int GetNMonitor(pCounter self); +int GetControlMonitor(pCounter self); +int SetControlMonitor(pCounter self, int channel); void SetMonitorValue(pCounter self, int index, long value); float GetCountTime(pCounter self, SConnection * pCon);