lorawan.cpp: enhance RX/TX callback functions
This commit is contained in:
parent
36f0a6255a
commit
4d3390383e
@ -264,9 +264,17 @@ void lora_send(void *pvParameters) {
|
|||||||
// switch (LMIC_sendWithCallback_strict(
|
// switch (LMIC_sendWithCallback_strict(
|
||||||
switch (LMIC_sendWithCallback(
|
switch (LMIC_sendWithCallback(
|
||||||
SendBuffer.MessagePort, SendBuffer.Message, SendBuffer.MessageSize,
|
SendBuffer.MessagePort, SendBuffer.Message, SendBuffer.MessageSize,
|
||||||
(cfg.countermode & 0x02), myTxCallback, NULL)) {
|
(cfg.countermode & 0x02), myTxCallback, &SendBuffer.MessagePort)) {
|
||||||
|
|
||||||
case LMIC_ERROR_SUCCESS:
|
case LMIC_ERROR_SUCCESS:
|
||||||
|
|
||||||
|
#if (TIME_SYNC_LORASERVER)
|
||||||
|
// if last packet sent was a timesync request, store TX timestamp
|
||||||
|
if (SendBuffer.MessagePort == TIMEPORT)
|
||||||
|
// store LMIC time when we started transmit of timesync request
|
||||||
|
store_timestamp(osticks2ms(os_getTime()), timesync_tx);
|
||||||
|
#endif
|
||||||
|
|
||||||
ESP_LOGI(TAG, "%d byte(s) sent to LORA", SendBuffer.MessageSize);
|
ESP_LOGI(TAG, "%d byte(s) sent to LORA", SendBuffer.MessageSize);
|
||||||
break;
|
break;
|
||||||
case LMIC_ERROR_TX_BUSY: // LMIC already has a tx message pending
|
case LMIC_ERROR_TX_BUSY: // LMIC already has a tx message pending
|
||||||
@ -544,6 +552,9 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
|||||||
#if (TIME_SYNC_LORASERVER)
|
#if (TIME_SYNC_LORASERVER)
|
||||||
// valid timesync answer -> call timesync processor
|
// valid timesync answer -> call timesync processor
|
||||||
if (port == TIMEPORT) {
|
if (port == TIMEPORT) {
|
||||||
|
// store LMIC time when we received the timesync answer
|
||||||
|
store_timestamp(osticks2ms(os_getTime()), timesync_rx);
|
||||||
|
// get and store gwtime from payload
|
||||||
recv_timesync_ans(pMsg, nMsg);
|
recv_timesync_ans(pMsg, nMsg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -558,11 +569,13 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
|||||||
// transmit complete message handler
|
// transmit complete message handler
|
||||||
void myTxCallback(void *pUserData, int fSuccess) {
|
void myTxCallback(void *pUserData, int fSuccess) {
|
||||||
|
|
||||||
#if (TIME_SYNC_LORASERVER)
|
uint8_t *const sendport = (uint8_t *)pUserData;
|
||||||
// if last packet sent was a timesync request, store TX timestamp
|
|
||||||
if (LMIC.pendTxPort == TIMEPORT)
|
if (fSuccess) {
|
||||||
store_time_sync_req(osticks2ms(LMIC.txend)); // milliseconds
|
// LMIC did tx on *sendport -> nothing yet to do here
|
||||||
#endif
|
} else {
|
||||||
|
// LMIC could not tx on *sendport -> error handling yet to come
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode LORAWAN MAC message
|
// decode LORAWAN MAC message
|
||||||
|
Loading…
Reference in New Issue
Block a user