Skip to content

Commit b0d2635

Browse files
committed
Huge bug fix
1 parent 10be76c commit b0d2635

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/LoRandom.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,19 @@ void resetLoRa() {
4343
}
4444

4545
uint8_t getLoRandomByte() {
46+
uint8_t x = (readRegister(RegRssiWideband) & 0b00000001);
47+
for (uint8_t j = 0; j < 7; j++) {
48+
x = (x << 1) | (readRegister(RegRssiWideband) & 0b00000001);
49+
}
50+
return x;
51+
}
52+
53+
uint8_t getLoRandomByteLMIC() {
4654
uint8_t x = 0;
4755
for (uint8_t j = 0; j < 8; j++) {
48-
x += (readRegister(RegRssiWideband) & 0b00000001);
49-
x = x << 1;
50-
//delay(1);
56+
uint8_t b;
57+
while((b = readRegister(RegRssiWideband) & 0x01) == (readRegister(RegRssiWideband) & 0x01));
58+
x = (x << 1) | b;
5159
}
5260
return x;
5361
}
@@ -75,6 +83,15 @@ void fillRandom(unsigned char *x, size_t len) {
7583
resetLoRa();
7684
}
7785

86+
void fillRandomLMIC(unsigned char *x, size_t len) {
87+
setupLoRandom();
88+
size_t i;
89+
for (i = 0; i < len; i++) {
90+
x[i] = getLoRandomByteLMIC();
91+
}
92+
resetLoRa();
93+
}
94+
7895
void fillRandom(unsigned char *x, size_t len, uint8_t except) {
7996
// used, for instance, when you want a non-zero value.
8097
// fillRandom(UUID, 16, 0);

0 commit comments

Comments
 (0)