如何解决为什么 0x90 变成 0xFF (255) 作为参数我 Eclipse 2021-03 CDT - C 代码?
我正在为工业 Can-bus 系统构建一个名为 Open SAE J1939 的 J1939 项目,我注意到 Eclipse CDT 有一些奇怪的地方。
我调用函数
ENUM_J1939_STATUS_CODES SAE_J1939_Send_Request_Address_Claimed(J1939 *j1939,uint8_t DA)
请注意,我正在使用 uint8_t DA = 0x90 = 144
为什么我会在这里得到 DA = 0xFF = 255
?这是 Eclipse CDT 2021-03 中的错误吗?
重现这个问题。只需下载库并运行 Main.c 文件。这个。
#include "stdlib.h"
#include "stdio.h"
/* Our includes */
#include "Open SAE J1939/Open_SAE_J1939.h"
#include "SAE J1939-71 Application Layer/SAE_J1939-71_Application_Layer.h"
#include "SAE J1939-73 Diagnostics Layer/SAE_J1939-73_Diagnostics_Layer.h"
#include "SAE J1939-81 Network Management Layer/SAE_J1939-81_Network_Management_Layer.h"
#include "ISO 11783 Tractors And Machinery For Agriculture And Forestry/ISO 11783-7 Implement Messages Application Layer/ISO_11783_7_Implement_Messages_Application_Layer.h"
int main() {
/* Create our J1939 structure with two ECU */
J1939 j1939_1;
J1939 j1939_2;
/* Important to set all to 0 */
memset(&j1939_1,sizeof(j1939_1));
memset(&j1939_2,sizeof(j1939_2));
/* Set the ECU address */
j1939_1.this_ECU_address = 0x80; /* From 0 to 253 because 254 = error address and 255 = broadcast address */
j1939_2.this_ECU_address = 0x90;
/* Set NAME for ECU 1 */
j1939_1.this_name.identity_number = 100; /* From 0 to 2097151 */
j1939_1.this_name.manufacturer_code = 300; /* From 0 to 2047 */
j1939_1.this_name.function_instance = 10; /* From 0 to 31 */
j1939_1.this_name.ECU_instance = 2; /* From 0 to 7 */
j1939_1.this_name.function = FUNCTION_VDC_MODULE; /* From 0 to 255 */
j1939_1.this_name.vehicle_system = 100; /* From 0 to 127 */
j1939_1.this_name.arbitrary_address_capable = 0; /* From 0 to 1 */
j1939_1.this_name.industry_group = INDUSTRY_GROUP_CONSTRUCTION; /* From 0 to 7 */
j1939_1.this_name.vehicle_system_instance = 10; /* From 0 to 15 */
/* Set NAME for ECU 2 */
j1939_2.this_name.identity_number = 1000; /* From 0 to 2097151 */
j1939_2.this_name.manufacturer_code = 400; /* From 0 to 2047 */
j1939_2.this_name.function_instance = 20; /* From 0 to 31 */
j1939_2.this_name.ECU_instance = 1; /* From 0 to 7 */
j1939_2.this_name.function = FUNCTION_AUXILIARY_VALVES_CONTROL; /* From 0 to 255 */
j1939_2.this_name.vehicle_system = 50; /* From 0 to 127 */
j1939_2.this_name.arbitrary_address_capable = 0; /* From 0 to 1 */
j1939_2.this_name.industry_group = INDUSTRY_GROUP_AGRICULTURAL_AND_FORESTRY; /* From 0 to 7 */
j1939_2.this_name.vehicle_system_instance = 15; /* From 0 to 15 */
/* Broadcast NAME from ECU 1 */
SAE_J1939_Send_Request_Address_Claimed(&j1939_1,0x90); /* Request ECU NAME from ECU 2 */
/* Listen for messages at ECU 2 */
Open_SAE_J1939_Listen_For_Messages(&j1939_2);
/* Send NAME from ECU 2 to ECU 1 */
SAE_J1939_Send_Request_Address_Claimed(&j1939_2,0x80); /* Request ECU NAME from ECU 1 */
/* Listen for messages at ECU 1 */
Open_SAE_J1939_Listen_For_Messages(&j1939_1);
/* Print information */
printf("How many external ECU are connected according to ECU 1? %i\n",j1939_1.number_of_ECU);
printf("How many external ECU are connected according to ECU 2? %i\n",j1939_2.number_of_ECU);
return 0;
}
解决方法
很可能你是编译器优化的受害者。底层调试器向你展示了一些寄存器或内存的内容,但真正的值在其他地方,如果下一次调用完成,它将被安排。哦,对 SAE_J1939_Send_Request()
的调用可能只是为了节省时钟周期的跳转,因为它是最后一次调用并且您返回其返回值。
请查看反汇编,并按照该级别的值进行操作。
另一种选择是降低优化级别。
顺便说一句,这与 Eclipse 无关。这是编译器/调试器的问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。