void applet_send_query(m2session* session) { /// The C-API for building commands can be bypassed in favor of directly /// putting data to the queue. That way is more efficient, but it also requires /// you to know more about DASH7 than just what order the templates should be. /// /// The query that we build will collect sensor configuration data back from /// all devices that support the sensor protocol. Much more interesting queries /// are possible. ot_u8 status; { //open request for single hop anycast query routing_tmpl routing; routing.hop_code = 0; otapi_open_request(ADDR_anycast, &routing); } { //use a command template for collection of single file from single file search command_tmpl command; command.opcode = (ot_u8)CMD_udp_on_file; command.type = (ot_u8)CMDTYPE_na2p_request; command.extension = (ot_u8)CMDEXT_none; otapi_put_command_tmpl(&status, &command); } { //write the dialog information (timeout, channels to use) dialog_tmpl dialog; dialog.channels = 0; //use same channel as request for response dialog.timeout = 0x41; //same as otutils_encode_timeout(512) -- 512 tick response slot otapi_put_dialog_tmpl(&status, &dialog); } { //write the query to search for the sensor protocol id static const ot_u8 query_str[10] = "APP=PongLT"; query_tmpl query; query.code = M2QC_COR_SEARCH + 10; // do a 100% length=10 correlation search query.mask = NULL; // don't do any masking (no partial matching) query.length = 10; // query_str is 10 bytes query.value = (ot_u8*)query_str; otapi_put_query_tmpl(&status, &query); } { //put in the information of the file to search (the user id) isfcomp_tmpl isfcomp; isfcomp.is_series = False; isfcomp.isf_id = ISF_ID(user_id); isfcomp.offset = 0; otapi_put_isf_comp(&status, &isfcomp); } { //put in UDP ports (from 254 to 255) and Ping ID q_writebyte(&txq, 254); q_writebyte(&txq, 255); q_writeshort(&txq, app.pingval); } //Done building command, close the request and send the dialog otapi_close_request(); }
void applet_send_query(m2session* session) { /// The C-API for building commands can be bypassed in favor of directly /// putting data to the queue. That way is more efficient, but it also requires /// you to know more about DASH7 than just what order the templates should be. /// /// The query that we build will collect sensor configuration data back from /// all devices that support the sensor protocol. Much more interesting queries /// are possible. { //open request for single hop anycast query routing_tmpl routing; routing.hop_code = 0; otapi_open_request(ADDR_anycast, &routing); } { //use a command template for collection of single file from single file search ot_u8 status; command_tmpl command; command.opcode = (ot_u8)CMD_collect_file_on_file; command.type = (ot_u8)CMDTYPE_na2p_request; command.extension = (ot_u8)CMDEXT_none; 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 = 512; //512 tick response timeout (1 tick = 0,977 ms) otapi_put_dialog_tmpl(&status, &dialog); } { //write the query to search for the sensor protocol id query_tmpl query; ot_u8 status; ot_u8 protocol_id; protocol_id = 0x02; // sensor protocol id = 0x02 query.code = M2QC_COR_SEARCH | 1; // do a 100% length=1 correlation search query.mask = NULL; // don't do any masking (no partial matching) query.length = 1; // look for one byte (0x02) query.value = &protocol_id; // (query.value is a string) otapi_put_query_tmpl(&status, &query); } { //put in the information of the file to search (the protocol list) ot_u8 status; isfcomp_tmpl isfcomp; isfcomp.is_series = False; isfcomp.isf_id = ISF_ID(protocol_list); isfcomp.offset = 0; otapi_put_isf_comp(&status, &isfcomp); } { //put in the information of the file to return (the sensor list) ot_u8 status; isfcall_tmpl isfcall; isfcall.is_series = False; isfcall.isf_id = ISF_ID(sensor_list); isfcall.max_return = 32; isfcall.offset = 0; otapi_put_isf_call(&status, &isfcall); } //Done building command, close the request and send the dialog otapi_close_request(); }