Skip to content

Commit

Permalink
Merge pull request #2 from lnls-sol/ip-test
Browse files Browse the repository at this point in the history
Ip test
  • Loading branch information
gabrielpreviato authored Oct 7, 2019
2 parents 39fd261 + 0f125a1 commit 4d89c8d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client/castApp/Db/reccaster.db
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ record(mbbi, "$(P)State-Sts") {
field(TWST, "Connecting")
field(THST, "Uploading")
field(FRST, "Done")
field(DESC, "Connection status")
}

record(stringin, "$(P)Msg-I") {
field(DTYP, "RecCaster")
field(PINI, "RUNNING")
field(SCAN, "I/O Intr")
field(DESC, "Connection message")
}

record(stringin, "$(P)Ip-I") {
field(DTYP, "RecCasterIp")
field(PINI, "RUNNING")
field(SCAN, "I/O Intr")
field(DESC, "IP of connected server")
}
33 changes: 33 additions & 0 deletions client/castApp/src/caster.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static void casterThread(void* junk)
caster_t *self=junk;

casterMsg(self, "Starting");
casterIp(self, "0.0.0.0");

while(1) {
int shutdown;
Expand All @@ -49,6 +50,7 @@ static void casterThread(void* junk)

self->current = casterStateListen;
casterMsg(self, "Searching");
casterIp(self, "0.0.0.0");


if(doCasterUDPPhase(self))
Expand Down Expand Up @@ -81,6 +83,8 @@ static void casterThread(void* junk)
char abuf[80];
sockAddrToA(&self->nameserv.sa, abuf, sizeof(abuf));
casterMsg(self, "Connecting to: %s", abuf);
// TODO: HERE
casterIp(self, abuf, abuf);
}

if(!doCasterTCPPhase(self))
Expand All @@ -91,10 +95,12 @@ static void casterThread(void* junk)
char abuf[80];
sockAddrToA(&self->nameserv.sa, abuf, sizeof(abuf));
casterMsg(self, "Lost server: %s", abuf);
casterIp(self, "0.0.0.0");
}
}

casterMsg(self, "Stopping");
casterIp(self, "0.0.0.0");

epicsEventSignal(self->shutdownEvent);
}
Expand All @@ -106,6 +112,13 @@ void casterShowMsgDefault(void* arg, struct _caster_t* self)
errlogMessage("\n");
}

static
void casterShowIpDefault(void* arg, struct _caster_t* self)
{
errlogMessage(self->hostip);
errlogMessage("\n");
}

void casterInit(caster_t *self)
{
memset(self, 0, sizeof(*self));
Expand All @@ -114,6 +127,7 @@ void casterInit(caster_t *self)
self->lock = epicsMutexMustCreate();
self->nextRecID = 1;
self->onmsg = &casterShowMsgDefault;
self->onip = &casterShowIpDefault;
self->current = casterStateInit;
self->timeout = reccastTimeout;

Expand Down Expand Up @@ -172,6 +186,25 @@ void casterMsg(caster_t *self, const char* msg, ...)
(*self->onmsg)(self->arg, self);
}

void casterIp(caster_t *self, const char* msg, ...)
{
int ret;
va_list args;

va_start(args, msg);
ret = epicsVsnprintf(self->hostip, sizeof(self->hostip), msg, args);
va_end(args);

if(ret<0) {
errlogMessage("casterIp failed\n");
return;
}

self->hostip[sizeof(self->hostip)-1] = '\0';

(*self->onip)(self->arg, self);
}

static
ssize_t casterSendRA(caster_t* self, epicsUInt8 type, size_t rid, const char* rtype, const char* rname, const char* rdesc)
{
Expand Down
5 changes: 5 additions & 0 deletions client/castApp/src/caster.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct _caster_t {
void *arg;
int (*getrecords)(void*, struct _caster_t*);
void (*onmsg)(void*, struct _caster_t*);
void (*onip)(void*, struct _caster_t*);

casterState current;

Expand All @@ -59,6 +60,7 @@ typedef struct _caster_t {

int shutdown;
char lastmsg[MAX_STRING_SIZE];
char hostip[MAX_STRING_SIZE];
} caster_t;

epicsShareFunc
Expand All @@ -68,6 +70,9 @@ void casterMsg(caster_t *self, const char* msg, ...) EPICS_PRINTF_STYLE(2,3);

#define ERRRET(VAL, CASTER, ...) do{ casterMsg(CASTER, __VA_ARGS__); return (VAL); }while(0)

epicsShareFunc
void casterIp(caster_t *self, const char* msg, ...) EPICS_PRINTF_STYLE(2,3);

epicsShareFunc
void casterInit(caster_t *self);
epicsShareFunc
Expand Down
19 changes: 19 additions & 0 deletions client/castApp/src/castinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct {
casterState laststate;
int intraccept;
char lastmsg[MAX_STRING_SIZE];
char hostip[MAX_STRING_SIZE];
} dpriv;

static dpriv thepriv;
Expand All @@ -34,6 +35,7 @@ void dsetshowmsg(void* arg, struct _caster_t* self)
epicsMutexMustLock(thepriv.lock);
thepriv.laststate = self->current;
strcpy(thepriv.lastmsg, self->lastmsg);
strcpy(thepriv.hostip, self->hostip);
epicsMutexUnlock(thepriv.lock);
if(thepriv.intraccept)
scanIoRequest(thepriv.scan);
Expand All @@ -56,6 +58,7 @@ static void casthook(initHookState state)

thecaster.getrecords = &casterPushPDB;
thecaster.onmsg = &dsetshowmsg;
thecaster.onip = &dsetshowmsg;

if(casterStart(&thecaster)) {
printf("reccaster failed to start...\n");
Expand All @@ -72,6 +75,7 @@ static void reccasterRegistrar(void)
scanIoInit(&thepriv.scan);
thepriv.laststate=casterStateInit;
strcpy(thepriv.lastmsg, "Initializing");
strcpy(thepriv.hostip, "Initializing");
}

static long init_record(void* prec)
Expand Down Expand Up @@ -103,6 +107,15 @@ static long read_stringin(stringinRecord *prec)
return 0;
}

static long read_stringinip(stringinRecord *prec)
{
epicsMutexMustLock(thepriv.lock);
strncpy(prec->val, thepriv.hostip, sizeof(prec->val));
prec->val[sizeof(prec->val)-1] = '\0';
epicsMutexUnlock(thepriv.lock);
return 0;
}

typedef struct {
dset common;
DEVSUPFUN read;
Expand All @@ -120,12 +133,18 @@ static dset5 devCasterSIMsg = {
(DEVSUPFUN)&read_stringin
};

static dset5 devCasterSIIp = {
DSETCOMMON,
(DEVSUPFUN)&read_stringinip
};

#include <epicsExport.h>

epicsExportAddress(double,reccastTimeout);
epicsExportAddress(double,reccastMaxHoldoff);

epicsExportAddress(dset, devCasterMBBIState);
epicsExportAddress(dset, devCasterSIMsg);
epicsExportAddress(dset, devCasterSIIp);

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")
device(stringin, INST_IO, devCasterSIIp, "RecCasterIp")

0 comments on commit 4d89c8d

Please sign in to comment.