terminal¶
Classes:
|
Central host to a fleet of |
-
class
Terminal
[source]¶ Bases:
PySide2.QtWidgets.QMainWindow
Central host to a fleet of
Pilot
s and user-facinggui
objects.Called as a module with the -f flag to give the location of a prefs file, eg:
python terminal.py -f prefs_file.json
if the -f flag is not passed, looks in the default location for prefs (ie. /usr/autopilot/prefs.json)
**Listens used by the internal
Net_Node
**Key
Method
Description
‘STATE’
A Pi has changed state
‘PING’
Someone wants to know if we’re alive
‘DATA’
Receiving data to store
‘HANDSHAKE’
Pilot first contact, telling us it’s alive and its IP
** Prefs needed by Terminal ** Typically set by
setup.setup_terminal
BASEDIR - Base directory for all local autopilot data, typically /usr/autopilot
MSGPORT - Port to use for our ROUTER listener, default 5560
DATADIR - os.path.join(params[‘BASEDIR’], ‘data’)
SOUNDDIR - os.path.join(params[‘BASEDIR’], ‘sounds’)
PROTOCOLDIR - os.path.join(params[‘BASEDIR’], ‘protocols’)
LOGDIR - os.path.join(params[‘BASEDIR’], ‘logs’)
REPODIR - Path to autopilot git repo
PILOT_DB - Location of pilot_db.json used to populate
pilots
- Variables
node (
Net_Node
) – Our Net_Node we use to communicate with our main networking objectnetworking (
Terminal_Station
) – Our networking object to communicate with the outside worldsubjects (dict) – A dictionary mapping subject ID to
Subject
object.pilots (dict) – A dictionary mapping pilot ID to a list of its subjects, its IP, and any other pilot attributes.
layout (
QtWidgets.QGridLayout
) – Layout used to organize widgetscontrol_panel (
Control_Panel
) – Control Panel to manage pilots and subjectsdata_panel (
Plot_Widget
) – Plots for each pilot and subject.logo (
QtWidgets.QLabel
) – Label holding our beautiful logo ;Xlogger (
logging.Logger
) – Used to log messages and network events.log_handler (
logging.FileHandler
) – Handler for logginglog_formatter (
logging.Formatter
) –Formats log entries as:
"%(asctime)s %(levelname)s : %(message)s"
Methods:
Start logging to a timestamped file in prefs.LOGDIR
initUI
()Initializes graphical elements of Terminal.
reset_ui
()Clear Layout and call
initUI()
againheartbeat
([once])Perioducally send an
INIT
message that checks the status of connected pilotstoggle_start
(starting, pilot[, subject])Start or Stop running the currently selected subject’s task.
l_data
(value)A Pilot has sent us data.
l_ping
(value)Todo
Reminder to implement heartbeating.
l_state
(value)A Pilot has changed state, keep track of it.
l_handshake
(value)Pilot is sending its IP and state on startup.
new_pilot
([ip, name])Make a new entry in
Terminal.pilots
and make appropriate GUI elements.Open a
gui.Protocol_Wizard
to create a new protocol.Gets recent weights from all
subjects
and open agui.Weights
window to view or set weights.If we change the protocol file, update the stored version in subject files
Batch reassign protocols and steps.
Calibrate
hardware.gpio.Solenoid
objects.Test bandwidth of Pilot connection with variable sized arrays as paylods
Select subject, step, and variables to plot a psychometric curve
closeEvent
(event)When Closing the Terminal Window, close any running subject objects, ‘KILL’ our networking object.
Attributes:
Get a list of all subject IDs
Returns: list: list of protocol files in
prefs.PROTOCOLDIR
Returns: subject_protocols (dict): a dictionary of subjects: [protocol, step]
-
heartbeat
(once=False)[source]¶ Perioducally send an
INIT
message that checks the status of connected pilotssent with frequency according to
Terminal.heartbeat_dur
- Parameters
once (bool) – if True, do a single heartbeat but don’t start a thread to do more.
-
toggle_start
(starting, pilot, subject=None)[source]¶ Start or Stop running the currently selected subject’s task. Sends a message containing the task information to the concerned pilot.
Each
Pilot_Panel
is given a lambda function that calls this one with the arguments specified SeePilot_Button
, as it is what calls this function.- Parameters
starting (bool) – Does this button press mean we are starting (True) or stopping (False) the task?
pilot – Which Pilot is starting or stopping?
subject – Which Subject is currently selected?
-
l_data
(value)[source]¶ A Pilot has sent us data.
value field of message should have subject and pilot added to dictionary for identification.
Any key in value that matches a column in the subject’s trial data table will be saved.
If the subject graduates after receiving this piece of data, stop the current task running on the Pilot and send the new one.
- Parameters
value (dict) – A dict of field-value pairs to save
-
l_ping
(value)[source]¶ Todo
Reminder to implement heartbeating.
Note
Currently unused, as Terminal Net_Node stability hasn’t been a problem and no universal system of heartbeating has been established (global stability has not been an issue).
- Parameters
value – (unused)
-
l_state
(value)[source]¶ A Pilot has changed state, keep track of it.
- Parameters
value (dict) – dict containing state .
-
l_handshake
(value)[source]¶ Pilot is sending its IP and state on startup.
If we haven’t heard of this pilot before, make a new entry in
pilots
andgui.Control_Panel.update_db()
.- Parameters
value (dict) – dict containing ip and state
-
new_pilot
(ip='', name=None)[source]¶ Make a new entry in
Terminal.pilots
and make appropriate GUI elements.- Parameters
ip (str) – Optional. if given, stored in db.
name (str) – If None, prompted for a name, otherwise used for entry in pilot DB.
-
new_protocol
()[source]¶ Open a
gui.Protocol_Wizard
to create a new protocol.Prompts for name of protocol, then saves in prefs.PROTOCOLDIR
-
property
subject_list
¶ Get a list of all subject IDs
- Returns
list of all subject IDs present in
Terminal.pilots
- Return type
-
subject_weights
()[source]¶ Gets recent weights from all
subjects
and open agui.Weights
window to view or set weights.
-
update_protocols
()[source]¶ If we change the protocol file, update the stored version in subject files
-
property
protocols
¶ Returns: list: list of protocol files in
prefs.PROTOCOLDIR
-
property
subject_protocols
¶ Returns: subject_protocols (dict): a dictionary of subjects: [protocol, step]
-
reassign_protocols
()[source]¶ Batch reassign protocols and steps.
Opens a
gui.Reassign
window after getting protocol data, and applies any changes made in the window.
-
calibrate_ports
()[source]¶ Calibrate
hardware.gpio.Solenoid
objects.See
gui.Calibrate_Water
.After calibration routine, send results to pilot for storage.
-
staticMetaObject
= <PySide2.QtCore.QMetaObject object>¶