done
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
|
||||
// Global variables
|
||||
char registers[MAX_REG];
|
||||
// const char* TAG = "Modbus_TCP"; // Tag used in logs
|
||||
static char* TAG = "Modbus_TCP"; // Tag used in logs
|
||||
|
||||
// Functions
|
||||
static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err);
|
||||
@@ -57,7 +57,7 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
text[TEXT_LENGTH - 1] = '\0';
|
||||
|
||||
if (p != NULL) {
|
||||
// LOG_INFO(TAG, "data not null\n");
|
||||
LOG_INFO(TAG, "data not null\n");
|
||||
// Process the modbus data
|
||||
tcp_recved(pcb, p->tot_len);
|
||||
pc = (char*)p->payload;
|
||||
@@ -67,7 +67,7 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
}
|
||||
|
||||
if (registers[MODBUS_MODE] == MULTIPLE_REG) { // Check if it's a Modbus Write Multiple Registers request (0x10)
|
||||
// LOG_INFO(TAG, "in writing multiple register mode\n");
|
||||
LOG_INFO(TAG, "in writing multiple register mode\n");
|
||||
background_red = (uint8_t)(registers[REG_01]); // 01
|
||||
background_green = (uint8_t)(registers[REG_02]); // 02
|
||||
background_blue = (uint8_t)(registers[REG_03]); // 03
|
||||
@@ -76,8 +76,7 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
text_color_blue = (uint8_t)(registers[REG_06]); // 06
|
||||
nr_img = (uint8_t)(registers[REG_07]); // 07
|
||||
|
||||
// LOG_INFO(TAG, "%d %d %d %d %d %d %d
|
||||
// ",background_red,background_green,background_blue,text_color_red,text_color_green,text_color_blue,nr_img);
|
||||
LOG_INFO(TAG, "%d %d %d %d %d %d %d",background_red,background_green,background_blue,text_color_red,text_color_green,text_color_blue,nr_img);
|
||||
|
||||
counter = 0;
|
||||
for (int i = START_DATA; i < REG_LENGTH; i++) {
|
||||
@@ -135,7 +134,7 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
}
|
||||
|
||||
} else {
|
||||
// LOG_INFO(TAG, "not in writing multiple register mode!!!\n");
|
||||
LOG_INFO(TAG, "not in writing multiple register mode!!!\n");
|
||||
}
|
||||
} else if (err == ERR_OK) {
|
||||
tcp_close(pcb); // When everything was ok close the TCP connection
|
||||
@@ -162,9 +161,11 @@ static err_t modbus_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
||||
*/
|
||||
void modbus_init(void) {
|
||||
struct tcp_pcb* modbus_pcb;
|
||||
LOG_INFO(TAG, "Initializing\n");
|
||||
modbus_pcb = tcp_new(); // Creating a new tcp pcb
|
||||
tcp_bind(modbus_pcb, IP_ADDR_ANY, MODBUSPORT); // Bind the modbus_pcb to port 502
|
||||
|
||||
modbus_pcb = tcp_listen(modbus_pcb); // Listen
|
||||
tcp_accept(modbus_pcb, modbus_accept); // Set callback function
|
||||
LOG_INFO(TAG, "initialized\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user