Developer World
Spresense Arduino Library v3.2.0-77d75a4
SensorClient.h
Go to the documentation of this file.
1/*
2 * SensorClient.h - Sensing include file for the Spresense SDK
3 * Copyright 2019 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
29#ifndef __SENSORCLIENT_H
30#define __SENSORCLIENT_H
31
38#include <stdbool.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42
43#include <sdk/config.h>
44#include <nuttx/init.h>
45#include <nuttx/arch.h>
46#include <asmp/mpshm.h>
47
48#include <pins_arduino.h>
49
50#include <sensing/sensor_api.h>
51#include <sensing/sensor_id.h>
52#include <sensing/sensor_ecode.h>
53
54#include <MemoryUtil.h>
55
56
63#define SENSORCLIENT_ECODE_OK 0x0
64
67#define SENSORCLIENT_ECODE_ACTIVATE_MANAGER_ERROR 0x1
68
71#define SENSORCLIENT_ECODE_DEACTIVATE_MANAGER_ERROR 0x2
72
75#define SENSORCLIENT_ECODE_SENSOR_CLIENT_ID_ERROR 0x3
76
79#define SENSORCLIENT_ECODE_MEMORY_ALLOCATE_ERROR 0x4
80
81
87{
88 SensorClientID00, /* 0 */
89 SensorClientID01, /* 1 */
90 SensorClientID02, /* 2 */
91 SensorClientID03, /* 3 */
92 SensorClientID04, /* 4 */
93 SensorClientID05, /* 5 */
94 SensorClientID06, /* 6 */
95 SensorClientID07, /* 7 */
96 SensorClientID08, /* 8 */
97 SensorClientID09, /* 9 */
98 SensorClientID10, /* 10 */
99 SensorClientID11, /* 11 */
100 SensorClientID12, /* 12 */
101 SensorClientID13, /* 13 */
102 SensorClientID14, /* 14 */
103 SensorClientID15, /* 15 */
104 SensorClientID16, /* 16 */
105 SensorClientID17, /* 17 */
106 SensorClientID18, /* 18 */
107 SensorClientID19, /* 19 */
108 SensorClientID20, /* 20 */
109 SensorClientID21, /* 21 */
110 SensorClientID22, /* 22 */
111 SensorClientID23, /* 23 */
112 NumOfGeneralSensorClientID,
113};
114
119enum
120{
121 SEN_selfID = SensorClientID00, /* 0 */
122 SEN_accelID = SensorClientID01, /* 1 */
123 SEN_accel1ID = SensorClientID02, /* 2 */
124 SEN_magID = SensorClientID03, /* 3 */
125 SEN_pressureID = SensorClientID04, /* 4 */
126 SEN_lightID = SensorClientID05, /* 5 */
127 SEN_pulseID = SensorClientID06, /* 6 */
128 SEN_tempID = SensorClientID07, /* 7 */
129 SEN_gyroID = SensorClientID08, /* 8 */
130 SEN_gnssID = SensorClientID09, /* 9 */
131 SEN_stepcounterID = SensorClientID10, /* 10 */
132 SEN_tramID = SensorClientID11, /* 11 */
133 SEN_gestureID = SensorClientID12, /* 12 */
134 SEN_compassID = SensorClientID13, /* 13 */
135 SEN_barometerID = SensorClientID14, /* 14 */
136 SEN_tramliteID = SensorClientID15, /* 15 */
137 SEN_vadID = SensorClientID16, /* 16 */
138 SEN_wuwsrID = SensorClientID17, /* 17 */
139 SEN_adcID = SensorClientID18, /* 18 */
140 SEN_reserve19ID = SensorClientID19, /* 19 */
141 SEN_app0ID = SensorClientID20, /* 20 */
142 SEN_app1ID = SensorClientID21, /* 21 */
143 SEN_app2ID = SensorClientID22, /* 22 */
144 SEN_app3ID = SensorClientID23, /* 23 */
145 SEN_ID_MAX = NumOfGeneralSensorClientID,
146};
147
148
149/* Convert SenserClientID to SubscriptionID */
150
151#define SUBSCRIPTION(x) (1 << (x))
152
153
160{
161public:
162
167 bool begin(int id,
168 uint32_t subscriptions = 0,
169 int rate = 0,
170 int sample_watermark_num = 0,
171 int size_per_sample = 0,
172 sensor_data_mh_callback_t cb =NULL);
173
174 bool begin(int id,
175 uint32_t subscriptions,
176 sensor_data_mh_callback_t cb);
177
182 bool end(void);
183
193 PoolId id,
194 FAR void* data,
195 uint32_t size_per_sample,
196 uint32_t freq,
197 uint32_t sample_watermark_num,
199 uint32_t timestamp);
207 MemMgrLite::MemHandle& mh,
208 uint32_t size_per_sample,
209 uint32_t freq,
210 uint32_t sample_watermark_num,
211 uint32_t timestamp);
212
213 int publish(FAR void *data,
214 uint32_t size_per_sample,
215 uint32_t freq,
216 uint32_t sample_watermark_num,
217 uint32_t timestamp);
218
225 void *subscribe(sensor_command_data_mh_t& data)
226 {
227 return data.mh.getVa();
228 }
229
230protected:
231 int m_id;
232 int m_rate;
233 int m_sample_watermark_num;
234 int m_size_per_sample;
235
236};
237
240#endif /* __SENSORCLIENT_H */
Definition: SensorClient.h:160
bool end(void)
Release sensor ID.
void * subscribe(sensor_command_data_mh_t &data)
Read sensing data from buffer.
Definition: SensorClient.h:225
int publish(PoolId id, FAR void *data, uint32_t size_per_sample, uint32_t freq, uint32_t sample_watermark_num, uint32_t timestamp)
Write sensing data from buffer.
int publish(MemMgrLite::MemHandle &mh, uint32_t size_per_sample, uint32_t freq, uint32_t sample_watermark_num, uint32_t timestamp)
Write sensing data from MemHandle.
bool begin(int id, uint32_t subscriptions=0, int rate=0, int sample_watermark_num=0, int size_per_sample=0, sensor_data_mh_callback_t cb=NULL)
Register sensor ID.
GeneralSensorClientID
Definition: SensorClient.h:87