upd
This commit is contained in:
@@ -24,7 +24,8 @@
|
||||
|
||||
void sendEncryptedFrame (const NodeEntry *targetNode, uint8_t payloadType, const uint8_t *plain, size_t plainLen) {
|
||||
FrameStruct frame;
|
||||
uint8_t offset = 0;
|
||||
memset(&frame, 0, sizeof(frame));
|
||||
size_t offset = 0;
|
||||
|
||||
// 1. Header
|
||||
frame.header =
|
||||
@@ -46,6 +47,8 @@ void sendEncryptedFrame (const NodeEntry *targetNode, uint8_t payloadType, const
|
||||
frame.payload + offset,
|
||||
&encLen);
|
||||
|
||||
MESH_LOGD(TAG, "Plain len: %d, enc len: %d", plainLen, encLen);
|
||||
|
||||
offset += encLen;
|
||||
|
||||
// 5. Finalize
|
||||
@@ -54,6 +57,7 @@ void sendEncryptedFrame (const NodeEntry *targetNode, uint8_t payloadType, const
|
||||
|
||||
hexdump ("Encrypted frame", frame.payload, frame.payloadLen);
|
||||
LoRaTransmit (&frame);
|
||||
MESH_LOGD (TAG, "Encrypted frame tx finish\n");
|
||||
}
|
||||
|
||||
void sendEncryptedTextMessage (const NodeEntry *targetNode, const PlainTextMessagePayload *msg) {
|
||||
@@ -317,52 +321,57 @@ void parseEncryptedPayload (const EncryptedPayloadStruct *enc) {
|
||||
Response resp;
|
||||
resp.tag = req.timestamp;
|
||||
enc->remNode->last_seen_rt = req.timestamp;
|
||||
uint8_t index2 = 0;
|
||||
resp.data[index2++] = TELEM_CHANNEL_SELF;
|
||||
resp.data[index2++] = LPP_TEMPERATURE;
|
||||
resp.dataLen = 0;
|
||||
resp.data[resp.dataLen++] = TELEM_CHANNEL_SELF;
|
||||
resp.data[resp.dataLen++] = LPP_TEMPERATURE;
|
||||
|
||||
int16_t dataTemp = getDeciTemperature();
|
||||
|
||||
printf ("The temperature is %d decicelsius\n", dataTemp);
|
||||
resp.data[resp.dataLen++] = (dataTemp >> 8) & 0xFF;
|
||||
|
||||
resp.data[index2++] = (dataTemp >> 8) & 0xFF;
|
||||
resp.data[resp.dataLen++] = dataTemp & 0xFF;
|
||||
|
||||
resp.data[index2++] = dataTemp & 0xFF;
|
||||
|
||||
|
||||
resp.data[index2++] = TELEM_CHANNEL_SELF;
|
||||
resp.data[index2++] = LPP_VOLTAGE;
|
||||
resp.data[resp.dataLen++] = TELEM_CHANNEL_SELF;
|
||||
resp.data[resp.dataLen++] = LPP_VOLTAGE;
|
||||
|
||||
int16_t dataVolt = stats.millivolts / 10;
|
||||
|
||||
resp.data[index2++] = (dataVolt >> 8) & 0xFF;
|
||||
resp.data[resp.dataLen++] = (dataVolt >> 8) & 0xFF;
|
||||
|
||||
resp.data[index2++] = dataVolt & 0xFF;
|
||||
resp.data[resp.dataLen++] = dataVolt & 0xFF;
|
||||
|
||||
resp.data[resp.dataLen++] = 2;
|
||||
resp.data[resp.dataLen++] = LPP_VOLTAGE;
|
||||
|
||||
dataVolt = 1973;
|
||||
|
||||
resp.data[resp.dataLen++] = (dataVolt >> 8) & 0xFF;
|
||||
|
||||
resp.data[resp.dataLen++] = dataVolt & 0xFF;
|
||||
|
||||
if (enc->remNode->authenticated) {
|
||||
|
||||
encode_gps (TELEM_CHANNEL_SELF, persistent.latitude / 1000000.0f, persistent.longitude / 1000000.0f, persistent.altitude / 100.0f, &(resp.data[index2]));
|
||||
// encode_gps(TELEM_CHANNEL_SELF, 48.1909f, 17.0303f, 234.0f, &(resp.data[index2]));
|
||||
|
||||
index2 += LPP_GPS_SIZE;
|
||||
}
|
||||
|
||||
if (enc->remNode->authenticated) {
|
||||
|
||||
resp.data[index2++] = 2;
|
||||
resp.data[index2++] = LPP_TEMPERATURE;
|
||||
resp.data[resp.dataLen++] = 2; // channel 2
|
||||
resp.data[resp.dataLen++] = LPP_TEMPERATURE;
|
||||
|
||||
int16_t jokeTemp = 6942;
|
||||
|
||||
resp.data[index2++] = (jokeTemp >> 8) & 0xFF;
|
||||
resp.data[resp.dataLen++] = (jokeTemp >> 8) & 0xFF;
|
||||
|
||||
resp.data[index2++] = jokeTemp & 0xFF;
|
||||
resp.data[resp.dataLen++] = jokeTemp & 0xFF;
|
||||
|
||||
resp.dataLen = index2;
|
||||
|
||||
encode_gps (TELEM_CHANNEL_SELF, persistent.latitude / 1000000.0f, persistent.longitude / 1000000.0f, persistent.altitude / 100.0f, &(resp.data[resp.dataLen]));
|
||||
// encode_gps(TELEM_CHANNEL_SELF, 48.1909f, 17.0303f, 234.0f, &(resp.data[resp.dataLen]));
|
||||
|
||||
resp.dataLen += LPP_GPS_SIZE + 2;
|
||||
}
|
||||
|
||||
|
||||
sendEncryptedResponse (enc->remNode, &resp);
|
||||
|
||||
printf ("Sent response, the temperature is %d decicelsius\n", dataTemp);
|
||||
|
||||
break;
|
||||
}
|
||||
case REQUEST_GET_MIN_MAX_AVG:
|
||||
@@ -421,8 +430,8 @@ void parseEncryptedPayload (const EncryptedPayloadStruct *enc) {
|
||||
}
|
||||
}
|
||||
|
||||
//#define STR_EQ_LIT(s, lit) (memcmp ((s), (lit), sizeof (lit) - 1) == 0)
|
||||
#define STR_EQ_LIT(s, lit) (strcmp(s, lit) == 0)
|
||||
// #define STR_EQ_LIT(s, lit) (memcmp ((s), (lit), sizeof (lit) - 1) == 0)
|
||||
#define STR_EQ_LIT(s, lit) (strcmp (s, lit) == 0)
|
||||
|
||||
void processCommand (char *cmd, NodeEntry *remNode) {
|
||||
PlainTextMessagePayload replyPayload;
|
||||
@@ -493,11 +502,11 @@ void processCommand (char *cmd, NodeEntry *remNode) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
else if (STR_EQ_LIT (cmd, "tempradio ")) {
|
||||
char tmp[64];
|
||||
strcpy (tmp, &cmd[10]);
|
||||
|
||||
|
||||
const char *parts[5];
|
||||
int num = mesh_ParseTextParts (tmp, parts, 5); // assume helper
|
||||
float freq = num > 0 ? strtof (parts[0], NULL) : 0.0f;
|
||||
@@ -575,9 +584,9 @@ void processCommand (char *cmd, NodeEntry *remNode) {
|
||||
*/
|
||||
} else if (memcmp (config, "public.key", 10) == 0) {
|
||||
strcpy (reply, "> ");
|
||||
hexdump_compact(persistent.pubkey, sizeof(persistent.pubkey), &(reply[2]), 70);
|
||||
hexdump_compact (persistent.pubkey, sizeof (persistent.pubkey), &(reply[2]), 70);
|
||||
} else if (memcmp (config, "role", 4) == 0) {
|
||||
sprintf (reply, "> %s", getStringRole(persistent.nodeType));
|
||||
sprintf (reply, "> %s", getStringRole (persistent.nodeType));
|
||||
} else if (memcmp (config, "adc.multiplier", 14) == 0) {
|
||||
sprintf (reply, "> %.3f", persistent.adcMultiplier);
|
||||
} else {
|
||||
@@ -613,7 +622,7 @@ void processCommand (char *cmd, NodeEntry *remNode) {
|
||||
persistent.allowReadOnly = 0;
|
||||
strcpy (reply, "OK");
|
||||
}
|
||||
//savePrefs();
|
||||
// savePrefs();
|
||||
/*
|
||||
} else if (memcmp (config, "flood.advert.interval ", 22) == 0) {
|
||||
int hours = _atoi (&config[22]);
|
||||
@@ -735,7 +744,7 @@ void processCommand (char *cmd, NodeEntry *remNode) {
|
||||
}
|
||||
// savePrefs();
|
||||
strcpy (reply, "OK - reboot to apply");
|
||||
|
||||
|
||||
} else if (memcmp (config, "adc.multiplier ", 15) == 0) {
|
||||
persistent.adcMultiplier = atof (&config[15]);
|
||||
if (persistent.adcMultiplier == 0.0f) {
|
||||
|
||||
Reference in New Issue
Block a user