I'm refactoring software that is created by my predecessor. The software can communicate over the can-bus. At this moment all devices are hardcoded in the software and my job is to make every deviceType configurable. (Saved in serialized classes and creatable with a Model creator). With the software, the devices can be configured, addressed and parameter set.
At the moment, it keeps track of the messages with flagged enums set in the uints paramsRequested and paramsUpdated. But this needs to be replaced with something else. Because this is not scaleable and configurable.
Example enum:
public enum FunctionParameters : uint
{
None = 0,
StatusInterval = 1 << 0,
Delay = 1 << 1,
Time = 1 << 2,
.....
}
A mesage is sent over the can-bus and is waiting asynchronosly on a reply.
When message comes in:
_paramsUpdated |= (uint) FunctionParameters.StatusInterval;
Another thread waits till message is arrived, to use it and checks if parameter isreceived.
while (((uint)_paramsUpdated & (uint)param) == 0)
{
// Do nothing
Thread.Sleep(threadSleepTimeMS);
//Thread.Yield();
}
When this takes too long, it will give a timeout exception. This works as intended at the moment.
The question is, are there alternatives that don't work with enum flags to keep track of this, because the new situation has multiple flexible flags.
I do not have time-out issues, it's more a architectual problem to replace enum flags with another system.
I maybe have the solution myself:
I added a class named ParameterFlag; This looks linke this:
_paramsUpdated will become:
When a message comes in:
Another thread waits till message is arrived, to use it and checks if parameter isreceived:
Thank you very much for your comments!