Skip to content

Commit e178c6c

Browse files
committed
LPWAN interface updated
1 parent a0e66da commit e178c6c

File tree

3 files changed

+20
-46
lines changed

3 files changed

+20
-46
lines changed

src/Arduino_LPWANConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LPWANConnectionHandler : public ConnectionHandler {
3636
virtual void update() = 0;
3737
virtual unsigned long getTime() = 0;
3838

39-
virtual void write(const uint8_t *buf, size_t size) = 0;
39+
virtual int write(const uint8_t *buf, size_t size) = 0;
4040
virtual int read() = 0;
4141
virtual bool available() = 0;
4242

src/Arduino_LoRaConnectionHandler.cpp

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -86,55 +86,29 @@ unsigned long LoRaConnectionHandler::getTime() {
8686
return 0;
8787
}
8888

89-
void LoRaConnectionHandler::write(const uint8_t *buf, size_t size) {
90-
int err;
91-
modem.beginPacket();
92-
modem.write(buf, size);
93-
err = modem.endPacket(true);
94-
if (err != size) {
95-
switch (err) {
96-
case -1: {
97-
Serial.println("Message length is bigger than max LoRa packet!");
98-
Serial.println(err);
99-
}
100-
break;
101-
case -2: {
102-
Serial.println("Message ack was not recieved, the message could not be delivered");
103-
}
104-
break;
105-
case 2: {
106-
Serial.println("LoRa generic error (LORA_ERROR)");
107-
}
108-
break;
109-
case 3: {
110-
Serial.println("LoRa malformed param error (LORA_ERROR_PARAM");
111-
}
112-
break;
113-
case 4: {
114-
Serial.println("LoRa chip is busy (LORA_ERROR_BUSY)");
115-
}
116-
break;
117-
case 5: {
118-
Serial.println("LoRa chip overflow error (LORA_ERROR_OVERFLOW)");
119-
}
120-
break;
121-
case 6: {
122-
Serial.println("LoRa no network error (LORA_ERROR_NO_NETWORK)");
123-
}
124-
break;
125-
case 7: {
126-
Serial.println("LoRa rx error (LORA_ERROR_RX)");
127-
}
128-
break;
129-
case 8: {
130-
Serial.println("LoRa unknown error (LORA_ERROR_UNKNOWN)");
131-
}
132-
break;
89+
int LoRaConnectionHandler::write(const uint8_t *buf, size_t size) {
90+
int err;
91+
modem.beginPacket();
92+
modem.write(buf, size);
93+
err = modem.endPacket(true);
94+
/*Error manager according pr #68 of MKRWAN repo*/
95+
if (err != size) {
96+
switch (err) {
97+
case -20: {Serial.println("Message length is bigger than max LoRa packet!");} break;
98+
case -1: {Serial.println("Message ack was not received, the message could not be delivered");} break;
99+
case -2: {Serial.println("LoRa generic error (LORA_ERROR)");} break;
100+
case -3: {Serial.println("LoRa malformed param error (LORA_ERROR_PARAM");} break;
101+
case -4: {Serial.println("LoRa chip is busy (LORA_ERROR_BUSY)");} break;
102+
case -5: {Serial.println("LoRa chip overflow error (LORA_ERROR_OVERFLOW)");} break;
103+
case -6: {Serial.println("LoRa no network error (LORA_ERROR_NO_NETWORK)");} break;
104+
case -7: {Serial.println("LoRa rx error (LORA_ERROR_RX)");} break;
105+
case -8: {Serial.println("LoRa unknown error (LORA_ERROR_UNKNOWN)");} break;
133106
}
134107
}
135108
else {
136109
Serial.println("Message sent correctly!");
137110
}
111+
return err;
138112
}
139113

140114
int LoRaConnectionHandler::read() {

src/Arduino_LoRaConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class LoRaConnectionHandler : public LPWANConnectionHandler {
4141
}
4242
void update();
4343

44-
void write(const uint8_t *buf, size_t size);
44+
int write(const uint8_t *buf, size_t size);
4545
int read();
4646
bool available();
4747

0 commit comments

Comments
 (0)