Hallo,
I have a windows c++ application which communicates with the micro controller. It send a request for status and receives it every 500 m sec. The status packet have 6 data bytes. Each byte indicating different functionality like temperature, power etc. If the temperature is high , a warning message should be printed on screen once and its the same for power off. The power off byte has several bits indicating power low, battery is discharging and so on. when the power is off, first the power off bit is set to one and then battery discharging bit is set to one. So every few seconds the bytes are different. What my question is what ever the functionality is the warning message should only appear once. Since I receive status packet every 500ms, until the power is switched on again or the temperature goes to normal, the warning message is popping up. At first i used memory compare(memcmp) to check the prev value with current value and if its different, only then warning is printed, but it doesn't work because when power is off, the bytes keep changing.I am sure how to check if the packet is new in case of poweroff.
struct Status{
std::uint8_t temperature;
std::uint8_t power;
//...
};
class State{
int power = -1; //indeterminate state
void process_temperature(const Status &status);
void process_power(const Status &status){
if ((status.power & POWER_FLAG) == POWER_FLAG){
//power is on
if (this->power != 1){
//power was just turned on
this->reset_warnings();
this->power = 1;
}
if ((status.power & POWER_BATT_CHARGING) == POWER_BATT_CHARGING){
//Do something.
}
}else{
if (this->power != 0){
//power was just turned off
this->notify_power_off();
this->power = 0;
}
}
//check whatever else is appropriate
}
void reset_warnings();
void notify_power_off();
public:
void update(const Status &status){
this->process_temperature(status);
this->process_power(status);
//...
}
};