Skip to content

TTK4145/elevator-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Elevator server

In the TTK4145 elevator project the elevator hardware is controlled by a server, which exposes a TCP interface. This repository contains the source code for that server, as well as a download link to the executable.

If you are on the lab, you should be able to start the elevator server from any terminal window by just running elevatorserver. Likewise, the simulator should also be runnable with simelevatorserver.

Executables

The executables for Windows and Linux can be found here.

The server should run in its own terminal, and should not need to be restarted if the client is restarted.

Remember to chmod +x elevatorserver in order to give yourself permission to run the downloaded file.

Running

Once the server has started, it will start listening on localhost:15657. You can then connect to it by using a client that adheres to the protocol.

Building from source

The elevator server is written in D, so you will need a D compiler.

Compile with dmd elevatorserver.d arduino_io_card.d


A low-level C driver is also included for completeness. This is not an elevator server, as it exposes its functionality through C function calls instead of a TCP connection. This means it does not expose an interface similar to the simulator, and therefore its usage is not recommended. Prefer using the C client with the elevator server instead.

Protocol

  • 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]
custom speed
[0,1]
speed
[0..255]
(defaults to 255 if custom speed is 0)
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.