Exemplo n.º 1
0
REAL64 util_attodt(CHAR *string)
{
CHAR copy[COPYBUFLEN];
CHAR *token[6];
INT16 errors, ntoken, yr, da, hr, mn, sc, ms;

/*  Check for special case ("present")  */

    if (strcasecmp(string, "present") == 0) return (double) 2147483647;

/*  Parse (copy of) string  */

    memcpy((void *) copy, (void *) string, (size_t) COPYBUFLEN-1);
    copy[COPYBUFLEN] = 0;

    ntoken = util_parse(copy, token, "-/.:(),;", 6, 0);

    yr = hr = mn = sc = ms = 0; da = 1;

/* Decode the various pieces */

    switch (ntoken) {

      case 6:
        ms = (INT16) atoi(token[5]);
      case 5:
        sc = (INT16) atoi(token[4]);
      case 4:
        mn = (INT16) atoi(token[3]);
      case 3:
        hr = (INT16) atoi(token[2]);
      case 2:
        da = (INT16) atoi(token[1]);
      case 1:
        yr = (INT16) atoi(token[0]) + ((strlen(token[0]) == 2) ? 1900 : 0);
        break;
      default:
        errno = EINVAL;
        return -1.0;
    }

    errors = 0;
    if (yr < 1970)          ++errors;
    if (da < 1 || da > 366) ++errors;
    if (hr < 0 || hr >  23) ++errors;
    if (mn < 0 || mn >  59) ++errors;
    if (sc < 0 || sc >  59) ++errors;
    if (ms < 0 || ms > 999) ++errors;
    
    if (errors) {
        errno = EINVAL;
        return -2.0;
    }

    return util_ydhmsmtod(yr, da, hr, mn, sc, ms);

}
Exemplo n.º 2
0
VOID reftek_com(
    UINT8 *src, UINT16 *exp, UINT16 *unit, UINT16 *seqno, REAL64 *tstamp
) {
UINT16 yr, da, hr, mn, sc, ms, stmp;

    yr = (UINT16) utilBcdToUint32(src + YEAR_OFF,   2, 0); 
    yr += (yr < 88) ? 2000 : 1900;  /* WARNING: fix this before 2099! */

    da = (UINT16) utilBcdToUint32(src + TIME_OFF,   3, 0);
    hr = (UINT16) utilBcdToUint32(src + TIME_OFF+1, 2, 1);
    mn = (UINT16) utilBcdToUint32(src + TIME_OFF+2, 2, 1);
    sc = (UINT16) utilBcdToUint32(src + TIME_OFF+3, 2, 1);
    ms = (UINT16) utilBcdToUint32(src + TIME_OFF+4, 3, 1);

    *exp  = (UINT16) utilBcdToUint32(src + EXPN_OFF,   2, 0); 
	memcpy(&stmp, src + UNIT_OFF, 2);
	*unit = (UINT16) ntohs(stmp);
	
    *seqno  = (UINT16) utilBcdToUint32(src + SEQN_OFF,   4, 0);
    *tstamp = util_ydhmsmtod(yr, da, hr, mn, sc, ms);
}
Exemplo n.º 3
0
BOOL reftek_eh(struct reftek_eh *dest, UINT8 *src)
{
UINT16 srate, yr, da, hr, mn, sc, ms;

/* Load the common header */

    reftek_com(src, &dest->exp, &dest->unit, &dest->seqno, &dest->tstamp);

/* Load the record specific parts */

    dest->evtno  = (UINT16) utilBcdToUint32(src + EVTN_OFF, 4, 0); 
    dest->stream = (UINT16) utilBcdToUint32(src + STRM_OFF, 2, 0);

    switch (utilBcdToUint32(src + FRMT_OFF, 2, 0)) {
      case 16:
        dest->format = REFTEK_F16;
        break;

      case 32:
        dest->format = REFTEK_F32;
        break;

      case 120:
        dest->format = REFTEK_FC0;
        break;

      default:
        errno = EINVAL;
        return FALSE;
    }

    sscanf((char *) (src + SINT_OFF), "%hd", &srate);
    dest->sint = (REAL32) 1.0 / (REAL32) srate;

    if (memcmp(src + TTYP_OFF, "CON", 3) == 0) {
        dest->trgtype = REFTEK_TRGCON;
    } else if (memcmp(src + TTYP_OFF, "CRS", 3) == 0) {
        dest->trgtype = REFTEK_TRGCRS;
    } else if (memcmp(src + TTYP_OFF, "EVT", 3) == 0) {
        dest->trgtype = REFTEK_TRGEVT;
    } else if (memcmp(src + TTYP_OFF, "EXT", 3) == 0) {
        dest->trgtype = REFTEK_TRGEXT;
    } else if (memcmp(src + TTYP_OFF, "LVL", 3) == 0) {
        dest->trgtype = REFTEK_TRGLVL;
    } else if (memcmp(src + TTYP_OFF, "RAD", 3) == 0) {
        dest->trgtype = REFTEK_TRGRAD;
    } else if (memcmp(src + TTYP_OFF, "TIM", 3) == 0) {
        dest->trgtype = REFTEK_TRGTIM;
    } else {
        errno = EINVAL;
        return FALSE;
    }

    sscanf((char *) (src + TRON_OFF), "%4hd%3hd%2hd%2hd%2hd%3hd",
        &yr, &da, &hr, &mn, &sc, &ms
    );
    dest->on = util_ydhmsmtod(yr, da, hr, mn, sc, ms);

    sscanf((char *) (src + TOFS_OFF), "%4hd%3hd%2hd%2hd%2hd%3hd",
        &yr, &da, &hr, &mn, &sc, &ms
    );
    dest->tofs = util_ydhmsmtod(yr, da, hr, mn, sc, ms);

    return TRUE;

}