Python
gradysim.encapsulator.python
Encapsulates protocols that run in prototype-mode. The encapsulator will wrap the protocol instance and handle interactions with the python simulator. It will also inject a provider instance that translates the protocol's calls into interactions with the python simulator.
PythonEncapsulator
Bases: IEncapsulator
Encapsulates the protocol to work with the python simulation.
Source code in gradysim\encapsulator\python.py
__init__(node, **handlers)
Instantiates a python encapsulator
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
Node being encapsulated |
required |
handlers
|
INodeHandler
|
Handlers being used in the simulation |
{}
|
Source code in gradysim\encapsulator\python.py
encapsulate(protocol)
Encapsulates the protocol instance. Injencts a PythonProvider instance into it
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protocol
|
Type[IProtocol]
|
Type of protocol being instantiated |
required |
Source code in gradysim\encapsulator\python.py
finish()
handle_packet(message)
handle_telemetry(telemetry)
handle_timer(timer)
PythonProvider
Bases: IProvider
Handles protocols actions translating them into actions inside the python simulation
Source code in gradysim\encapsulator\python.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
__init__(node, **handlers)
Instantiates a python provider
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
Node being encapsulated |
required |
handlers
|
INodeHandler
|
Handlers being used in the simulation |
{}
|
Source code in gradysim\encapsulator\python.py
cancel_timer(timer)
Cancels a timer using the timer handler. If one is not present in the simulation issues a warning and does nothing
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timer
|
str
|
Timer being cancelled |
required |
Returns:
Source code in gradysim\encapsulator\python.py
current_time()
Returns the current time consulted from the timer handler. If one is not present issues a warning and returns zero.
Returns:
| Type | Description |
|---|---|
float
|
Simulation timestamp in seconds or zero if no timer handler is present |
Source code in gradysim\encapsulator\python.py
get_id()
Returns the node's unique identifier in the simulation
Returns:
| Type | Description |
|---|---|
int
|
the node's unique identifier in the simulation |
schedule_timer(timer, timestamp)
Schedules a timer using the timer handler. If one is not present in the simulation issues a warning and does nothing
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timer
|
str
|
Timer being ser |
required |
timestamp
|
float
|
Timestamp when it should fire |
required |
Returns:
Source code in gradysim\encapsulator\python.py
send_communication_command(command)
Forwards a communication command to the communication handler. If the simulation is running with no communication handler issues a warning and does nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
CommunicationCommand
|
Communication command being sent |
required |
Source code in gradysim\encapsulator\python.py
send_mobility_command(command)
Forwards a mobility command to the mobility handler. If the simulation is running without a mobility handler issues a warning and does nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
MobilityCommand
|
Command being sent |
required |