This simulator is a drop-in alternative to the elevator hardware server that interfaces to the hardware at the lab. Communication to the simulator is over TCP, with the same protocol as the hardware server.
Main features:
- 2 to 9 floors: Test the elevator with a different number of floors
- Fully customizable controls: Dvorak and azerty users rejoice!
- Full-time manual motor override: Control the motor directly, simulating motor stop or unexpected movement.
- Button hold: Hold down buttons by using uppercase letters.
Executables for Windows and Linux can be found here
The server is intended to run in its own window, as it also takes keyboard input to simulate button presses. The server should not need to be restarted if the client is restarted.
Remember to chmod +x SimElevatorServer
in order to give yourself permission to run downloaded files.
The simulator has several configuration options, which you can find listed here. The most relevant options are:
--port
: This is the TCP port used to connect to the simulator, which defaults to 15657.
You should change this number in order to not interfere with other people's running simulators.
You can start multiple simulators with different port numbers to run multiple elevators on a single machine.--numfloors
: The number of floors 2 to 9), which defaults to 4.
Options passed on the command line (eg. ./SimElevatorServer --port 12345
) override the options in the the simulator.con
config file, which in turn override the defaults baked in to the program. simulator.con
must exist in the same folder as the executable in order to be loaded.
Options are not case sensitive.
- Up:
qwertyui
- Down:
sdfghjkl
- Cab:
zxcvbnm,.
- Stop:
p
- Obstruction:
-
- Motor manual override: Down:
7
, Stop:8
, Up:9
- Move elevator back in bounds (away from the end stop switches):
0
Up, down, cab and stop buttons can be toggled (and thereby held down) by using uppercase letters.
+-----------+-----------------+
| | #> |
| Floor | 0 1* 2 3 |Connected
+-----------+-----------------+-----------+
| Hall Up | * - - | Door: - |
| Hall Down | - - * | Stop: - |
| Cab | - - * - | Obstr: ^ |
+-----------+-----------------+---------43+
The ascii-art-style display is updated whenever the state of the simulated elevator is updated.
A print count (number of times a new state is printed) is shown in the lower right corner of the display. Try to avoid writing to the (simulated) hardware if nothing has happened. A jump of 20-50 in the printcount is fine (even expected), but if there are larger jumps or there is a continuous upward count, it may be time to re-evaluate some design choices.
Since the simulator changes the terminal input mode (in order to read key presses without you having to press Enter), the input mode is sometimes broken if the simulator does not quit properly. Type reset
and hit Enter to reset the terminal completely if this happens.
The server is written in D, so you will need a D compiler to run it. I recommend using the dmd compiler (since this is the only one I have tested it with), which you can get from The D lang website.
Compile with dmd -w -g src/sim_server.d src/timer_event.d -ofSimElevatorServer
If your client works with the elevator hardware server, then it should work with the simulator with no changes.
- All TCP messages must have a length of 4 bytes
- The instructions for reading from the hardware send replies that are 4 bytes long, where the last byte is always 0
- The instructions for writing to the hardware do not send any replies
Writing | Instruction | ||||||||
Reload config (file and args) | 0 | X | X | X | |||||
Motor direction | 1 | direction [-1 (255),0,1] |
X | X | |||||
Order button light | 2 | button [0,1,2] |
floor [0..NF] |
value [0,1] |
|||||
Floor indicator | 3 | floor [0..NF] |
X | X | |||||
Door open light | 4 | value [0,1] |
X | X | |||||
Stop button light | 5 | value [0,1] |
X | X | |||||
Reading | Instruction | Output | |||||||
Order button | 6 | button [0,1,2] |
floor [0..NF] |
X | Returns: | 6 | pressed [0,1] |
0 | 0 |
Floor sensor | 7 | X | X | X | Returns: | 7 | at floor [0,1] |
floor [0..NF] |
0 |
Stop button | 8 | X | X | X | Returns: | 8 | pressed [0,1] |
0 | 0 |
Obstruction switch | 9 | X | X | X | Returns: | 9 | active [0,1] |
0 | 0 |
NF = Num floors. X = Don't care. |
Button types (for reading the button and setting the button light) are in the order 0: Hall Up
, 1: Hall Down
, 2: Cab
.
Since interfacing is done over TCP, you can also use command-line utilities to interface with the simulator server. For example, to read the current floor:
echo -e '\x07\x00\x00\x00' | netcat localhost 15657 | od -tx1