Skip to content

Commit 777537b

Browse files
committed
Error management refactoring
1 parent fb26c34 commit 777537b

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/Arduino_LoRaConnectionHandler.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,33 @@ int LoRaConnectionHandler::write(const uint8_t *buf, size_t size) {
6161
err = modem.endPacket(true);
6262
if (err != size) {
6363
switch (err) {
64-
case -20: {
65-
Serial.println("Message length is bigger than max LoRa packet!");
66-
} break;
67-
case -1: {
64+
case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: {
6865
Serial.println("Message ack was not received, the message could not be delivered");
6966
} break;
70-
case -2: {
67+
case LoRaCommunicationError::LORA_ERROR_GENERIC: {
7168
Serial.println("LoRa generic error (LORA_ERROR)");
7269
} break;
73-
case -3: {
70+
case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: {
7471
Serial.println("LoRa malformed param error (LORA_ERROR_PARAM");
7572
} break;
76-
case -4: {
73+
case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: {
7774
Serial.println("LoRa chip is busy (LORA_ERROR_BUSY)");
7875
} break;
79-
case -5: {
76+
case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: {
8077
Serial.println("LoRa chip overflow error (LORA_ERROR_OVERFLOW)");
8178
} break;
82-
case -6: {
79+
case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: {
8380
Serial.println("LoRa no network error (LORA_ERROR_NO_NETWORK)");
8481
} break;
85-
case -7: {
82+
case LoRaCommunicationError::LORA_ERROR_RX_PACKET: {
8683
Serial.println("LoRa rx error (LORA_ERROR_RX)");
8784
} break;
88-
case -8: {
85+
case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: {
8986
Serial.println("LoRa unknown error (LORA_ERROR_UNKNOWN)");
9087
} break;
88+
case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: {
89+
Serial.println("Message length is bigger than max LoRa packet!");
90+
} break;
9191
}
9292
} else {
9393
Serial.println("Message sent correctly!");

src/Arduino_LoRaConnectionHandler.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626

2727
#include "Arduino_LPWANConnectionHandler.h"
2828

29+
typedef enum {
30+
LORA_ERROR_ACK_NOT_RECEIVED = -1,
31+
LORA_ERROR_GENERIC = -2,
32+
LORA_ERROR_WRONG_PARAM = -3,
33+
LORA_ERROR_COMMUNICATION_BUSY = -4,
34+
LORA_ERROR_MESSAGE_OVERFLOW = -5,
35+
LORA_ERROR_NO_NETWORK_AVAILABLE = -6,
36+
LORA_ERROR_RX_PACKET = -7,
37+
LORA_ERROR_REASON_UNKNOWN = -8,
38+
LORA_ERROR_MAX_PACKET_SIZE = -20
39+
} LoRaCommunicationError;
40+
2941
/******************************************************************************
3042
CLASS DECLARATION
3143
******************************************************************************/

0 commit comments

Comments
 (0)