minor refactor

This commit is contained in:
Scott Powell
2025-04-11 19:11:06 +10:00
parent 4704ea8dae
commit 1d4ae9f3c4
3 changed files with 23 additions and 23 deletions

View File

@@ -101,11 +101,11 @@ void Dispatcher::checkRecv() {
#endif
pkt->header = raw[i++];
if (pkt->hasTransCodes()) {
memcpy(&pkt->trans_codes[0], &raw[i], 2); i += 2;
memcpy(&pkt->trans_codes[1], &raw[i], 2); i += 2;
if (pkt->hasTransportCodes()) {
memcpy(&pkt->transport_codes[0], &raw[i], 2); i += 2;
memcpy(&pkt->transport_codes[1], &raw[i], 2); i += 2;
} else {
pkt->trans_codes[0] = pkt->trans_codes[1] = 0;
pkt->transport_codes[0] = pkt->transport_codes[1] = 0;
}
pkt->path_len = raw[i++];
@@ -218,9 +218,9 @@ void Dispatcher::checkSend() {
raw[len++] = NODE_ID;
#endif
raw[len++] = outbound->header;
if (outbound->hasTransCodes()) {
memcpy(&raw[len], &outbound->trans_codes[0], 2); len += 2;
memcpy(&raw[len], &outbound->trans_codes[1], 2); len += 2;
if (outbound->hasTransportCodes()) {
memcpy(&raw[len], &outbound->transport_codes[0], 2); len += 2;
memcpy(&raw[len], &outbound->transport_codes[1], 2); len += 2;
}
raw[len++] = outbound->path_len;
memcpy(&raw[len], outbound->path, outbound->path_len); len += outbound->path_len;

View File

@@ -11,7 +11,7 @@ Packet::Packet() {
}
int Packet::getRawLength() const {
return 2 + path_len + payload_len + (hasTransCodes() ? 4 : 0);
return 2 + path_len + payload_len + (hasTransportCodes() ? 4 : 0);
}
void Packet::calculatePacketHash(uint8_t* hash) const {
@@ -28,9 +28,9 @@ void Packet::calculatePacketHash(uint8_t* hash) const {
uint8_t Packet::writeTo(uint8_t dest[]) const {
uint8_t i = 0;
dest[i++] = header;
if (hasTransCodes()) {
memcpy(&dest[i], &trans_codes[0], 2); i += 2;
memcpy(&dest[i], &trans_codes[1], 2); i += 2;
if (hasTransportCodes()) {
memcpy(&dest[i], &transport_codes[0], 2); i += 2;
memcpy(&dest[i], &transport_codes[1], 2); i += 2;
}
dest[i++] = path_len;
memcpy(&dest[i], path, path_len); i += path_len;
@@ -41,11 +41,11 @@ uint8_t Packet::writeTo(uint8_t dest[]) const {
bool Packet::readFrom(const uint8_t src[], uint8_t len) {
uint8_t i = 0;
header = src[i++];
if (hasTransCodes()) {
memcpy(&trans_codes[0], &src[i], 2); i += 2;
memcpy(&trans_codes[1], &src[i], 2); i += 2;
if (hasTransportCodes()) {
memcpy(&transport_codes[0], &src[i], 2); i += 2;
memcpy(&transport_codes[1], &src[i], 2); i += 2;
} else {
trans_codes[0] = trans_codes[1] = 0;
transport_codes[0] = transport_codes[1] = 0;
}
path_len = src[i++];
if (path_len > sizeof(path)) return false; // bad encoding

View File

@@ -11,10 +11,10 @@ namespace mesh {
#define PH_VER_SHIFT 6
#define PH_VER_MASK 0x03 // 2-bits
#define ROUTE_TYPE_TRANS_FLOOD 0x00 // flood mode + transport codes
#define ROUTE_TYPE_FLOOD 0x01 // flood mode, needs 'path' to be built up (max 64 bytes)
#define ROUTE_TYPE_DIRECT 0x02 // direct route, 'path' is supplied
#define ROUTE_TYPE_TRANS_DIRECT 0x03 // direct route + transport codes
#define ROUTE_TYPE_TRANSPORT_FLOOD 0x00 // flood mode + transport codes
#define ROUTE_TYPE_FLOOD 0x01 // flood mode, needs 'path' to be built up (max 64 bytes)
#define ROUTE_TYPE_DIRECT 0x02 // direct route, 'path' is supplied
#define ROUTE_TYPE_TRANSPORT_DIRECT 0x03 // direct route + transport codes
#define PAYLOAD_TYPE_REQ 0x00 // request (prefixed with dest/src hashes, MAC) (enc data: timestamp, blob)
#define PAYLOAD_TYPE_RESPONSE 0x01 // response to REQ or ANON_REQ (prefixed with dest/src hashes, MAC) (enc data: timestamp, blob)
@@ -43,7 +43,7 @@ public:
uint8_t header;
uint16_t payload_len, path_len;
uint16_t trans_codes[2];
uint16_t transport_codes[2];
uint8_t path[MAX_PATH_SIZE];
uint8_t payload[MAX_PACKET_PAYLOAD];
int8_t _snr;
@@ -59,10 +59,10 @@ public:
*/
uint8_t getRouteType() const { return header & PH_ROUTE_MASK; }
bool isRouteFlood() const { return getRouteType() == ROUTE_TYPE_FLOOD || getRouteType() == ROUTE_TYPE_TRANS_FLOOD; }
bool isRouteDirect() const { return getRouteType() == ROUTE_TYPE_DIRECT || getRouteType() == ROUTE_TYPE_TRANS_DIRECT; }
bool isRouteFlood() const { return getRouteType() == ROUTE_TYPE_FLOOD || getRouteType() == ROUTE_TYPE_TRANSPORT_FLOOD; }
bool isRouteDirect() const { return getRouteType() == ROUTE_TYPE_DIRECT || getRouteType() == ROUTE_TYPE_TRANSPORT_DIRECT; }
bool hasTransCodes() const { return getRouteType() == ROUTE_TYPE_TRANS_FLOOD || getRouteType() == ROUTE_TYPE_TRANS_DIRECT; }
bool hasTransportCodes() const { return getRouteType() == ROUTE_TYPE_TRANSPORT_FLOOD || getRouteType() == ROUTE_TYPE_TRANSPORT_DIRECT; }
/**
* \returns one of PAYLOAD_TYPE_ values