20
20
*/
21
21
/* **********************************************************************/
22
22
SensorModel::SensorModel () {
23
- _msg_sensor_event = wippersnapper_sensor_SensorEvent_init_default ;
23
+ _msg_sensor_event = wippersnapper_sensor_SensorEvent_init_zero ;
24
24
}
25
25
26
26
/* **********************************************************************/
27
27
/* !
28
28
@brief SensorModel destructor
29
29
*/
30
30
/* **********************************************************************/
31
- SensorModel::~SensorModel () {}
32
-
33
- /* **********************************************************************/
34
- /* !
35
- @brief Decodes a SensorEvent message into a SensorModel object.
36
- @param stream
37
- The input stream
38
- @returns True if the SensorEvent message was successfully decoded,
39
- False otherwise.
40
- */
41
- /* **********************************************************************/
42
- bool SensorModel::decodeSensorEvent (pb_istream_t *stream) {
43
- // Decode the stream into theSensorEvent message
44
- if (!pb_decode (stream, wippersnapper_sensor_SensorEvent_fields,
45
- &_msg_sensor_event)) {
46
- return false ;
47
- }
48
- return true ;
49
- }
50
-
51
- /* **********************************************************************/
52
- /* !
53
- @brief Clears the SensorEvent message.
54
- */
55
- /* **********************************************************************/
56
- void SensorModel::clearSensorEvent () {
57
- _msg_sensor_event = wippersnapper_sensor_SensorEvent_init_default;
58
- }
59
-
60
- /* **********************************************************************/
61
- /* !
62
- @brief Returns a SensorEvent message.
63
- @returns The SensorEvent message.
64
- */
65
- /* **********************************************************************/
66
- wippersnapper_sensor_SensorEvent *SensorModel::getSensorEvent () {
67
- return &_msg_sensor_event;
68
- }
69
-
70
- /* **********************************************************************/
71
- /* !
72
- @brief Returns the the SensorEvent message's type.
73
- @returns The type of the SensorEvent message, as a SensorType.
74
- */
75
- /* **********************************************************************/
76
- wippersnapper_sensor_SensorType SensorModel::getSensorType () {
77
- return _msg_sensor_event.type ;
78
- }
79
-
80
- /* **********************************************************************/
81
- /* !
82
- @brief Returns the the SensorEvent message's which_value field.
83
- @returns The which_value field of the SensorEvent message.
84
- */
85
- /* **********************************************************************/
86
- pb_size_t SensorModel::getSensorEventWhichValue () {
87
- return _msg_sensor_event.which_value ;
31
+ SensorModel::~SensorModel () {
32
+ // Zero-out the SensorEvent message
33
+ _msg_sensor_event = wippersnapper_sensor_SensorEvent_init_zero;
88
34
}
89
35
90
- /* **********************************************************************/
91
- /* !
92
- @brief Returns the the SensorEvent message's float value field.
93
- @returns The float value of the SensorEvent message.
94
- */
95
- /* **********************************************************************/
96
- float SensorModel::getValueFloat () {
97
- return _msg_sensor_event.value .float_value ;
36
+ wippersnapper_sensor_SensorEvent *SensorModel::GetSensorEventMessage () {
37
+ return &_msg_sensor_event;
98
38
}
99
39
100
- /* **********************************************************************/
101
- /* !
102
- @brief Returns the the SensorEvent message's bool value field.
103
- @returns The bool value of the SensorEvent message.
104
- */
105
- /* **********************************************************************/
106
- bool SensorModel::getValueBool () { return _msg_sensor_event.value .bool_value ; }
40
+ bool SensorModel::EncodeSensorEventMessage () {
41
+ // Obtain size of the class' SensorEvent message
42
+ size_t sz_msg;
43
+ if (!pb_get_encoded_size (&sz_msg, wippersnapper_sensor_SensorEvent_fields, &_msg_sensor_event))
44
+ return false ;
107
45
108
- /* **********************************************************************/
109
- /* !
110
- @brief Returns the the SensorEvent message's vector value field.
111
- @returns The vector value of the SensorEvent message.
112
- */
113
- /* **********************************************************************/
114
- wippersnapper_sensor_SensorEvent_SensorEvent3DVector
115
- SensorModel::getValueVector () {
116
- return _msg_sensor_event.value .vector_value ;
46
+ // Encode the class' SensorEvent message
47
+ uint8_t buf[sz_msg];
48
+ pb_ostream_t msg_stream = pb_ostream_from_buffer (buf, sizeof (buf));
49
+ return pb_encode (&msg_stream, wippersnapper_sensor_SensorEvent_fields,
50
+ &_msg_sensor_event);
117
51
}
118
52
119
- /* **********************************************************************/
120
- /* !
121
- @brief Returns the the SensorEvent message's orientation value field.
122
- @returns The orientation value of the SensorEvent message.
123
- */
124
- /* **********************************************************************/
125
- wippersnapper_sensor_SensorEvent_SensorEventOrientation
126
- SensorModel::getValueOrientation () {
127
- return _msg_sensor_event.value .orientation_value ;
128
- }
129
53
130
- /* **********************************************************************/
131
- /* !
132
- @brief Returns the the SensorEvent message's color value field.
133
- @returns The color value of the SensorEvent message.
134
- */
135
- /* **********************************************************************/
136
- wippersnapper_sensor_SensorEvent_SensorEventColor SensorModel::getValueColor () {
137
- return _msg_sensor_event.value .color_value ;
54
+ void SensorModel::CreateSensorEventFloat (wippersnapper_sensor_SensorType sensor_type, float sensor_value) {
55
+ // Zero-out the previous SensorEvent message
56
+ _msg_sensor_event = wippersnapper_sensor_SensorEvent_init_zero;
57
+ // Fill in the SensorEvent message
58
+ _msg_sensor_event.type = sensor_type;
59
+ _msg_sensor_event.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
60
+ _msg_sensor_event.value .float_value = sensor_value;
138
61
}
0 commit comments