I am doing some tcp/ip query response. So now I have extracted the bytes that contain the status of my sensor as a string.
std::string loadingSeqStatus=data_buffer.substr(10, 1);
Now every bit in my byte indicates a certain status of my sensor. And it goes in a flow sequence. So I need to access the latest bit updated and link it to my enum types.
E.g. I query and get a response as 01(Hex), which means 0000 0001, which means some type of my enum. In my next query and I receive 03 that is 0000 0011, where the second bit means the next step. For the time being, I am assuming, given the sensor specification, the bits will be set in chronological order that is only after 2nd bit is high the 3rd bit could be set high but not the other way round, i.e. only after 0000 0011 I can get 0000 0111, but it cannot be 0000 0101, as every state depends on the previous.
Someone, please suggest me a way to access the latest update. Maybe I can run a for loop and do some bit shifting. Like:
for(int i = 7; i <= 0; i--){
bool[] sensor_status_list;
sensor_status_list.push_back(loadingSeqStatus & (1 << i) ? 1 : 0);
//and then maybe check which bit is
}
But then this is updating the entire list everytime, so basically I have to map it with some table, that is when 0001 1111, which is 1F that means something in my map??!! Very confusing, hope I could convey my requirement. Kindly help.
Aucun commentaire:
Enregistrer un commentaire