Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions client/castApp/src/castinit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

#include <osiSock.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand All @@ -10,6 +12,8 @@
#include <iocsh.h>
#include <errlog.h>

#include <epicsStdio.h>
#include <drvSup.h>
#include <devSup.h>
#include <dbScan.h>
#include <stringinRecord.h>
Expand All @@ -25,6 +29,7 @@ typedef struct {
epicsMutexId lock;
IOSCANPVT scan;
casterState laststate;
osiSockAddr lastserv;
int intraccept;
char lastmsg[MAX_STRING_SIZE];
} dpriv;
Expand All @@ -36,6 +41,7 @@ void dsetshowmsg(void* arg, struct _caster_t* self)
{
epicsMutexMustLock(thepriv.lock);
thepriv.laststate = self->current;
memcpy(&thepriv.lastserv, &self->nameserv, sizeof(self->nameserv));
strcpy(thepriv.lastmsg, self->lastmsg);
epicsMutexUnlock(thepriv.lock);
if(thepriv.intraccept)
Expand Down Expand Up @@ -212,6 +218,48 @@ static void reccasterRegistrar(void)
iocshRegister(&addReccasterEnvVarsFuncDef,addReccasterEnvVarsCallFunc);
}

static long drv_report(int lvl)
{
casterState laststate;
const char * lastname = "UNKNOWN";
char lastmsg[MAX_STRING_SIZE] = "";
osiSockAddr lastserv;

epicsMutexMustLock(thepriv.lock);
switch(laststate = thepriv.laststate) {
#define CASE(NAME) case casterState ## NAME : lastname = #NAME ; break
CASE(Init);
CASE(Listen);
CASE(Connect);
CASE(Upload);
CASE(Done);
#undef CASE
}
memcpy(lastmsg, thepriv.lastmsg, sizeof(thepriv.lastmsg));
lastmsg[sizeof(lastmsg)-1] = '\0';
memcpy(&lastserv, &thepriv.lastserv, sizeof(thepriv.lastserv));
epicsMutexUnlock(thepriv.lock);

printf(" State: %s\n", lastname);
printf(" Msg: %s\n", lastmsg);

// reuse char buffer
ipAddrToDottedIP(&lastserv.ia, lastmsg, sizeof(lastmsg));
lastmsg[sizeof(lastmsg)-1] = '\0';

switch(laststate) {
case casterStateConnect:
case casterStateUpload:
case casterStateDone:
printf(" Server: %s\n", lastname);
break;
default:
break;
}

return 0;
}

static long init_record(void* prec)
{
return 0;
Expand Down Expand Up @@ -241,6 +289,12 @@ static long read_stringin(stringinRecord *prec)
return 0;
}

static drvet drvCaster = {
2,
(DRVSUPFUN)drv_report,
NULL,
};

typedef struct {
dset common;
DEVSUPFUN read;
Expand All @@ -266,4 +320,6 @@ epicsExportAddress(double,reccastMaxHoldoff);
epicsExportAddress(dset, devCasterMBBIState);
epicsExportAddress(dset, devCasterSIMsg);

epicsExportAddress(drvet, drvCaster);

epicsExportRegistrar(reccasterRegistrar);
1 change: 1 addition & 0 deletions client/castApp/src/reccaster.dbd
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ variable(reccastTimeout,double)
variable(reccastMaxHoldoff,double)
device(mbbi, INST_IO, devCasterMBBIState, "RecCaster")
device(stringin, INST_IO, devCasterSIMsg, "RecCaster")
driver(drvCaster)
Loading