diff --git a/APP_Framework/Framework/control/plc_protocol/fins/fins.c b/APP_Framework/Framework/control/plc_protocol/fins/fins.c index 0cbfeec88..925cce00a 100644 --- a/APP_Framework/Framework/control/plc_protocol/fins/fins.c +++ b/APP_Framework/Framework/control/plc_protocol/fins/fins.c @@ -28,6 +28,12 @@ static uint8_t handshake_require_command[] = {0x46, 0x49, 0x4E, 0x53, 0x00, 0x00 static uint8_t handshake_respond_buff[24] = {0}; static uint8_t recv_buff[1024] = {0}; +/** + * @description: Fins Get Area Code + * @param area_char - area char + * @param type - fins data type + * @return success : area_char error : 0 + */ static uint8_t FinsAreaCode(char area_char, FinsDataType type) { uint8_t area_code = 0; @@ -42,7 +48,20 @@ static uint8_t FinsAreaCode(char area_char, FinsDataType type) return area_code; } -static uint16_t FinsCommandGenerate(uint8_t *p_command, uint16_t plc_ip_4, uint16_t pc_ip_4, FinsCommandCode command_code, char area_char, +/** + * @description: Fins Cmd Genetare + * @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 + * @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) { uint8_t index = 0; @@ -71,7 +90,7 @@ static uint16_t FinsCommandGenerate(uint8_t *p_command, uint16_t plc_ip_4, uint1 p_command[index++] = FINS_DA2; p_command[index++] = FINS_SNA; - p_command[index++] = pc_ip_4; + p_command[index++] = local_ip_4; p_command[index++] = FINS_SA2; p_command[index++] = FINS_SID; @@ -88,6 +107,12 @@ static uint16_t FinsCommandGenerate(uint8_t *p_command, uint16_t plc_ip_4, uint1 return index; } +/** + * @description: Fins Data Transform from Receive Buffer To Control-Data + * @param p_read_item - read item pointer + * @param recv_buff - receive buff + * @return success : 0 error : -1 + */ static int FinsTransformRecvBuffToData(FinsReadItem *p_read_item, uint8_t *recv_buff) { FinsDataInfo *p_fins_data_info = &(p_read_item->data_info); @@ -102,7 +127,7 @@ static int FinsTransformRecvBuffToData(FinsReadItem *p_read_item, uint8_t *recv_ if (FINS_COMMAND_CODE_READ == command_code) { uint16_t data_length = p_read_item->data_length; - ControlPrintList("DATA", recv_buff, data_length * (FINS_DATA_TYPE_BIT == p_read_item->data_type ? 1 : 2)); + ControlPrintfList("DATA", recv_buff, data_length * (FINS_DATA_TYPE_BIT == p_read_item->data_type ? 1 : 2)); printf("Receive data is "); if (FINS_DATA_TYPE_BIT == p_read_item->data_type) { @@ -128,6 +153,12 @@ static int FinsTransformRecvBuffToData(FinsReadItem *p_read_item, uint8_t *recv_ return 0; } +/** + * @description: Fins Protocol Handshake + * @param socket - socket + * @param local_ip_4 - last local ip + * @return success : 0 error : -1 -2 + */ static int FinsHandshake(int32_t socket, uint16_t local_ip_4) { handshake_require_command[18] = (uint8_t)(local_ip_4 >> 8); @@ -135,7 +166,7 @@ static int FinsHandshake(int32_t socket, uint16_t local_ip_4) uint8_t try_count = 0; while (try_count < 10) { - ControlPrintList("SEND", (uint8_t *)handshake_require_command, sizeof(handshake_require_command)); + ControlPrintfList("SEND", (uint8_t *)handshake_require_command, sizeof(handshake_require_command)); int32_t write_error = socket_write(socket, handshake_require_command, sizeof(handshake_require_command)); if (write_error < 0) { printf("Write socket error, errno is %d!", errno); @@ -144,7 +175,7 @@ static int FinsHandshake(int32_t socket, uint16_t local_ip_4) if (recv_length < 0) { printf("Read socket error, errno is %d!", errno); } else { - ControlPrintList("RECV", (uint8_t *)handshake_respond_buff, recv_length); + ControlPrintfList("RECV", (uint8_t *)handshake_respond_buff, recv_length); /*check fins handshake respond*/ uint8_t error_code = handshake_respond_buff[15]; @@ -166,6 +197,13 @@ static int FinsHandshake(int32_t socket, uint16_t local_ip_4) return -2; } +/** + * @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) { uint8_t try_count = 0; @@ -177,7 +215,7 @@ static int FinsGetData(int32_t socket, FinsReadItem *p_read_item, struct Control memset(recv_buff, 0, sizeof(recv_buff)); while (try_count < 10) { - ControlPrintList("SEND", p_base_data_info->p_command, p_base_data_info->command_length); + ControlPrintfList("SEND", p_base_data_info->p_command, p_base_data_info->command_length); try_count++; write_error = socket_write(socket, p_base_data_info->p_command, p_base_data_info->command_length); @@ -190,7 +228,7 @@ static int FinsGetData(int32_t socket, FinsReadItem *p_read_item, struct Control if (recv_length < 0) { printf("Read socket error, errno is %d!", errno); } else { - ControlPrintList("RECV", recv_buff, recv_length); + ControlPrintfList("RECV", recv_buff, recv_length); return FinsTransformRecvBuffToData(p_read_item, recv_buff); } } @@ -205,6 +243,20 @@ static int FinsGetData(int32_t socket, FinsReadItem *p_read_item, struct Control return -2; } +/** + * @description: Fins Data Info Init + * @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) { @@ -237,6 +289,11 @@ static int FinsInitialDataInfo(FinsReadItem *p_read_item, uint16_t plc_ip_4, uin return 0; } +/** + * @description: Fins Receive Plc Data Task + * @param parameter - parameter pointer + * @return + */ void *ReceivePlcDataTask(void *parameter) { int i = 0; @@ -289,6 +346,11 @@ void *ReceivePlcDataTask(void *parameter) } } +/** + * @description: Fins Protocol Open + * @param control_protocol - control protocol pointer + * @return success : 0 error + */ int FinsOpen(struct ControlProtocol *control_protocol) { ControlProtocolOpenDef(control_protocol); @@ -296,11 +358,25 @@ int FinsOpen(struct ControlProtocol *control_protocol) return 0; } +/** + * @description: Fins Protocol Close + * @param control_protocol - control protocol pointer + * @return success : 0 error + */ int FinsClose(struct ControlProtocol *control_protocol) { ControlProtocolCloseDef(); + + return 0; } +/** + * @description: Fins Protocol Read Data + * @param control_protocol - control protocol pointer + * @param buf - read data buffer + * @param len - read data length + * @return success : data length error : 0 + */ int FinsRead(struct ControlProtocol *control_protocol, void *buf, size_t len) { return CircularAreaAppRead(circular_area, buf, len); @@ -315,6 +391,12 @@ static struct ControlDone fins_protocol_done = ._ioctl = NULL, }; +/** + * @description: Fins Protocol Cmd Generate + * @param p_recipe - recipe pointer + * @param protocol_format_info - protocol format info pointer + * @return success : 0 error : -1 + */ int FinsProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatInfo *protocol_format_info) { int ret = 0; @@ -337,12 +419,17 @@ int FinsProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatInfo *pr cJSON_GetObjectItem(protocol_format_info->read_single_item_json, "data_length")->valueint, p_recipe->protocol_data->data + last_data_length); - ControlPrintList("CMD", fins_read_item->data_info.base_data_info.p_command, fins_read_item->data_info.base_data_info.command_length); + 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); return ret; } +/** + * @description: Fins Protocol Init + * @param p_recipe - recipe pointer + * @return success : 0 error : -1 + */ int FinsProtocolInit(struct ControlRecipe *p_recipe) { struct ControlProtocol *p_control_protocol = CONTAINER_OF(p_recipe, struct ControlProtocol, recipe); diff --git a/APP_Framework/Framework/control/shared/Makefile b/APP_Framework/Framework/control/shared/Makefile index e26f03b9b..bd8322529 100755 --- a/APP_Framework/Framework/control/shared/Makefile +++ b/APP_Framework/Framework/control/shared/Makefile @@ -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 diff --git a/APP_Framework/Framework/control/shared/control.c b/APP_Framework/Framework/control/shared/control.c index 6ebd1394a..3834a327f 100755 --- a/APP_Framework/Framework/control/shared/control.c +++ b/APP_Framework/Framework/control/shared/control.c @@ -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) { diff --git a/APP_Framework/Framework/control/shared/control_def.c b/APP_Framework/Framework/control/shared/control_def.c index 1e77cef62..61443a091 100644 --- a/APP_Framework/Framework/control/shared/control_def.c +++ b/APP_Framework/Framework/control/shared/control_def.c @@ -19,6 +19,7 @@ */ #include +#include /*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; diff --git a/APP_Framework/Framework/control/shared/control_def.h b/APP_Framework/Framework/control/shared/control_def.h index fafb7d6f2..10e5dfd0a 100644 --- a/APP_Framework/Framework/control/shared/control_def.h +++ b/APP_Framework/Framework/control/shared/control_def.h @@ -25,16 +25,12 @@ #include #include #include +#include #ifdef LIB_USING_CJSON #include #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 diff --git a/APP_Framework/Framework/control/shared/control_io.c b/APP_Framework/Framework/control/shared/control_io.c new file mode 100644 index 000000000..830e6d5b7 --- /dev/null +++ b/APP_Framework/Framework/control/shared/control_io.c @@ -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 + +/** + * @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); +} diff --git a/APP_Framework/Framework/control/shared/control_io.h b/APP_Framework/Framework/control/shared/control_io.h new file mode 100644 index 000000000..52c501486 --- /dev/null +++ b/APP_Framework/Framework/control/shared/control_io.h @@ -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 +#include + +#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