Skip to content

Commit

Permalink
Merge pull request #15 from tidewise/update_alarm_state
Browse files Browse the repository at this point in the history
fix: Always update alarm state
  • Loading branch information
doudou authored Mar 12, 2024
2 parents 2e73cd1 + 6e2b81d commit 5ef3005
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 4 additions & 6 deletions tasks/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ void Task::updateHook()
_inverter_state.write(state_out);

int current_alarm = m_driver->readCurrentAlarm();
if (current_alarm) {
AlarmState alarmState;
alarmState.time = Time::now();
alarmState.current_alarm = current_alarm;
_alarm_state.write(alarmState);
}
AlarmState alarmState;
alarmState.time = Time::now();
alarmState.current_alarm = current_alarm;
_alarm_state.write(alarmState);

if (now - m_last_temperature_update > _temperature_period.get()) {
_temperatures.write(m_driver->readTemperatures());
Expand Down
9 changes: 9 additions & 0 deletions test/task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@
assert_equal 1, sample.current_alarm
end

it "outputs an zeroed alarm state structure if there is no alarm" do
modbus_configure_and_start

now = Time.now
sample = modbus_expect_execution(@writer, @reader).to { have_one_new_sample task.alarm_state_port }
assert Time.at(now.tv_sec, 0) < sample.time
assert_equal 0, sample.current_alarm
end

it "outputs a fault state structure and transitions to fault if the inverter is in under-voltage" do
modbus_configure_and_start

Expand Down

0 comments on commit 5ef3005

Please sign in to comment.