开发者

getting variables from master struct

I am trying to create different messages to be transferred between two hosts. The program structure that I am following is to create a master struct where all the variables to be passed in different messages are declared. Then I have created different struct for different messages using the same variables from master struct, the values of which I am trying to pass is through pointers. Below is the rough outline of what I am trying to do. I dont know whether this is the right approach or there is another better way to do it.

The errors that I am getting while compiling are: 1. expression must have a constant value 2. incomplete type is not allowed

Both are pointed when I try to create an instance of message structure开发者_运维知识库 and passing the pointers of master struct.

Please help.

[code]

struct Master{

char  Bulk_Charging_Complete : 1;
char  Charging_Complete : 1;
short Vehicle_Energy_Capacity;
char  Vehicle_RESS_SOC;
short Vehicle_Maximum_Power_Limit : 13;
short Vehicle_Maximum_Current_Limit: 13;
short Vehicle_Maximum_Voltage_Limit: 13;
short Charger_Maximum_Power_Limit: 13;
short Charger_Maximum_Current_Limit: 13;
short Charger_Maximum_Voltage_Limit: 14;
short Charge_Current_Request: 13;
} Power;


/* create a pointer of type Master struct and point to instance of that struct type,i.e Power */


struct Master *power_pointer = &Power;    


// creating a structure of a message, the value to its variables will be fetched by pointer to the master structure

struct {
short var1 : 1;
char var2 : 4;
short var3 : 1;
short var4 : 4;  
}EV_msg_01;

// creating a structure of a message, the value to its variables will be fetched by pointer to the master structure

struct {
short var1 : 1;
short var2 : 4;
short var3 : 1;
short var4 : 4;  
}station_msg_01;



struct EV_msg  EV_msg_01 = {
                      power_pointer->Vehicle_Energy_Capacity,power_pointer->Vehicle_RESS_SOC,power_pointer->Vehicle_Maximum_Power_Limit,power_pointer->Vehicle_Maximum_Current_Limit
                      };


struct station_msg_01 station_msg_01 = {
                      power_pointer->Charger_Maximum_Power_Limit, power_pointer->Charger_Maximum_Current_Limit,power_pointer->Charger_Maximum_Voltage_Limit,power_pointer->Charge_Current_Request
                      };

[/code]


I haven't the foggiest idea of what you said there, or what you're trying to do. But:

struct {
short var1 : 1;
char var2 : 4;
short var3 : 1;
short var4 : 4;  
}EV_msg_01;

creates a variable called EV_msg_01 of an anonymous type.

struct EV_msg  EV_msg_01 = {

EV_msg is not defined anywhere, and the variable EV_msg_01 already exists, it was defined in the first part.

struct station_msg_01 station_msg_01 = {

station_msg_01 is a variable that was already declared also, not a type. And you can't have a variable with the same name as a type.

EV_msg_01 = { power_pointer->Vehicle_Energy_Capacity, }

I have no idea what you intended, but that assignment attempts to assign Vehicle_Energy_Capacity (a short) to a short : 1; (a bool?) and zero initializes the other members.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜