Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how state conversion functions are called by SmartCoreProcessor #272

Open
danngreen opened this issue May 31, 2024 · 0 comments
Open

Comments

@danngreen
Copy link
Member

It seems Element state conversion functions for 4ms elements are never called. That is, the convertState() overloads in 4ms_element_state_conversions.hh are not called. The reason is that SmartCoreProcessor getState() creates a reference to the variant-alternative type, and calls convertState() using that type. So, given a Toggle3posHoriz type, it will call convertState(FlipSwitch&), and ignores the overload for convertState(Toggle3posHoriz&). This can be verified by having the overload return bogus values and noticing nothing changes in the modules.

Second, this is tied into the issue that the 4ms_element_state_conversions.hh header needs to be included before the SmartCoreProcessor.hh header. Doing this is easy to forget or overlook.

In the PI PR #267 I moved the FlipSwitch overload to the general state conversion header, so at least the second point above is not an issue for now, but we still are just getting lucky that the generic FlipSwitch conversion values matches the underlying enum values.

This whole issue would go away if we insisted that any State_t enum's values were all calculated in the same way as their parent Element-variant type. In that case we wouldn't need brand-specific conversion functions. But we'd lose the safety and flexibility of enum classes.

Another solution would be to have SmartCoreProcessor call the right convertState() function. I played with this a bit, but didn't find any simple answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant