Appiko
sensepi_ble.h
1 /*
2  * sensepi_ble.h : BLE Support file for SensePi 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_SENSE_PIR_SENSEPI_BLE_H_
31 #define APPLICATION_SENSE_PIR_SENSEPI_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 }__attribute__ ((packed)) sensepi_sysinfo ;
47 typedef enum
48 {
49  TIMER_ONLY,
53 
57 typedef struct
58 {
65  uint8_t day_or_night: 1;
67  uint8_t threshold: 7;
68 }__attribute__ ((packed)) oper_time_t;
69 
73 typedef struct
74 {
76  oper_time_t oper_time;
102  uint32_t mode;
105  uint8_t threshold;
107  uint8_t amplification;
109  uint16_t intr_trig_timer;
110 }__attribute__ ((packed)) pir_conf_t;
111 
115 typedef struct
116 {
118  uint16_t timer_interval;
119  oper_time_t oper_time;
120  uint32_t mode;
121 }__attribute__ ((packed)) timer_conf_t;
122 
126 typedef struct
127 {
131  pir_conf_t pir_conf;
133  timer_conf_t timer_conf;
134 }__attribute__ ((packed)) sensepi_config_t ;
135 
136 typedef struct
137 {
138  uint8_t * adv_data;
139  uint16_t adv_len;
140  uint8_t * scan_rsp_data;
141  uint16_t scan_rsp_len;
142 }
143 sensepi_ble_adv_data_t;
144 
151 void sensepi_ble_init(void (*ble_sd_evt)(ble_evt_t * evt),
152  void (* config_update)(sensepi_config_t * cfg));
153 
158 void sensepi_ble_update_sysinfo(sensepi_sysinfo * sysinfo);
159 
164 void sensepi_ble_update_config(sensepi_config_t * config);
165 
169 void sensepi_ble_disconn(void);
170 
175 void sensepi_ble_stack_init(void);
176 
184 void sensepi_ble_service_init(void);
185 
190 void sensepi_ble_gap_params_init(void);
191 
197 void sensepi_ble_adv_init(sensepi_ble_adv_data_t * sensepi_ble_adv_data);
198 
202 void sensepi_ble_adv_start(void);
203 
204 #endif /* APPLICATION_SENSE_PIR_SENSEPI_BLE_H_ */
205 
uint8_t amplification
Definition: sensepi_ble.h:107
void sensepi_ble_update_sysinfo(sensepi_sysinfo *sysinfo)
Updates the characteristic that stores the sysinfo.
Definition: sensepi_ble.c:179
uint8_t day_or_night
Definition: sensepi_ble.h:65
void sensepi_ble_gap_params_init(void)
Generic Access Profile initialization. The device name, and the preferred connection parameters are s...
Definition: sensepi_ble.c:338
void sensepi_ble_stack_init(void)
Function for initializing the BLE stack by enabling the SoftDevice and the BLE event interrupt.
Definition: sensepi_ble.c:208
void sensepi_ble_adv_start(void)
Function to start advertising.
Definition: sensepi_ble.c:406
void sensepi_ble_service_init(void)
Create the Service and its characteristics for the SensePi device. There is a read-only characteristi...
Definition: sensepi_ble.c:243
uint32_t mode
Definition: sensepi_ble.h:102
void sensepi_ble_init(void(*ble_sd_evt)(ble_evt_t *evt), void(*config_update)(sensepi_config_t *cfg))
Initialize the handlers to pass the BLE SD events and the configuration received from the mobile app.
Definition: sensepi_ble.c:161
void sensepi_ble_update_config(sensepi_config_t *config)
Updates the characteristic that stores the SensePi config.
Definition: sensepi_ble.c:193
Strcture for Operation time.
Definition: sensepi_ble.h:38
Trigger only on motion detection.
Definition: sensepi_ble.h:51
void sensepi_ble_disconn(void)
Disconnect the current active connection, if already connected.
Definition: sensepi_ble.c:168
trigger_conf_t trig_conf
Definition: sensepi_ble.h:129
pir_conf_t pir_conf
Definition: sensepi_ble.h:131
uint16_t intr_trig_timer
Definition: sensepi_ble.h:109
Trigger only on timer.
Definition: sensepi_ble.h:50
oper_time_t oper_time
Definition: sensepi_ble.h:76
void sensepi_ble_adv_init(sensepi_ble_adv_data_t *sensepi_ble_adv_data)
Function to initializing the advertising.
Definition: sensepi_ble.c:361
uint8_t threshold
Definition: sensepi_ble.h:67
timer_conf_t timer_conf
Definition: sensepi_ble.h:133
uint16_t timer_interval
Definition: sensepi_ble.h:118
trigger_conf_t
Enum of all posiible modes of operation.
Definition: sensepi_ble.h:47