forked from xuos/xiuos
feat add control_framework, support fins protocol, add control_io.c and function descriptions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
SRC_FILES := control.c control_def.c
|
||||
SRC_FILES := control.c control_def.c control_io.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ ControlProtocolType control_protocol;
|
||||
|
||||
/**
|
||||
* @description: Control Framework Find certain Protocol
|
||||
* @param
|
||||
* @param void
|
||||
* @return Control Protocol pointer
|
||||
*/
|
||||
ControlProtocolType ControlProtocolFind(void)
|
||||
@@ -36,7 +36,7 @@ ControlProtocolType ControlProtocolFind(void)
|
||||
/**
|
||||
* @description: Control Framework Protocol Init
|
||||
* @param control_protocol - control protocol pointer
|
||||
* @return success: 0 error : -1
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
static int ControlProtocolInit(ControlProtocolType control_protocol)
|
||||
{
|
||||
@@ -65,7 +65,7 @@ _out:
|
||||
* @description: Analyze Recipe
|
||||
* @param control_protocol - Control Protocol pointer
|
||||
* @param recipe_name - recipe name
|
||||
* @return success: 0 error : -1
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
static int ControlAnalyzeRecipe(ControlProtocolType control_protocol, const char *recipe_name)
|
||||
{
|
||||
@@ -134,7 +134,11 @@ static int ControlAnalyzeRecipe(ControlProtocolType control_protocol, const char
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*Control Framework Protocol Open*/
|
||||
/**
|
||||
* @description: Control Framework Protocol Open
|
||||
* @param control_protocol - Control Protocol pointer
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
int ControlProtocolOpen(struct ControlProtocol *control_protocol)
|
||||
{
|
||||
CONTROL_PARAM_CHECK(control_protocol);
|
||||
@@ -148,7 +152,11 @@ int ControlProtocolOpen(struct ControlProtocol *control_protocol)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Control Framework Protocol Close*/
|
||||
/**
|
||||
* @description: Control Framework Protocol Close
|
||||
* @param control_protocol - Control Protocol pointer
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
int ControlProtocolClose(struct ControlProtocol *control_protocol)
|
||||
{
|
||||
CONTROL_PARAM_CHECK(control_protocol);
|
||||
@@ -162,7 +170,13 @@ int ControlProtocolClose(struct ControlProtocol *control_protocol)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Control Framework Protocol Read Date*/
|
||||
/**
|
||||
* @description: Control Framework Protocol Read Data
|
||||
* @param control_protocol - Control Protocol pointer
|
||||
* @param buf - read buffer
|
||||
* @param len - read data length
|
||||
* @return success : data length error : -1
|
||||
*/
|
||||
int ControlProtocolRead(struct ControlProtocol *control_protocol, void *buf, size_t len)
|
||||
{
|
||||
CONTROL_PARAM_CHECK(control_protocol);
|
||||
@@ -176,7 +190,13 @@ int ControlProtocolRead(struct ControlProtocol *control_protocol, void *buf, siz
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Control Framework Protocol Write Cmd*/
|
||||
/**
|
||||
* @description: Control Framework Protocol Write Cmd
|
||||
* @param control_protocol - Control Protocol pointer
|
||||
* @param buf - write buffer
|
||||
* @param len - write data length
|
||||
* @return success : data length error : -1
|
||||
*/
|
||||
int ControlProtocolWrite(struct ControlProtocol *control_protocol, const void *buf, size_t len)
|
||||
{
|
||||
CONTROL_PARAM_CHECK(control_protocol);
|
||||
@@ -190,7 +210,13 @@ int ControlProtocolWrite(struct ControlProtocol *control_protocol, const void *b
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Control Framework Protocol Ioctl*/
|
||||
/**
|
||||
* @description: Control Framework Protocol Ioctl
|
||||
* @param control_protocol - Control Protocol pointer
|
||||
* @param cmd - ioctl cmd
|
||||
* @param args - args
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
int ControlProtocolIoctl(struct ControlProtocol *control_protocol, int cmd, void *args)
|
||||
{
|
||||
CONTROL_PARAM_CHECK(control_protocol);
|
||||
@@ -206,7 +232,8 @@ int ControlProtocolIoctl(struct ControlProtocol *control_protocol, int cmd, void
|
||||
|
||||
/**
|
||||
* @description: Control Framework Init
|
||||
* @return success: 0 error : -1
|
||||
* @param void
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
int ControlFrameworkInit(void)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <control_def.h>
|
||||
#include <control_io.h>
|
||||
|
||||
/*using cirtular area to receive data*/
|
||||
#define PLC_DATA_LENGTH 1024
|
||||
@@ -58,6 +59,12 @@ static struct ControlProtocolInitParam protocol_init[] =
|
||||
{ PROTOCOL_END, NULL },
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Control Framework Sub_Protocol Desc Init
|
||||
* @param p_recipe - Control recipe pointer
|
||||
* @param sub_protocol_desc - sub_protocol desc
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
static int ControlProtocolInitDesc(struct ControlRecipe *p_recipe, struct ControlProtocolInitParam sub_protocol_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
@@ -72,6 +79,11 @@ static int ControlProtocolInitDesc(struct ControlRecipe *p_recipe, struct Contro
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Protocol Data Header Format
|
||||
* @param p_recipe - Control recipe pointer
|
||||
* @return
|
||||
*/
|
||||
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
|
||||
@@ -87,6 +99,11 @@ static void FormatDataHeader(struct ControlRecipe *p_recipe)
|
||||
data[7] = p_recipe->read_item_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Get Recipe Total Data Length
|
||||
* @param read_item_list_json - read_item_list_json pointer
|
||||
* @return success : total_data_length error : 0
|
||||
*/
|
||||
static uint16_t GetRecipeTotalDataLength(cJSON* read_item_list_json)
|
||||
{
|
||||
uint16_t read_item_count = cJSON_GetArraySize(read_item_list_json);
|
||||
@@ -99,6 +116,12 @@ static uint16_t GetRecipeTotalDataLength(cJSON* read_item_list_json)
|
||||
return total_data_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Basic Serial Configure
|
||||
* @param p_recipe - Control recipe pointer
|
||||
* @param p_recipe_file_json - p_recipe_file_json pointer
|
||||
* @return
|
||||
*/
|
||||
static void ControlBasicSerialConfig(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_json)
|
||||
{
|
||||
cJSON *p_serial_config_json = cJSON_GetObjectItem(p_recipe_file_json, "serial_config");
|
||||
@@ -110,6 +133,12 @@ static void ControlBasicSerialConfig(struct ControlRecipe *p_recipe, cJSON *p_re
|
||||
p_recipe->serial_config.baud_rate, p_recipe->serial_config.data_bits, p_recipe->serial_config.stop_bits, p_recipe->serial_config.check_mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Basic Socket Configure
|
||||
* @param p_recipe - Control recipe pointer
|
||||
* @param p_recipe_file_json - p_recipe_file_json pointer
|
||||
* @return
|
||||
*/
|
||||
static void ControlBasicSocketConfig(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_json)
|
||||
{
|
||||
cJSON *p_socket_address_json = cJSON_GetObjectItem(p_recipe_file_json, "socket_config");
|
||||
@@ -146,7 +175,14 @@ static void ControlBasicSocketConfig(struct ControlRecipe *p_recipe, cJSON *p_re
|
||||
local_ip_string, plc_ip_string, gateway_ip_string, p_recipe->socket_config.port);
|
||||
}
|
||||
|
||||
void ControlPrintList(char name[5], uint8_t *number_list, uint16_t length)
|
||||
/**
|
||||
* @description: Control Framework Printf List Function
|
||||
* @param name - printf function name
|
||||
* @param number_list - number_list pointer
|
||||
* @param length - number_list length
|
||||
* @return
|
||||
*/
|
||||
void ControlPrintfList(char name[5], uint8_t *number_list, uint16_t length)
|
||||
{
|
||||
printf("\n******************%5s****************\n", name);
|
||||
for (int32_t i = 0;i < length;i ++) {
|
||||
@@ -155,6 +191,11 @@ void ControlPrintList(char name[5], uint8_t *number_list, uint16_t length)
|
||||
printf("\n**************************************\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Connect Socket
|
||||
* @param p_plc - basic socket plc pointer
|
||||
* @return success : 0 error : -1 -2 -3 -4 -5
|
||||
*/
|
||||
int ControlConnectSocket(BasicSocketPlc *p_plc)
|
||||
{
|
||||
if (p_plc->socket >= 0)
|
||||
@@ -179,10 +220,12 @@ int ControlConnectSocket(BasicSocketPlc *p_plc)
|
||||
printf("Error setting TCP_NODELAY function!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setsockopt(plc_socket, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, (socklen_t)sizeof(struct timeval)) < 0) {
|
||||
printf("Error setting SO_SNDTIMEO function!\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (setsockopt(plc_socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, (socklen_t)sizeof(struct timeval)) < 0) {
|
||||
printf("Error setting SO_RCVTIMEO function!\n");
|
||||
return -3;
|
||||
@@ -204,6 +247,11 @@ int ControlConnectSocket(BasicSocketPlc *p_plc)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Disconnect Socket
|
||||
* @param p_plc - basic socket plc pointer
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
int ControlDisconnectSocket(BasicSocketPlc *p_plc)
|
||||
{
|
||||
if (p_plc->socket < 0)
|
||||
@@ -216,6 +264,11 @@ int ControlDisconnectSocket(BasicSocketPlc *p_plc)
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Protocol Open for Sub_Protocol, Init Circular Area and Receive Data Task
|
||||
* @param control_protocol - Control protocol pointer
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
int ControlProtocolOpenDef(struct ControlProtocol *control_protocol)
|
||||
{
|
||||
g_circular_area = CircularAreaAppInit(PLC_DATA_LENGTH);
|
||||
@@ -234,6 +287,11 @@ int ControlProtocolOpenDef(struct ControlProtocol *control_protocol)
|
||||
PrivTaskStartup(&recv_plc_data_task);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Protocol Open for Sub_Protocol, Release Circular Area and Delete Receive Data Task
|
||||
* @param void
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
int ControlProtocolCloseDef(void)
|
||||
{
|
||||
CircularAreaAppRelease(g_circular_area);
|
||||
@@ -243,6 +301,11 @@ int ControlProtocolCloseDef(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Get Value Memory Size From Recipe File
|
||||
* @param uniform_value_type - uniform value type
|
||||
* @return success : size error : 0
|
||||
*/
|
||||
uint8_t GetValueTypeMemorySize(UniformValueType uniform_value_type)
|
||||
{
|
||||
switch (uniform_value_type)
|
||||
@@ -271,16 +334,20 @@ uint8_t GetValueTypeMemorySize(UniformValueType uniform_value_type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Peripheral Device Init
|
||||
* @param p_recipe - Control recipe pointer
|
||||
* @return success : 0 error :
|
||||
*/
|
||||
int ControlPeripheralInit(struct ControlRecipe *p_recipe)
|
||||
{
|
||||
switch (p_recipe->communication_type)
|
||||
{
|
||||
case 0://Socket Init
|
||||
lwip_config_tcp(0, p_recipe->socket_config.local_ip, p_recipe->socket_config.netmask, p_recipe->socket_config.gateway);
|
||||
SocketInit(p_recipe->socket_config.local_ip, p_recipe->socket_config.netmask, p_recipe->socket_config.gateway);
|
||||
break;
|
||||
case 1://Serial Init
|
||||
// Uart485Init(p_recipe->serial_config.baud_rate, p_recipe->serial_config.data_bits,
|
||||
// p_recipe->serial_config.stop_bits, p_recipe->serial_config.check_mode);
|
||||
SerialInit(p_recipe->serial_config.baud_rate, p_recipe->serial_config.data_bits, p_recipe->serial_config.stop_bits, p_recipe->serial_config.check_mode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -289,6 +356,13 @@ int ControlPeripheralInit(struct ControlRecipe *p_recipe)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
if (protocol_type != (ProtocolType)(cJSON_GetObjectItem(p_recipe_file_json, "protocol_type")->valueint)) {
|
||||
@@ -308,10 +382,10 @@ int RecipeBasicInformation(struct ControlRecipe *p_recipe, int protocol_type, cJ
|
||||
|
||||
switch (p_recipe->communication_type)
|
||||
{
|
||||
case 0://Socket Config
|
||||
case 0://Get Socket Config
|
||||
ControlBasicSocketConfig(p_recipe, p_recipe_file_json);
|
||||
break;
|
||||
case 1://Serial Config
|
||||
case 1://Get Serial Config
|
||||
ControlBasicSerialConfig(p_recipe, p_recipe_file_json);
|
||||
break;
|
||||
default:
|
||||
@@ -321,6 +395,13 @@ int RecipeBasicInformation(struct ControlRecipe *p_recipe, int protocol_type, cJ
|
||||
printf("\n************************************************************\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -25,16 +25,12 @@
|
||||
#include <list.h>
|
||||
#include <circular_area_app.h>
|
||||
#include <control.h>
|
||||
#include <control_io.h>
|
||||
|
||||
#ifdef LIB_USING_CJSON
|
||||
#include <cJSON.h>
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_LWIP
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -48,11 +44,6 @@ extern "C" {
|
||||
} \
|
||||
}while (0)
|
||||
|
||||
#ifdef BSP_USING_LWIP
|
||||
#define socket_write lwip_write
|
||||
#define socket_read lwip_read
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UNIFORM_BOOL = 1,
|
||||
@@ -141,16 +132,22 @@ int RecipeBasicInformation(struct ControlRecipe *p_recipe, int protocol_type, cJ
|
||||
/*Get the variable need to read from recipe file*/
|
||||
void RecipeReadVariableItem(struct ControlRecipe *p_recipe, int protocol_type, cJSON *p_recipe_file_json);
|
||||
|
||||
/*Control Framework Peripheral Device Init*/
|
||||
int ControlPeripheralInit(struct ControlRecipe *p_recipe);
|
||||
|
||||
void ControlPrintList(char name[5], uint8_t *number_list, uint16_t length);
|
||||
/*Control Framework Printf List Function*/
|
||||
void ControlPrintfList(char name[5], uint8_t *number_list, uint16_t length);
|
||||
|
||||
/*Control Framework Connect Socket*/
|
||||
int ControlConnectSocket(BasicSocketPlc *p_plc);
|
||||
|
||||
/*Control Framework Disconnect Socket*/
|
||||
int ControlDisconnectSocket(BasicSocketPlc *p_plc);
|
||||
|
||||
/*Control Framework Protocol Open for Sub_Protocol, Init Circular Area and Receive Data Task*/
|
||||
int ControlProtocolOpenDef(struct ControlProtocol *control_protocol);
|
||||
|
||||
/*Control Framework Protocol Open for Sub_Protocol, Release Circular Area and Delete Receive Data Task*/
|
||||
int ControlProtocolCloseDef(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
48
APP_Framework/Framework/control/shared/control_io.c
Normal file
48
APP_Framework/Framework/control/shared/control_io.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file control_io.c
|
||||
* @brief low level io code for control framework
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-11-21
|
||||
*/
|
||||
|
||||
#include <control_io.h>
|
||||
|
||||
/**
|
||||
* @description: Control Framework Socket Init
|
||||
* @param ip - local ip pointer
|
||||
* @param mask - netmask pointer
|
||||
* @param gw - gateway pointer
|
||||
* @return
|
||||
*/
|
||||
void SocketInit(char *ip, char *mask, char *gw)
|
||||
{
|
||||
#ifdef BSP_USING_LWIP
|
||||
lwip_config_tcp(0, ip, mask, gw);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Control Framework Serial Init
|
||||
* @param baud_rate - baud rate
|
||||
* @param data_bits - data bits
|
||||
* @param stop_bits - stop bits
|
||||
* @param check_mode - check mode
|
||||
* @return
|
||||
*/
|
||||
void SerialInit(uint32_t baud_rate, uint8_t data_bits, uint8_t stop_bits, uint8_t check_mode)
|
||||
{
|
||||
// Uart485Init(baud_rate, data_bits, stop_bits, check_mode);
|
||||
}
|
||||
51
APP_Framework/Framework/control/shared/control_io.h
Normal file
51
APP_Framework/Framework/control/shared/control_io.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file control_io.h
|
||||
* @brief code for control framework io adapter
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-11-21
|
||||
*/
|
||||
|
||||
#ifndef CONTROL_IO_H
|
||||
#define CONTROL_IO_H
|
||||
|
||||
#include <transform.h>
|
||||
#include <list.h>
|
||||
|
||||
#ifdef BSP_USING_LWIP
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_LWIP
|
||||
#define socket_write lwip_write
|
||||
#define socket_read lwip_read
|
||||
#endif
|
||||
|
||||
/*Control Framework Socket Init*/
|
||||
void SocketInit(char *ip, char *mask, char *gw);
|
||||
|
||||
/*Control Framework Serial Init*/
|
||||
void SerialInit(uint32_t baud_rate, uint8_t data_bits, uint8_t stop_bits, uint8_t check_mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user