You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -117,6 +117,55 @@ int main(int argc, char **argv)
117
117
}
118
118
```
119
119
120
+
## Mocking sensors in development
121
+
122
+
The library provides a mock implementation of the `ProximityConnection` class that can be used for testing and development purposes. This allows you to simulate the behavior of a real sensor without needing to connect to an actual device.
123
+
124
+
In this snippet, we create a mock connection, construct a mock message, and set the mock data to be returned by the mock connection. The mock message is then encoded and used to simulate the behavior of a real sensor.
125
+
126
+
```cpp
127
+
ProximityConnection* conn;
128
+
129
+
if (mock) {
130
+
ProximityMockConnection* mock_conn = new ProximityMockConnection();
// This is the value that will be returned by the mock sensor
153
+
ChannelValue::from_micrometers(2000.0, range)
154
+
));
155
+
156
+
// Encode the mock message to the messages buffer
157
+
mock_message.encode(messages, payload_size);
158
+
// Set the mock data to return on recv calls
159
+
mock_conn->set_recv_data(messages, payload_size);
160
+
// Assign the mock connection to the abstract connection
161
+
conn = mock_conn;
162
+
} else {
163
+
conn = new ProximitySocketConnection(ip, port);
164
+
}
165
+
166
+
ProximitySensor* proximity_sensor = new ProximitySensor(conn, rate, 2.0);
167
+
```
168
+
120
169
## Provided verification binary
121
170
122
171
The library provides a standalone binary that can be used to read data from the capa NCDT control unit and output the measurements to the console. After installing the library, the binary can be found in the `bin` directory. The binary is called `capancdt_read_sensor` amd can be used as follows:
0 commit comments