How to use Panel to display 4-byte floating point numbers in CAPL

During the development and testing of ADAS, we often encounter display problems with floating-point numbers. The storage of floating-point numbers in ECUs often uses 4 bytes. Many people who encounter such problems directly search the Internet for floating-point number processing software or web tools to display floating-point numbers. This adds unnecessary workload and manual entry process to the development and testing process.

In fact, CAPL comes with a function to handle floating-point numbers, and you only need to write a small program to solve it perfectly. Go directly to the source code:

byte data[4]; // four-byte floating point number
dword temp;
temp = data[0] << 24;
temp += data[1] << 16;
temp += data[2] << 8;
temp += data[3]; // Convert the array to four-byte data
floatValue = interpretAsFloat(temp); // The floating-point number conversion function provided in CAPL converts the dword type to the floating-point number type
@floatdata = (double )floatValue; // Here the floating-point number is cast to double type,

Assign value to system variables and then need to define a double type variable floatdata in environment->system variables (the definition of floating-point numbers in environment->system variables only has double type).

Next, you can define a control in the Panel, and then attach the variable floatdata. In this way, floating point numbers can be displayed in the Panel.

Useful friends are welcome to collect and like!

Guess you like

Origin blog.csdn.net/weixin_47348488/article/details/109961343