Skip to content

Commit 9093249

Browse files
author
Bjoern Schmidt
committed
controller expects rtu from app (build 184+ needed)
1 parent 0d825ce commit 9093249

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

BOdisplay.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// example
3434
//:304100305F\r\n
3535
// 0 A 0 (as chars)
36-
uint8_t ui8_rx_buffer[17]; // modbus ascii with max 8 bytes payload (array including padding)
36+
uint8_t ui8_rx_buffer[17]; // modbus ascii with max 8 bytes payload (array including padding) // modbus rtu uses only 11 bytes
3737
uint8_t ui8_tx_buffer[53]; // (max 24*8bit key + 24*8bit data points + bounced checksum(+ key) + address + function + checksum) (array excluding padding)
3838
uint8_t ui8_rx_converted_buffer[7]; // for decoded ascii values
3939

@@ -395,23 +395,49 @@ void display_init() {
395395
// noop just here to have a common interface
396396
}
397397

398-
void display_update() {
399-
398+
uint8_t readRtu(){
399+
uart_fill_rx_packet_buffer(ui8_rx_buffer, 11, &ui8_rx_buffer_counter);
400+
if (ui8_rx_buffer_counter == 11) {
401+
ui8_rx_converted_buffer[0] = ui8_rx_buffer[0];
402+
ui8_rx_converted_buffer[1] = ui8_rx_buffer[1];
403+
ui8_rx_converted_buffer[2] = ui8_rx_buffer[2];
404+
ui8_rx_converted_buffer[3] = ui8_rx_buffer[3];
405+
ui8_rx_converted_buffer[4] = ui8_rx_buffer[4];
406+
ui8_rx_converted_buffer[5] = ui8_rx_buffer[5];
407+
ui8_rx_converted_buffer[6] = ui8_rx_buffer[6];
408+
// allow fetching of new data
409+
ui8_rx_buffer_counter = 0;
410+
return 1;
411+
}
412+
return 0;
413+
}
400414

415+
uint8_t readAscii(){
401416
uart_fill_rx_packet_buffer(ui8_rx_buffer, 17, &ui8_rx_buffer_counter);
402-
403-
404417
if (ui8_rx_buffer_counter == 17) {
405-
406-
uint8_t calculatedLrc;
407-
408418
ui8_rx_converted_buffer[0] = (hex2int(ui8_rx_buffer[1]) << 4) + hex2int(ui8_rx_buffer[2]);
409419
ui8_rx_converted_buffer[1] = (hex2int(ui8_rx_buffer[3]) << 4) + hex2int(ui8_rx_buffer[4]);
410420
ui8_rx_converted_buffer[2] = (hex2int(ui8_rx_buffer[5]) << 4) + hex2int(ui8_rx_buffer[6]);
411421
ui8_rx_converted_buffer[3] = (hex2int(ui8_rx_buffer[7]) << 4) + hex2int(ui8_rx_buffer[8]);
412422
ui8_rx_converted_buffer[4] = (hex2int(ui8_rx_buffer[9]) << 4) + hex2int(ui8_rx_buffer[10]);
413423
ui8_rx_converted_buffer[5] = (hex2int(ui8_rx_buffer[11]) << 4) + hex2int(ui8_rx_buffer[12]);
414424
ui8_rx_converted_buffer[6] = (hex2int(ui8_rx_buffer[13]) << 4) + hex2int(ui8_rx_buffer[14]);
425+
// allow fetching of new data
426+
ui8_rx_buffer_counter = 0;
427+
return 1;
428+
}
429+
return 0;
430+
}
431+
432+
uint8_t readUart(){
433+
return readRtu();
434+
}
435+
436+
void display_update() {
437+
438+
if (readUart()) {
439+
440+
uint8_t calculatedLrc;
415441
calculatedLrc = calcLRC(ui8_rx_converted_buffer, 0, 6);
416442

417443

@@ -458,8 +484,6 @@ void display_update() {
458484
sendPreparedPackage();
459485
}
460486

461-
// allow fetching of new data
462-
ui8_rx_buffer_counter = 0;
463487
}
464488
}
465489

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
#define TQS_CALIB 0.0
4646
#define ACA 670
4747
#define EEPROM_NOINIT // eeprom will not be cleared
48-
#define EEPROM_INIT_MAGIC_BYTE 89 // makes sure (chance of fail 1/255) eeprom is invalidated after flashing new config
48+
#define EEPROM_INIT_MAGIC_BYTE 249 // makes sure (chance of fail 1/255) eeprom is invalidated after flashing new config
4949

5050
#endif /* CONFIG_H_ */

0 commit comments

Comments
 (0)