Quick changes
This commit is contained in:
@@ -16,7 +16,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "lcd_api.h"
|
#include "lcd_api.h"
|
||||||
#include "llfs.h"
|
#include "llfs.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
void modbus_init( void );
|
void modbus_init(void);
|
||||||
|
|
||||||
#endif /* INC_MODBUS_H_ */
|
#endif /* INC_MODBUS_H_ */
|
||||||
|
|||||||
@@ -2,19 +2,21 @@
|
|||||||
|
|
||||||
#define MAX_REG 250
|
#define MAX_REG 250
|
||||||
#define EXTENSION_LENGHT 4
|
#define EXTENSION_LENGHT 4
|
||||||
|
#define TEXT_LENGHT 200
|
||||||
|
#define MULTIPLE_REG 0x10
|
||||||
|
#define ASCII_UNDERSCORE 95
|
||||||
|
|
||||||
|
|
||||||
char registers[MAX_REG];
|
char registers[MAX_REG];
|
||||||
|
|
||||||
static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){
|
static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){
|
||||||
int i;
|
|
||||||
int j;
|
int j;
|
||||||
int len;
|
int len;
|
||||||
int lenght;
|
int lenght;
|
||||||
char extention[EXTENSION_LENGHT];
|
char extention[EXTENSION_LENGHT];
|
||||||
char *pc;
|
char *pc;
|
||||||
char *textstring;
|
char *textstring;
|
||||||
char text[200];
|
char text[TEXT_LENGHT];
|
||||||
uint8_t bg_red = 0;
|
uint8_t bg_red = 0;
|
||||||
uint8_t bg_green = 0;
|
uint8_t bg_green = 0;
|
||||||
uint8_t bg_blue = 0;
|
uint8_t bg_blue = 0;
|
||||||
@@ -26,24 +28,24 @@ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *
|
|||||||
uint32_t result_txt = 0;
|
uint32_t result_txt = 0;
|
||||||
|
|
||||||
for(i = 0; i < 100; i++){
|
for(i = 0; i < 100; i++){
|
||||||
text[i] = 95;
|
text[i] = ASCII_UNDERSCORE; // Putting underscores in the whole array
|
||||||
}
|
}
|
||||||
text[199] = '\0';
|
text[199] = '\0';
|
||||||
|
|
||||||
if (p != NULL){
|
if (p != NULL){
|
||||||
printf("data not null\n");
|
LOG_INFO(TAG, "data not null\n");
|
||||||
// here im going to procces the modbusdata
|
// here im going to procces the modbusdata
|
||||||
tcp_recved( pcb, p->tot_len );
|
tcp_recved( pcb, p->tot_len );
|
||||||
pc = (char*)p->payload;
|
pc = (char*)p->payload;
|
||||||
len = p->tot_len;
|
len = p->tot_len;
|
||||||
|
|
||||||
// putting the bufer in the register array
|
// putting the bufer in the register array
|
||||||
for(i = 0; i < len; i++) {
|
for(int i = 0; i < len; i++) {
|
||||||
registers[i] = pc[i]; // getting the error "void value not ignored as it ought to be" on this line
|
registers[i] = pc[i]; // getting the error "void value not ignored as it ought to be" on this line
|
||||||
}
|
}
|
||||||
|
|
||||||
if(registers[7] == 0x10){ // Check if it's a Modbus Write Multiple Registers request (0x10)
|
if(registers[7] == MULTIPLE_REG){ // Check if it's a Modbus Write Multiple Registers request (0x10)
|
||||||
printf("in writing multiple register mode\n");
|
LOG_INFO(TAG, "in writing multiple register mode\n");
|
||||||
}
|
}
|
||||||
// putting the values from the array in their variable
|
// putting the values from the array in their variable
|
||||||
bg_red = (uint8_t)(registers[14]); // 01
|
bg_red = (uint8_t)(registers[14]); // 01
|
||||||
@@ -54,7 +56,7 @@ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *
|
|||||||
txt_blue = (uint8_t)(registers[24]); // 06
|
txt_blue = (uint8_t)(registers[24]); // 06
|
||||||
nr_img = (uint8_t)(registers[26]); // 07
|
nr_img = (uint8_t)(registers[26]); // 07
|
||||||
|
|
||||||
printf("%d %d %d %d %d %d %d ",bg_red,bg_green,bg_blue,txt_red,txt_green,txt_blue,nr_img);
|
LOG_INFO(TAG, "%d %d %d %d %d %d %d ",bg_red,bg_green,bg_blue,txt_red,txt_green,txt_blue,nr_img);
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
for(i = 28; i < 428; i++){
|
for(i = 28; i < 428; i++){
|
||||||
@@ -63,11 +65,6 @@ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *
|
|||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 100; i++){
|
|
||||||
printf("%c ", text[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
// processing the text data to screen
|
// processing the text data to screen
|
||||||
textstring = text;
|
textstring = text;
|
||||||
|
|
||||||
@@ -123,11 +120,6 @@ static err_t modbus_accept(void *arg, struct tcp_pcb *pcb, err_t err)
|
|||||||
LWIP_UNUSED_ARG(err); // Eliminates compiler warning about unused arguments
|
LWIP_UNUSED_ARG(err); // Eliminates compiler warning about unused arguments
|
||||||
tcp_setprio(pcb, TCP_PRIO_MIN); // Sets the priority of a connection.
|
tcp_setprio(pcb, TCP_PRIO_MIN); // Sets the priority of a connection.
|
||||||
tcp_recv(pcb, modbus_incomming_data); // sets which function is being called when new data arives
|
tcp_recv(pcb, modbus_incomming_data); // sets which function is being called when new data arives
|
||||||
tcp_err(pcb, NULL); // sets the function thats called when an error ocours
|
|
||||||
tcp_poll(pcb, NULL, 4); // the aplication is being polled every 4 seconds
|
|
||||||
tcp_write(pcb, "TEST\r\n", 8, 0); // pcb , data , lenght in bytes , apiflags
|
|
||||||
printf("connected\n");
|
|
||||||
tcp_sent(pcb, NULL); // Specifies the callback function that should be called when data has successfully been received
|
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user