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

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

A protocol of your own

Two chips talk through a logic memory: pack messages from sequence number, id and value, write an acknowledgement back and prevent double execution.

Lesson 20 min Week 42

What you learn today

  • Messages from id and value
  • Acknowledgement
  • Ordering

A chip in the control room should tell a chip in the pump station what to do: pump on, setpoint 250, toggle the light. A logic memory between the two holds exactly one number. To turn that into a conversation, you need an agreement – a protocol.

Messages from id and value

A message has three parts, packed into one number:

BitsFieldMeaning
0–15value0 to 65535
16–23idwhat to do
24–31numberrunning number of the message

You define the ids and write them into both chips:

IdCommand
1pump “Haupt” on or off (value 1 or 0)
2show setpoint
3toggle light

The sender packs with ins:

move msg value
ins msg id 16 8
ins msg seq 24 8
sbn MEMORY HASH("Postfach") Setting msg

Acknowledgement

The receiver reads the mailbox, executes the command and writes the message number into a second memory, the acknowledgement. From that the sender sees that its message has arrived.

Ordering and double execution

A logic memory keeps its value. So the receiver reads the same message again every tick. For “pump on” that does not matter, for “toggle light” it does: the light would toggle twice per second. Hence the number: the receiver remembers the last one and only executes when a new one arrives.

ext seq msg 24 8
beq seq last start     # already handled
move last seq

For the ordering there is one rule: the sender only sends the next message once the acknowledgement shows its number. Otherwise it overwrites a message nobody has read yet. After 255 the number starts at 0 again – it only has to differ from the last one.

Warning

After a restart of the receiver, last is 0 at first. If an old message is still in the mailbox, it would execute it a second time. So read the acknowledgement into last at start – it holds the number that was handled most recently.

Diagram

Devices on the data network with type and name IC housing IC10 StructureGasSensor „Lager“ StructureGasSensor „Werkstatt“ StructureWallHeater „Lagerheizung“ StructureWallHeater „Lagerheizung“ StructureWallHeater „Werkstattheizung“ lbn SENSOR HASH("Lager") reads only this sensor sbn HEATER HASH("Lagerheizung") switches both at once
The sender writes into the mailbox, the receiver executes and writes the number into the acknowledgement.

Exercise

Task

Write the receiver. The mailbox “Postfach” holds messages following the table above:

  • id 1: pump “Haupt” On = value
  • id 2: display “Soll” = value
  • id 3: toggle light “Licht”
  • execute each new number exactly once, ignore unknown ids
  • then write the number into “Quittung”
  • if the mailbox is missing, nothing happens

Hints

Hint 1

ext seq msg 24 8, then beq seq last start – old message, do nothing.

Hint 2

For each id a bne id N next before the action.

Hint 3

Toggle: read the light, seqz, write back.

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