/* * file: todCheckSub.c * purpose: subroutine to compare remote IOC time of date with * local IOCManager sioc time of date * * created: 12-Oct-2009 * * revision history: * 12-Sep-2009 Sonya Hoobler initial version * * remarks: * Read in two time of date strings * Use strptime function to convert to tm struct * Convert each TOD to seconds since 1900 * Take difference of the two * diff = absolute value of difference * Copy diff to VALA * If -10 #include /* for calloc */ #include /* for DBADDR */ #include #include #include #include /* for struct aSubRecord */ #include #include long TODCheck(struct aSubRecord *psub) { char a[20]; /* Time of date strings */ char b[20]; struct tm tma; struct tm tmb; long asec; /* TOD converted to seconds since 1900 */ long bsec; long diff; long c; if( psub == NULL) return 0; strcpy(a,(char *)psub->a); strcpy(b,(char *)psub->b); *((epicsInt32 *)(psub->vala)) = 0; *((epicsInt32 *)(psub->valb)) = 0; if (strcmp(b,"") == 0) return 0; /* Read TOD string into tm struct */ if (!strptime(a,"%m/%d/%Y %H:%M:%S",&tma)) return 0; if (!strptime(b,"%m/%d/%Y %H:%M:%S",&tmb)) return 0; /* Convert to seconds since 1900 */ asec = ((((365*tma.tm_year)+(tma.tm_yday))*24 + tma.tm_hour)*60 + tma.tm_min)*60 + tma.tm_sec; bsec = ((((365*tmb.tm_year)+(tmb.tm_yday))*24 + tmb.tm_hour)*60 + tmb.tm_min)*60 + tmb.tm_sec; diff = bsec-asec; /* Copy diff to VALA */ *((epicsInt32 *)(psub->vala)) = diff; c = *((epicsInt32 *)(psub->c)); if (abs(diff) < c ) *((epicsInt32 *)(psub->valb)) = 1; else *((epicsInt32 *)(psub->valb)) = 0; return 0; } epicsRegisterFunction(TODCheck);