Skip to content

Commit 3d8243f

Browse files
author
CTSchorsch
committed
connect lora to packet/command structure
test with COMM_GET_VALUE ok
1 parent aa4e056 commit 3d8243f

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

lora/SX1278.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ int SX1278_LoRaEntryRx(SX1278_t *module, uint8_t length, uint32_t timeout) {
164164
module->packetLength = length;
165165

166166
SX1278_config(module); //Setting base parameter
167+
SX1278_disableInvertIQ();
167168
SX1278_SPIWrite(REG_LR_PADAC, 0x84); //Normal and RX
168169
SX1278_SPIWrite(LR_RegHopPeriod, 0xFF); //No FHSS
169170
SX1278_SPIWrite(REG_LR_DIOMAPPING1, 0x01);//DIO=00,DIO1=00,DIO2=00, DIO3=01
@@ -173,10 +174,8 @@ int SX1278_LoRaEntryRx(SX1278_t *module, uint8_t length, uint32_t timeout) {
173174
addr = SX1278_SPIRead(LR_RegFifoRxBaseAddr); //Read RxBaseAddr
174175
SX1278_SPIWrite(LR_RegFifoAddrPtr, addr); //RxBaseAddr->FiFoAddrPtr
175176
SX1278_SPIWrite(LR_RegOpMode, 0x8d); //Mode//Low Frequency Mode
176-
//SX1278_SPIWrite(module, LR_RegOpMode,0x05); //Continuous Rx Mode //High Frequency Mode
177177
module->readBytes = 0;
178178

179-
SX1278_disableInvertIQ();
180179

181180
while (1) {
182181
if ((SX1278_SPIRead(LR_RegModemStat) & 0x04) == 0x04) { //Rx-on going RegModemStat

lora/lora.c

+12-14
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static void process_packet(unsigned char* data, unsigned int len);
5151
static void send_packet(unsigned char* data, unsigned int len);
5252

5353
void lora_send_packet(unsigned char* data, unsigned int len) {
54-
5554
if (!send_mutex_init_done) {
5655
chMtxObjectInit(&send_mutex);
5756
send_mutex_init_done = true;
@@ -66,11 +65,8 @@ static void process_packet(unsigned char* data, unsigned int len) {
6665
}
6766

6867
static void send_packet(unsigned char* data, unsigned int len) {
69-
70-
int erg;
71-
72-
erg = SX1278_LoRaEntryTx(&SX1278, len, 100);
73-
erg = SX1278_LoRaTxPacket(&SX1278, (uint8_t*)data, len, 100);
68+
SX1278_LoRaEntryTx(&SX1278, len, 100);
69+
SX1278_LoRaTxPacket(&SX1278, (uint8_t*)data, len, 100);
7470
}
7571

7672
void lora_init(void) {
@@ -82,7 +78,7 @@ void lora_init(void) {
8278
palSetPadMode(HW_LORA_SPI_PORT_MOSI, HW_LORA_SPI_PIN_MOSI, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
8379
palSetPadMode(HW_LORA_SPI_PORT_DIO0, HW_LORA_SPI_PIN_DIO0, PAL_MODE_INPUT);
8480
palSetPadMode(HW_LORA_SPI_PORT_RESET, HW_LORA_SPI_PIN_RESET, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
85-
SX1278_init(&SX1278, 868000000, SX1278_POWER_17DBM, SX1278_LORA_SF_7, SX1278_LORA_BW_250KHZ, SX1278_LORA_CR_4_5, SX1278_LORA_CRC_DIS, 100);
81+
SX1278_init(&SX1278, 868000000, SX1278_POWER_17DBM, SX1278_LORA_SF_7, SX1278_LORA_BW_250KHZ, SX1278_LORA_CR_4_5, SX1278_LORA_CRC_DIS, 10);
8682
if (!thread_is_running) {
8783
chThdCreateStatic(packet_process_thread_wa, sizeof(packet_process_thread_wa), NORMALPRIO, packet_process_thread, NULL);
8884
thread_is_running = true;
@@ -95,22 +91,24 @@ void lora_stop(void) {
9591
static THD_FUNCTION(packet_process_thread, arg) {
9692
(void)arg;
9793

98-
unsigned char buffer[128];
94+
uint8_t erg;
95+
uint8_t buffer[255];
9996
chRegSetThreadName("LoRa proc");
10097

10198
buffer[0] = COMM_GET_VALUES;
10299

103100
while (!commands_is_initialized()) {
104101
chThdSleepMilliseconds(10);
105102
}
106-
103+
erg=SX1278_LoRaEntryRx(&SX1278, 255, 200);
107104
for (;;) {
108-
//simulate a received packet to trigger send_packet
109-
commands_process_packet(buffer, 1, lora_send_packet);
110-
SX1278_LoRaEntryRx(&SX1278, 100, 100);
111-
if (SX1278_LoRaRxPacket(&SX1278)) {
112-
process_packet(SX1278.rxBuffer, SX1278.readBytes);
105+
erg = SX1278_LoRaRxPacket(&SX1278);
106+
if (erg > 0) {
107+
for (int i=0; i<SX1278.readBytes; i++)
108+
packet_process_byte(SX1278.rxBuffer[i],&packet_state);
109+
erg=SX1278_LoRaEntryRx(&SX1278, 255, 200);
113110
}
111+
chThdSleepMilliseconds(10);
114112
}
115113
}
116114

lora/lora.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "SX1278_hw.h"
1010

1111
// Functions
12-
void rfm95w_init(void);
13-
void rfm95w_stop(void);
12+
void lora_init(void);
13+
void lora_stop(void);
1414

1515
#endif /* HWCONF_DRV8301_H_ */

0 commit comments

Comments
 (0)