From 9b271afdb29edec13191f4b8847a171b8d87531f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 10 Mar 2023 15:13:26 +0100 Subject: [PATCH] answer build for voltage register --- modbus.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/modbus.c b/modbus.c index e3113fb..e1b789c 100644 --- a/modbus.c +++ b/modbus.c @@ -40,12 +40,34 @@ void modbus_timer(void) modbus_analyse_and_answer(); } - +extern uint16_t measure_voltage(); uint8_t modbus_analyse_and_answer(void) { // TODO -> complete the modbus analyse and answer + if(rx_buf[0] == modbusAddress){ + tx_buf[0] = rx_buf[0]; + tx_buf[1] = rx_buf[1]; + + switch(rx_buf[1]){ + case READ_INPUT_REGISTERS: + tx_buf[2] = 2; + tx_buf[4] = input_registers[0]; + tx_buf[3] = input_registers[0]>>8; + // todo choose register + break; + case READ_HOLDING_REGISTERS: + //todo + break; + case WRITE_SINGLE_REGISTER: + //todo + break; + // todo CRC + } + + + } rx_buf[0] = 0; - // sprintf(tx_buf, "%i", modbusAddress, ); + // }