ot_bool applet_beacon_discovery() { { //create a new session (it will get copied to session stack) session_tmpl session; session.channel = 0x00; session.flagmask = 0; session.flags = 0; session.subnet = 0; session.subnetmask = 0; session.timeout = 16; otapi_new_session(&session, NULL); } { //open request for broadcast otapi_open_request(ADDR_broadcast, NULL); } { //use a command template for collection of single file from single file search ot_u8 status; command_tmpl command; command.opcode = (ot_u8)CMD_announce_file; command.type = (ot_u8)CMDTYPE_na2p_request; command.extension = (ot_u8)CMDEXT_no_response; otapi_put_command_tmpl(&status, &command); } { //write the dialog information (timeout, channels to use) ot_u8 status; dialog_tmpl dialog; dialog.channels = 0; //use same channel as request for response dialog.timeout = 0; //0 tick response timeout (1 tick = 0,977 ms) otapi_put_dialog_tmpl(&status, &dialog); } { //write the ISF return data (note: use isfcall template) ot_u8 status; isfcall_tmpl isfcall; isfcall.is_series = False; isfcall.isf_id = ISF_ID(network_settings); isfcall.max_return = ISF_LEN(network_settings); isfcall.offset = 0; otapi_put_isf_return(&status, &isfcall); } //Done building command, close the request and send the dialog otapi_close_request(); //otapi_start_dialog(); return True; }
void sub_build_uhfmsg(ot_int* buffer) { /// This is the routine that builds the DASH7 UDP generic protocol message. /// The protocol has data elements marked by a letter (T, V, R, E, D) that /// signify Temperature, Voltage, RSSI (LF), PaLFi wake Event, and RX Data. /// The elements are fixed/known length. session_tmpl s_tmpl; command_tmpl c_tmpl; ot_u8* data_start; ot_u8 status; // Create a new session: you could change these parameters // Use "CHAN1" for odd events, "CHAN2" for even events s_tmpl.channel = (palfi.wake_event & 1) ? ALERT_CHAN1 : ALERT_CHAN2; s_tmpl.subnetmask = 0; // Use default subnet s_tmpl.flagmask = 0; // Use default app-flags s_tmpl.timeout = 10; // Do CSMA for no more than 10 ticks (~10 ms) otapi_new_session(&s_tmpl); // Broadcast request (takes no 2nd argument) otapi_open_request(ADDR_broadcast, NULL); // Insert Transport-Layer headers c_tmpl.type = CMDTYPE_na2p_request; c_tmpl.opcode = CMD_udp_on_file; c_tmpl.extension= CMDEXT_no_response; otapi_put_command_tmpl(&status, &c_tmpl); otapi_put_dialog_tmpl(&status, NULL); // NULL = defaults // UDP Header q_writebyte(&txq, 255); // Source Port: 255 (custom application port) q_writebyte(&txq, 255); // Destination Port (same value) data_start = txq.putcursor; // Place temperature data q_writebyte(&txq, 'T'); q_writeshort(&txq, buffer[0]); // Place Voltage data q_writebyte(&txq, 'V'); q_writeshort(&txq, buffer[1]); // Place RSSI data q_writebyte(&txq, 'R'); q_writestring(&txq, (ot_u8*)&palfi.rssi1, 3); // Place Action data q_writebyte(&txq, 'E'); q_writebyte(&txq, (ot_int)palfi.wake_event); // Dump some received data if (palfi.wake_event) { q_writebyte(&txq, 'D'); q_writestring(&txq, palfi.rxdata, 8); } // Store this information into the Port 255 file for continuous, automated // reporting by DASH7/OpenTag until it is updated next time. The length of // this information is always 23 bytes. { vlFILE* fp; fp = ISF_open_su(255); if (fp != NULL) { vl_store(fp, 23, data_start); vl_close(fp); } } // Finish Message otapi_close_request(); }