diff --git a/APP_Framework/Applications/control_app/plc_demo/xinje/Makefile b/APP_Framework/Applications/control_app/plc_demo/xinje/Makefile index fcf6b1e27..a9157a614 100755 --- a/APP_Framework/Applications/control_app/plc_demo/xinje/Makefile +++ b/APP_Framework/Applications/control_app/plc_demo/xinje/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := xsdh-60a32-e.c xdh-60t4-e.c +SRC_FILES := xdh_60t4_e.c xsdh_60a32_e.c include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/xinje/xdh_60t4_e.c b/APP_Framework/Applications/control_app/plc_demo/xinje/xdh_60t4_e.c index 498451102..3ed40cccd 100644 --- a/APP_Framework/Applications/control_app/plc_demo/xinje/xdh_60t4_e.c +++ b/APP_Framework/Applications/control_app/plc_demo/xinje/xdh_60t4_e.c @@ -19,6 +19,7 @@ */ #include + void ControlXDHTest(void) { int i, j = 0; diff --git a/APP_Framework/Applications/control_app/plc_demo/xinje/xsdh_60a32_e.c b/APP_Framework/Applications/control_app/plc_demo/xinje/xsdh_60a32_e.c index cca093524..87b6a7780 100644 --- a/APP_Framework/Applications/control_app/plc_demo/xinje/xsdh_60a32_e.c +++ b/APP_Framework/Applications/control_app/plc_demo/xinje/xsdh_60a32_e.c @@ -20,6 +20,7 @@ #include + void ControlXSDHTest(void) { int i, j = 0; diff --git a/APP_Framework/Framework/control/plc_protocol/s7/README.doc b/APP_Framework/Framework/control/plc_protocol/s7/README.doc deleted file mode 100644 index 73bff5193..000000000 Binary files a/APP_Framework/Framework/control/plc_protocol/s7/README.doc and /dev/null differ diff --git a/APP_Framework/Framework/control/plc_protocol/s7/s7.c b/APP_Framework/Framework/control/plc_protocol/s7/s7.c index 9ea8d6433..757aaa3e8 100644 --- a/APP_Framework/Framework/control/plc_protocol/s7/s7.c +++ b/APP_Framework/Framework/control/plc_protocol/s7/s7.c @@ -102,24 +102,6 @@ static struct ControlDone s7_protocol_done = ._ioctl = NULL, }; -/** - * @description: S7 Protocol Value Type - * @param uniform_value_type - uniform value type - * @return success : 0-8 error : -1 - */ -static uint8_t GetUniformValueTypeMemorySize(UniformValueType uniform_value_type) -{ - if (uniform_value_type == UNIFORM_BOOL || uniform_value_type == UNIFORM_INT8 || uniform_value_type == UNIFORM_UINT8) - return 1; - if (uniform_value_type == UNIFORM_INT16 || uniform_value_type == UNIFORM_UINT16) - return 2; - if (uniform_value_type == UNIFORM_INT32 || uniform_value_type == UNIFORM_UINT32 || uniform_value_type == UNIFORM_FLOAT) - return 4; - if (uniform_value_type == UNIFORM_DOUBLE) - return 8; - return 0; -} - /** * @description: Push Data Onto a Stack One By One * @param datastack - data stack pointer @@ -181,7 +163,7 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe) } TS7DataItem data_info = ((S7ReadItem*)p_read_item + i)->data_info; Cli_ReadMultiVars(s7_plc, &data_info, 1); - uint16_t Size = GetUniformValueTypeMemorySize(((S7ReadItem*)p_read_item + i)->value_type); + uint16_t Size = GetValueTypeMemorySize(((S7ReadItem*)p_read_item + i)->value_type); PrintHexNumberList("s7 recv", data_info.pdata,Size); PushDataIntoStack(s7_data,data_info.pdata,Size); MdelayKTask(100); @@ -200,6 +182,79 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe) return 0; } +/** + * @description: S7 Protocol read item Init + * @param p_read_item - read item pointer + * @param read_item_json - read item json pointer + * @param p_data - unused + * @return success : 0 error : -1 + */ +static uint8_t InitialS7ReadItem(S7ReadItem* p_read_item, cJSON* read_item_json, uint8_t* p_data) +{ + p_read_item->value_type = cJSON_GetObjectItem(read_item_json, "value_type")->valueint; + strncpy(p_read_item->value_name, cJSON_GetObjectItem(read_item_json, "value_name")->valuestring, 20); + TS7DataItem* p_data_info = &(p_read_item->data_info); + p_data_info->Amount = cJSON_GetObjectItem(read_item_json, "amount")->valueint; + p_data_info->Start = cJSON_GetObjectItem(read_item_json, "start")->valueint; + p_data_info->DBNumber = cJSON_GetObjectItem(read_item_json, "db_number")->valueint; + char* area_valuestring = cJSON_GetObjectItem(read_item_json, "area")->valuestring; + if (strcmp(area_valuestring, "I") == 0) + p_data_info->Area = S7AreaPE; + else if (strcmp(area_valuestring, "Q") == 0) + p_data_info->Area = S7AreaPA; + else if (strcmp(area_valuestring, "M") == 0) + p_data_info->Area = S7AreaMK; + else if (strcmp(area_valuestring, "DB") == 0) + p_data_info->Area = S7AreaDB; + else if (strcmp(area_valuestring, "C") == 0) + p_data_info->Area = S7AreaCT; + else if (strcmp(area_valuestring, "T") == 0) + p_data_info->Area = S7AreaTM; + char* wordlen_valuestring = cJSON_GetObjectItem(read_item_json, "wordlen")->valuestring; + if (strcmp(wordlen_valuestring, "Bit") == 0) + p_data_info->WordLen = S7WLBit; + else if (strcmp(wordlen_valuestring, "Byte") == 0) + p_data_info->WordLen = S7WLByte; + else if (strcmp(wordlen_valuestring, "Word") == 0) + p_data_info->WordLen = S7WLWord; + else if (strcmp(wordlen_valuestring, "DWord") == 0) + p_data_info->WordLen = S7WLDWord; + else if (strcmp(wordlen_valuestring, "Real") == 0) + p_data_info->WordLen = S7WLReal; + else if (strcmp(wordlen_valuestring, "Counter") == 0) + p_data_info->WordLen = S7WLCounter; + else if (strcmp(wordlen_valuestring, "Timer") == 0) + p_data_info->WordLen = S7WLTimer; + p_data_info->pdata = p_data; + printf("value_type is %d, amount is %d, start is %04d, db_number is %d, area is 0x%03x, wordlen is %d.\n", + p_read_item->value_type, p_data_info->Amount, p_data_info->Start, p_data_info->DBNumber, + p_data_info->Area, p_data_info->WordLen); + return GetValueTypeMemorySize(p_read_item->value_type); +} + +/** + * @description: S7 Protocol Cmd Generate + * @param p_recipe - recipe pointer + * @param protocol_format_info - protocol format info pointer + * @return success : 0 error : -1 + */ +int S7ProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatInfo *protocol_format_info) +{ + int ret = 0; + uint8_t* S7_plc_read_data = malloc(p_recipe->protocol_data.data_length); + uint16_t S7_plc_read_data_index = 8; + cJSON *read_single_item_json = protocol_format_info->read_single_item_json; + int i = protocol_format_info->read_item_index; + if (i == 0) + p_recipe->read_item = malloc(sizeof(S7ReadItem) * p_recipe->read_item_count); + S7_plc_read_data_index += InitialS7ReadItem((S7ReadItem*)(p_recipe->read_item) + i, + read_single_item_json,S7_plc_read_data + S7_plc_read_data_index); + if (S7_plc_read_data_index == 8) { + ret = -1; + printf("%s read %d item failed!\n", __func__, i); + } + return ret; +} /** * @description: S7 Protocol Init * @param p_recipe - recipe pointer @@ -212,12 +267,8 @@ int S7ProtocolInit(struct ControlRecipe *p_recipe) PrivFree(p_recipe->read_item); return -1; } - memset(p_recipe->read_item, 0, sizeof(S7ReadItem)); - - // p_recipe->ControlProtocolFormatCmd = S7ProtocolFormatCmd; - + p_recipe->ControlProtocolFormatCmd = S7ProtocolFormatCmd; p_recipe->done = &s7_protocol_done; - return 0; } diff --git a/APP_Framework/Framework/control/shared/control.c b/APP_Framework/Framework/control/shared/control.c index dbc018c85..41872df38 100755 --- a/APP_Framework/Framework/control/shared/control.c +++ b/APP_Framework/Framework/control/shared/control.c @@ -20,7 +20,6 @@ #include #include -//#include "s7.h" /** * @description: Control Framework Find certain Protocol @@ -284,17 +283,6 @@ int ControlFrameworkInit(void) printf("%u %u\n",control_protocol->recipe->total_data_length,control_protocol->recipe->device_id); printf("%s ControlPeripheralInit done\n", __func__); - - //s7 read - - - - // ret = ReadPlcDataByRecipe(control_protocol->recipe); - // if (ret < 0) { - // printf("%s failed!\n", __func__); - // PrivFree(control_protocol); - // goto _out; - // } _out: return ret; diff --git a/APP_Framework/Framework/control/shared/control.h b/APP_Framework/Framework/control/shared/control.h index bd1be0749..0bc58b8a6 100644 --- a/APP_Framework/Framework/control/shared/control.h +++ b/APP_Framework/Framework/control/shared/control.h @@ -24,6 +24,7 @@ #include #include + #ifdef __cplusplus extern "C" { #endif diff --git a/APP_Framework/Framework/control/shared/control_def.c b/APP_Framework/Framework/control/shared/control_def.c index 2531503df..4808b2423 100644 --- a/APP_Framework/Framework/control/shared/control_def.c +++ b/APP_Framework/Framework/control/shared/control_def.c @@ -20,7 +20,6 @@ #include #include -#include "s7.h" /*using cirtular area to receive data*/ #define PLC_DATA_LENGTH 1024 @@ -430,73 +429,6 @@ int RecipeBasicInformation(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_ printf("\n************************************************************\n"); } -static uint8_t GetS7ValueTypeMemorySize(UniformValueType uniform_value_type) -{ - if (uniform_value_type == UNIFORM_BOOL || uniform_value_type == UNIFORM_INT8 || uniform_value_type == UNIFORM_UINT8) - return 1; - if (uniform_value_type == UNIFORM_INT16 || uniform_value_type == UNIFORM_UINT16) - return 2; - if (uniform_value_type == UNIFORM_INT32 || uniform_value_type == UNIFORM_UINT32 || uniform_value_type == UNIFORM_FLOAT) - return 4; - if (uniform_value_type == UNIFORM_DOUBLE) - return 8; - return 0; -} - -/** - * @description: S7 Protocol read item Init - * @param p_read_item - read item pointer - * @param read_item_json - read item json pointer - * @param p_data - unused - * @return success : 0 error : -1 - */ -static uint8_t InitialS7ReadItem(S7ReadItem* p_read_item, cJSON* read_item_json, uint8_t* p_data) -{ - p_read_item->value_type = cJSON_GetObjectItem(read_item_json, "value_type")->valueint; - strncpy(p_read_item->value_name, cJSON_GetObjectItem(read_item_json, "value_name")->valuestring, 20); - TS7DataItem* p_data_info = &(p_read_item->data_info); - p_data_info->Amount = cJSON_GetObjectItem(read_item_json, "amount")->valueint; - p_data_info->Start = cJSON_GetObjectItem(read_item_json, "start")->valueint; - p_data_info->DBNumber = cJSON_GetObjectItem(read_item_json, "db_number")->valueint; - char* area_valuestring = cJSON_GetObjectItem(read_item_json, "area")->valuestring; - if (strcmp(area_valuestring, "I") == 0) - p_data_info->Area = S7AreaPE; - else if (strcmp(area_valuestring, "Q") == 0) - p_data_info->Area = S7AreaPA; - else if (strcmp(area_valuestring, "M") == 0) - p_data_info->Area = S7AreaMK; - else if (strcmp(area_valuestring, "DB") == 0) - p_data_info->Area = S7AreaDB; - else if (strcmp(area_valuestring, "C") == 0) - p_data_info->Area = S7AreaCT; - else if (strcmp(area_valuestring, "T") == 0) - p_data_info->Area = S7AreaTM; - char* wordlen_valuestring = cJSON_GetObjectItem(read_item_json, "wordlen")->valuestring; - if (strcmp(wordlen_valuestring, "Bit") == 0) - p_data_info->WordLen = S7WLBit; - else if (strcmp(wordlen_valuestring, "Byte") == 0) - p_data_info->WordLen = S7WLByte; - else if (strcmp(wordlen_valuestring, "Word") == 0) - p_data_info->WordLen = S7WLWord; - else if (strcmp(wordlen_valuestring, "DWord") == 0) - p_data_info->WordLen = S7WLDWord; - else if (strcmp(wordlen_valuestring, "Real") == 0) - p_data_info->WordLen = S7WLReal; - else if (strcmp(wordlen_valuestring, "Counter") == 0) - p_data_info->WordLen = S7WLCounter; - else if (strcmp(wordlen_valuestring, "Timer") == 0) - p_data_info->WordLen = S7WLTimer; - p_data_info->pdata = p_data; - printf("value_type is %d, amount is %d, start is %04d, db_number is %d, area is 0x%03x, wordlen is %d.\n", - p_read_item->value_type, p_data_info->Amount, p_data_info->Start, p_data_info->DBNumber, - p_data_info->Area, p_data_info->WordLen); - return GetS7ValueTypeMemorySize(p_read_item->value_type); -} - - - - - /** * @description: Control Framework Read Variable Item Function * @param p_recipe - Control recipe pointer @@ -526,37 +458,15 @@ void RecipeReadVariableItem(struct ControlRecipe *p_recipe, cJSON *p_recipe_file /*Format Data Header, Reference "CONTROL FRAMEWORK READ DATA FORMAT"*/ FormatDataHeader(p_recipe); uint16_t read_item_count = p_recipe->read_item_count; - - - uint8_t* S7_plc_read_data; - S7_plc_read_data = malloc(p_recipe->protocol_data.data_length); - uint16_t S7_plc_read_data_index = 8; - for (i = 0; i < read_item_count; i ++) { 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 = i; - switch (p_recipe->protocol_type) { - - case PROTOCOL_S7: - if (i == 0) - p_recipe->read_item = malloc(sizeof(S7ReadItem) * p_recipe->read_item_count); - S7_plc_read_data_index += InitialS7ReadItem((S7ReadItem*)(p_recipe->read_item) + i, - read_single_item_json,S7_plc_read_data + S7_plc_read_data_index); - if (S7_plc_read_data_index == 8) { - printf("%s read %d item failed!\n", __func__, i); - continue; - } - break; - - default: - /*Format Protocol Cmd By Analyze Variable Item One By One*/ - ret = p_recipe->ControlProtocolFormatCmd(p_recipe, &protocol_format_info); + /*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__, i); continue; - } } } }