Merge pull request #2130 from liamcottle/refactor/channel-data
Adjustments to PR #1928 - Custom Group Data
This commit is contained in:
@@ -1107,21 +1107,36 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
uint8_t channel_idx = cmd_frame[i++];
|
||||||
|
uint8_t path_len = cmd_frame[i++];
|
||||||
|
|
||||||
|
// validate path len, allowing 0xFF for flood
|
||||||
|
if (!mesh::Packet::isValidPathLen(path_len) && path_len != OUT_PATH_UNKNOWN) {
|
||||||
|
MESH_DEBUG_PRINTLN("CMD_SEND_CHANNEL_DATA invalid path size: %d", path_len);
|
||||||
|
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse provided path if not flood
|
||||||
|
uint8_t path[MAX_PATH_SIZE];
|
||||||
|
if (path_len != OUT_PATH_UNKNOWN) {
|
||||||
|
i += mesh::Packet::writePath(path, &cmd_frame[i], path_len);
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t data_type = ((uint16_t)cmd_frame[i]) | (((uint16_t)cmd_frame[i + 1]) << 8);
|
uint16_t data_type = ((uint16_t)cmd_frame[i]) | (((uint16_t)cmd_frame[i + 1]) << 8);
|
||||||
i += 2;
|
i += 2;
|
||||||
uint8_t channel_idx = cmd_frame[i++];
|
|
||||||
const uint8_t *payload = &cmd_frame[i];
|
const uint8_t *payload = &cmd_frame[i];
|
||||||
int payload_len = (len > (size_t)i) ? (int)(len - i) : 0;
|
int payload_len = (len > (size_t)i) ? (int)(len - i) : 0;
|
||||||
|
|
||||||
ChannelDetails channel;
|
ChannelDetails channel;
|
||||||
if (!getChannel(channel_idx, channel)) {
|
if (!getChannel(channel_idx, channel)) {
|
||||||
writeErrFrame(ERR_CODE_NOT_FOUND); // bad channel_idx
|
writeErrFrame(ERR_CODE_NOT_FOUND); // bad channel_idx
|
||||||
} else if (data_type == 0) {
|
} else if (data_type == DATA_TYPE_RESERVED) {
|
||||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||||
} else if (payload_len > MAX_CHANNEL_DATA_LENGTH) {
|
} else if (payload_len > MAX_CHANNEL_DATA_LENGTH) {
|
||||||
MESH_DEBUG_PRINTLN("CMD_SEND_CHANNEL_DATA payload too long: %d > %d", payload_len, MAX_CHANNEL_DATA_LENGTH);
|
MESH_DEBUG_PRINTLN("CMD_SEND_CHANNEL_DATA payload too long: %d > %d", payload_len, MAX_CHANNEL_DATA_LENGTH);
|
||||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||||
} else if (sendGroupData(channel.channel, data_type, payload, payload_len)) {
|
} else if (sendGroupData(channel.channel, path, path_len, data_type, payload, payload_len)) {
|
||||||
writeOKFrame();
|
writeOKFrame();
|
||||||
} else {
|
} else {
|
||||||
writeErrFrame(ERR_CODE_TABLE_FULL);
|
writeErrFrame(ERR_CODE_TABLE_FULL);
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ bool BaseChatMesh::sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& chan
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseChatMesh::sendGroupData(mesh::GroupChannel& channel, uint16_t data_type, const uint8_t* data, int data_len) {
|
bool BaseChatMesh::sendGroupData(mesh::GroupChannel& channel, uint8_t* path, uint8_t path_len, uint16_t data_type, const uint8_t* data, int data_len) {
|
||||||
if (data_len < 0) {
|
if (data_len < 0) {
|
||||||
MESH_DEBUG_PRINTLN("sendGroupData: invalid negative data_len=%d", data_len);
|
MESH_DEBUG_PRINTLN("sendGroupData: invalid negative data_len=%d", data_len);
|
||||||
return false;
|
return false;
|
||||||
@@ -502,7 +502,13 @@ bool BaseChatMesh::sendGroupData(mesh::GroupChannel& channel, uint16_t data_type
|
|||||||
MESH_DEBUG_PRINTLN("sendGroupData: unable to create group datagram, data_len=%d", data_len);
|
MESH_DEBUG_PRINTLN("sendGroupData: unable to create group datagram, data_len=%d", data_len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path_len == OUT_PATH_UNKNOWN) {
|
||||||
sendFloodScoped(channel, pkt);
|
sendFloodScoped(channel, pkt);
|
||||||
|
} else {
|
||||||
|
sendDirect(pkt, path, path_len);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public:
|
|||||||
int sendMessage(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& expected_ack, uint32_t& est_timeout);
|
int sendMessage(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& expected_ack, uint32_t& est_timeout);
|
||||||
int sendCommandData(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& est_timeout);
|
int sendCommandData(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& est_timeout);
|
||||||
bool sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& channel, const char* sender_name, const char* text, int text_len);
|
bool sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& channel, const char* sender_name, const char* text, int text_len);
|
||||||
bool sendGroupData(mesh::GroupChannel& channel, uint16_t data_type, const uint8_t* data, int data_len);
|
bool sendGroupData(mesh::GroupChannel& channel, uint8_t* path, uint8_t path_len, uint16_t data_type, const uint8_t* data, int data_len);
|
||||||
int sendLogin(const ContactInfo& recipient, const char* password, uint32_t& est_timeout);
|
int sendLogin(const ContactInfo& recipient, const char* password, uint32_t& est_timeout);
|
||||||
int sendAnonReq(const ContactInfo& recipient, const uint8_t* data, uint8_t len, uint32_t& tag, uint32_t& est_timeout);
|
int sendAnonReq(const ContactInfo& recipient, const uint8_t* data, uint8_t len, uint32_t& tag, uint32_t& est_timeout);
|
||||||
int sendRequest(const ContactInfo& recipient, uint8_t req_type, uint32_t& tag, uint32_t& est_timeout);
|
int sendRequest(const ContactInfo& recipient, uint8_t req_type, uint32_t& tag, uint32_t& est_timeout);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#define TXT_TYPE_PLAIN 0 // a plain text message
|
#define TXT_TYPE_PLAIN 0 // a plain text message
|
||||||
#define TXT_TYPE_CLI_DATA 1 // a CLI command
|
#define TXT_TYPE_CLI_DATA 1 // a CLI command
|
||||||
#define TXT_TYPE_SIGNED_PLAIN 2 // plain text, signed by sender
|
#define TXT_TYPE_SIGNED_PLAIN 2 // plain text, signed by sender
|
||||||
|
#define DATA_TYPE_RESERVED 0x0000 // reserved for future use
|
||||||
#define DATA_TYPE_DEV 0xFFFF // developer namespace for experimenting with group/channel datagrams and building apps
|
#define DATA_TYPE_DEV 0xFFFF // developer namespace for experimenting with group/channel datagrams and building apps
|
||||||
|
|
||||||
class StrHelper {
|
class StrHelper {
|
||||||
|
|||||||
Reference in New Issue
Block a user