This simulator is an extension to elev.c that lets you use both the actual elevator at the real-time lab, and a simulated elevator.
The simulated elevator is a server which is intended to be run in its own window. Communication with the server is done over TCP. elev.c has been modified to act as a client, where the network portion is written with linux in mind (as this is what you use at the lab, and libcomedi also only works on linux). However, it is possible to write a client in another language, thus avoiding the OS-specific C code entirely.
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.
Main features:
- 2 to 9 floors: Test the elevator with a different number of floors
- Fully customizable controls: Dvorak and qwertz 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.
The only difference is:
elev_init(elev_type e);- Takes either
ET_ComediorET_Simulation
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.
Running:
rdmd sim_server.d, ifsimulator.conis in the folder you are runningrdmdfrom, orrdmd sim_server.d [configfile], to specify a another config file.
See simulator.con for all the config options.
- Up:
qwertyui - Down:
sdfghjkl - Cab:
zxcvbnm,. - Stop:
p - Obstruction:
- - Motor manual override: Down:
7, Stop:8, Up:9
Up, down, cab and stop button can be toggled (and thereby held down) by using uppercase letters.
+-----------+-----------------+
| | #> |
| Floor | 0 1* 2 3 |
+-----------+-----------------+-----------+
| 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.
You can use the simulator entirely without the C client code by creating your own client in the language of your choice. The binary protocol for interfacing with the server is outlined below:
- 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 | 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. | |||||||||
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