forked from xuos/xiuos
feat add control_framework, read json file OK
This commit is contained in:
parent
2a8a11849d
commit
bc47ae644f
|
@ -18,6 +18,31 @@
|
|||
* @date 2022.9.27
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
void ControlOmronTest(void)
|
||||
{
|
||||
uint16_t read_data_length = 0;
|
||||
uint8_t read_data[1024] = {0};
|
||||
ControlProtocolType fins_protocol = ControlProtocolFind();
|
||||
if (NULL == fins_protocol) {
|
||||
printf("%s get fins protocol %p failed\n", __func__, fins_protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s get fins protocol %p successfull\n", __func__, fins_protocol);
|
||||
|
||||
if (CONTROL_REGISTERED == fins_protocol->protocol_status) {
|
||||
ControlProtocolOpen(fins_protocol);
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
for (int i = 0; i < 10; i ++) {
|
||||
read_data_length = ControlProtocolRead(fins_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] fins data %d using receipe file\n", __func__, i, read_data_length);
|
||||
}
|
||||
|
||||
//ControlProtocolClose(fins_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlOmronTest, Omron Plc FINS Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#define FINS_COMMAND_LENGTH 34
|
||||
|
||||
static struct CircularAreaApp *circular_area;
|
||||
static BasicSocketPlc plc_socket = {0};
|
||||
|
||||
static uint8_t handshake_require_command[] = {0x46, 0x49, 0x4E, 0x53, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
static uint8_t handshake_respond_buff[24] = {0};
|
||||
|
@ -53,18 +53,19 @@ static uint8_t FinsAreaCode(char area_char, FinsDataType type)
|
|||
* @param p_command - command pointer
|
||||
* @param plc_ip_4 - last plc ip
|
||||
* @param local_ip_4 - last local ip
|
||||
* @param command_code - fins command code
|
||||
* @param area_char - area char
|
||||
* @param data_type - fins data type
|
||||
* @param start_address - fins cmd start address
|
||||
* @param bit_address - fins cmd bit address
|
||||
* @param data_length - fins cmd data length
|
||||
* @param p_read_item - p_read_item pointer
|
||||
* @return success : index error : 0
|
||||
*/
|
||||
static uint16_t FinsCommandGenerate(uint8_t *p_command, uint16_t plc_ip_4, uint16_t local_ip_4, FinsCommandCode command_code, char area_char,
|
||||
FinsDataType data_type, uint16_t start_address, uint8_t bit_address, uint16_t data_length)
|
||||
static uint16_t FinsCommandGenerate(uint8_t *p_command, uint16_t plc_ip_4, uint16_t local_ip_4, FinsReadItem *p_read_item)
|
||||
{
|
||||
uint8_t index = 0;
|
||||
uint16_t command_code = p_read_item->data_info.command_code;
|
||||
uint8_t area_char = p_read_item->area_char;
|
||||
uint16_t data_type = p_read_item->data_type;
|
||||
uint16_t start_address = p_read_item->start_address;
|
||||
uint8_t bit_address = p_read_item->bit_address;
|
||||
uint16_t data_length = p_read_item->data_length;
|
||||
|
||||
p_command[index++] = (uint8_t)(FINS_HEADER_HEAD >> (3 * 8));
|
||||
p_command[index++] = (uint8_t)(FINS_HEADER_HEAD >> (2 * 8));
|
||||
p_command[index++] = (uint8_t)(FINS_HEADER_HEAD >> (1 * 8));
|
||||
|
@ -201,10 +202,9 @@ static int FinsHandshake(int32_t socket, uint16_t local_ip_4)
|
|||
* @description: Fins Get Data From Socket
|
||||
* @param socket - socket
|
||||
* @param p_read_item - read item pointer
|
||||
* @param p_recipe - control recipe pointer
|
||||
* @return success : 0 error : -1 -2
|
||||
*/
|
||||
static int FinsGetData(int32_t socket, FinsReadItem *p_read_item, struct ControlRecipe *p_recipe)
|
||||
static int FinsGetData(int32_t socket, FinsReadItem *p_read_item)
|
||||
{
|
||||
uint8_t try_count = 0;
|
||||
int32_t write_error = 0;
|
||||
|
@ -248,34 +248,22 @@ static int FinsGetData(int32_t socket, FinsReadItem *p_read_item, struct Control
|
|||
* @param p_read_item - read item pointer
|
||||
* @param plc_ip_4 - last plc ip
|
||||
* @param local_ip_4 - last local ip
|
||||
* @param command_code - fins command code
|
||||
* @param area_char - area char
|
||||
* @param data_type - fins data type
|
||||
* @param start_address - fins cmd start address
|
||||
* @param bit_address - fins cmd bit address
|
||||
* @param data_length - fins cmd data length
|
||||
* @param p_data - control-data pointer
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
static int FinsInitialDataInfo(FinsReadItem *p_read_item, uint16_t plc_ip_4, uint16_t local_ip_4, FinsCommandCode command_code,
|
||||
char area_char, FinsDataType data_type, uint16_t start_address, uint8_t bit_address, uint16_t data_length, uint8_t *p_data)
|
||||
static int FinsInitialDataInfo(FinsReadItem *p_read_item, uint16_t plc_ip_4, uint16_t local_ip_4, uint8_t *p_data)
|
||||
{
|
||||
p_read_item->area_char = area_char;
|
||||
p_read_item->data_type = data_type;
|
||||
p_read_item->data_info.command_code = command_code;
|
||||
p_read_item->start_address = start_address;
|
||||
p_read_item->bit_address = bit_address;
|
||||
p_read_item->data_length = data_length;
|
||||
uint16_t data_length = p_read_item->data_length;
|
||||
|
||||
BasicPlcDataInfo *p_base_data_info = &(p_read_item->data_info.base_data_info);
|
||||
switch (command_code)
|
||||
switch (p_read_item->data_info.command_code)
|
||||
{
|
||||
case FINS_COMMAND_CODE_READ:
|
||||
data_length *= (data_type == FINS_DATA_TYPE_BIT ? 1 : 2);
|
||||
data_length *= (p_read_item->data_type == FINS_DATA_TYPE_BIT ? 1 : 2);
|
||||
p_base_data_info->command_length = FINS_COMMAND_LENGTH;
|
||||
p_base_data_info->p_command = (p_data == NULL ? PrivMalloc(FINS_COMMAND_LENGTH + data_length) : PrivMalloc(FINS_COMMAND_LENGTH));
|
||||
p_base_data_info->p_command = PrivMalloc(FINS_COMMAND_LENGTH);
|
||||
p_base_data_info->data_size = data_length;
|
||||
p_base_data_info->p_data = (p_data == NULL ? p_base_data_info->p_command + FINS_COMMAND_LENGTH : p_data);
|
||||
p_base_data_info->p_data = p_data;
|
||||
break;
|
||||
case FINS_COMMAND_CODE_WRITE:
|
||||
//To Do
|
||||
|
@ -283,8 +271,7 @@ static int FinsInitialDataInfo(FinsReadItem *p_read_item, uint16_t plc_ip_4, uin
|
|||
default:
|
||||
return -1;
|
||||
}
|
||||
uint16_t command_length = FinsCommandGenerate(p_base_data_info->p_command, plc_ip_4, local_ip_4, command_code, area_char,
|
||||
data_type, start_address, bit_address, data_length);
|
||||
FinsCommandGenerate(p_base_data_info->p_command, plc_ip_4, local_ip_4, p_read_item);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -303,12 +290,11 @@ void *ReceivePlcDataTask(void *parameter)
|
|||
uint16_t read_item_size = sizeof(FinsReadItem);
|
||||
|
||||
struct ControlProtocol *control_protocol = (struct ControlProtocol *)parameter;
|
||||
circular_area = (struct CircularAreaApp *)control_protocol->args;
|
||||
struct CircularAreaApp *circular_area = (struct CircularAreaApp *)control_protocol->args;
|
||||
FinsReadItem *fins_read_item = (FinsReadItem *)control_protocol->recipe->read_item;
|
||||
fins_data = control_protocol->recipe->protocol_data->data;
|
||||
data_length = control_protocol->recipe->protocol_data->data_length;
|
||||
fins_data = control_protocol->recipe->protocol_data.data;
|
||||
data_length = control_protocol->recipe->protocol_data.data_length;
|
||||
|
||||
BasicSocketPlc plc_socket;
|
||||
memset(&plc_socket, 0, sizeof(BasicSocketPlc));
|
||||
memcpy(plc_socket.ip, control_protocol->recipe->socket_config.plc_ip, 4);
|
||||
plc_socket.port = control_protocol->recipe->socket_config.port;
|
||||
|
@ -333,16 +319,17 @@ void *ReceivePlcDataTask(void *parameter)
|
|||
|
||||
plc_socket.secondary_connect_flag = 1;
|
||||
|
||||
FinsGetData(plc_socket.socket, (FinsReadItem *)fins_read_item + i, control_protocol->recipe);
|
||||
FinsGetData(plc_socket.socket, (FinsReadItem *)fins_read_item + i);
|
||||
}
|
||||
|
||||
/*read all variable item data, put them into circular_area*/
|
||||
if (i == control_protocol->recipe->read_item_count) {
|
||||
printf("%s get %d item %d length\n", __func__, i, data_length);
|
||||
CircularAreaAppWrite(circular_area, fins_data, data_length, 0);
|
||||
}
|
||||
|
||||
/*read data every single 200ms*/
|
||||
PrivTaskDelay(200);
|
||||
PrivTaskDelay(control_protocol->recipe->read_period);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,6 +352,8 @@ int FinsOpen(struct ControlProtocol *control_protocol)
|
|||
*/
|
||||
int FinsClose(struct ControlProtocol *control_protocol)
|
||||
{
|
||||
ControlDisconnectSocket(&plc_socket);
|
||||
|
||||
ControlProtocolCloseDef();
|
||||
|
||||
return 0;
|
||||
|
@ -379,6 +368,7 @@ int FinsClose(struct ControlProtocol *control_protocol)
|
|||
*/
|
||||
int FinsRead(struct ControlProtocol *control_protocol, void *buf, size_t len)
|
||||
{
|
||||
struct CircularAreaApp *circular_area = (struct CircularAreaApp *)control_protocol->args;
|
||||
return CircularAreaAppRead(circular_area, buf, len);
|
||||
}
|
||||
|
||||
|
@ -400,27 +390,25 @@ static struct ControlDone fins_protocol_done =
|
|||
int FinsProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatInfo *protocol_format_info)
|
||||
{
|
||||
int ret = 0;
|
||||
static uint8_t last_data_length = 0;
|
||||
|
||||
p_recipe->read_item = PrivMalloc(sizeof(FinsReadItem) * p_recipe->read_item_count);
|
||||
FinsReadItem *fins_read_item = (FinsReadItem *)(p_recipe->read_item) + protocol_format_info->read_item_index;
|
||||
|
||||
|
||||
fins_read_item->value_type = cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "value_type")->valueint;
|
||||
strncpy(fins_read_item->value_name, cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "value_name")->valuestring, 20);
|
||||
|
||||
strncpy(&fins_read_item->area_char, cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "area_char")->valuestring, 1);
|
||||
fins_read_item->data_type = cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "data_type")->valueint;
|
||||
fins_read_item->data_info.command_code = FINS_COMMAND_CODE_READ;
|
||||
fins_read_item->start_address = cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "start_address")->valueint;
|
||||
fins_read_item->bit_address = cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "bit_address")->valueint;
|
||||
fins_read_item->data_length = cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "data_length")->valueint;
|
||||
|
||||
ret = FinsInitialDataInfo(fins_read_item,
|
||||
p_recipe->socket_config.plc_ip[3],
|
||||
p_recipe->socket_config.local_ip[3],
|
||||
FINS_COMMAND_CODE_READ,
|
||||
cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "area_char")->valuestring[0],
|
||||
cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "data_type")->valueint,
|
||||
cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "start_address")->valueint,
|
||||
cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "bit_address")->valueint,
|
||||
cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "data_length")->valueint,
|
||||
p_recipe->protocol_data->data + last_data_length);
|
||||
protocol_format_info->p_read_item_data + protocol_format_info->last_item_size);
|
||||
|
||||
ControlPrintfList("CMD", fins_read_item->data_info.base_data_info.p_command, fins_read_item->data_info.base_data_info.command_length);
|
||||
last_data_length = GetValueTypeMemorySize(fins_read_item->value_type);
|
||||
protocol_format_info->last_item_size = GetValueTypeMemorySize(fins_read_item->value_type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -431,23 +419,16 @@ int FinsProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatInfo *pr
|
|||
* @return success : 0 error : -1
|
||||
*/
|
||||
int FinsProtocolInit(struct ControlRecipe *p_recipe)
|
||||
{
|
||||
struct ControlProtocol *p_control_protocol = CONTAINER_OF(p_recipe, struct ControlProtocol, recipe);
|
||||
if (NULL == p_control_protocol) {
|
||||
printf("%s get control protocol failed\n", __func__);
|
||||
{
|
||||
p_recipe->read_item = PrivMalloc(sizeof(FinsReadItem) * p_recipe->read_item_count);
|
||||
if (NULL == p_recipe->read_item) {
|
||||
PrivFree(p_recipe->read_item);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FinsReadItem *fins_read_item = PrivMalloc(sizeof(FinsReadItem) * p_recipe->read_item_count);
|
||||
if (NULL == fins_read_item) {
|
||||
PrivFree(fins_read_item);
|
||||
return -1;
|
||||
}
|
||||
p_recipe->read_item = (void *)fins_read_item;
|
||||
|
||||
|
||||
p_recipe->ControlProtocolFormatCmd = FinsProtocolFormatCmd;
|
||||
|
||||
p_control_protocol->done = &fins_protocol_done;
|
||||
p_recipe->done = &fins_protocol_done;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"netmask": "255.255.254.0",
|
||||
"port": 9600
|
||||
},
|
||||
"protocol_type": 6,
|
||||
"protocol_type": 5,
|
||||
"read_period": 100,
|
||||
"read_item_list": [
|
||||
{
|
||||
|
|
|
@ -70,9 +70,9 @@ typedef struct
|
|||
FinsDataInfo data_info;
|
||||
|
||||
UniformValueType value_type;
|
||||
char value_name[20];
|
||||
uint8_t value_name[20];
|
||||
|
||||
char area_char;
|
||||
uint8_t area_char;
|
||||
FinsDataType data_type;
|
||||
uint16_t start_address;
|
||||
uint8_t bit_address;
|
||||
|
|
|
@ -74,6 +74,9 @@ static int ControlAnalyzeRecipe(ControlProtocolType control_protocol, const char
|
|||
uint16_t recipe_file_length = 0;
|
||||
char *recipe_file_buf;
|
||||
|
||||
/*wait for SD-card mount done*/
|
||||
PrivTaskDelay(5000);
|
||||
|
||||
//Step1 : read recipe file data from SD card or other store device
|
||||
recipe_file_fd = PrivOpen(recipe_name, O_RDONLY);
|
||||
if (recipe_file_fd < 0) {
|
||||
|
@ -110,7 +113,6 @@ static int ControlAnalyzeRecipe(ControlProtocolType control_protocol, const char
|
|||
//Step2 : CJSON analyze
|
||||
#ifdef LIB_USING_CJSON
|
||||
cJSON *recipe_file_json = cJSON_Parse(recipe_file_buf);
|
||||
PrivFree(recipe_file_buf);
|
||||
if (NULL == recipe_file_json) {
|
||||
printf("Parse recipe_file_buf failed!\n");
|
||||
return -1;
|
||||
|
@ -120,14 +122,22 @@ static int ControlAnalyzeRecipe(ControlProtocolType control_protocol, const char
|
|||
memset(control_protocol->recipe, 0, sizeof(struct ControlRecipe));
|
||||
|
||||
/*Get basic information from recipe file*/
|
||||
if (RecipeBasicInformation(control_protocol->recipe, control_protocol->protocol_type, recipe_file_json) < 0) {
|
||||
if (RecipeBasicInformation(control_protocol->recipe, recipe_file_json) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
control_protocol->protocol_type = control_protocol->recipe->protocol_type;
|
||||
|
||||
printf("%s %d control_protocol %p recipe %p\n", __func__, __LINE__, control_protocol, control_protocol->recipe);
|
||||
|
||||
/*Get the variable need to read from recipe file*/
|
||||
RecipeReadVariableItem(control_protocol->recipe, control_protocol->protocol_type, recipe_file_json);
|
||||
RecipeReadVariableItem(control_protocol->recipe, recipe_file_json);
|
||||
|
||||
control_protocol->done = control_protocol->recipe->done;
|
||||
|
||||
cJSON_Delete(recipe_file_json);
|
||||
|
||||
PrivFree(recipe_file_buf);
|
||||
printf("Read and parse recipe file done!\n");
|
||||
#endif
|
||||
|
||||
|
@ -247,6 +257,8 @@ int ControlFrameworkInit(void)
|
|||
goto _out;
|
||||
}
|
||||
|
||||
printf("%s malloc control_protocol %p\n", __func__, control_protocol);
|
||||
|
||||
//Control Protocol Struct Init
|
||||
ret = ControlProtocolInit(control_protocol);
|
||||
if (ret < 0) {
|
||||
|
@ -255,6 +267,8 @@ int ControlFrameworkInit(void)
|
|||
goto _out;
|
||||
}
|
||||
|
||||
printf("%s malloc CONTROL_RECIPE_FILE %s\n", __func__, CONTROL_RECIPE_FILE);
|
||||
|
||||
//Read Recipe File, Get Control Protocol Configure Param
|
||||
ret = ControlAnalyzeRecipe(control_protocol, CONTROL_RECIPE_FILE);
|
||||
if (ret < 0) {
|
||||
|
@ -265,6 +279,8 @@ int ControlFrameworkInit(void)
|
|||
|
||||
control_protocol->protocol_status = CONTROL_REGISTERED;
|
||||
|
||||
printf("%s recipe %p\n", __func__, control_protocol->recipe);
|
||||
|
||||
ret = ControlPeripheralInit(control_protocol->recipe);
|
||||
if (ret < 0) {
|
||||
printf("%s failed!\n", __func__);
|
||||
|
@ -272,6 +288,8 @@ int ControlFrameworkInit(void)
|
|||
goto _out;
|
||||
}
|
||||
|
||||
printf("%s ControlPeripheralInit done\n", __func__);
|
||||
|
||||
_out:
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ extern "C" {
|
|||
|
||||
struct ControlProtocol;
|
||||
typedef struct ControlProtocol *ControlProtocolType;
|
||||
typedef struct ControlData *ControlDataType;
|
||||
|
||||
struct ControlDone
|
||||
{
|
||||
|
@ -76,7 +75,6 @@ struct ControlProtocol
|
|||
|
||||
sem_t sem;
|
||||
pthread_mutex_t lock;
|
||||
//struct DoublelistNode link;
|
||||
};
|
||||
|
||||
/*Control Framework Protocol Init*/
|
||||
|
@ -85,12 +83,6 @@ int ControlFrameworkInit(void);
|
|||
/*Control Framework Find certain Protocol*/
|
||||
ControlProtocolType ControlProtocolFind(void);
|
||||
|
||||
// /*Control Framework Protocol Register*/
|
||||
// int ControlProtocolRegister(struct ControlProtocol *control_protocol);
|
||||
|
||||
// /*Control Framework Protocol Unregister*/
|
||||
// int ControlProtocolUnregister(struct ControlProtocol *control_protocol);
|
||||
|
||||
/*Control Framework Protocol Open*/
|
||||
int ControlProtocolOpen(struct ControlProtocol *control_protocol);
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ static int ControlProtocolInitDesc(struct ControlRecipe *p_recipe, struct Contro
|
|||
for( i = 0; sub_protocol_desc[i].fn != NULL; i++ ) {
|
||||
if (p_recipe->protocol_type == sub_protocol_desc[i].protocol_type) {
|
||||
ret = sub_protocol_desc[i].fn(p_recipe);
|
||||
printf("control protocol initialize %d %s\n", sub_protocol_desc[i].protocol_type, ret == 0 ? "success" : "failed");
|
||||
printf("%s initialize %d %s\n", __func__, sub_protocol_desc[i].protocol_type, ret == 0 ? "success" : "failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -87,16 +87,16 @@ static int ControlProtocolInitDesc(struct ControlRecipe *p_recipe, struct Contro
|
|||
static void FormatDataHeader(struct ControlRecipe *p_recipe)
|
||||
{
|
||||
uint16_t plc_read_data_length = CONTROL_DATA_HEAD_LENGTH + p_recipe->total_data_length;//Head length is CONTROL_DATA_HEAD_LENGTH
|
||||
uint8_t *data = p_recipe->protocol_data->data;
|
||||
uint8_t *data = p_recipe->protocol_data.data;
|
||||
|
||||
data[0] = CONTROL_DATA_HEAD_1;
|
||||
data[1] = CONTROL_DATA_HEAD_2;
|
||||
data[2] = (p_recipe->device_id) >> 8;
|
||||
data[3] = p_recipe->device_id;
|
||||
data[4] = (plc_read_data_length) >> 8;
|
||||
data[5] = plc_read_data_length;
|
||||
data[6] = (p_recipe->read_item_count) >> 8;
|
||||
data[7] = p_recipe->read_item_count;
|
||||
data[2] = (uint8_t)(p_recipe->device_id >> 8);
|
||||
data[3] = (uint8_t)p_recipe->device_id;
|
||||
data[4] = (uint8_t)(plc_read_data_length >> 8);
|
||||
data[5] = (uint8_t)plc_read_data_length;
|
||||
data[6] = (uint8_t)(p_recipe->read_item_count >> 8);
|
||||
data[7] = (uint8_t)p_recipe->read_item_count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,8 +236,12 @@ int ControlConnectSocket(BasicSocketPlc *p_plc)
|
|||
return -4;
|
||||
}
|
||||
|
||||
printf("%s %d ip %u.%u.%u.%u port %d\n", __func__, __LINE__,
|
||||
p_plc->ip[0], p_plc->ip[1], p_plc->ip[2], p_plc->ip[3],
|
||||
p_plc->port);
|
||||
|
||||
if (connect(plc_socket, (struct sockaddr*)&plc_addr_in, sizeof(struct sockaddr)) == -1) {
|
||||
printf("Connect plc socket failed!\n");
|
||||
printf("Connect plc socket failed!errno %d\n", errno);
|
||||
closesocket(plc_socket);
|
||||
return -5;
|
||||
} else {
|
||||
|
@ -359,17 +363,12 @@ int ControlPeripheralInit(struct ControlRecipe *p_recipe)
|
|||
/**
|
||||
* @description: Control Framework Get Recipe Basic Information
|
||||
* @param p_recipe - Control recipe pointer
|
||||
* @param protocol_type - protocol type
|
||||
* @param p_recipe_file_json - recipe_file_json pointer
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
int RecipeBasicInformation(struct ControlRecipe *p_recipe, int protocol_type, cJSON *p_recipe_file_json)
|
||||
int RecipeBasicInformation(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_json)
|
||||
{
|
||||
if (protocol_type != (ProtocolType)(cJSON_GetObjectItem(p_recipe_file_json, "protocol_type")->valueint)) {
|
||||
printf("protocol type not match!\n");
|
||||
return -1;
|
||||
}
|
||||
p_recipe->protocol_type = protocol_type;
|
||||
p_recipe->protocol_type = (ProtocolType)(cJSON_GetObjectItem(p_recipe_file_json, "protocol_type")->valueint);
|
||||
|
||||
p_recipe->device_id = cJSON_GetObjectItem(p_recipe_file_json, "device_id")->valueint;
|
||||
strncpy(p_recipe->device_name, cJSON_GetObjectItem(p_recipe_file_json, "device_name")->valuestring, 20);
|
||||
|
@ -394,17 +393,16 @@ int RecipeBasicInformation(struct ControlRecipe *p_recipe, int protocol_type, cJ
|
|||
|
||||
printf("\n************************************************************\n");
|
||||
}
|
||||
|
||||
extern int FinsProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatInfo *protocol_format_info);
|
||||
/**
|
||||
* @description: Control Framework Read Variable Item Function
|
||||
* @param p_recipe - Control recipe pointer
|
||||
* @param protocol_type - protocol type
|
||||
* @param p_recipe_file_json - recipe_file_json pointer
|
||||
* @return
|
||||
*/
|
||||
void RecipeReadVariableItem(struct ControlRecipe *p_recipe, int protocol_type, cJSON *p_recipe_file_json)
|
||||
void RecipeReadVariableItem(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_json)
|
||||
{
|
||||
int ret = 0;
|
||||
int i, ret = 0;
|
||||
|
||||
ProtocolFormatInfo protocol_format_info;
|
||||
memset(&protocol_format_info, 0, sizeof(ProtocolFormatInfo));
|
||||
|
@ -416,10 +414,13 @@ void RecipeReadVariableItem(struct ControlRecipe *p_recipe, int protocol_type, c
|
|||
p_recipe->total_data_length = GetRecipeTotalDataLength(read_item_list_json);
|
||||
|
||||
/*Malloc Read Data Pointer, Reference "CONTROL FRAMEWORK READ DATA FORMAT"*/
|
||||
p_recipe->protocol_data = PrivMalloc(sizeof(struct ProtocolData));
|
||||
p_recipe->protocol_data->data = PrivMalloc(CONTROL_DATA_HEAD_LENGTH + p_recipe->total_data_length);
|
||||
p_recipe->protocol_data->data_length = CONTROL_DATA_HEAD_LENGTH + p_recipe->total_data_length;
|
||||
memset(p_recipe->protocol_data->data, 0, p_recipe->protocol_data->data_length);
|
||||
p_recipe->protocol_data.data = PrivMalloc(CONTROL_DATA_HEAD_LENGTH + p_recipe->total_data_length);
|
||||
p_recipe->protocol_data.data_length = CONTROL_DATA_HEAD_LENGTH + p_recipe->total_data_length;
|
||||
memset(p_recipe->protocol_data.data, 0, p_recipe->protocol_data.data_length);
|
||||
|
||||
protocol_format_info.p_read_item_data = p_recipe->protocol_data.data + CONTROL_DATA_HEAD_LENGTH;
|
||||
|
||||
printf("%s %d recipe %p\n", __func__, __LINE__, p_recipe);
|
||||
|
||||
/*Init The Control Protocol*/
|
||||
ControlProtocolInitDesc(p_recipe, protocol_init);
|
||||
|
@ -427,18 +428,26 @@ void RecipeReadVariableItem(struct ControlRecipe *p_recipe, int protocol_type, c
|
|||
/*Format Data Header, Reference "CONTROL FRAMEWORK READ DATA FORMAT"*/
|
||||
FormatDataHeader(p_recipe);
|
||||
|
||||
for (uint16_t read_item_index = 0; read_item_index < p_recipe->read_item_count; read_item_index ++) {
|
||||
cJSON *read_single_item_json = cJSON_GetArrayItem(read_item_list_json, read_item_index);
|
||||
uint16_t read_item_count = p_recipe->read_item_count;
|
||||
|
||||
printf("%s %d protocol_format_info %p read_item_count %p\n", __func__, __LINE__, &protocol_format_info, &(p_recipe->read_item_count));
|
||||
|
||||
for (i = 0; i < read_item_count; i ++) {
|
||||
printf("%s %d read_item_index %d read_item_count %d\n", __func__, __LINE__, i, read_item_count);
|
||||
|
||||
cJSON *read_single_item_json = cJSON_GetArrayItem(read_item_list_json, i);
|
||||
|
||||
protocol_format_info.read_single_item_json = read_single_item_json;
|
||||
protocol_format_info.read_item_index = read_item_index;
|
||||
protocol_format_info.read_item_index = i;
|
||||
|
||||
/*Format Protocol Cmd By Analyze Variable Item One By One*/
|
||||
ret = p_recipe->ControlProtocolFormatCmd(p_recipe, &protocol_format_info);
|
||||
if (ret < 0) {
|
||||
printf("%s read %d item failed!\n", __func__, read_item_index);
|
||||
printf("%s read %d item failed!\n", __func__, i);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s %d ret %d recipe %p count %p [%d] [%d]\n", __func__, __LINE__, ret, p_recipe, &(p_recipe->read_item_count), p_recipe->read_item_count, read_item_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,9 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
cJSON *read_single_item_json;
|
||||
uint8_t *p_read_item_data;
|
||||
uint16_t read_item_index;//Variable item index(1 ++)
|
||||
uint8_t last_item_size;
|
||||
}ProtocolFormatInfo;
|
||||
|
||||
struct ProtocolData
|
||||
|
@ -104,7 +106,7 @@ struct SocketConfig
|
|||
|
||||
struct ControlRecipe
|
||||
{
|
||||
char device_name[20];
|
||||
uint8_t device_name[20];
|
||||
uint16_t device_id;
|
||||
uint16_t read_period;
|
||||
uint16_t read_item_count;
|
||||
|
@ -114,11 +116,12 @@ struct ControlRecipe
|
|||
ProtocolType protocol_type;
|
||||
|
||||
void *read_item;
|
||||
struct ControlDone *done;
|
||||
|
||||
struct SerialConfig serial_config;
|
||||
struct SocketConfig socket_config;
|
||||
|
||||
struct ProtocolData *protocol_data;
|
||||
struct ProtocolData protocol_data;
|
||||
|
||||
int (*ControlProtocolFormatCmd)(struct ControlRecipe *p_recipe, ProtocolFormatInfo *protocol_format_info);
|
||||
};
|
||||
|
@ -127,10 +130,10 @@ struct ControlRecipe
|
|||
uint8_t GetValueTypeMemorySize(UniformValueType uniform_value_type);
|
||||
|
||||
/*Get basic information from recipe file*/
|
||||
int RecipeBasicInformation(struct ControlRecipe *p_recipe, int protocol_type, cJSON *p_recipe_file_json);
|
||||
int RecipeBasicInformation(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_json);
|
||||
|
||||
/*Get the variable need to read from recipe file*/
|
||||
void RecipeReadVariableItem(struct ControlRecipe *p_recipe, int protocol_type, cJSON *p_recipe_file_json);
|
||||
void RecipeReadVariableItem(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_json);
|
||||
|
||||
/*Control Framework Peripheral Device Init*/
|
||||
int ControlPeripheralInit(struct ControlRecipe *p_recipe);
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
*/
|
||||
void SocketInit(char *ip, char *mask, char *gw)
|
||||
{
|
||||
printf("%s ip %d.%d.%d.%d mask %d.%d.%d.%d gw %d.%d.%d.%d\n", __func__,
|
||||
ip[0], ip[1], ip[2], ip[3],
|
||||
mask[0], mask[1], mask[2], mask[3],
|
||||
gw[0], gw[1], gw[2], gw[3]);
|
||||
#ifdef BSP_USING_LWIP
|
||||
lwip_config_tcp(0, ip, mask, gw);
|
||||
#endif
|
||||
|
|
|
@ -48,8 +48,7 @@ Modification:
|
|||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
|
||||
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x1000;
|
||||
STACK_SIZE = 0x4000;
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
void enet_delay(void)
|
||||
{
|
||||
volatile uint32_t i = 0;
|
||||
for (i = 0; i < 1000000; ++i)
|
||||
for (i = 0; i < 10000000; ++i)
|
||||
{
|
||||
__asm("NOP"); /* delay */
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#include "board.h"
|
||||
#include <shell.h>
|
||||
|
||||
#define EXAMPLE_SEMC_START_ADDRESS (0x80000000U)
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ typedef unsigned int nfds_t;
|
|||
#define MEMP_LIB_MALLOC 1
|
||||
#define MEMP_MEM_MALLOC 1
|
||||
|
||||
#define lw_print //KPrintf
|
||||
#define lw_print KPrintf
|
||||
#define lw_error KPrintf
|
||||
#define lw_notice KPrintf
|
||||
|
||||
|
|
Loading…
Reference in New Issue