void otapi_log(ot_u8 subcode, ot_int length, ot_u8* data) { /// Log raw data that is able to fit in the MPipe output queue. if (otapi_log_header(subcode, length)) { q_writestring(mpipe.alp.outq, data, length); mpipe_send(); } }
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; }
void otapi_log_msg(logmsg_type logcmd, ot_int label_len, ot_int data_len, ot_u8* label, ot_u8* data) { /// Log a "Message" if it fits in the MPipe output queue. A "Message" is a /// text label, plus a space, plus a data payload. The client should know how /// to read-back Message data. Check here for more information about messages: /// http://www.indigresso.com/wiki/doku.php?id=opentag:otlib:logger ot_int payload_length = label_len + 1 + data_len; //q_empty(mpipe.alp.outq); if (otapi_log_header(logcmd, payload_length)) { sub_logmsg(label_len, data_len, label, data); mpipe_send(); } }
void otapi_log_hexmsg(ot_int label_len, ot_int data_len, ot_u8* label, ot_u8* data) { /// This creates a "Message" (see otapi_log_msg()) in utf-8 text that includes /// binary data that has been converted to hex on the server side. It is more /// efficient to use otapi_log_msg() with a client that understands Message /// formatting, but if you don't have one of those, this function works. ot_int payload_length = label_len + 1 + (data_len<<1); if (otapi_log_header(7, payload_length)) { q_writestring(mpipe.alp.outq, label, label_len); q_writebyte(mpipe.alp.outq, ' '); payload_length = otutils_bin2hex(data, mpipe.alp.outq->putcursor, data_len); mpipe.alp.outq->putcursor += payload_length; //#mpipe.alp.outq->length += payload_length; mpipe_send(); } }