forked from xuos/xiuos
modify CIP stack overflow
This commit is contained in:
parent
54fb48f17b
commit
a247de691c
|
@ -39,7 +39,7 @@ void Controlabl30Test(void)
|
||||||
read_data_length = ControlProtocolRead(CIP_protocol, read_data, sizeof(read_data));
|
read_data_length = ControlProtocolRead(CIP_protocol, read_data, sizeof(read_data));
|
||||||
printf("%s read [%d] CIP data %d using receipe file\n", __func__, i, read_data_length);
|
printf("%s read [%d] CIP data %d using receipe file\n", __func__, i, read_data_length);
|
||||||
i++;
|
i++;
|
||||||
PrivTaskDelay(10000);
|
PrivTaskDelay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ControlProtocolClose(CIP_protocol);
|
//ControlProtocolClose(CIP_protocol);
|
||||||
|
|
|
@ -221,6 +221,7 @@ cip_error_code_e read_value(int fd, const char *address, int length, byte_array_
|
||||||
if (cip_read_response(fd, &response))
|
if (cip_read_response(fd, &response))
|
||||||
ret = cip_analysis_read_byte(response, out_bytes);
|
ret = cip_analysis_read_byte(response, out_bytes);
|
||||||
// printf("%s %hu\n",__func__,response.data);
|
// printf("%s %hu\n",__func__,response.data);
|
||||||
|
free(response.data);
|
||||||
}
|
}
|
||||||
free(core_cmd.data);
|
free(core_cmd.data);
|
||||||
}
|
}
|
||||||
|
@ -266,6 +267,7 @@ bool initialization_on_connect(int fd)
|
||||||
|
|
||||||
// 返回成功的信号 -> Return a successful signal
|
// 返回成功的信号 -> Return a successful signal
|
||||||
return is_ok;
|
return is_ok;
|
||||||
|
free(temp.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cip_read_response(int fd, byte_array_info *response)
|
bool cip_read_response(int fd, byte_array_info *response)
|
||||||
|
|
|
@ -172,9 +172,10 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
|
||||||
// ret = ab_cip_write_short(fd, address, w_s_val);
|
// ret = ab_cip_write_short(fd, address, w_s_val);
|
||||||
// printf("Write\t %s \tshort:\t %d, \tret: %d\n", address, w_s_val, ret);
|
// printf("Write\t %s \tshort:\t %d, \tret: %d\n", address, w_s_val, ret);
|
||||||
// GET_RESULT(ret);
|
// GET_RESULT(ret);
|
||||||
|
|
||||||
|
s_val = 0;
|
||||||
ret = ab_cip_read_short(fd, address, &s_val);
|
ret = ab_cip_read_short(fd, address, &s_val);
|
||||||
// printf("Read\t %s \tshort:\t %d\n", address, s_val);
|
printf("Read\t %s \tshort:\t %d\n", address, s_val);
|
||||||
GET_RESULT(ret);
|
GET_RESULT(ret);
|
||||||
memcpy(val,&s_val,sizeof(s_val));
|
memcpy(val,&s_val,sizeof(s_val));
|
||||||
PushDataIntoStack(CIP_data,val,2);
|
PushDataIntoStack(CIP_data,val,2);
|
||||||
|
@ -188,7 +189,7 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
|
||||||
// printf("Write\t %s \tint32:\t %d, \tret: %d\n", address, w_i_val, ret);
|
// printf("Write\t %s \tint32:\t %d, \tret: %d\n", address, w_i_val, ret);
|
||||||
// GET_RESULT(ret);
|
// GET_RESULT(ret);
|
||||||
|
|
||||||
|
i_val = 0;
|
||||||
ret = ab_cip_read_int32(fd, address, &i_val);
|
ret = ab_cip_read_int32(fd, address, &i_val);
|
||||||
// printf("Read\t %s \tint32:\t %d\n", address, i_val);
|
// printf("Read\t %s \tint32:\t %d\n", address, i_val);
|
||||||
GET_RESULT(ret);
|
GET_RESULT(ret);
|
||||||
|
@ -204,6 +205,7 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
|
||||||
// printf("Write\t %s \tushort:\t %d, \tret: %d\n", address, w_us_val, ret);
|
// printf("Write\t %s \tushort:\t %d, \tret: %d\n", address, w_us_val, ret);
|
||||||
// GET_RESULT(ret);
|
// GET_RESULT(ret);
|
||||||
|
|
||||||
|
us_val = 0;
|
||||||
ret = ab_cip_read_ushort(fd, address, &us_val);
|
ret = ab_cip_read_ushort(fd, address, &us_val);
|
||||||
// printf("Read\t %s \tushort:\t %d\n", address, us_val);
|
// printf("Read\t %s \tushort:\t %d\n", address, us_val);
|
||||||
GET_RESULT(ret);
|
GET_RESULT(ret);
|
||||||
|
@ -219,6 +221,7 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
|
||||||
// printf("Write\t %s \tuint32:\t %d, \tret: %d\n", address, w_ui_val, ret);
|
// printf("Write\t %s \tuint32:\t %d, \tret: %d\n", address, w_ui_val, ret);
|
||||||
// GET_RESULT(ret);
|
// GET_RESULT(ret);
|
||||||
|
|
||||||
|
ui_val = 0;
|
||||||
ret = ab_cip_read_uint32(fd, address, &ui_val);
|
ret = ab_cip_read_uint32(fd, address, &ui_val);
|
||||||
// printf("Read\t %s \tuint32:\t %d\n", address, ui_val);
|
// printf("Read\t %s \tuint32:\t %d\n", address, ui_val);
|
||||||
GET_RESULT(ret);
|
GET_RESULT(ret);
|
||||||
|
@ -234,6 +237,7 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
|
||||||
// printf("Write\t %s \tdouble:\t %lf, \tret: %d\n", address, w_d_val, ret);
|
// printf("Write\t %s \tdouble:\t %lf, \tret: %d\n", address, w_d_val, ret);
|
||||||
// GET_RESULT(ret);
|
// GET_RESULT(ret);
|
||||||
|
|
||||||
|
d_val = 0.0;
|
||||||
ret = ab_cip_read_double(fd, address, &d_val);
|
ret = ab_cip_read_double(fd, address, &d_val);
|
||||||
// printf("Read\t %s \tdouble:\t %lf\n", address, d_val);
|
// printf("Read\t %s \tdouble:\t %lf\n", address, d_val);
|
||||||
GET_RESULT(ret);
|
GET_RESULT(ret);
|
||||||
|
@ -249,24 +253,26 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
|
||||||
// printf("Write\t %s \tfloat:\t %f, \tret: %d\n", address, w_f_val, ret);
|
// printf("Write\t %s \tfloat:\t %f, \tret: %d\n", address, w_f_val, ret);
|
||||||
// GET_RESULT(ret);
|
// GET_RESULT(ret);
|
||||||
|
|
||||||
|
f_val = 0.0;
|
||||||
ret = ab_cip_read_float(fd, address, &f_val);
|
ret = ab_cip_read_float(fd, address, &f_val);
|
||||||
// printf("Read\t %s \tfloat:\t %f\n", address, f_val);
|
printf("Read\t %s \tfloat:\t %f\n", address, f_val);
|
||||||
GET_RESULT(ret);
|
GET_RESULT(ret);
|
||||||
memcpy(val,&f_val,sizeof(us_val));
|
memcpy(val,&f_val,sizeof(us_val));
|
||||||
PushDataIntoStack(CIP_data,val,1);
|
PushDataIntoStack(CIP_data,val,4);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("value type no found!\n");
|
printf("value type no found!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ControlPrintfList("CIP RECV", CIP_data, data_length);
|
// ControlPrintfList("CIP RECV", CIP_data, data_length);
|
||||||
}
|
}
|
||||||
printf("All Failed count: %d\n", faild_count);
|
printf("All Failed count: %d\n", faild_count);
|
||||||
if(faild_count != 0)
|
if(faild_count != 0)
|
||||||
{
|
{
|
||||||
ab_cip_disconnect(fd);
|
ab_cip_disconnect(fd);
|
||||||
system("pause");
|
printf("get value failed!\n");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/*read all variable item data, put them into circular_area*/
|
/*read all variable item data, put them into circular_area*/
|
||||||
printf("%s get %d item %d length\n", __func__, i, data_length);
|
printf("%s get %d item %d length\n", __func__, i, data_length);
|
||||||
|
|
Loading…
Reference in New Issue