Skip to content

Commit f499d4e

Browse files
committed
fix: crash when EXPANSION MODULE is activated
1 parent 4f395df commit f499d4e

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

ModbusApp/Modbus.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ const char* exceptionCodes[] = {
4545
"",
4646
"GATEWAY PATH\nUNAVAILABLE"
4747
"GATEWAY TARGET DEVICE\nFAILED TO RESPOND"};
48-
49-
uint16_t getCRC(uint8_t* buf, uint8_t len) {
50-
uint16_t crc = 0xFFFF;
51-
52-
for(int pos = 0; pos < len; pos++) {
53-
crc ^= (uint16_t)buf[pos];
54-
55-
for(int i = 8; i != 0; i--) {
56-
if((crc & 0x0001) != 0) {
57-
crc >>= 1;
58-
crc ^= 0xA001;
59-
} else
60-
crc >>= 1;
61-
}
62-
}
63-
return crc;
64-
}
6548
////////////////////////// ViewDispatcher Callbacks //////////////////////////
6649
static bool CustomEventCB(void* context, uint32_t event) {
6750
furi_assert(context);
@@ -196,18 +179,22 @@ void modbus_app_free(App* app) {
196179
storage_file_free(app->LOGfile);
197180
furi_record_close(RECORD_STORAGE);
198181
furi_record_close(RECORD_DIALOGS);
182+
furi_record_close(RECORD_EXPANSION);
183+
expansion_enable(app->expansion);
199184
free(app);
200185
}
201186

202187
////////////////////////// Entry Point //////////////////////////
203188
int32_t Modbus_app(void* p) {
204189
UNUSED(p);
190+
App* app = modbus_app_alloc();
191+
Gui* gui = furi_record_open(RECORD_GUI);
192+
app->expansion = furi_record_open(RECORD_EXPANSION);
193+
expansion_disable(app->expansion);
205194
furi_hal_gpio_init_simple(&gpio_ext_pc0, GpioModeOutputPushPull);
206195
furi_hal_gpio_init_simple(&gpio_ext_pc1, GpioModeOutputPushPull);
207196
furi_hal_gpio_write(&gpio_ext_pc0, 0);
208197
furi_hal_gpio_write(&gpio_ext_pc1, 0);
209-
App* app = modbus_app_alloc();
210-
Gui* gui = furi_record_open(RECORD_GUI);
211198
view_dispatcher_attach_to_gui(app->viewDispatcher, gui, ViewDispatcherTypeFullscreen);
212199
scene_manager_next_scene(app->sceneManager, app_scene_main);
213200
view_dispatcher_run(app->viewDispatcher);

ModbusApp/Modbus.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <gui/view_dispatcher.h>
1212
#include <dialogs/dialogs.h>
1313
#include <storage/storage.h>
14+
#include <expansion/expansion.h>
15+
#include <expansion/expansion_settings.h>
1416

1517
#include <stm32wbxx_ll_lpuart.h>
1618
#include <stm32wbxx_ll_usart.h>
@@ -120,6 +122,7 @@ typedef struct {
120122
uint8_t msgBuf[RX_BUF_SIZE + 1];
121123
size_t msgLen;
122124
RingBuffer* ringBuffer;
125+
Expansion* expansion;
123126
} App;
124127

125128
typedef enum {
@@ -152,5 +155,4 @@ extern const char* parityValues[];
152155
extern const char* saveLOGValues[];
153156
extern const char* outputFormatValues[];
154157
extern const char* functionNames[];
155-
extern const char* exceptionCodes[];
156-
uint16_t getCRC(uint8_t* buf, uint8_t len);
158+
extern const char* exceptionCodes[];

ModbusApp/modbus_parser/modbus_parser.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
#include "../Modbus.h"
44
#include "../modbus_ring_buffer/modbus_ring_buffer.h"
55

6+
uint16_t getCRC(uint8_t* buf, uint8_t len) {
7+
uint16_t crc = 0xFFFF;
8+
9+
for(int pos = 0; pos < len; pos++) {
10+
crc ^= (uint16_t)buf[pos];
11+
12+
for(int i = 8; i != 0; i--) {
13+
if((crc & 0x0001) != 0) {
14+
crc >>= 1;
15+
crc ^= 0xA001;
16+
} else
17+
crc >>= 1;
18+
}
19+
}
20+
return crc;
21+
}
22+
623
static void discreteValuesParser(void* context, uint8_t* buff, size_t len, FuriString* data) {
724
App* app = context;
825
uint8_t value = 0;

ModbusApp/modbus_parser/modbus_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
#include <furi.h>
44

55
void handle_rx_data_cb(uint8_t* buf, size_t len, void* context);
6+
uint16_t getCRC(uint8_t* buf, uint8_t len);

ModbusApp/modbus_sender/modbus_sender.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "modbus_sender.h"
2+
#include "../modbus_parser/modbus_parser.h"
23

34
void ModbusSender(void* context) {
45
App* app = context;

ModbusApp/scenes/msgs_buffer_scene.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../Modbus.h"
2+
#include "../modbus_parser/modbus_parser.h"
23

3-
////////////////////////// MSGsBuffer Scene ////////////////////////
44
void OnItemEnterCB(void* context, uint32_t index) {
55
App* app = context;
66
uint8_t start = index ? app->ringBuffer->delimiters[index - 1] + 1 : 0;

ModbusApp/scenes/settings_scene.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#include "../modbus_storage/modbus_storage.h"
33
#include "../modbus_uart/modbus_uart.h"
44

5-
////////////////////////// Settings Scene //////////////////////////
5+
6+
67
void itemChangedCB(VariableItem* item) {
78
App* app = variable_item_get_context(item);
89
uint8_t index = variable_item_get_current_value_index(item);

0 commit comments

Comments
 (0)