1 /*
2  * Copyright (c) 2022 Chipsea Technologies (Shenzhen) Corp., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup PanSensor
18  * @{
19  *
20  * @brief Provides standard open APIs for you to use common capabilities of sensors.
21  *
22  * For example, you can call these APIs to obtain sensor information,
23  * subscribe to or unsubscribe from sensor data, enable or disable a sensor,
24  * and set the sensor data reporting mode.
25  *
26  * @since 5
27  */
28 
29 /**
30  * @file sensor_agent_type.h
31  *
32  * @brief Defines the basic data used by the sensor agent to manage sensors.
33  *
34  * @since 5
35  */
36 
37 #ifndef SENSOR_AGENT_TYPE_H
38 #define SENSOR_AGENT_TYPE_H
39 
40 #include <stdint.h>
41 
42 #ifdef __cplusplus
43 #if __cplusplus
44 extern "C" {
45 #endif
46 #endif
47 
48 /** Maximum length of the sensor name */
49 #ifndef AFE_NAME_MAX_LEN2
50 #define AFE_NAME_MAX_LEN2 48
51 #endif /* SENSOR_NAME_MAX_LEN */
52 /** Size of sensor data */
53 #ifndef AFE_USER_DATA_SIZE
54 #define AFE_USER_DATA_SIZE 512
55 #endif /* AFE_USER_DATA_SIZE */
56 /** Maximum length of the sensor version */
57 #ifndef VERSION_MAX_LEN
58 #define VERSION_MAX_LEN 16
59 #endif /* VERSION_MAX_LEN */
60 
61 /**
62  * @brief Enumerates sensor types.
63  *
64  * @since 5
65  */
66 typedef enum {
67     TYPE_ID_NONE = 0,                   /**< None, for testing only */
68     TYPE_ID_PHOTOPLETHYSMOGRAPH = 129,    /**< Photoplethysmography sensor */
69     TYPE_ID_ELECTROCARDIOGRAPH = 130,     /**< Electrocardiogram (ECG) sensor */
70     TYPE_ID_HEART_RATE = 278,            /**< Heart rate sensor */
71     TYPE_ID_WEAR_DETECTION = 280,        /**< Wear detection sensor */
72     TYPE_ID_MAX = 0xFFF,      /**< Maximum number of sensor type IDs */
73 } MedicalSensorTypeId;
74 
75 /**
76  * @brief Defines sensor information.
77  *
78  * @since 5
79  */
80 typedef struct MedicalSensorInfo {
81     char sensorName[AFE_NAME_MAX_LEN2];   /**< Sensor name */
82     char vendorName[AFE_NAME_MAX_LEN2];   /**< Sensor vendor */
83     char firmwareVersion[VERSION_MAX_LEN];  /**< Sensor firmware version */
84     char hardwareVersion[VERSION_MAX_LEN];  /**< Sensor hardware version */
85     int32_t sensorTypeId;  /**< Sensor type ID */
86     int32_t sensorId;      /**< Sensor ID */
87     float maxRange;        /**< Maximum measurement range of the sensor */
88     float precision;       /**< Sensor accuracy */
89     float power;           /**< Sensor power */
90 } MedicalSensorInfo;
91 
92 /**
93  * @brief Defines the data reported by the sensor.
94  *
95  * @since 5
96  */
97 typedef struct SensorEvent {
98     int32_t sensorTypeId;  /**< Sensor type ID */
99     int32_t version;       /**< Sensor algorithm version */
100     int64_t timestamp;     /**< Time when sensor data was reported */
101     uint32_t option;       /**< Sensor data options, including the measurement range and accuracy */
102     int32_t mode;          /**< Sensor data reporting mode (described in {@link SensorMode}) */
103     uint8_t *data;         /**< Sensor data */
104     uint32_t dataLen;      /**< Sensor data length */
105 } SensorEvent;
106 
107 struct Test {
108 char ip[30];
109 char name[30];
110 int32_t *data;
111 };
112 
113 /**
114  * @brief Defines the callback for data reporting by the sensor agent.
115  *
116  * @since 5
117  */
118 typedef void (*RecordSensorCallback)(SensorEvent *event);
119 
120 /**
121  * @brief Defines a reserved field for the sensor data subscriber.
122  *
123  * @since 5
124  */
125 typedef struct UserData {
126     uint8_t userData[AFE_USER_DATA_SIZE];  /**< Reserved for the sensor data subscriber */
127 } UserData;
128 
129 /**
130  * @brief Defines information about the sensor data subscriber.
131  *
132  * @since 5
133  */
134 typedef struct MedicalSensorUser {
135     char name[AFE_NAME_MAX_LEN2];  /**< Name of the sensor data subscriber */
136     RecordSensorCallback callback;   /**< Callback for reporting sensor data */
137     UserData *userData;              /**< Reserved field for the sensor data subscriber */
138 } MedicalSensorUser;
139 
140 /**
141  * @brief Enumerates data reporting modes of sensors.
142  *
143  * @since 5
144  */
145 typedef enum SensorMode {
146     SENSOR_DEFAULT_MODE = 0,   /**< Default data reporting mode */
147     SENSOR_REALTIME_MODE = 1,  /**< Real-time data reporting mode to report a group of data each time */
148     SENSOR_ON_CHANGE = 2,   /**< Real-time data reporting mode to report data upon status changes */
149     SENSOR_ONE_SHOT = 3,    /**< Real-time data reporting mode to report data only once */
150     SENSOR_FIFO_MODE = 4,   /**< FIFO-based data reporting mode to report data based on the <b>BatchCnt</b> setting */
151     SENSOR_MODE_MAX2,        /**< Maximum sensor data reporting mode */
152 } SensorMode;
153 
154 /**
155  * @brief ppg传感器的数据结构
156  */
157 typedef struct PpgData {
158     uint32_t reserve : 2;
159     uint32_t adcData : 22;
160     uint32_t tl : 2;
161     uint32_t rx : 2;
162     uint32_t phaseGroup : 4;
163 } PpgData;
164 
165 
166 /**
167  * @brief 心率传感器的数据结构
168  */
169 typedef struct HeartRateData {
170     /**< 心率值,单位bpm */
171     int32_t heartRateBpm;
172     /**< 心率状态 */
173     int32_t temperatureStatus;
174 } HeartRateData;
175 
176 /**
177  * @brief 佩戴检测传感器的数据结构
178  */
179 typedef struct WearDetectionData {
180     /**< 标量 */
181     int32_t scalar;
182 } WearDetectionData;
183 
184 #ifdef __cplusplus
185 #if __cplusplus
186 }
187 #endif
188 #endif
189 #endif /* SENSOR_AGENT_TYPE_H */
190 /**< @} */