stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 291

Day 291 of 365 · Expert · Month 10: Bits and data

Watchdog: is the other chip alive?

A watchdog checks whether another chip is still running: count heartbeats, detect a standstill after a patience time, the NaN trap when comparing and taking over emergency mode.

Lesson 18 min Week 42

What you learn today

  • Count heartbeats
  • Detect failure
  • Take over emergency mode

A chip that runs past the end of the program is silent and dead – without an error message. A chip somebody takes out is too. If the living module's heating depends on it, you only notice when it gets cold. A second chip can keep watch: the watchdog.

Heartbeats

The monitored chip counts a pulse up in every main loop and writes it into a logic memory:

add pulse pulse 1
sbn MEMORY HASH("Puls") Setting pulse     # heartbeat

As long as it runs, the value changes every tick. If it stands still, the chip has stopped, is stuck in a loop without this code or is gone.

Detecting failure

The watchdog compares the pulse with the last value. Same: a counter counts up. Different: counter to 0. Only when the counter exceeds the patience does the chip count as failed – a single missed tick is not a failure yet.

seq tmp pulse old
add still still tmp
mul still still tmp
move old pulse
sgt dead still PATIENCE

mul still still tmp is the trick from watering: if tmp is 0, the counter drops to 0.

Warning

NaN is never equal to NaN, not even to itself. If the pulse memory is missing, seq tmp pulse old gives 0 every tick, the counter stays at 0 – and the watchdog never reports a failure. A separate snan is therefore mandatory.

Taking over emergency mode

When the watchdog reports a failure, it must not just warn. It takes over the bare essentials itself: an emergency heater, a vent, a valve closed. When the pulse comes back, it hands over again.

Choose the patience to match the monitored chip. A chip with sleep 5 only pulses every ten ticks – a patience of 10 would be too tight.

Tip

Watchdogs work in both directions: two chips can watch each other. If one fails, the other takes over – that is the basic idea of every redundancy.

Diagram

Ticks and yield on a timeline tick 0 · 0.0 s tick 1 · 0.5 s tick 2 · 1.0 s tick 3 · 1.5 s 5 instr. yield 5 instr. yield 5 instr. yield 128 instr. no yield: limit hit Device values only change between two ticks.
The pulse has to change. If it stays the same longer than the patience time, the chip counts as failed.

Exercise

Task

Write the watchdog for the pulse in the memory “Puls”:

  • if the pulse stays the same for more than PATIENCE = 10 ticks, the chip counts as failed
  • if the memory is missing, failed at once
  • on failure: light “Ausfall” on and heater “Notheizung” on
  • when the pulse comes back, both off again

Hints

Hint 1

seq tmp pulse old, add still still tmp, mul still still tmp, then move old pulse.

Hint 2

Failure: sgt dead still PATIENCE.

Hint 3

Plus snan tmp pulse and or dead dead tmp.

Quiz

3 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere