#include #include #include #include #include #include #include #include /* * This is subroutine will ping device with following parameters * - inpa: device name * - inpb: ping count (-c) * - inpc: ping deadband (-w) */ #define HEAD "ping" #define TAIL " > /dev/null" const char statOK[] = "DEVICE OK\0"; const char statBAD[] = "DEVICE MISSING\0"; static long pingDevice(aSubRecord *paSub) { if(paSub == NULL) return 0; char command[80]; char params[30]; char *device; long *count; long *deadband; memset(command, 0, 80); device = (char *)paSub->a; count = (long *)paSub->b; deadband = (long *)paSub->c; sprintf(params," -c %d -w %d -i 0.3 ", (int)*count, (int)*deadband); strncpy(command, HEAD, strlen(HEAD)); strncat(command, params, strlen(params)); strncat(command, device, strlen(device)); strncat(command, TAIL, strlen(TAIL)); if(system(command) != 0) { time_t now = time(0); char buff[100]; strftime (buff, 100, "%Y-%m-%d %H:%M:%S", localtime (&now)); errlogSevPrintf(errlogMajor,"%s :ERROR: Problem with pinging %s\n",buff,device); paSub->vala = (void *)statBAD; return (-1); } paSub->vala = (void*)statOK; return 0; } epicsRegisterFunction(pingDevice);