0
我想創建不同的消息在兩臺主機之間傳輸。我遵循的程序結構是創建一個主結構,其中聲明瞭在不同消息中傳遞的所有變量。 然後我使用master結構中的相同變量爲不同的消息創建了不同的結構體,我試圖傳遞的值是通過指針。 下面是我想要做的事情的大致輪廓。我不知道這是正確的方法,還是有另一種更好的方法來做到這一點。從主結構獲取變量結構
在編譯時,我得到的錯誤是: 1.表達式必須有一個恆定的值 2.不完全類型是不允許
兩者都指出,當我嘗試創建消息結構和傳球的實例主結構的指針。
請幫忙。
[代碼]
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
};
[/代碼]
這應該是什麼語言? –
對我來說看起來像C –