예제 #1
0
BOOL rtp_want(RTP *rtp, UINT8 *pkt)
{
UINT16 exp, type, unit, seqno, stream;
REAL64 tstamp;

/* If we've requested everything, then we don't even check.
 * This means garbage can go through, but one man's garbage
 * is another man's data.
 */

    if (rtp->attr.at_pmask == RTP_PMASK_ALL) return TRUE;

/* Now, see if it is a desired type */

    type = reftek_type(pkt);
    if ((rtp->attr.at_pmask & type) == 0) return FALSE;

/* We have no knowledge of the contents of special packet, so if this
 * is one and we want them then we get them all.  Note that from our
 * point of view, "special" and "command" packets are both "special".
 */

    if (type == RTP_PMASK_SPEC) return TRUE;

/* If we don't have UNIT id filtering in place then we are done */

    if (rtp->attr.at_dasid == 0) return TRUE;

/* Decode the common header to see if this is from the desired unit */

    reftek_com(pkt, &exp, &unit, &seqno, &tstamp);
    if (unit != rtp->attr.at_dasid) return FALSE;

/* Only stream filtering remains, so if this isn't a DT packet we're done */

    if (type != RTP_PMASK_DT) return TRUE;

/* We are going to "cheat" and decode the stream id here, instead of
 * via the reftek_dt library routine.  This is for efficiency, since
 * the library routine also deals with the data part, which we are not
 * interested in here.
 */

    stream = (UINT16) utilBcdToUint32(pkt + STRM_OFF, 2, 0);
    return ((rtp->attr.at_smask & (1 << stream)) == 0) ? FALSE : TRUE;
}
예제 #2
0
파일: com.c 프로젝트: Fran89/seiscomp3
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);
}
예제 #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;

}