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 spirit1_coredump() { ///debugging function to dump-out register values of RF core (not all are used) ot_u8 i = 0; ot_u8 regval; ot_u8 label[] = { 'R', 'E', 'G', '_', 0, 0 }; do { regval = spirit1_read(i); otutils_bin2hex(&label[4], &i, 1); logger_msg(MSG_raw, 6, 1, label, ®val); //mpipedrv_wait(); delay_ms(5); } while (++i != 0); }
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(); } }
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); }
void sys_sig_rfaterminate(ot_int pcode, ot_int scode) { /// Hint: RFxRX_e1 label means the received frame has bad CRC. ot_u8 loglabel[8] = {'R', 'F', 'F', 0, 'X', '_', 0, 0}; ot_u8* logdata; ot_int logdata_len; otapi_led2_off(); //Orange LED off otapi_led1_off(); //Green LED off /// Error Handler: /// <LI> If there is an error code, put the code in the log label. </LI> /// <LI> Else if the code is for RX termination, just return. You can /// comment this and uncomment cases 1 & 2 from the switch block if /// you want to log on RX termination. </LI> /// <LI> Else, the code is for TX or CCA. Append the channel number to /// the log label (in hex) </LI> if (scode < 0) { loglabel[6] = 'e'; loglabel[7] = (ot_int)('0') - scode; } else if (pcode < 3) { return; } else { otutils_bin2hex(&(phymac[0].channel), &loglabel[6], 1); } /// Look at the control code an form the label to reflect the type switch (pcode) { /// RX driver process termination: /// (1) background scan ended, (2) or foreground scan ended //case 1: loglabel[2] = 'B'; //case 2: loglabel[3] = 'R'; // logdata_len = rxq.length; // logdata = rxq.front; // break; /// TX CCA/CSMA driver process termination: /// (3) TX CSMA process ended case 3: loglabel[2] = 'C'; loglabel[3] = 'C'; loglabel[4] = 'A'; logdata_len = 0; logdata = NULL; // suppress compiler warning break; /// TX driver process termination /// Background Flood (4) or Foreground TX (5): turn-on green and log TX case 4: loglabel[2] = 'B'; case 5: loglabel[3] = 'T'; logdata_len = txq.length; logdata = txq.front; break; /// Unknown code, don't log any data default: return; } /// Log in ASCII hex the prepared driver message otapi_log_msg(MSG_raw, 8, logdata_len, loglabel, logdata); }