Code Index
network module
- class src.network.Client(server_ip, server_port, **kwargs)
Bases:
NetworkInterface- send(val)
Sends the data to the server
- Parameters:
val – the angle or the error
- Returns:
- class src.network.NetworkInterface(send_errors: bool = True, precision: int = 360, message_bytes: int = 2, **kwargs)
Bases:
objectAbstracts the send method, and how to do the preprocessing of the data to send
- Parameters:
send_errors – flag if errors should be sent or only logged
precision (int) – the base degree of the angle, defaults to 360
message_bytes – how many bytes the data should have in ethernet and serial, 2^(8*message_bytes) has to be bigger than precission, defaults to 2
kwargs – a catch-all argument, so constructor can be filled by config
- Variables:
max_precision – equals 2^(8 * message_bytes), the highest 10 values are reserved for error codes
NOT_FOUND – max_precision - 1, an error code for a not found ball
WRONG_ORDER – max_precision - 2, an error code for a failed race condition
ERROR – max_precision - 3, an error code, for a general error
LOST_CONNECTION – max_precision - 4, an error code, for a lost camera-pi
- preprocess_message(data: float) -> (<class 'int'>, <class 'bool'>)
Rebases the data from 360 degree to the given precision.
- Parameters:
data (float) – the date which should be converted
- Returns:
the angle in the new base cast to int and if this is an error
- Return type:
(int, bool)
- send(val)
A placeholder which will be overwritten by its parents
- Parameters:
val – the data
- class src.network.Server(server_ip, server_port, serial, print_debug=False, **kwargs)
Bases:
Thread,NetworkInterfaceThe server class. Manages the incoming connections from clients, pipes data to the serial port and is logging the values for a later plotting usage
- Parameters:
server_ip – the ip of the server (has to be localhost)
server_port – the port we are waiting for connections
serial – the configuration for the serial class
print_debug – a flag if debug output should be printed or discarded
kwargs – a catch-all parameter for additional config given
- Variables:
serial – A object of the
SerialCom
- latest_values()
Returns only the last value from each host in each category time, angle and error as plain value
- Returns:
dict[hostname][category] : value
- print(msg)
Helper method which suppresses debug output if not configured
- run() None
Runs the network server. This method is started in a separate thread It iterates through all connection sockets, including the server, watching for new data or connections. The first given data is the hostname, so a reconnect with the same hostname is possible server vice
- save_values(data, address, is_error: bool)
Saves the value (or error) in an value array, together with the time. The hostname is used as a a top level key.
- Parameters:
data – the data
address – connection address, where the hostname can be deducted from
is_error – a flag if this data is an error code, so we do nat have to check here
- Returns:
- send(val)
does not send the data to the server, because this is the server already. So it justs saves the data and pipes the data through to the serial interface. If you want to send something else then just the hostdata, like an average from all 3 values, you need to change this method
- Parameters:
val –
- Returns:
- stop()
Saves the data which was sent in a result.mat and result.yml file
- Returns:
- src.network.addr(s: socket)
A helper method to get a unique string per connection
- Parameters:
s – the socket object
- Returns:
a unique string per connection
- src.network.init_network(is_server: bool, server_ip: str, server_port: int = 9999, **kwargs) NetworkInterface
This function is a wrapper for dynamic construction of the Client or Server Class depending on the config file, some parameters are only relevant in a server context
- src.network.now()
A helper method to get an integer value which can be used as a time axis
- Returns:
a time integer in ms, repeats every 10.000 seconds
serial module
- class src.serial.SerialCom(verbose=False, com='/dev/serial0', baud=9600, active=True, message_bytes=2, send_mode=1, send_errors=False)
Bases:
objectOrganizes the serial communication to the dspace card
- Parameters:
verbose – flag if more output should be given, defaults to false
com – the com port to use, on linux a file, defaults to ‘/dev/serial0’ (rpi v4)
baud – the baud rate
active – flag if serial connection should be established, usefull for mockup usage, defaults to True
message_bytes – the length in bytes of the send message per given data, defaults to 2
send_mode – the send mode (not yet implemented)
send_errors – flag if errors should be transmitted, defaults to False (not yet implemented)
- write(angle: int)
The method to call to write an int over the serial line
- Parameters:
angle – the angle in int