---
# System prepended metadata

title: 'Quick Start: a simple demo'

---

# Quick Start: a simple demo
This document will help you run a simple demo.
We'll only use the code in `main` branch.
## Prep: Software
- OS: Ubuntu 20.04 LTS
- Language: C++14
- tool & library
    - g++, make

### Setup
- g++, make
Use `build-essential` package directly.
If on ubuntu, install via the command:
```shell 
apt install build-essential
```
Note: if the above command failed, you may want to use `apt update` first.

### Download Project
Github: https://github.com/seanpai96/APNM
2 important branches:
- main
This branch contains our implementation of NM. main files can also serve as a simple demo runs in terminal. 
We'll only use `main` branch in this document.
- GPIO
This branch is for demo purpose only. (However, we won't use it this time since it needs additional dependency.)
Note that the changes made in this branch may not comply to related AUTOSAR specifications.
Those changes include exposing internal states, websocket connection with presenting websites and GPIO controls.

## Prep: Hardware
This demo requires at least 3 machines. We use Raspberry Pi 3 & 4 as our machines.

### Setting
We use a router to connect all three machines, all three of them need to have their own IP. In our case, we use an additional Raspberry Pi with openWrt system as router, connecting to a network switch, and three machines connects to the switch.

As long as three machines are in same LAN network and **the LAN supports Multicast** it's fine.

## Run the demo
After finishing the above preparations, you're ready to run the demo.
Your 3 machines should run `main1.c` `main2.c` `main3.c`, each on a machine.
`main1.c` will control node 0 and node 2.
`main2.c` will control node 1.
`main3.c` will control node 3.

Rename the chosen file to `main.c`, and use `make` command to generate a `main` executable. Remember, each machine should run a different main source.

All main files accept commands directly from your terminal (stdin), the following are the commands for each main file.

### Control of `main1.c`
This file use `on1` `on2` `off1` `off2` commands to affect the status of cluster 1 and 2.
When using `on1`, node 0 is activated (via handle 0) and will soon start sending messages, thus changing the status of cluster 1.
`off1`, on the other hand, stop node 0 from sending messages.
`on2`, `off2` act in the same way. They controls node 2 and affect the status of cluster 2.

### Control of `main2.c`/`main3.c`
These files only involve single node, so only command `on`/`off` is provided.
Just like the above description, while `main2.c` controls node 1 and cluster 1, `main3.c` controls node 3 and cluster 2.

If you're unfamiliar with these terms or just don't know what are we talking about this the above 2 sections, you should probably visit the [NM concepts and behavior section](https://hackmd.io/Pf56ai2cTUmC8U9PIPLjDA#Concepts-and-behavior) to have a much detailed explaination.

### Result
The state of each node will be printed.
Format:
```
"NodeID: {id} Tick: {counter} current_state: {node state}"
```
Also, when the status of a handle is changed, the massage will be printed.
```
"{handle} network mode set to {true/false}"
```
Here, true/false means kFullCom/kNoCom.


![](https://hackmd.io/_uploads/B1GedDyP2.jpg)
(Example Screenshot)

You may observe the output of each machine and check the behavior of clusters and nodes.