Beispiel #1
0
ot_bool m2qp_sig_udp(ot_u8 srcport, ot_u8 dstport, id_tmpl* user_id) {
    static const char* label[]  = { "PongID: ", ", RSSI: ", ", Link: " };
    ot_u16  pongval;
    ot_u8   i;
    ot_u8   scratch;

    //1. Read the PONG VAL
    pongval = q_readshort(&rxq);

    // Request: Copy PING VAL to PONG
    if (dstport == 254) {
        q_writeshort(&txq, pongval);
        return True;
    }

#   if defined(BOARD_eZ430Chronos)
    // Chronos doesn't have a normal MPipe, so print-out responses on the LCD
    
#   else
    // Response: Compare PING Val to PONG Val and write output to MPipe
    if ((dstport == 255) && (app.pingval == pongval)) {
        // Prepare logging header: UTF8 (text log) is subcode 1, dummy length is 0
        otapi_log_header(1, 0);
        
        // Print out the three parameters for PongLT, one at a time.
        // If you are new to OpenTag, this is a common example of a state-
        // based code structure JP likes to use.
        i = 0;
        while (1) {
            q_writestring(mpipe.alp.outq, (ot_u8*)label[i], 8);
            switch (i++) {
                case 0: scratch = otutils_bin2hex(  mpipe.alp.outq->putcursor, 
                                                    user_id->value,
                                                    user_id->length     );
                        break;
                
                case 1: scratch = otutils_int2dec(mpipe.alp.outq->putcursor, radio.last_rssi);
                        break;
                        
                case 2: scratch = otutils_int2dec(mpipe.alp.outq->putcursor, dll.last_nrssi);
                        break;
                        
                case 3: goto m2qp_sig_udp_PRINTDONE;
            }
            
            mpipe.alp.outq->putcursor  += scratch;
            mpipe.alp.outq->length     += scratch;
        }

        // Close the log file, send it out, return success
        m2qp_sig_udp_PRINTDONE:
        otapi_log_direct();
        return True;
    }
#   endif

    return False;
}
Beispiel #2
0
ot_int slistf(ot_u8* dst, const char* label, char format, ot_u8 number, ot_u8* src) {
    ot_u8* scratch;
    ot_u8* dst_start;
    ot_int inc;

    dst_start   = dst;
    scratch     = (ot_u8*)label;
    while (*scratch != 0) {
        *dst++ = *scratch++;
    }

    if (format == 'x') {
        dst += otutils_bin2hex((ot_u8*)src, dst, number);
        goto slistf_END;
    }

    inc = (format == 'b') - (format == 's');

    if (inc != 0) {
        ot_uni16 value;
        while (number > 0) {
            number--;
            if (inc > 0) {
                value.sshort = (ot_int)*((ot_s8*)src);
            }
            else {
                value.ubyte[1] = *src++;
                value.ubyte[0] = *src;
            }
            src++;
            dst += otutils_int2dec(dst, value.sshort);
        }
    }

    else {
        *dst++ = ' ';
        memcpy(dst, src, number);
        dst += number;
    }

    slistf_END:
    return (ot_int)(dst - dst_start);
}