-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsesPorts.py
More file actions
executable file
·156 lines (113 loc) · 6.53 KB
/
UsesPorts.py
File metadata and controls
executable file
·156 lines (113 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
#
#
# AUTO-GENERATED
#
# Source: UsesPorts.spd.xml
from ossie.resource import start_component
import logging
from UsesPorts_base import *
class UsesPorts_i(UsesPorts_base):
"""<DESCRIPTION GOES HERE>"""
def constructor(self):
"""
This is called by the framework immediately after your component registers with the system.
In general, you should add customization here and not in the __init__ constructor. If you have
a custom port implementation you can override the specific implementation here with a statement
similar to the following:
self.some_port = MyPortImplementation()
"""
# TODO add customization here.
def process(self):
"""
Basic functionality:
The process method should process a single "chunk" of data and then return. This method
will be called from the processing thread again, and again, and again until it returns
FINISH or stop() is called on the component. If no work is performed, then return NOOP.
StreamSRI:
To create a StreamSRI object, use the following code (this generates a normalized SRI that does not flush the queue when full):
sri = bulkio.sri.create("my_stream_id")
PrecisionUTCTime:
To create a PrecisionUTCTime object, use the following code:
tstamp = bulkio.timestamp.now()
Ports:
Each port instance is accessed through members of the following form: self.port_<PORT NAME>
Data is obtained in the process function through the getPacket call (BULKIO only) on a
provides port member instance. The optional argument is a timeout value, in seconds.
A zero value is non-blocking, while a negative value is blocking. Constants have been
defined for these values, bulkio.const.BLOCKING and bulkio.const.NON_BLOCKING. If no
timeout is given, it defaults to non-blocking.
The return value is a named tuple with the following fields:
- dataBuffer
- T
- EOS
- streamID
- SRI
- sriChanged
- inputQueueFlushed
If no data is available due to a timeout, all fields are None.
To send data, call the appropriate function in the port directly. In the case of BULKIO,
convenience functions have been added in the port classes that aid in output.
Interactions with non-BULKIO ports are left up to the component developer's discretion.
Messages:
To receive a message, you need (1) an input port of type MessageEvent, (2) a message prototype described
as a structure property of kind message, (3) a callback to service the message, and (4) to register the callback
with the input port.
Assuming a property of type message is declared called "my_msg", an input port called "msg_input" is declared of
type MessageEvent, create the following code:
def msg_callback(self, msg_id, msg_value):
print msg_id, msg_value
Register the message callback onto the input port with the following form:
self.port_input.registerMessage("my_msg", UsesPorts_i.MyMsg, self.msg_callback)
To send a message, you need to (1) create a message structure, and (2) send the message over the port.
Assuming a property of type message is declared called "my_msg", an output port called "msg_output" is declared of
type MessageEvent, create the following code:
msg_out = UsesPorts_i.MyMsg()
this.port_msg_output.sendMessage(msg_out)
Accessing the Device Manager and Domain Manager:
Both the Device Manager hosting this Device and the Domain Manager hosting
the Device Manager are available to the Device.
To access the Domain Manager:
dommgr = self.getDomainManager().getRef();
To access the Device Manager:
devmgr = self.getDeviceManager().getRef();
Properties:
Properties are accessed directly as member variables. If the property name is baudRate,
then accessing it (for reading or writing) is achieved in the following way: self.baudRate.
To implement a change callback notification for a property, create a callback function with the following form:
def mycallback(self, id, old_value, new_value):
pass
where id is the property id, old_value is the previous value, and new_value is the updated value.
The callback is then registered on the component as:
self.addPropertyChangeListener('baudRate', self.mycallback)
Example:
# This example assumes that the component has two ports:
# - A provides (input) port of type bulkio.InPortsPort called dataPorts_in
# - A uses (output) port of type bulkio.OutFloatPort called dataFloat_out
# The mapping between the port and the class if found in the component
# base class.
# This example also makes use of the following Properties:
# - A float value called amplitude
# - A boolean called increaseAmplitude
packet = self.port_dataPorts_in.getPacket()
if packet.dataBuffer is None:
return NOOP
outData = range(len(packet.dataBuffer))
for i in range(len(packet.dataBuffer)):
if self.increaseAmplitude:
outData[i] = float(packet.dataBuffer[i]) * self.amplitude
else:
outData[i] = float(packet.dataBuffer[i])
# NOTE: You must make at least one valid pushSRI call
if packet.sriChanged:
self.port_dataFloat_out.pushSRI(packet.SRI);
self.port_dataFloat_out.pushPacket(outData, packet.T, packet.EOS, packet.streamID)
return NORMAL
"""
# TODO fill in your code here
self._log.debug("process() example log message")
return NOOP
if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)
logging.debug("Starting Component")
start_component(UsesPorts_i)