Appiko
sensebe_ble.h
1 /*
2  * sensebe_ble.h : BLE Support file for SenseBe application
3  * Copyright (C) 2019 Appiko
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
30 #ifndef APPLICATION_SENSEBE_BLE_H_
31 #define APPLICATION_SENSEBE_BLE_H_
32 
33 #include "stdint.h"
34 #include "stdbool.h"
35 #include "ble.h"
36 #include "dev_id_fw_ver.h"
37 
38 typedef struct
39 {
40  dev_id_t id;
41  uint8_t battery_status;
42  fw_ver_t fw_ver;
43  uint8_t board_sel;
44 }__attribute__ ((packed)) sensebe_sysinfo ;
48 typedef enum
49 {
50  TIMER_ONLY,
54 
58 typedef enum
59 {
60  LIGHTNING,
61  FAST,
62  NORM,
65 
69 typedef struct
70 {
77  uint8_t day_or_night: 1;
79  uint8_t threshold: 7;
80 }__attribute__ ((packed)) oper_time_t;
81 
85 typedef struct
86 {
88  uint8_t pre_focus : 1;
114  uint8_t mode : 7;
115  uint16_t larger_value;
116  uint8_t smaller_value;
117 }__attribute__ ((packed)) cam_oper_t;
118 
122 typedef enum
123 {
124  TIMER_ALL,
125 
126  MOTION_ALL, //at rx side
127 
128 // RADIO_ALL, //at tx side
129 
130 // TIMER_DAY,
131 // TIMER_NIGHT,
132 
133 // MOTION_DAY,
134 // MOTION_NIGHT,
135 
136 // RADIO_DAY,
137 // RADIO_NIGHT,
138  MAX_TRIGGERS,
140 
141 
142 
146 typedef struct
147 {
149  oper_time_t oper_time;
151  uint16_t detect_window;
153  uint16_t intr_trig_timer;
154 }__attribute__ ((packed)) tssp_conf_t;
155 
159 typedef struct
160 {
162  uint16_t timer_interval;
164  oper_time_t oper_time;
165 }__attribute__ ((packed)) timer_conf_t;
166 
170 typedef struct
171 {
173  trigger_conf_t trig_conf;
175  cam_oper_t cam_trigs[MAX_TRIGGERS];
179  tssp_conf_t tssp_conf;
181  timer_conf_t timer_conf;
183 }__attribute__ ((packed)) sensebe_config_t ;
184 
185 typedef struct
186 {
187  uint8_t * adv_data;
188  uint16_t adv_len;
189  uint8_t * scan_rsp_data;
190  uint16_t scan_rsp_len;
191 }
192 sensebe_ble_adv_data_t;
193 
200 void sensebe_ble_init(void (*ble_sd_evt)(ble_evt_t * evt),
201  void (* config_update)(sensebe_config_t * cfg));
202 
207 void sensebe_ble_update_sysinfo(sensebe_sysinfo * sysinfo);
208 
213 void sensebe_ble_update_config(sensebe_config_t * config);
214 
218 void sensebe_ble_disconn(void);
219 
224 void sensebe_ble_stack_init(void);
225 
233 void sensebe_ble_service_init(void);
234 
239 void sensebe_ble_gap_params_init(void);
240 
246 void sensebe_ble_adv_init(sensebe_ble_adv_data_t * sensebe_ble_adv_data);
247 
251 void sensebe_ble_adv_start(void);
252 
253 #endif /* APPLICATION_SENSEBE_BLE_H_ */
254 
void sensebe_ble_update_sysinfo(sensebe_sysinfo *sysinfo)
Updates the characteristic that stores the sysinfo.
Definition: sensebe_ble.c:187
Lightning mode.
Definition: sensebe_ble.h:61
device_speed_t speed
Definition: sensebe_ble.h:177
Normal mode.
Definition: sensebe_ble.h:63
void sensebe_ble_stack_init(void)
Function for initializing the BLE stack by enabling the SoftDevice and the BLE event interrupt.
Definition: sensebe_ble.c:216
void sensebe_ble_service_init(void)
Create the Service and its characteristics for the SensePi device. There is a read-only characteristi...
Definition: sensebe_ble.c:251
void sensebe_ble_init(void(*ble_sd_evt)(ble_evt_t *evt), void(*config_update)(sensebe_config_t *cfg))
Initialize the handlers to pass the BLE SD events and the configuration received from the mobile app.
Definition: sensebe_ble.c:169
uint16_t detect_window
Definition: sensebe_ble.h:151
uint8_t mode
Definition: sensebe_ble.h:114
Strcture for Operation time.
Definition: sensepi_ble.h:38
void sensebe_ble_disconn(void)
Disconnect the current active connection, if already connected.
Definition: sensebe_ble.c:176
uint8_t pre_focus
Definition: sensebe_ble.h:88
Fast mode.
Definition: sensebe_ble.h:62
cam_trig_ls_t
Enum to store the list of camera triggers possible.
Definition: sensebe_ble.h:122
void sensebe_ble_update_config(sensebe_config_t *config)
Updates the characteristic that stores the SensePi config.
Definition: sensebe_ble.c:201
void sensebe_ble_adv_start(void)
Function to start advertising.
Definition: sensebe_ble.c:414
tssp_conf_t tssp_conf
Definition: sensebe_ble.h:179
Trigger only on timer.
Definition: sensebe_ble.h:51
void sensebe_ble_gap_params_init(void)
Generic Access Profile initialization. The device name, and the preferred connection parameters are s...
Definition: sensebe_ble.c:346
Trigger only on motion detection.
Definition: sensebe_ble.h:52
device_speed_t
Enum to select operation speed for Device.
Definition: sensebe_ble.h:58
void sensebe_ble_adv_init(sensebe_ble_adv_data_t *sensebe_ble_adv_data)
Function to initializing the advertising.
Definition: sensebe_ble.c:369
trigger_conf_t
Enum of all posiible modes of operation.
Definition: sensebe_ble.h:48