Skip to content

Commit

Permalink
MKRWAN fix modemSend binary to use hex-translated bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
flhofer committed Jul 25, 2021
1 parent fa55962 commit ca0bd8b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/MKRWAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ const T& Max(const T& a, const T& b)
#define AT_QM "?"

#define ARDUINO_LORA_MAXBUFF 64 // hard coded limit in middleware and driver
#define FMT_HEX 0
#define FMT_BIN 1

#define LORA_NL "\r"
static const char LORA_OK[] = "+OK";
Expand Down Expand Up @@ -343,6 +345,7 @@ class LoRaModem : public Stream // @suppress("Class has a virtual method and non
mask_size = 1;
region = EU868;
compat_mode = false;
formatBin = false;
msize = ARDUINO_LORA_MAXBUFF;
}

Expand All @@ -361,6 +364,7 @@ class LoRaModem : public Stream // @suppress("Class has a virtual method and non
uint16_t channelsMask[6];
_lora_band region;
bool compat_mode;
bool formatBin;
size_t msize;

public:
Expand Down Expand Up @@ -758,8 +762,12 @@ class LoRaModem : public Stream // @suppress("Class has a virtual method and non
return setValue(GF(AT_SLEEP), on);
}

bool format(bool hexMode) {
return setValue(GF(AT_FORMAT), hexMode);
bool format(bool mode) {
if (setValue(GF(AT_FORMAT), mode)){
formatBin = mode;
return true;
}
return false;
}

/*
Expand Down Expand Up @@ -920,13 +928,23 @@ class LoRaModem : public Stream // @suppress("Class has a virtual method and non
return -20;
}

if (formatBin)
len *=2; // ->TO hex

if (confirmed) {
sendAT(GF(AT_CTX), " ", len);
} else {
sendAT(GF(AT_UTX), " ", len);
}

stream.write((uint8_t*)buff, len);
if (formatBin){
char chr[3];
for (size_t i = 0; i<len; i+=2, buff=(uint8_t *)buff+1){
sprintf(chr, "%02x", *(uint8_t *)buff);
stream.write(chr, 2);
}
}
else
stream.write((uint8_t*)buff, len);

int8_t rc = waitResponse();
if (rc == 1) { ///< OK
Expand Down

0 comments on commit ca0bd8b

Please sign in to comment.