@@ -45,6 +45,7 @@ UARTModel::~UARTModel() {
45
45
@return True if the message was decoded successfully, False otherwise.
46
46
*/
47
47
bool UARTModel::DecodeUartAdd (pb_istream_t *stream) {
48
+ WS_DEBUG_PRINTLN (" [uart] Decoding UartAdd message..." );
48
49
memset (&_msg_UartAdd, 0 , sizeof (_msg_UartAdd));
49
50
return pb_decode (stream, wippersnapper_uart_UartAdd_fields, &_msg_UartAdd);
50
51
}
@@ -53,37 +54,41 @@ bool UARTModel::DecodeUartAdd(pb_istream_t *stream) {
53
54
@brief Gets a pointer to the decoded UartAdd message.
54
55
@return Pointer to the decoded UartAdd message.
55
56
*/
56
- wippersnapper_uart_UartAdd *UARTModel::GetUartAddMsg () {
57
- return &_msg_UartAdd;
58
- }
57
+ wippersnapper_uart_UartAdd *UARTModel::GetUartAddMsg () { return &_msg_UartAdd; }
59
58
60
59
/* !
61
60
@brief Encodes a UartAdded message.
62
61
@param uart_nbr
63
- The UART port number (eg: 0, 1, 2, etc.) that the device was attached to.
62
+ The UART port number (eg: 0, 1, 2, etc.) that the device was
63
+ attached to.
64
64
@param type
65
- The category of device attached to the UART port, corresponds to its driver type.
65
+ The category of device attached to the UART port, corresponds to its
66
+ driver type.
66
67
@param id
67
68
The unique identifier string for the UART device.
68
69
@param success
69
- True if the device on the UART port was successfully initialized, False otherwise.
70
+ True if the device on the UART port was successfully initialized,
71
+ False otherwise.
70
72
@return True if the message was encoded successfully, False otherwise.
71
73
*/
72
- bool UARTModel::EncodeUartAdded (int32_t uart_nbr, wippersnapper_uart_UartDeviceType type, const char *id, bool success) {
73
- _msg_UartAdded.uart_nbr = uart_nbr;
74
- _msg_UartAdded.type = type;
75
- strncpy (_msg_UartAdded.device_id , id, sizeof (_msg_UartAdded.device_id ) - 1 );
76
- _msg_UartAdded.device_id [sizeof (_msg_UartAdded.device_id ) - 1 ] = ' \0 ' ;
77
- _msg_UartAdded.success = success;
78
- // Calculate the size of the encoded message
79
- size_t sz_msg;
80
- if (!pb_get_encoded_size (&sz_msg, wippersnapper_uart_UartAdded_fields,
81
- &_msg_UartAdded))
82
- return false ;
83
- // Attempt to encode the message into a buffer
84
- uint8_t buf[sz_msg];
85
- pb_ostream_t msg_stream = pb_ostream_from_buffer (buf, sizeof (buf));
86
- return pb_encode (&msg_stream, wippersnapper_uart_UartAdded_fields, &_msg_UartAdded);
74
+ bool UARTModel::EncodeUartAdded (int32_t uart_nbr,
75
+ wippersnapper_uart_UartDeviceType type,
76
+ const char *id, bool success) {
77
+ _msg_UartAdded.uart_nbr = uart_nbr;
78
+ _msg_UartAdded.type = type;
79
+ strncpy (_msg_UartAdded.device_id , id, sizeof (_msg_UartAdded.device_id ) - 1 );
80
+ _msg_UartAdded.device_id [sizeof (_msg_UartAdded.device_id ) - 1 ] = ' \0 ' ;
81
+ _msg_UartAdded.success = success;
82
+ // Calculate the size of the encoded message
83
+ size_t sz_msg;
84
+ if (!pb_get_encoded_size (&sz_msg, wippersnapper_uart_UartAdded_fields,
85
+ &_msg_UartAdded))
86
+ return false ;
87
+ // Attempt to encode the message into a buffer
88
+ uint8_t buf[sz_msg];
89
+ pb_ostream_t msg_stream = pb_ostream_from_buffer (buf, sizeof (buf));
90
+ return pb_encode (&msg_stream, wippersnapper_uart_UartAdded_fields,
91
+ &_msg_UartAdded);
87
92
}
88
93
89
94
/* !
@@ -103,7 +108,8 @@ wippersnapper_uart_UartAdded *UARTModel::GetUartAddedMsg() {
103
108
*/
104
109
bool UARTModel::DecodeUartDeviceRemove (pb_istream_t *stream) {
105
110
memset (&_msg_UartRemove, 0 , sizeof (_msg_UartRemove));
106
- return pb_decode (stream, wippersnapper_uart_UartRemove_fields, &_msg_UartRemove);
111
+ return pb_decode (stream, wippersnapper_uart_UartRemove_fields,
112
+ &_msg_UartRemove);
107
113
}
108
114
109
115
/* !
@@ -118,25 +124,30 @@ wippersnapper_uart_UartRemove *UARTModel::GetUartRemoveMsg() {
118
124
@brief Clears an UartInputEvent message.
119
125
*/
120
126
void UARTModel::ClearUartInputEventMsg () {
121
- memset (&_msg_UartInputEvent, 0 , sizeof (_msg_UartInputEvent));
127
+ memset (&_msg_UartInputEvent, 0 , sizeof (_msg_UartInputEvent));
122
128
}
123
129
124
130
/* !
125
131
@brief Configures an UartInputEvent message with addressing information.
126
132
@param uart_nbr
127
- The UART port number (eg: 0, 1, 2, etc.) that the device is attached to.
133
+ The UART port number (eg: 0, 1, 2, etc.) that the device is attached
134
+ to.
128
135
@param type
129
- The category of device attached to the UART port, corresponds to its driver type.
136
+ The category of device attached to the UART port, corresponds to its
137
+ driver type.
130
138
@param device_id
131
139
The unique identifier string for the UART device.
132
140
*/
133
- void UARTModel::ConfigureUartInputEventMsg (uint32_t uart_nbr, wippersnapper_uart_UartDeviceType type, const char *device_id) {
134
- // Addressing information
135
- _msg_UartInputEvent.uart_nbr = uart_nbr;
136
- _msg_UartInputEvent.type = type;
137
- strncpy (_msg_UartInputEvent.device_id , device_id, sizeof (_msg_UartInputEvent.device_id ) - 1 );
138
- _msg_UartInputEvent.device_id [sizeof (_msg_UartInputEvent.device_id ) - 1 ] = ' \0 ' ;
139
-
141
+ void UARTModel::ConfigureUartInputEventMsg (
142
+ uint32_t uart_nbr, wippersnapper_uart_UartDeviceType type,
143
+ const char *device_id) {
144
+ // Addressing information
145
+ _msg_UartInputEvent.uart_nbr = uart_nbr;
146
+ _msg_UartInputEvent.type = type;
147
+ strncpy (_msg_UartInputEvent.device_id , device_id,
148
+ sizeof (_msg_UartInputEvent.device_id ) - 1 );
149
+ _msg_UartInputEvent.device_id [sizeof (_msg_UartInputEvent.device_id ) - 1 ] =
150
+ ' \0 ' ;
140
151
}
141
152
142
153
/* !
@@ -147,61 +158,64 @@ void UARTModel::ConfigureUartInputEventMsg(uint32_t uart_nbr, wippersnapper_uart
147
158
The type of sensor that produced the event.
148
159
@return True if the event was added successfully, False otherwise.
149
160
*/
150
- bool UARTModel::AddUartInputEvent (sensors_event_t &event, wippersnapper_sensor_SensorType sensor_type) {
151
- if (_msg_UartInputEvent.events_count >= MAX_UART_INPUT_EVENTS) {
152
- return false ; // Maximum number of events reached
153
- }
154
-
155
- // Configure the sensor event
156
- wippersnapper_sensor_SensorEvent &sensor_event = _msg_UartInputEvent.events [_msg_UartInputEvent.events_count ];
157
- sensor_event.type = sensor_type;
158
-
159
- // Handle different sensor types
160
- switch (sensor_type) {
161
- case wippersnapper_sensor_SensorType_SENSOR_TYPE_PM10_STD:
162
- sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
163
- sensor_event.value .float_value = event.pm10_std ;
164
- break ;
165
- case wippersnapper_sensor_SensorType_SENSOR_TYPE_PM25_STD:
166
- sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
167
- sensor_event.value .float_value = event.pm25_std ;
168
- break ;
169
- case wippersnapper_sensor_SensorType_SENSOR_TYPE_PM100_STD:
170
- sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
171
- sensor_event.value .float_value = event.pm100_std ;
172
- break ;
173
- // TODO: Add more cases for other sensor types
174
- default :
175
- sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
176
- sensor_event.value .float_value = event.data [0 ];
177
- break ;
178
- }
179
-
180
- _msg_UartInputEvent.events_count ++;
181
- return true ;
161
+ bool UARTModel::AddUartInputEvent (sensors_event_t &event,
162
+ wippersnapper_sensor_SensorType sensor_type) {
163
+ if (_msg_UartInputEvent.events_count >= MAX_UART_INPUT_EVENTS) {
164
+ return false ; // Maximum number of events reached
165
+ }
166
+
167
+ // Configure the sensor event
168
+ wippersnapper_sensor_SensorEvent &sensor_event =
169
+ _msg_UartInputEvent.events [_msg_UartInputEvent.events_count ];
170
+ sensor_event.type = sensor_type;
171
+
172
+ // Handle different sensor types
173
+ switch (sensor_type) {
174
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_PM10_STD:
175
+ sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
176
+ sensor_event.value .float_value = event.pm10_std ;
177
+ break ;
178
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_PM25_STD:
179
+ sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
180
+ sensor_event.value .float_value = event.pm25_std ;
181
+ break ;
182
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_PM100_STD:
183
+ sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
184
+ sensor_event.value .float_value = event.pm100_std ;
185
+ break ;
186
+ // TODO: Add more cases for other sensor types
187
+ default :
188
+ sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
189
+ sensor_event.value .float_value = event.data [0 ];
190
+ break ;
191
+ }
192
+
193
+ _msg_UartInputEvent.events_count ++;
194
+ return true ;
182
195
}
183
196
184
197
/* !
185
198
@brief Encodes a UartInputEvent message.
186
199
@return True if the message was encoded successfully, False otherwise.
187
200
*/
188
201
bool UARTModel::EncodeUartInputEvent () {
189
- // Calculate the size of the encoded message
190
- size_t sz_msg;
191
- if (!pb_get_encoded_size (&sz_msg, wippersnapper_uart_UartInputEvent_fields,
192
- &_msg_UartInputEvent))
193
- return false ;
194
-
195
- // Attempt to encode the message into a buffer
196
- uint8_t buf[sz_msg];
197
- pb_ostream_t msg_stream = pb_ostream_from_buffer (buf, sizeof (buf));
198
- return pb_encode (&msg_stream, wippersnapper_uart_UartInputEvent_fields, &_msg_UartInputEvent);
202
+ // Calculate the size of the encoded message
203
+ size_t sz_msg;
204
+ if (!pb_get_encoded_size (&sz_msg, wippersnapper_uart_UartInputEvent_fields,
205
+ &_msg_UartInputEvent))
206
+ return false ;
207
+
208
+ // Attempt to encode the message into a buffer
209
+ uint8_t buf[sz_msg];
210
+ pb_ostream_t msg_stream = pb_ostream_from_buffer (buf, sizeof (buf));
211
+ return pb_encode (&msg_stream, wippersnapper_uart_UartInputEvent_fields,
212
+ &_msg_UartInputEvent);
199
213
}
200
214
201
215
/* !
202
216
@brief Gets a pointer to the UartInputEvent message.
203
217
@return Pointer to the UartInputEvent message.
204
218
*/
205
219
wippersnapper_uart_UartInputEvent *UARTModel::GetUartInputEventMsg () {
206
- return &_msg_UartInputEvent;
220
+ return &_msg_UartInputEvent;
207
221
}
0 commit comments