Skip to content

Commit 577e2a4

Browse files
committed
Fixes OPR Mesages
1 parent 5e6294f commit 577e2a4

File tree

3 files changed

+80
-62
lines changed

3 files changed

+80
-62
lines changed

Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ build: RAK831 RAK831_OPR RAK2245 RAK2245_OPR
5555
rm -rf lora_gateway; \
5656
git clone https://github.com/Lora-net/lora_gateway.git; \
5757
cd lora_gateway; \
58-
cp ../config/library.cfg ./libloragw/library.cfg; \
5958
cp ../config/loragw_hal_opr.c ./libloragw/src/loragw_hal.c; \
60-
echo "DEBUG_OPR= $(DEBUG_OPR)" >> ./libloragw/library.cfg; \
61-
perl -pi -e 's/#define SPI_SPEED\s+\d+/#define SPI_SPEED $(SPI_SPEED)/g' ./libloragw/src/loragw_spi.native.c;
62-
cd src/$(BOARD)/lora_gateway; make
59+
cp ../config/library.cfg ./libloragw/library.cfg; \
60+
perl -pi -e 's/#define DEBUG_OPR\s+\d+/#define DEBUG_OPR $(DEBUG_OPR)/g' ./libloragw/src/loragw_hal.c; \
61+
perl -pi -e 's/#define SPI_SPEED\s+\d+/#define SPI_SPEED $(SPI_SPEED)/g' ./libloragw/src/loragw_hal.c; \
62+
perl -pi -e 's/#define SPI_SPEED\s+\d+/#define SPI_SPEED $(SPI_SPEED)/g' ./libloragw/src/loragw_spi.native.c; \
63+
cd src/$(BOARD)/lora_gateway; \
64+
make
6365

6466
cd src/$(BOARD); \
6567
rm -rf packet_forwarder; \
@@ -135,15 +137,15 @@ RAK2245_OPR: RAK2245_OPR_package
135137

136138

137139
RAK831: export BOARD=RAK831
138-
RAK831: export SPI_SPEED=6500000
140+
RAK831: export SPI_SPEED=6000000
139141
RAK831: export DEBUG_OPR=0
140142
RAK831: RAK831_echo
141143
RAK831: RAK831_compile
142144
RAK831: RAK831_copy
143145
RAK831: RAK831_package
144146

145147
RAK831_OPR: export BOARD=RAK831
146-
RAK831_OPR: export SPI_SPEED=6500000
148+
RAK831_OPR: export SPI_SPEED=6000000
147149
RAK831_OPR: export DEBUG_OPR=1
148150
RAK831_OPR: RAK831_OPR_echo
149151
RAK831_OPR: RAK831_OPR_compile

src/RAK2245/config/loragw_hal_opr.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Maintainer: Sylvain Miermont
3636
/* -------------------------------------------------------------------------- */
3737
/* --- PRIVATE MACROS ------------------------------------------------------- */
3838

39+
#define DEBUG_OPR 0
40+
#define SPI_SPEED 0
41+
42+
#define STR_HELPER(x) #x
43+
#define STR(x) STR_HELPER(x)
44+
3945
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
4046
#if DEBUG_HAL == 1
4147
#define DEBUG_MSG(str) fprintf(stderr, str)
@@ -50,9 +56,9 @@ Maintainer: Sylvain Miermont
5056
#endif
5157

5258
#if DEBUG_OPR == 1
53-
#define DEBUG_OPR(str, ...) printf(str, ##__VA_ARGS__)
59+
#define DEBUG_OPR_PRINTF(str, ...) printf(str, ##__VA_ARGS__)
5460
#else
55-
#define DEBUG_OPR(str, ...)
61+
#define DEBUG_OPR_PRINTF(str, ...)
5662
#endif
5763

5864
#define IF_HZ_TO_REG(f) (f << 5)/15625
@@ -99,7 +105,7 @@ Maintainer: Sylvain Miermont
99105
const uint8_t ifmod_config[LGW_IF_CHAIN_NB] = LGW_IFMODEM_CONFIG;
100106

101107
/* Version string, used to identify the library version/options once compiled */
102-
const char lgw_version_string[] = "Version: " LIBLORAGW_VERSION ";";
108+
const char lgw_version_string[] = "Version: " LIBLORAGW_VERSION " SPI_SPEED: " STR(SPI_SPEED) " OPR: " STR(DEBUG_OPR) ";";
103109

104110
/* -------------------------------------------------------------------------- */
105111
/* --- PRIVATE VARIABLES ---------------------------------------------------- */
@@ -1094,6 +1100,8 @@ int lgw_start(void) {
10941100
wait_ms(8400);
10951101
}
10961102

1103+
DEBUG_OPR_PRINTF("INFO: OPR debugging Enabled\n");
1104+
10971105
lgw_is_started = true;
10981106
return LGW_HAL_SUCCESS;
10991107
}
@@ -1200,15 +1208,15 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
12001208
strftime(ts_buff, sizeof ts_buff, "%z", ts_timeinfo);
12011209
#endif
12021210

1203-
DEBUG_OPR("# OPR |%s.%09ld %s| ", ts_bufi, ts_ns, ts_buff);
1204-
DEBUG_OPR("size_bytes:%i ", p->size);
1211+
DEBUG_OPR_PRINTF("# OPR |%s.%09ld %s| ", ts_bufi, ts_ns, ts_buff);
1212+
DEBUG_OPR_PRINTF("size_bytes:%i ", p->size);
12051213

12061214
p->rf_chain = (uint8_t)if_rf_chain[p->if_chain];
12071215
p->freq_hz = (uint32_t)((int32_t)rf_rx_freq[p->rf_chain] + if_freq[p->if_chain]);
12081216
p->rssi = (float)buff[sz+5] + rf_rssi_offset[p->rf_chain];
12091217

12101218
// Test
1211-
DEBUG_OPR("ch:%02i Freq:%03.2f Rssi:%04.0f ", p->rf_chain, (float)p->freq_hz/1000000, p->rssi - RSSI_MULTI_BIAS);
1219+
DEBUG_OPR_PRINTF("ch:%02i Freq:%03.2f Rssi:%04.0f ", p->rf_chain, (float)p->freq_hz/1000000, p->rssi - RSSI_MULTI_BIAS);
12121220

12131221

12141222
if ((ifmod == IF_LORA_MULTI) || (ifmod == IF_LORA_STD)) {
@@ -1218,30 +1226,30 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
12181226
p->status = STAT_CRC_OK;
12191227
crc_en = 1;
12201228
// Test
1221-
DEBUG_OPR("crc: 1 ");
1229+
DEBUG_OPR_PRINTF("crc: 1 ");
12221230
break;
12231231
case 7:
12241232
p->status = STAT_CRC_BAD;
12251233
crc_en = 1;
1226-
DEBUG_OPR("crc:-1 ");
1234+
DEBUG_OPR_PRINTF("crc:-1 ");
12271235
break;
12281236
case 1:
12291237
p->status = STAT_NO_CRC;
12301238
crc_en = 0;
1231-
DEBUG_OPR("crc: 0 ");
1239+
DEBUG_OPR_PRINTF("crc: 0 ");
12321240
break;
12331241
default:
12341242
p->status = STAT_UNDEFINED;
12351243
crc_en = 0;
1236-
DEBUG_OPR("crc: ? ");
1244+
DEBUG_OPR_PRINTF("crc: ? ");
12371245
}
12381246
p->modulation = MOD_LORA;
12391247
p->snr = ((float)((int8_t)buff[sz+2]))/4;
12401248
p->snr_min = ((float)((int8_t)buff[sz+3]))/4;
12411249
p->snr_max = ((float)((int8_t)buff[sz+4]))/4;
12421250

12431251
// Test
1244-
DEBUG_OPR("snr:%06.2f min_snr:%06.2f max_snr:%06.2f ", p->snr, p->snr_min, p->snr_max);
1252+
DEBUG_OPR_PRINTF("snr:%06.2f min_snr:%06.2f max_snr:%06.2f ", p->snr, p->snr_min, p->snr_max);
12451253

12461254
if (ifmod == IF_LORA_MULTI) {
12471255
p->bandwidth = BW_125KHZ; /* fixed in hardware */
@@ -1250,13 +1258,13 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
12501258
}
12511259
sf = (buff[sz+1] >> 4) & 0x0F;
12521260
switch (sf) {
1253-
case 7: p->datarate = DR_LORA_SF7; DEBUG_OPR("sf: 7 "); break;
1254-
case 8: p->datarate = DR_LORA_SF8; DEBUG_OPR("sf: 8 "); break;
1255-
case 9: p->datarate = DR_LORA_SF9; DEBUG_OPR("sf: 9 "); break;
1256-
case 10: p->datarate = DR_LORA_SF10; DEBUG_OPR("sf:10 "); break;
1257-
case 11: p->datarate = DR_LORA_SF11; DEBUG_OPR("sf:11 "); break;
1258-
case 12: p->datarate = DR_LORA_SF12; DEBUG_OPR("sf:12 "); break;
1259-
default: p->datarate = DR_UNDEFINED; DEBUG_OPR("sf:err ");
1261+
case 7: p->datarate = DR_LORA_SF7; DEBUG_OPR_PRINTF("sf: 7 "); break;
1262+
case 8: p->datarate = DR_LORA_SF8; DEBUG_OPR_PRINTF("sf: 8 "); break;
1263+
case 9: p->datarate = DR_LORA_SF9; DEBUG_OPR_PRINTF("sf: 9 "); break;
1264+
case 10: p->datarate = DR_LORA_SF10; DEBUG_OPR_PRINTF("sf:10 "); break;
1265+
case 11: p->datarate = DR_LORA_SF11; DEBUG_OPR_PRINTF("sf:11 "); break;
1266+
case 12: p->datarate = DR_LORA_SF12; DEBUG_OPR_PRINTF("sf:12 "); break;
1267+
default: p->datarate = DR_UNDEFINED; DEBUG_OPR_PRINTF("sf:err ");
12601268
}
12611269
cr = (buff[sz+1] >> 1) & 0x07;
12621270
switch (cr) {
@@ -1266,14 +1274,14 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
12661274
case 4: p->coderate = CR_LORA_4_8; break;
12671275
default: p->coderate = CR_UNDEFINED;
12681276
}
1269-
DEBUG_OPR("cr:4/%d ", cr+4);
1277+
DEBUG_OPR_PRINTF("cr:4/%d ", cr+4);
12701278

12711279
/* determine if 'PPM mode' is on, needed for timestamp correction */
12721280
if (SET_PPM_ON(p->bandwidth,p->datarate)) {
12731281
ppm = 1;
1274-
DEBUG_OPR("ppm:1 ");
1282+
DEBUG_OPR_PRINTF("ppm:1 ");
12751283
} else {
1276-
DEBUG_OPR("ppm:0 ");
1284+
DEBUG_OPR_PRINTF("ppm:0 ");
12771285
ppm = 0;
12781286
}
12791287

@@ -1372,18 +1380,18 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
13721380
p->count_us = raw_timestamp - timestamp_correction;
13731381
p->crc = (uint16_t)buff[sz+10] + ((uint16_t)buff[sz+11] << 8);
13741382
#if DEBUG_OPR == 1
1375-
DEBUG_OPR("crc:%04X ", p->crc);
1376-
DEBUG_OPR("tmsp:%010u ", raw_timestamp);
1377-
DEBUG_OPR("diff:%06u ", raw_timestamp - raw_timestamp_old);
1383+
DEBUG_OPR_PRINTF("crc:%04X ", p->crc);
1384+
DEBUG_OPR_PRINTF("tmsp:%010u ", raw_timestamp);
1385+
DEBUG_OPR_PRINTF("diff:%06u ", raw_timestamp - raw_timestamp_old);
13781386
raw_timestamp_old = raw_timestamp;
1379-
DEBUG_OPR("mID:%02X ", buff[sz+12]);
1387+
DEBUG_OPR_PRINTF("mID:%02X ", buff[sz+12]);
13801388
//printf("rxMaxBinPos:%03i ", (uint16_t)buff[sz+13] + ((uint16_t)buff[sz+14] << 8) );
1381-
DEBUG_OPR("rxCorrSNR:%02i ", buff[sz+15]);
1389+
DEBUG_OPR_PRINTF("rxCorrSNR:%02i ", buff[sz+15]);
13821390

13831391
for(int i = 0; i < p->size; i++)
1384-
DEBUG_OPR("%02X", buff[i]);
1392+
DEBUG_OPR_PRINTF("%02X", buff[i]);
13851393

1386-
DEBUG_OPR("\n");
1394+
DEBUG_OPR_PRINTF("\n");
13871395
#endif
13881396
/* advance packet FIFO */
13891397
lgw_reg_w(LGW_RX_PACKET_DATA_FIFO_NUM_STORED, 0);

src/RAK831/config/loragw_hal_opr.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Maintainer: Sylvain Miermont
3636
/* -------------------------------------------------------------------------- */
3737
/* --- PRIVATE MACROS ------------------------------------------------------- */
3838

39+
#define DEBUG_OPR 0
40+
#define SPI_SPEED 0
41+
42+
#define STR_HELPER(x) #x
43+
#define STR(x) STR_HELPER(x)
44+
3945
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
4046
#if DEBUG_HAL == 1
4147
#define DEBUG_MSG(str) fprintf(stderr, str)
@@ -50,9 +56,9 @@ Maintainer: Sylvain Miermont
5056
#endif
5157

5258
#if DEBUG_OPR == 1
53-
#define DEBUG_OPR(str, ...) printf(str, ##__VA_ARGS__)
59+
#define DEBUG_OPR_PRINTF(str, ...) printf(str, ##__VA_ARGS__)
5460
#else
55-
#define DEBUG_OPR(str, ...)
61+
#define DEBUG_OPR_PRINTF(str, ...)
5662
#endif
5763

5864
#define IF_HZ_TO_REG(f) (f << 5)/15625
@@ -99,7 +105,7 @@ Maintainer: Sylvain Miermont
99105
const uint8_t ifmod_config[LGW_IF_CHAIN_NB] = LGW_IFMODEM_CONFIG;
100106

101107
/* Version string, used to identify the library version/options once compiled */
102-
const char lgw_version_string[] = "Version: " LIBLORAGW_VERSION ";";
108+
const char lgw_version_string[] = "Version: " LIBLORAGW_VERSION " SPI_SPEED: " STR(SPI_SPEED) " OPR: " STR(DEBUG_OPR) ";";
103109

104110
/* -------------------------------------------------------------------------- */
105111
/* --- PRIVATE VARIABLES ---------------------------------------------------- */
@@ -1094,6 +1100,8 @@ int lgw_start(void) {
10941100
wait_ms(8400);
10951101
}
10961102

1103+
DEBUG_OPR_PRINTF("INFO: OPR debugging Enabled\n");
1104+
10971105
lgw_is_started = true;
10981106
return LGW_HAL_SUCCESS;
10991107
}
@@ -1200,15 +1208,15 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
12001208
strftime(ts_buff, sizeof ts_buff, "%z", ts_timeinfo);
12011209
#endif
12021210

1203-
DEBUG_OPR("# OPR |%s.%09ld %s| ", ts_bufi, ts_ns, ts_buff);
1204-
DEBUG_OPR("size_bytes:%i ", p->size);
1211+
DEBUG_OPR_PRINTF("# OPR |%s.%09ld %s| ", ts_bufi, ts_ns, ts_buff);
1212+
DEBUG_OPR_PRINTF("size_bytes:%i ", p->size);
12051213

12061214
p->rf_chain = (uint8_t)if_rf_chain[p->if_chain];
12071215
p->freq_hz = (uint32_t)((int32_t)rf_rx_freq[p->rf_chain] + if_freq[p->if_chain]);
12081216
p->rssi = (float)buff[sz+5] + rf_rssi_offset[p->rf_chain];
12091217

12101218
// Test
1211-
DEBUG_OPR("ch:%02i Freq:%03.2f Rssi:%04.0f ", p->rf_chain, (float)p->freq_hz/1000000, p->rssi - RSSI_MULTI_BIAS);
1219+
DEBUG_OPR_PRINTF("ch:%02i Freq:%03.2f Rssi:%04.0f ", p->rf_chain, (float)p->freq_hz/1000000, p->rssi - RSSI_MULTI_BIAS);
12121220

12131221

12141222
if ((ifmod == IF_LORA_MULTI) || (ifmod == IF_LORA_STD)) {
@@ -1218,30 +1226,30 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
12181226
p->status = STAT_CRC_OK;
12191227
crc_en = 1;
12201228
// Test
1221-
DEBUG_OPR("crc: 1 ");
1229+
DEBUG_OPR_PRINTF("crc: 1 ");
12221230
break;
12231231
case 7:
12241232
p->status = STAT_CRC_BAD;
12251233
crc_en = 1;
1226-
DEBUG_OPR("crc:-1 ");
1234+
DEBUG_OPR_PRINTF("crc:-1 ");
12271235
break;
12281236
case 1:
12291237
p->status = STAT_NO_CRC;
12301238
crc_en = 0;
1231-
DEBUG_OPR("crc: 0 ");
1239+
DEBUG_OPR_PRINTF("crc: 0 ");
12321240
break;
12331241
default:
12341242
p->status = STAT_UNDEFINED;
12351243
crc_en = 0;
1236-
DEBUG_OPR("crc: ? ");
1244+
DEBUG_OPR_PRINTF("crc: ? ");
12371245
}
12381246
p->modulation = MOD_LORA;
12391247
p->snr = ((float)((int8_t)buff[sz+2]))/4;
12401248
p->snr_min = ((float)((int8_t)buff[sz+3]))/4;
12411249
p->snr_max = ((float)((int8_t)buff[sz+4]))/4;
12421250

12431251
// Test
1244-
DEBUG_OPR("snr:%06.2f min_snr:%06.2f max_snr:%06.2f ", p->snr, p->snr_min, p->snr_max);
1252+
DEBUG_OPR_PRINTF("snr:%06.2f min_snr:%06.2f max_snr:%06.2f ", p->snr, p->snr_min, p->snr_max);
12451253

12461254
if (ifmod == IF_LORA_MULTI) {
12471255
p->bandwidth = BW_125KHZ; /* fixed in hardware */
@@ -1250,13 +1258,13 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
12501258
}
12511259
sf = (buff[sz+1] >> 4) & 0x0F;
12521260
switch (sf) {
1253-
case 7: p->datarate = DR_LORA_SF7; DEBUG_OPR("sf: 7 "); break;
1254-
case 8: p->datarate = DR_LORA_SF8; DEBUG_OPR("sf: 8 "); break;
1255-
case 9: p->datarate = DR_LORA_SF9; DEBUG_OPR("sf: 9 "); break;
1256-
case 10: p->datarate = DR_LORA_SF10; DEBUG_OPR("sf:10 "); break;
1257-
case 11: p->datarate = DR_LORA_SF11; DEBUG_OPR("sf:11 "); break;
1258-
case 12: p->datarate = DR_LORA_SF12; DEBUG_OPR("sf:12 "); break;
1259-
default: p->datarate = DR_UNDEFINED; DEBUG_OPR("sf:err ");
1261+
case 7: p->datarate = DR_LORA_SF7; DEBUG_OPR_PRINTF("sf: 7 "); break;
1262+
case 8: p->datarate = DR_LORA_SF8; DEBUG_OPR_PRINTF("sf: 8 "); break;
1263+
case 9: p->datarate = DR_LORA_SF9; DEBUG_OPR_PRINTF("sf: 9 "); break;
1264+
case 10: p->datarate = DR_LORA_SF10; DEBUG_OPR_PRINTF("sf:10 "); break;
1265+
case 11: p->datarate = DR_LORA_SF11; DEBUG_OPR_PRINTF("sf:11 "); break;
1266+
case 12: p->datarate = DR_LORA_SF12; DEBUG_OPR_PRINTF("sf:12 "); break;
1267+
default: p->datarate = DR_UNDEFINED; DEBUG_OPR_PRINTF("sf:err ");
12601268
}
12611269
cr = (buff[sz+1] >> 1) & 0x07;
12621270
switch (cr) {
@@ -1266,14 +1274,14 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
12661274
case 4: p->coderate = CR_LORA_4_8; break;
12671275
default: p->coderate = CR_UNDEFINED;
12681276
}
1269-
DEBUG_OPR("cr:4/%d ", cr+4);
1277+
DEBUG_OPR_PRINTF("cr:4/%d ", cr+4);
12701278

12711279
/* determine if 'PPM mode' is on, needed for timestamp correction */
12721280
if (SET_PPM_ON(p->bandwidth,p->datarate)) {
12731281
ppm = 1;
1274-
DEBUG_OPR("ppm:1 ");
1282+
DEBUG_OPR_PRINTF("ppm:1 ");
12751283
} else {
1276-
DEBUG_OPR("ppm:0 ");
1284+
DEBUG_OPR_PRINTF("ppm:0 ");
12771285
ppm = 0;
12781286
}
12791287

@@ -1372,18 +1380,18 @@ int lgw_receive(uint8_t max_pkt, struct lgw_pkt_rx_s *pkt_data) {
13721380
p->count_us = raw_timestamp - timestamp_correction;
13731381
p->crc = (uint16_t)buff[sz+10] + ((uint16_t)buff[sz+11] << 8);
13741382
#if DEBUG_OPR == 1
1375-
DEBUG_OPR("crc:%04X ", p->crc);
1376-
DEBUG_OPR("tmsp:%010u ", raw_timestamp);
1377-
DEBUG_OPR("diff:%06u ", raw_timestamp - raw_timestamp_old);
1383+
DEBUG_OPR_PRINTF("crc:%04X ", p->crc);
1384+
DEBUG_OPR_PRINTF("tmsp:%010u ", raw_timestamp);
1385+
DEBUG_OPR_PRINTF("diff:%06u ", raw_timestamp - raw_timestamp_old);
13781386
raw_timestamp_old = raw_timestamp;
1379-
DEBUG_OPR("mID:%02X ", buff[sz+12]);
1387+
DEBUG_OPR_PRINTF("mID:%02X ", buff[sz+12]);
13801388
//printf("rxMaxBinPos:%03i ", (uint16_t)buff[sz+13] + ((uint16_t)buff[sz+14] << 8) );
1381-
DEBUG_OPR("rxCorrSNR:%02i ", buff[sz+15]);
1389+
DEBUG_OPR_PRINTF("rxCorrSNR:%02i ", buff[sz+15]);
13821390

13831391
for(int i = 0; i < p->size; i++)
1384-
DEBUG_OPR("%02X", buff[i]);
1392+
DEBUG_OPR_PRINTF("%02X", buff[i]);
13851393

1386-
DEBUG_OPR("\n");
1394+
DEBUG_OPR_PRINTF("\n");
13871395
#endif
13881396
/* advance packet FIFO */
13891397
lgw_reg_w(LGW_RX_PACKET_DATA_FIFO_NUM_STORED, 0);

0 commit comments

Comments
 (0)