modify s7 read value num

This commit is contained in:
Wien.b
2023-10-11 01:39:36 -07:00
parent 62e3006e1a
commit 38481e2ae2
43 changed files with 3736 additions and 13 deletions

View File

@@ -55,6 +55,7 @@ typedef enum
PROTOCOL_MELSEC_3E_IQ_R,
PROTOCOL_MELSEC_1C,
PROTOCOL_MELSEC_3C,
PROTOCOL_FREEMODBUS_TCP_SERVER,
PROTOCOL_END
}ProtocolType;

View File

@@ -49,6 +49,10 @@ extern int ModbusUartProtocolInit(struct ControlRecipe *p_recipe);
extern int S7ProtocolInit(struct ControlRecipe *p_recipe);
#endif
#ifdef CONTROL_PROTOCOL_FREEMODBUS_TCP_SERVER
extern int FreeModbusTcpServerInit(struct ControlRecipe *p_recipe);
#endif
/*
CONTROL FRAMEWORK READ DATA FORMAT:
| HEAD |device_id|read data length|read item count| data |
@@ -88,6 +92,10 @@ static struct ControlProtocolInitParam protocol_init[] =
{ PROTOCOL_S7, S7ProtocolInit },
#endif
#ifdef CONTROL_PROTOCOL_FREEMODBUS_TCP_SERVER
{ PROTOCOL_FREEMODBUS_TCP_SERVER, FreeModbusTcpServerInit },
#endif
{ PROTOCOL_END, NULL },
};
@@ -143,7 +151,8 @@ static uint16_t GetRecipeTotalDataLength(cJSON* read_item_list_json)
for (uint16_t read_item_index = 0; read_item_index < read_item_count; read_item_index++) {
cJSON* read_item_json = cJSON_GetArrayItem(read_item_list_json, read_item_index);
UniformValueType value_type = cJSON_GetObjectItem(read_item_json, "value_type")->valueint;
total_data_length += GetValueTypeMemorySize(value_type);
int value_num = cJSON_GetObjectItem(read_item_json, "amount")->valueint;
total_data_length += GetValueTypeMemorySize(value_type, value_num);
}
return total_data_length;
}
@@ -345,26 +354,26 @@ int ControlProtocolCloseDef(void)
* @param uniform_value_type - uniform value type
* @return success : size error : 0
*/
uint8_t GetValueTypeMemorySize(UniformValueType uniform_value_type)
uint8_t GetValueTypeMemorySize(UniformValueType uniform_value_type,int value_num)
{
switch (uniform_value_type)
{
case UNIFORM_BOOL:
case UNIFORM_INT8:
case UNIFORM_UINT8:
return 1;
return 1* value_num;
break;
case UNIFORM_INT16:
case UNIFORM_UINT16:
return 2;
return 2* value_num;
break;
case UNIFORM_INT32:
case UNIFORM_UINT32:
case UNIFORM_FLOAT:
return 4;
return 4* value_num;
break;
case UNIFORM_DOUBLE:
return 8;
return 8* value_num;
break;
default:
break;

View File

@@ -130,7 +130,7 @@ struct ControlRecipe
};
/*Get Value Type Memory Size*/
uint8_t GetValueTypeMemorySize(UniformValueType uniform_value_type);
uint8_t GetValueTypeMemorySize(UniformValueType uniform_value_type,int value_num);
/*Get basic information from recipe file*/
int RecipeBasicInformation(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_json);