Commit | Line | Data |
---|---|---|
840183eb FD |
1 | import bt2 |
2 | import math | |
3 | ||
4 | bt2.register_plugin(__name__, "test_debug_info") | |
5 | ||
6 | ||
7 | class CompleteIter(bt2._UserMessageIterator): | |
8 | def __init__(self, config, output_port): | |
9 | ec = output_port.user_data | |
10 | sc = ec.stream_class | |
11 | tc = sc.trace_class | |
12 | ||
13 | trace = tc() | |
14 | stream = trace.create_stream(sc) | |
15 | ||
16 | ev = self._create_event_message(ec, stream, default_clock_snapshot=123) | |
17 | ||
18 | ev.event.payload_field["bool"] = False | |
19 | ev.event.payload_field["real_single"] = 2.0 | |
20 | ev.event.payload_field["real_double"] = math.pi | |
21 | ev.event.payload_field["int32"] = 121 | |
22 | ev.event.payload_field["int3"] = -1 | |
23 | ev.event.payload_field["int9_hex"] = -92 | |
24 | ev.event.payload_field["uint32"] = 121 | |
25 | ev.event.payload_field["uint61"] = 299792458 | |
26 | ev.event.payload_field["uint5_oct"] = 29 | |
27 | ev.event.payload_field["struct"]['str'] = "Rotisserie St-Hubert" | |
28 | ev.event.payload_field["struct"]['option_real'] = math.pi | |
29 | ev.event.payload_field["string"] = "ð" | |
30 | ev.event.payload_field["dyn_array"] = [1.2, 2 / 3, 42.3, math.pi] | |
31 | ev.event.payload_field["dyn_array_len"] = 4 | |
32 | ev.event.payload_field["dyn_array_with_len"] = [5.2, 5 / 3, 42.5, math.pi * 12] | |
33 | ev.event.payload_field["sta_array"] = ['ð°', 'ðĶī', ' ð'] | |
34 | ev.event.payload_field["option_none"] | |
35 | ev.event.payload_field["option_some"] = "NORMANDIN" | |
36 | ev.event.payload_field["option_bool_selector"] = True | |
37 | ev.event.payload_field["option_bool"] = "Mike's" | |
38 | ev.event.payload_field["option_int_selector"] = 1 | |
39 | ev.event.payload_field["option_int"] = "Barbies resto bar grill" | |
40 | ev.event.payload_field['variant'].selected_option_index = 0 | |
41 | ev.event.payload_field["variant"] = "Couche-Tard" | |
42 | ||
43 | self._msgs = [ | |
44 | self._create_stream_beginning_message(stream), | |
45 | ev, | |
46 | self._create_stream_end_message(stream), | |
47 | ] | |
48 | ||
49 | def __next__(self): | |
50 | if len(self._msgs) > 0: | |
51 | return self._msgs.pop(0) | |
52 | else: | |
53 | raise StopIteration | |
54 | ||
55 | ||
56 | @bt2.plugin_component_class | |
57 | class CompleteSrc(bt2._UserSourceComponent, message_iterator_class=CompleteIter): | |
58 | def __init__(self, config, params, obj): | |
59 | tc = self._create_trace_class() | |
60 | cc = self._create_clock_class() | |
61 | sc = tc.create_stream_class(default_clock_class=cc) | |
62 | ||
63 | dyn_array_elem_fc = tc.create_double_precision_real_field_class() | |
64 | dyn_array_with_len_elem_fc = tc.create_double_precision_real_field_class() | |
65 | dyn_array_with_len_fc = tc.create_unsigned_integer_field_class(19) | |
66 | sta_array_elem_fc = tc.create_string_field_class() | |
67 | option_some_fc = tc.create_string_field_class() | |
68 | variant_fc = tc.create_variant_field_class() | |
69 | variant_fc.append_option( | |
70 | name='var_str', field_class=tc.create_string_field_class() | |
71 | ) | |
72 | option_none_fc = tc.create_double_precision_real_field_class() | |
73 | struct_fc = tc.create_structure_field_class() | |
74 | struct_option_fc = tc.create_double_precision_real_field_class() | |
75 | struct_fc.append_member('str', tc.create_string_field_class()) | |
76 | struct_fc.append_member( | |
77 | 'option_real', | |
78 | tc.create_option_without_selector_field_class(struct_option_fc), | |
79 | ) | |
80 | option_bool_selector_fc = tc.create_bool_field_class() | |
81 | option_int_selector_fc = tc.create_unsigned_integer_field_class(8) | |
82 | ||
83 | payload = tc.create_structure_field_class() | |
84 | payload += [ | |
85 | ("bool", tc.create_bool_field_class()), | |
86 | ("real_single", tc.create_single_precision_real_field_class()), | |
87 | ("real_double", tc.create_double_precision_real_field_class()), | |
88 | ("int32", tc.create_signed_integer_field_class(32)), | |
89 | ("int3", tc.create_signed_integer_field_class(3)), | |
90 | ( | |
91 | "int9_hex", | |
92 | tc.create_signed_integer_field_class( | |
93 | 9, preferred_display_base=bt2.IntegerDisplayBase.HEXADECIMAL | |
94 | ), | |
95 | ), | |
96 | ("uint32", tc.create_unsigned_integer_field_class(32)), | |
97 | ("uint61", tc.create_unsigned_integer_field_class(61)), | |
98 | ( | |
99 | "uint5_oct", | |
100 | tc.create_unsigned_integer_field_class( | |
101 | 5, preferred_display_base=bt2.IntegerDisplayBase.OCTAL | |
102 | ), | |
103 | ), | |
104 | ("struct", struct_fc), | |
105 | ("string", tc.create_string_field_class()), | |
106 | ("dyn_array", tc.create_dynamic_array_field_class(dyn_array_elem_fc)), | |
107 | ("dyn_array_len", dyn_array_with_len_fc), | |
108 | ( | |
109 | "dyn_array_with_len", | |
110 | tc.create_dynamic_array_field_class( | |
111 | dyn_array_with_len_elem_fc, length_fc=dyn_array_with_len_fc | |
112 | ), | |
113 | ), | |
114 | ("sta_array", tc.create_dynamic_array_field_class(sta_array_elem_fc)), | |
115 | ( | |
116 | "option_none", | |
117 | tc.create_option_without_selector_field_class(option_none_fc), | |
118 | ), | |
119 | ( | |
120 | "option_some", | |
121 | tc.create_option_without_selector_field_class(option_some_fc), | |
122 | ), | |
123 | ("option_bool_selector", option_bool_selector_fc), | |
124 | ( | |
125 | "option_bool", | |
126 | tc.create_option_with_bool_selector_field_class( | |
127 | tc.create_string_field_class(), option_bool_selector_fc | |
128 | ), | |
129 | ), | |
130 | ( | |
131 | "option_bool_reversed", | |
132 | tc.create_option_with_bool_selector_field_class( | |
133 | tc.create_string_field_class(), | |
134 | option_bool_selector_fc, | |
135 | selector_is_reversed=True, | |
136 | ), | |
137 | ), | |
138 | ("option_int_selector", option_int_selector_fc), | |
139 | ( | |
140 | "option_int", | |
141 | tc.create_option_with_integer_selector_field_class( | |
142 | tc.create_string_field_class(), | |
143 | option_int_selector_fc, | |
144 | bt2.UnsignedIntegerRangeSet([(1, 3), (18, 44)]), | |
145 | ), | |
146 | ), | |
147 | ("variant", variant_fc), | |
148 | ] | |
149 | ec = sc.create_event_class(name="my-event", payload_field_class=payload) | |
150 | ||
151 | self._add_output_port("some-name", ec) |