lhakpa dorji
/
TAIST_modbus_Assignment
Modbus serial assignment
Fork of TAIST_modbus by
Diff: modbus.cpp
- Revision:
- 1:b50d9b988d1e
- Parent:
- 0:f306cb0263a6
--- a/modbus.cpp Wed Mar 14 06:17:48 2018 +0000 +++ b/modbus.cpp Wed Mar 14 14:55:36 2018 +0000 @@ -7,7 +7,7 @@ enum state {IDLE, RECEPTION, END} protState = IDLE; int process_buffer(char *buf, uint8_t *frame) -{ +{printf("Modbus buffer\n"); int status = 0; uint8_t sum = 0; uint8_t lrc, i; @@ -33,12 +33,12 @@ } void modbus_init(uint8_t id) -{ +{printf("Modbus Initial ID\n"); nodeId = id; } uint16_t modbus_read(uint16_t offset) -{ +{ printf("Modbus Read\n"); if (offset < ADDR_RANGE) { return regValue[offset]; } @@ -48,7 +48,7 @@ uint16_t modbus_update(uint8_t offset, uint16_t val) { uint16_t tmp; - + printf("Modbus Update\n"); if (offset < ADDR_RANGE) { tmp = regValue[offset]; regValue[offset] = val; @@ -69,18 +69,23 @@ protState = RECEPTION; idx = 0; status = 0; + printf("IDLE case \n"); } break; case RECEPTION: + printf("Reception case \n"); if ((ch >= '0') && (ch <= '9')) { - buf[idx++] = ch; + buf[idx++] = ch; + printf("character length0-9\n"); } else if ((ch >= 'a') && (ch <= 'f')) { buf[idx++] = ch; } else if ((ch >= 'A') && (ch <= 'F')) { buf[idx++] = ch; } else if (ch == '\r') { + printf("type \r END \n"); buf[idx] = 0; protState = END; + } else { protState = IDLE; } @@ -90,6 +95,7 @@ if (process_buffer(buf, frame)) { if ((frame[0] == nodeId) && (frame[1] == FUNC_CODE)) { status = 1; + printf("END\n"); } } } @@ -100,4 +106,4 @@ } return status; -} +} \ No newline at end of file