-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix(sensors): Share sync line control bitmasks #799
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc5aa9a
add another singletop so sensor hardware instances can share their bi…
ryanthecoder cc185f2
update tests
ryanthecoder cd326d3
format
ryanthecoder 731bc97
remove prints
ryanthecoder 5d1fa27
use inverse operator
ryanthecoder b3af515
fix pipette-simulators
ryanthecoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -43,6 +43,70 @@ static auto get_mask_from_id(can::ids::SensorId sensor) -> uint8_t { | |||||
return static_cast<uint8_t>(mask_enum); | ||||||
} | ||||||
|
||||||
class SensorHardwareSyncControlSingleton { | ||||||
public: | ||||||
SensorHardwareSyncControlSingleton() = default; | ||||||
virtual ~SensorHardwareSyncControlSingleton() = default; | ||||||
SensorHardwareSyncControlSingleton( | ||||||
const SensorHardwareSyncControlSingleton&) = default; | ||||||
auto operator=(const SensorHardwareSyncControlSingleton&) | ||||||
-> SensorHardwareSyncControlSingleton& = default; | ||||||
SensorHardwareSyncControlSingleton(SensorHardwareSyncControlSingleton&&) = | ||||||
default; | ||||||
auto operator=(SensorHardwareSyncControlSingleton&&) | ||||||
-> SensorHardwareSyncControlSingleton& = default; | ||||||
|
||||||
[[nodiscard]] auto mask_satisfied() const -> bool { | ||||||
if (set_sync_required_mask != | ||||||
static_cast<uint8_t>(SensorIdBitMask::UNUSED)) { | ||||||
printf("%x is required\n", set_sync_required_mask); | ||||||
printf("%x sync_state_mask\n", sync_state_mask); | ||||||
// if anything is "required" only sync when they are all triggered | ||||||
return (sync_state_mask & set_sync_required_mask) == | ||||||
set_sync_required_mask; | ||||||
} | ||||||
return (sync_state_mask & set_sync_enabled_mask) != 0; | ||||||
} | ||||||
|
||||||
auto set_sync(can::ids::SensorId sensor) -> void { | ||||||
// force the bit for this sensor to 1 | ||||||
printf("setting sync on %x sensor\n", get_mask_from_id(sensor)); | ||||||
sync_state_mask |= get_mask_from_id(sensor); | ||||||
} | ||||||
|
||||||
auto reset_sync(can::ids::SensorId sensor) -> void { | ||||||
// force the bit for this sensor to 0 | ||||||
sync_state_mask &= 0xFF ^ get_mask_from_id(sensor); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's the more common way I've seen, anyway |
||||||
} | ||||||
|
||||||
auto set_sync_enabled(can::ids::SensorId sensor, bool enabled) -> void { | ||||||
uint8_t applied_mask = get_mask_from_id(sensor); | ||||||
if (!enabled) { | ||||||
// force enabled bit to 0 | ||||||
set_sync_enabled_mask &= 0xFF ^ applied_mask; | ||||||
} else { | ||||||
// force enabled bit to 1 | ||||||
set_sync_enabled_mask |= applied_mask; | ||||||
} | ||||||
} | ||||||
|
||||||
auto set_sync_required(can::ids::SensorId sensor, bool required) -> void { | ||||||
uint8_t applied_mask = get_mask_from_id(sensor); | ||||||
if (!required) { | ||||||
// force required bit to 0 | ||||||
set_sync_required_mask &= 0xFF ^ applied_mask; | ||||||
} else { | ||||||
// force required bit to 1 | ||||||
set_sync_required_mask |= applied_mask; | ||||||
} | ||||||
} | ||||||
|
||||||
private: | ||||||
uint8_t set_sync_required_mask = 0x00; | ||||||
uint8_t set_sync_enabled_mask = 0x00; | ||||||
uint8_t sync_state_mask = 0x00; | ||||||
}; | ||||||
|
||||||
class SensorHardwareVersionSingleton { | ||||||
public: | ||||||
SensorHardwareVersionSingleton() = default; | ||||||
|
@@ -66,8 +130,9 @@ class SensorHardwareVersionSingleton { | |||||
/** abstract sensor hardware device for a sync line */ | ||||||
class SensorHardwareBase { | ||||||
public: | ||||||
SensorHardwareBase(SensorHardwareVersionSingleton& version_wrapper) | ||||||
: version_wrapper{version_wrapper} {} | ||||||
SensorHardwareBase(SensorHardwareVersionSingleton& version_wrapper, | ||||||
SensorHardwareSyncControlSingleton& sync_control) | ||||||
: version_wrapper{version_wrapper}, sync_control{sync_control} {} | ||||||
virtual ~SensorHardwareBase() = default; | ||||||
SensorHardwareBase(const SensorHardwareBase&) = default; | ||||||
auto operator=(const SensorHardwareBase&) -> SensorHardwareBase& = delete; | ||||||
|
@@ -79,40 +144,27 @@ class SensorHardwareBase { | |||||
virtual auto check_tip_presence() -> bool = 0; | ||||||
|
||||||
[[nodiscard]] auto mask_satisfied() const -> bool { | ||||||
if (set_sync_required_mask != | ||||||
static_cast<uint8_t>(SensorIdBitMask::UNUSED)) { | ||||||
// if anything is "required" only sync when they are all triggered | ||||||
return (sync_state_mask & set_sync_required_mask) == | ||||||
set_sync_required_mask; | ||||||
} | ||||||
return (sync_state_mask & set_sync_enabled_mask) != 0; | ||||||
return sync_control.mask_satisfied(); | ||||||
} | ||||||
|
||||||
auto set_sync(can::ids::SensorId sensor) -> void { | ||||||
// force the bit for this sensor to 1 | ||||||
sync_state_mask |= get_mask_from_id(sensor); | ||||||
sync_control.set_sync(sensor); | ||||||
// update sync state now that requirements are different | ||||||
if (mask_satisfied()) { | ||||||
set_sync(); | ||||||
} | ||||||
} | ||||||
|
||||||
auto reset_sync(can::ids::SensorId sensor) -> void { | ||||||
// force the bit for this sensor to 0 | ||||||
sync_state_mask &= 0xFF ^ get_mask_from_id(sensor); | ||||||
sync_control.reset_sync(sensor); | ||||||
// update sync state now that requirements are different | ||||||
if (!mask_satisfied()) { | ||||||
reset_sync(); | ||||||
} | ||||||
} | ||||||
|
||||||
auto set_sync_enabled(can::ids::SensorId sensor, bool enabled) -> void { | ||||||
uint8_t applied_mask = get_mask_from_id(sensor); | ||||||
if (!enabled) { | ||||||
// force enabled bit to 0 | ||||||
set_sync_enabled_mask &= 0xFF ^ applied_mask; | ||||||
} else { | ||||||
// force enabled bit to 1 | ||||||
set_sync_enabled_mask |= applied_mask; | ||||||
} | ||||||
sync_control.set_sync_enabled(sensor, enabled); | ||||||
// update sync state now that requirements are different | ||||||
if (mask_satisfied()) { | ||||||
set_sync(); | ||||||
|
@@ -122,14 +174,7 @@ class SensorHardwareBase { | |||||
} | ||||||
|
||||||
auto set_sync_required(can::ids::SensorId sensor, bool required) -> void { | ||||||
uint8_t applied_mask = get_mask_from_id(sensor); | ||||||
if (!required) { | ||||||
// force required bit to 0 | ||||||
set_sync_required_mask &= 0xFF ^ applied_mask; | ||||||
} else { | ||||||
// force required bit to 1 | ||||||
set_sync_required_mask |= applied_mask; | ||||||
} | ||||||
sync_control.set_sync_required(sensor, required); | ||||||
// update sync state now that requirements are different | ||||||
if (mask_satisfied()) { | ||||||
set_sync(); | ||||||
|
@@ -142,10 +187,8 @@ class SensorHardwareBase { | |||||
} | ||||||
|
||||||
private: | ||||||
uint8_t set_sync_required_mask = 0x00; | ||||||
uint8_t set_sync_enabled_mask = 0x00; | ||||||
uint8_t sync_state_mask = 0x00; | ||||||
SensorHardwareVersionSingleton& version_wrapper; | ||||||
SensorHardwareSyncControlSingleton& sync_control; | ||||||
}; | ||||||
|
||||||
struct SensorHardwareContainer { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm don't like these even they compile out