sort of working
r1049 | dcl | 2006-08-09 12:03:55 +1000 (Wed, 09 Aug 2006) | 2 lines
This commit is contained in:
@@ -70,8 +70,28 @@ typedef struct {
|
||||
int iPort;
|
||||
float dummy_threshold;
|
||||
struct { int length; char body[8192]; } buffer;
|
||||
unsigned long long counter_value;
|
||||
} BeamMon, *pBeamMon;
|
||||
|
||||
|
||||
static void flog(char flag, char* pText) {
|
||||
FILE* file;
|
||||
file = fopen("flog.txt", "a");
|
||||
if (file) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
fprintf(file, "%02d:%02d:%02d:%06d::%c::%s",
|
||||
tv.tv_sec % (24 * 3600) / 3600,
|
||||
tv.tv_sec % (3600) / 60,
|
||||
tv.tv_sec % 60,
|
||||
tv.tv_usec,
|
||||
flag,
|
||||
pText);
|
||||
if (strchr(pText, '\n') == NULL)
|
||||
fputc('\n', file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
/** \brief Writes a line to the Monitor
|
||||
* used for sending commands.
|
||||
*
|
||||
@@ -86,6 +106,8 @@ static int MonWrite(pBeamMon self, char* text) {
|
||||
int status;
|
||||
|
||||
len = strlen(text);
|
||||
if (len > 0)
|
||||
flog('>', text);
|
||||
|
||||
/*@+matchanyintegral@ let size_t from strlen match int */
|
||||
status = writeRS232(self->controller, text, len);
|
||||
@@ -97,12 +119,25 @@ static int MonWrite(pBeamMon self, char* text) {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static int MonHandleInput(pBeamMon self, int timeout) {
|
||||
static void HandleReport(CounterDriver *cntrData)
|
||||
{
|
||||
//REPORT 01:45:11.021097 29798167
|
||||
//0123456789012345678901234567890
|
||||
BeamMon* self = NULL;
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
/* TODO better than this */
|
||||
self->counter_value = strtoull(&self->buffer.body[22], NULL, 10);
|
||||
}
|
||||
|
||||
static int MonHandleInput(CounterDriver *cntrData, int timeout) {
|
||||
BeamMon* self = NULL;
|
||||
int iRet, len;
|
||||
int iLen = 0;
|
||||
int jLen = 0;
|
||||
char reply[1024];
|
||||
char* pTerm;
|
||||
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
while (availableRS232(self->controller)) {
|
||||
len = sizeof(reply);
|
||||
iRet = readRS232(self->controller, reply, &len);
|
||||
@@ -125,7 +160,27 @@ static int MonHandleInput(pBeamMon self, int timeout) {
|
||||
if (pTerm)
|
||||
{
|
||||
/* TODO handle the line */
|
||||
fputs(self->buffer.body, stderr);
|
||||
flog('<', self->buffer.body);
|
||||
const char et[] = "EVENT TERMINAL";
|
||||
if (strncasecmp(self->buffer.body, et, sizeof(et) - 1) == 0) {
|
||||
if (self->state == HWBusy)
|
||||
self->state = HWIdle;
|
||||
}
|
||||
const char eri[] = "EVENT RANGE IN";
|
||||
if (strncasecmp(self->buffer.body, eri, sizeof(eri) - 1) == 0)
|
||||
if (self->state == HWPause)
|
||||
self->state = HWBusy;
|
||||
const char ero[] = "EVENT RANGE OUT";
|
||||
if (strncasecmp(self->buffer.body, ero, sizeof(ero) - 1) == 0)
|
||||
if (self->state == HWBusy)
|
||||
self->state = HWPause;
|
||||
const char rpt[] = "REPORT";
|
||||
if (strncasecmp(self->buffer.body, rpt, sizeof(rpt) - 1) == 0) {
|
||||
if (self->state == HWBusy)
|
||||
HandleReport(cntrData);
|
||||
else if (self->state == HWIdle)
|
||||
MonWrite(self, "SICS REPORT OFF");
|
||||
}
|
||||
self->buffer.length = 0;
|
||||
}
|
||||
}
|
||||
@@ -149,7 +204,11 @@ static int MonGetStatus(CounterDriver *cntrData, float *fControl) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
MonHandleInput(self, 0);
|
||||
MonHandleInput(cntrData, 0);
|
||||
if (cntrData->eMode == eTimer)
|
||||
*fControl = cntrData->fTime;
|
||||
else
|
||||
*fControl = cntrData->fLastCurrent;
|
||||
switch (self->state) {
|
||||
case HWIdle:
|
||||
return HWIdle;
|
||||
@@ -171,8 +230,26 @@ static int MonGetStatus(CounterDriver *cntrData, float *fControl) {
|
||||
*/
|
||||
static int MonStart(CounterDriver *cntrData) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
char str[100];
|
||||
snprintf(str, sizeof(str), "START %s, %f, %f, %f\n",
|
||||
cntrData->eMode == eTimer ? "eTimer" :
|
||||
cntrData->eMode == ePreset ? "ePreset" : "Unknown",
|
||||
cntrData->fPreset,
|
||||
cntrData->fLastCurrent,
|
||||
cntrData->fTime);
|
||||
flog('.', str);
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
if (cntrData->eMode == eTimer) {
|
||||
MonWrite(self, "SICS SET TE_CHECK=TIMER");
|
||||
} else {
|
||||
MonWrite(self, "SICS SET TE_CHECK=COUNTER");
|
||||
}
|
||||
snprintf(str, sizeof(str), "SICS SET TERMINAL=%llu",
|
||||
(unsigned long long) cntrData->fPreset);
|
||||
MonWrite(self, str);
|
||||
MonWrite(self, "SICS START");
|
||||
MonWrite(self, "SICS REPORT ON");
|
||||
self->state = HWBusy;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -184,6 +261,8 @@ static int MonPause(CounterDriver *cntrData) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
MonWrite(self, "PAUSE");
|
||||
self->state = HWPause;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -195,6 +274,8 @@ static int MonContinue(CounterDriver *cntrData) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
MonWrite(self, "CONTINUE");
|
||||
self->state = HWBusy;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -205,6 +286,8 @@ static int MonHalt(CounterDriver *cntrData) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
MonWrite(self, "STOP");
|
||||
self->state = HWBusy;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -215,7 +298,9 @@ static int MonHalt(CounterDriver *cntrData) {
|
||||
static int MonReadValues(CounterDriver *cntrData) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
flog('.', "MonReadValues");
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
/* TODO*/
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -229,7 +314,9 @@ static int MonReadValues(CounterDriver *cntrData) {
|
||||
static int MonGetError(CounterDriver *cntrData, int *iCode, char *error, int iErrLen) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
flog('.', "MonGetError");
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
/* TODO*/
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -244,6 +331,7 @@ static int MonGetError(CounterDriver *cntrData, int *iCode, char *error, int iEr
|
||||
static int MonTryAndFixIt(CounterDriver *cntrData, int iCode) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
flog('.', "MonTryAndFixIt");
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
assert(self != NULL);
|
||||
|
||||
@@ -251,6 +339,7 @@ static int MonTryAndFixIt(CounterDriver *cntrData, int iCode) {
|
||||
case NOTCONNECTED:
|
||||
initRS232(self->controller);
|
||||
return COREDO;
|
||||
/* TODO*/
|
||||
}
|
||||
return COTERM;
|
||||
}
|
||||
@@ -261,14 +350,18 @@ static int MonTryAndFixIt(CounterDriver *cntrData, int iCode) {
|
||||
* \param *name the name of the parameter to set.
|
||||
* \param iCter counter to set
|
||||
*/
|
||||
static int MonSet(CounterDriver *cntrData, char *name, int iCter, float FVal) {
|
||||
static int MonSet(CounterDriver *cntrData, char *name, int iCter, float fVal) {
|
||||
BeamMon *self = NULL;
|
||||
char str[100];
|
||||
snprintf(str, 100, "MonSet(%s, %d, %f)", name, iCter, fVal);
|
||||
flog('.', str);
|
||||
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
if(strcmp(name,"threshold") == 0){
|
||||
//TODO set threshold
|
||||
self->dummy_threshold = FVal;
|
||||
self->dummy_threshold = fVal;
|
||||
}
|
||||
/* TODO*/
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -276,11 +369,15 @@ static int MonGet(CounterDriver *cntrData, char *name, int iCter, float *fVal) {
|
||||
BeamMon *self = NULL;
|
||||
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
if(strcmp(name,"threshold") == 0){
|
||||
if(strcasecmp(name,"threshold") == 0){
|
||||
//TODO get threshold
|
||||
*fVal = self->dummy_threshold;
|
||||
}
|
||||
/* TODO*/
|
||||
|
||||
char str[100];
|
||||
snprintf(str, 100, "MonGet(%s, %d, %f)", name, iCter, *fVal);
|
||||
flog('.', str);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -288,6 +385,9 @@ static int MonSend(CounterDriver *cntrData, char *pText, char *pReply, int iRepl
|
||||
BeamMon *self = NULL;
|
||||
|
||||
self = (BeamMon *) cntrData->pData;
|
||||
MonWrite(self, pText);
|
||||
/* TODO*/
|
||||
snprintf(pReply, iReplyLen, "MonSend Response\r\n");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -297,6 +397,7 @@ static void KillMon(pCounterDriver cntrData) {
|
||||
if (self) {
|
||||
if (self->host)
|
||||
free(self->host);
|
||||
/* TODO*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,6 +469,7 @@ static void KillMon(pCounterDriver cntrData) {
|
||||
pCntDriv->TryAndFixIt = MonTryAndFixIt;
|
||||
pCntDriv->Set = MonSet;
|
||||
pCntDriv->Get = MonGet;
|
||||
pCntDriv->Send = MonSend;
|
||||
|
||||
pCntDriv->iNoOfMonitors = 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user