4646#define CMD_SET_CUSTOM_VAR 41
4747#define CMD_GET_ADVERT_PATH 42
4848#define CMD_GET_TUNING_PARAMS 43
49+ // NOTE: CMD range 44..49 parked, potentially for WiFi operations
50+ #define CMD_SEND_BINARY_REQ 50
4951
5052#define RESP_CODE_OK 0
5153#define RESP_CODE_ERR 1
9294#define PUSH_CODE_LOG_RX_DATA 0x88
9395#define PUSH_CODE_TRACE_DATA 0x89
9496#define PUSH_CODE_NEW_ADVERT 0x8A
95- #define PUSH_CODE_TELEMETRY_RESPONSE 0x8B
97+ #define PUSH_CODE_BINARY_RESPONSE 0x8B // was 'PUSH_CODE_TELEMETRY_RESPONSE'
9698
9799#define ERR_CODE_UNSUPPORTED_CMD 1
98100#define ERR_CODE_NOT_FOUND 2
@@ -490,11 +492,11 @@ void MyMesh::onContactResponse(const ContactInfo &contact, const uint8_t *data,
490492 memcpy (&out_frame[i], &data[4 ], len - 4 );
491493 i += (len - 4 );
492494 _serial->writeFrame (out_frame, i);
493- } else if (len > 4 && tag == pending_telemetry ) { // check for telemetry response
494- pending_telemetry = 0 ;
495+ } else if (len > 4 && tag == pending_req ) { // check for matching response tag
496+ pending_req = 0 ;
495497
496498 int i = 0 ;
497- out_frame[i++] = PUSH_CODE_TELEMETRY_RESPONSE ;
499+ out_frame[i++] = PUSH_CODE_BINARY_RESPONSE ;
498500 out_frame[i++] = 0 ; // reserved
499501 memcpy (&out_frame[i], contact.id .pub_key , 6 );
500502 i += 6 ; // pub_key_prefix
@@ -566,7 +568,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
566568 _cli_rescue = false ;
567569 offline_queue_len = 0 ;
568570 app_target_ver = 0 ;
569- pending_login = pending_status = pending_telemetry = 0 ;
571+ pending_login = pending_status = pending_req = 0 ;
570572 next_ack_idx = 0 ;
571573 sign_data = NULL ;
572574 dirty_contacts_expiry = 0 ;
@@ -1103,7 +1105,7 @@ void MyMesh::handleCmdFrame(size_t len) {
11031105 if (result == MSG_SEND_FAILED) {
11041106 writeErrFrame (ERR_CODE_TABLE_FULL);
11051107 } else {
1106- pending_telemetry = pending_status = 0 ;
1108+ pending_req = pending_status = 0 ;
11071109 memcpy (&pending_login, recipient->id .pub_key , 4 ); // match this to onContactResponse()
11081110 out_frame[0 ] = RESP_CODE_SENT;
11091111 out_frame[1 ] = (result == MSG_SEND_SENT_FLOOD) ? 1 : 0 ;
@@ -1123,7 +1125,7 @@ void MyMesh::handleCmdFrame(size_t len) {
11231125 if (result == MSG_SEND_FAILED) {
11241126 writeErrFrame (ERR_CODE_TABLE_FULL);
11251127 } else {
1126- pending_telemetry = pending_login = 0 ;
1128+ pending_req = pending_login = 0 ;
11271129 // FUTURE: pending_status = tag; // match this in onContactResponse()
11281130 memcpy (&pending_status, recipient->id .pub_key , 4 ); // legacy matching scheme
11291131 out_frame[0 ] = RESP_CODE_SENT;
@@ -1135,7 +1137,7 @@ void MyMesh::handleCmdFrame(size_t len) {
11351137 } else {
11361138 writeErrFrame (ERR_CODE_NOT_FOUND); // contact not found
11371139 }
1138- } else if (cmd_frame[0 ] == CMD_SEND_TELEMETRY_REQ && len >= 4 + PUB_KEY_SIZE) {
1140+ } else if (cmd_frame[0 ] == CMD_SEND_TELEMETRY_REQ && len >= 4 + PUB_KEY_SIZE) { // can deprecate, in favour of CMD_SEND_BINARY_REQ
11391141 uint8_t *pub_key = &cmd_frame[4 ];
11401142 ContactInfo *recipient = lookupContactByPubKey (pub_key, PUB_KEY_SIZE);
11411143 if (recipient) {
@@ -1145,7 +1147,7 @@ void MyMesh::handleCmdFrame(size_t len) {
11451147 writeErrFrame (ERR_CODE_TABLE_FULL);
11461148 } else {
11471149 pending_status = pending_login = 0 ;
1148- pending_telemetry = tag; // match this in onContactResponse()
1150+ pending_req = tag; // match this in onContactResponse()
11491151 out_frame[0 ] = RESP_CODE_SENT;
11501152 out_frame[1 ] = (result == MSG_SEND_SENT_FLOOD) ? 1 : 0 ;
11511153 memcpy (&out_frame[2 ], &tag, 4 );
@@ -1162,14 +1164,35 @@ void MyMesh::handleCmdFrame(size_t len) {
11621164 sensors.querySensors (0xFF , telemetry);
11631165
11641166 int i = 0 ;
1165- out_frame[i++] = PUSH_CODE_TELEMETRY_RESPONSE ;
1167+ out_frame[i++] = PUSH_CODE_BINARY_RESPONSE ;
11661168 out_frame[i++] = 0 ; // reserved
11671169 memcpy (&out_frame[i], self_id.pub_key , 6 );
11681170 i += 6 ; // pub_key_prefix
11691171 uint8_t tlen = telemetry.getSize ();
11701172 memcpy (&out_frame[i], telemetry.getBuffer (), tlen);
11711173 i += tlen;
11721174 _serial->writeFrame (out_frame, i);
1175+ } else if (cmd_frame[0 ] == CMD_SEND_BINARY_REQ && len >= 2 + PUB_KEY_SIZE) {
1176+ uint8_t *pub_key = &cmd_frame[1 ];
1177+ ContactInfo *recipient = lookupContactByPubKey (pub_key, PUB_KEY_SIZE);
1178+ if (recipient) {
1179+ uint8_t *req_data = &cmd_frame[1 + PUB_KEY_SIZE];
1180+ uint32_t tag, est_timeout;
1181+ int result = sendRequest (*recipient, req_data, len - (1 + PUB_KEY_SIZE), tag, est_timeout);
1182+ if (result == MSG_SEND_FAILED) {
1183+ writeErrFrame (ERR_CODE_TABLE_FULL);
1184+ } else {
1185+ pending_status = pending_login = 0 ;
1186+ pending_req = tag; // match this in onContactResponse()
1187+ out_frame[0 ] = RESP_CODE_SENT;
1188+ out_frame[1 ] = (result == MSG_SEND_SENT_FLOOD) ? 1 : 0 ;
1189+ memcpy (&out_frame[2 ], &tag, 4 );
1190+ memcpy (&out_frame[6 ], &est_timeout, 4 );
1191+ _serial->writeFrame (out_frame, 10 );
1192+ }
1193+ } else {
1194+ writeErrFrame (ERR_CODE_NOT_FOUND); // contact not found
1195+ }
11731196 } else if (cmd_frame[0 ] == CMD_HAS_CONNECTION && len >= 1 + PUB_KEY_SIZE) {
11741197 uint8_t *pub_key = &cmd_frame[1 ];
11751198 if (hasConnectionTo (pub_key)) {
0 commit comments