mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-05 00:55:43 +01:00
Prepare Base for sync service
This commit is contained in:
parent
b3d449e1d3
commit
8e604ec81a
@ -8,6 +8,6 @@
|
|||||||
#define SYNC_SERVICE_H
|
#define SYNC_SERVICE_H
|
||||||
|
|
||||||
int sync_service_init(void);
|
int sync_service_init(void);
|
||||||
int sync_service_run(void);
|
uint32_t sync_service_run(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
#define TRACING_H
|
#define TRACING_H
|
||||||
|
|
||||||
int tracing_init(void);
|
int tracing_init(void);
|
||||||
int tracing_run(void);
|
uint32_t tracing_run(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -65,7 +65,11 @@ void main(void) {
|
|||||||
printk("Components initialized! Starting Tracing and Gatt...\n");
|
printk("Components initialized! Starting Tracing and Gatt...\n");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
tracing_run();
|
uint32_t tracing_sleep_ms = tracing_run();
|
||||||
sync_service_run();
|
uint32_t sync_sleep_ms = sync_service_run();
|
||||||
|
|
||||||
|
uint32_t sleep_ms = MIN(tracing_sleep_ms, sync_sleep_ms);
|
||||||
|
//printk("Sleeping a bit (%u ms)...\n", sleep_ms);
|
||||||
|
k_sleep(K_MSEC(sleep_ms)); // TODO: what to put here?
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
@ -12,16 +12,35 @@
|
|||||||
#include <sys/byteorder.h>
|
#include <sys/byteorder.h>
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
|
|
||||||
#include <bluetooth/bluetooth.h>
|
#define SYNC_ADV_INTERVAL_MS (60*1000)
|
||||||
#include <bluetooth/conn.h>
|
#define SYNC_ADV_DURATION_MS 500
|
||||||
#include <bluetooth/uuid.h>
|
#define SYNC_CONN_INIT_WAIT_MS 250
|
||||||
#include <bluetooth/gatt.h>
|
|
||||||
|
|
||||||
|
K_TIMER_DEFINE(sync_adv_timer, NULL, NULL);
|
||||||
|
|
||||||
int sync_service_init(void) {
|
int sync_service_init(void) {
|
||||||
return 0; // TODO!
|
// We init the timers (which should run periodically!)
|
||||||
|
// we directly want to advertise ourselfs after the start -> should reduce unwanted delays
|
||||||
|
k_timer_start(&sync_adv_timer, K_NO_WAIT, K_MSEC(SYNC_ADV_INTERVAL_MS));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sync_service_run(void) {
|
void sync_service_handle_connection() {
|
||||||
return 0;
|
|
||||||
|
// TODO: Implement me!
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t sync_service_run(void) {
|
||||||
|
|
||||||
|
if (k_timer_status_get(&sync_adv_timer) > 0) {
|
||||||
|
|
||||||
|
// TODO: START ADVERTISEMENTS
|
||||||
|
//printk("Advertising Sync service...!\n");
|
||||||
|
k_sleep(K_MSEC(SYNC_ADV_DURATION_MS));
|
||||||
|
// TODO: STOP ADVERTISEMENTS
|
||||||
|
}
|
||||||
|
// TODO: CHECK IF A CONNECTION HAPPENED UNTIL NOW if so -> handle it!
|
||||||
|
|
||||||
|
// we return the timer time so that main can sleep
|
||||||
|
return k_timer_remaining_get(&sync_adv_timer);
|
||||||
}
|
}
|
@ -26,10 +26,9 @@
|
|||||||
typedef ENIntervalIdentifier ENIntervalIdentifier;
|
typedef ENIntervalIdentifier ENIntervalIdentifier;
|
||||||
|
|
||||||
#define RPI_ROTATION_MS (11*60*1000)
|
#define RPI_ROTATION_MS (11*60*1000)
|
||||||
#define SCAN_INTERVAL_MS (10*1000)
|
#define SCAN_INTERVAL_MS (60*1000)
|
||||||
#define SCAN_DURATION_MS 1000
|
#define SCAN_DURATION_MS 1000
|
||||||
#define ADV_INTERVAL_MS 220
|
#define ADV_INTERVAL_MS 220
|
||||||
#define ADV_DURATION_MS 1000
|
|
||||||
|
|
||||||
|
|
||||||
K_TIMER_DEFINE(rpi_timer, NULL, NULL);
|
K_TIMER_DEFINE(rpi_timer, NULL, NULL);
|
||||||
@ -49,14 +48,10 @@ int tracing_init()
|
|||||||
k_timer_start(&adv_timer, K_MSEC(ADV_INTERVAL_MS), K_MSEC(ADV_INTERVAL_MS));
|
k_timer_start(&adv_timer, K_MSEC(ADV_INTERVAL_MS), K_MSEC(ADV_INTERVAL_MS));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tracing_run()
|
uint32_t tracing_run()
|
||||||
{
|
{
|
||||||
if (k_timer_status_get(&rpi_timer) > 0) {
|
if (k_timer_status_get(&rpi_timer) > 0) {
|
||||||
on_rpi();
|
on_rpi();
|
||||||
@ -70,13 +65,10 @@ int tracing_run()
|
|||||||
on_adv();
|
on_adv();
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sleep(K_MSEC(ADV_INTERVAL_MS)); // TODO: what to put here?
|
// we return the minimum timer time so that main can sleep
|
||||||
|
return MIN( k_timer_remaining_get(&rpi_timer),
|
||||||
//printk("covid start\n");
|
MIN(k_timer_remaining_get(&scan_timer),
|
||||||
|
k_timer_remaining_get(&adv_timer)));
|
||||||
|
|
||||||
//printk("covid end\n");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user