mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2025-01-07 11:54:24 +01:00
move to from u32_t to uint32_t and so one to make all compilers happy
This commit is contained in:
parent
8d5738c66f
commit
2639b39faf
@ -25,10 +25,10 @@
|
|||||||
#include "covid.h"
|
#include "covid.h"
|
||||||
|
|
||||||
typedef struct contact {
|
typedef struct contact {
|
||||||
u32_t most_recent_contact_time; //TODO: what is the correct type here?
|
uint32_t most_recent_contact_time; //TODO: what is the correct type here?
|
||||||
u32_t first_contact_time; //TODO: what is the correct type here?
|
uint32_t first_contact_time; //TODO: what is the correct type here?
|
||||||
u16_t cnt;
|
uint16_t cnt;
|
||||||
s8_t max_rssi;
|
int8_t max_rssi;
|
||||||
rolling_proximity_identifier_t rolling_proximity_identifier;
|
rolling_proximity_identifier_t rolling_proximity_identifier;
|
||||||
associated_encrypted_metadata_t associated_encrypted_metadata;
|
associated_encrypted_metadata_t associated_encrypted_metadata;
|
||||||
} contact_t;
|
} contact_t;
|
||||||
@ -36,7 +36,7 @@ typedef struct contact {
|
|||||||
#define MAX_CONTACTS 1000
|
#define MAX_CONTACTS 1000
|
||||||
|
|
||||||
static contact_t contacts[MAX_CONTACTS];
|
static contact_t contacts[MAX_CONTACTS];
|
||||||
static u32_t contact_count = 0;
|
static uint32_t contact_count = 0;
|
||||||
|
|
||||||
|
|
||||||
void print_rpi(rolling_proximity_identifier_t* rpi){
|
void print_rpi(rolling_proximity_identifier_t* rpi){
|
||||||
@ -63,7 +63,7 @@ contact_t* find_contact(rolling_proximity_identifier_t* rpi, associated_encrypte
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_add_contact(u32_t contact_time, rolling_proximity_identifier_t* rpi, associated_encrypted_metadata_t* aem, s8_t rssi){
|
int check_add_contact(uint32_t contact_time, rolling_proximity_identifier_t* rpi, associated_encrypted_metadata_t* aem, int8_t rssi){
|
||||||
contact_t* contact = find_contact(rpi, aem);
|
contact_t* contact = find_contact(rpi, aem);
|
||||||
if( contact == NULL ){
|
if( contact == NULL ){
|
||||||
if( contact_count >= MAX_CONTACTS ){
|
if( contact_count >= MAX_CONTACTS ){
|
||||||
@ -101,9 +101,9 @@ int check_add_contact(u32_t contact_time, rolling_proximity_identifier_t* rpi, a
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct period_contact {
|
typedef struct period_contact {
|
||||||
u32_t duration;
|
uint32_t duration;
|
||||||
u16_t cnt;
|
uint16_t cnt;
|
||||||
s8_t max_rssi; //TODO also store avg rssi?
|
int8_t max_rssi; //TODO also store avg rssi?
|
||||||
rolling_proximity_identifier_t rolling_proximity_identifier;
|
rolling_proximity_identifier_t rolling_proximity_identifier;
|
||||||
associated_encrypted_metadata_t associated_encrypted_metadata;
|
associated_encrypted_metadata_t associated_encrypted_metadata;
|
||||||
} period_contact_t;
|
} period_contact_t;
|
||||||
@ -118,7 +118,7 @@ typedef struct period_contacts{
|
|||||||
|
|
||||||
static period_contacts_t period_contacts[PERIODS];
|
static period_contacts_t period_contacts[PERIODS];
|
||||||
static int period_index = 0;
|
static int period_index = 0;
|
||||||
static s32_t next_infected_key_id = 0;
|
static int32_t next_infected_key_id = 0;
|
||||||
|
|
||||||
//10 minutes are over and we got new keys. Time to also sort our short term contacts and move them to long-term log
|
//10 minutes are over and we got new keys. Time to also sort our short term contacts and move them to long-term log
|
||||||
//TODO: move long-term storage to flash, as we have limited space in RAM
|
//TODO: move long-term storage to flash, as we have limited space in RAM
|
||||||
@ -207,7 +207,7 @@ void add_infected_key(period_t* period){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32_t get_next_infected_key_id(){
|
uint32_t get_next_infected_key_id(){
|
||||||
return next_infected_key_id;
|
return next_infected_key_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
#include "covid.h"
|
#include "covid.h"
|
||||||
|
|
||||||
void init_contacts();
|
void init_contacts();
|
||||||
int check_add_contact(u32_t contact_time, rolling_proximity_identifier_t* rpi, associated_encrypted_metadata_t* aem, s8_t rssi);
|
int check_add_contact(uint32_t contact_time, rolling_proximity_identifier_t* rpi, associated_encrypted_metadata_t* aem, int8_t rssi);
|
||||||
void key_change(int current_period_index);
|
void key_change(int current_period_index);
|
||||||
|
|
||||||
void add_infected_key(period_t* period);
|
void add_infected_key(period_t* period);
|
||||||
u32_t get_next_infected_key_id();
|
uint32_t get_next_infected_key_id();
|
||||||
|
|
||||||
void print_rpi(rolling_proximity_identifier_t* rpi);
|
void print_rpi(rolling_proximity_identifier_t* rpi);
|
||||||
void print_aem(associated_encrypted_metadata_t* aem);
|
void print_aem(associated_encrypted_metadata_t* aem);
|
||||||
|
@ -44,13 +44,13 @@ static struct bt_data ad[] = {
|
|||||||
BT_DATA(BT_DATA_SVC_DATA16, &covid_adv_svd, sizeof(covid_adv_svd_t))
|
BT_DATA(BT_DATA_SVC_DATA16, &covid_adv_svd, sizeof(covid_adv_svd_t))
|
||||||
};
|
};
|
||||||
|
|
||||||
static void scan_cb(const bt_addr_le_t *addr, s8_t rssi, u8_t adv_type, struct net_buf_simple *buf)
|
static void scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
if( adv_type == 3 ){
|
if( adv_type == 3 ){
|
||||||
u8_t len = 0;
|
uint8_t len = 0;
|
||||||
|
|
||||||
while (buf->len > 1) {
|
while (buf->len > 1) {
|
||||||
u8_t type;
|
uint8_t type;
|
||||||
|
|
||||||
len = net_buf_simple_pull_u8(buf);
|
len = net_buf_simple_pull_u8(buf);
|
||||||
if (!len) {
|
if (!len) {
|
||||||
|
@ -94,16 +94,16 @@ static const struct bt_data ad[] = {
|
|||||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0xF2),
|
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0xF2),
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssize_t read_next_key(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_next_key(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
u32_t id = get_next_infected_key_id();
|
uint32_t id = get_next_infected_key_id();
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &id, sizeof(id));
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &id, sizeof(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t read_key_cnt(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_cnt(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
unsigned int cnt = get_period_cnt_if_infected();
|
unsigned int cnt = get_period_cnt_if_infected();
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &cnt, sizeof(unsigned int));
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &cnt, sizeof(unsigned int));
|
||||||
}
|
}
|
||||||
static ssize_t read_key_0(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_0(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(0, &size);
|
period_t* p = get_period_if_infected(0, &size);
|
||||||
// printk("read key 0, size %u, pointer %p\n", size, p);
|
// printk("read key 0, size %u, pointer %p\n", size, p);
|
||||||
@ -111,67 +111,67 @@ static ssize_t read_key_0(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
|||||||
// printk("RPI: "); print_rpi((rolling_proximity_identifier_t*)&p->periodKey); printk("\n");
|
// printk("RPI: "); print_rpi((rolling_proximity_identifier_t*)&p->periodKey); printk("\n");
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_1(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_1(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(1, &size);
|
period_t* p = get_period_if_infected(1, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_2(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_2(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(2, &size);
|
period_t* p = get_period_if_infected(2, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_3(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_3(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(3, &size);
|
period_t* p = get_period_if_infected(3, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_4(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_4(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(4, &size);
|
period_t* p = get_period_if_infected(4, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_5(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_5(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(5, &size);
|
period_t* p = get_period_if_infected(5, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_6(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_6(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(6, &size);
|
period_t* p = get_period_if_infected(6, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_7(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_7(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(7, &size);
|
period_t* p = get_period_if_infected(7, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_8(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_8(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(8, &size);
|
period_t* p = get_period_if_infected(8, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_9(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_9(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(9, &size);
|
period_t* p = get_period_if_infected(9, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_10(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_10(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(10, &size);
|
period_t* p = get_period_if_infected(10, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_11(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_11(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(11, &size);
|
period_t* p = get_period_if_infected(11, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_12(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_12(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(12, &size);
|
period_t* p = get_period_if_infected(12, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
||||||
}
|
}
|
||||||
static ssize_t read_key_13(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset){
|
static ssize_t read_key_13(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
period_t* p = get_period_if_infected(13, &size);
|
period_t* p = get_period_if_infected(13, &size);
|
||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
||||||
@ -180,8 +180,8 @@ static ssize_t read_key_13(struct bt_conn *conn, const struct bt_gatt_attr *attr
|
|||||||
//TODO: copy more than one key
|
//TODO: copy more than one key
|
||||||
static ssize_t write_new_key(struct bt_conn *conn,
|
static ssize_t write_new_key(struct bt_conn *conn,
|
||||||
const struct bt_gatt_attr *attr,
|
const struct bt_gatt_attr *attr,
|
||||||
const void *buf, u16_t len, u16_t offset,
|
const void *buf, uint16_t len, uint16_t offset,
|
||||||
u8_t flags)
|
uint8_t flags)
|
||||||
{
|
{
|
||||||
//printk("write key\n");
|
//printk("write key\n");
|
||||||
if( offset != 0 ){
|
if( offset != 0 ){
|
||||||
@ -197,7 +197,7 @@ static ssize_t write_new_key(struct bt_conn *conn,
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void connected(struct bt_conn *conn, u8_t err)
|
static void connected(struct bt_conn *conn, uint8_t err)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -207,7 +207,7 @@ static void connected(struct bt_conn *conn, u8_t err)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void disconnected(struct bt_conn *conn, u8_t reason)
|
static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||||
{
|
{
|
||||||
//printk("Disconnected (reason 0x%02x)\n", reason);
|
//printk("Disconnected (reason 0x%02x)\n", reason);
|
||||||
}
|
}
|
||||||
|
@ -91,13 +91,13 @@
|
|||||||
static struct gpio_callback button_0_cb_data;
|
static struct gpio_callback button_0_cb_data;
|
||||||
static struct gpio_callback button_1_cb_data;
|
static struct gpio_callback button_1_cb_data;
|
||||||
|
|
||||||
void button_0_pressed(struct device *dev, struct gpio_callback *cb, u32_t pins){
|
void button_0_pressed(struct device *dev, struct gpio_callback *cb, uint32_t pins){
|
||||||
set_infection(true);
|
set_infection(true);
|
||||||
gpio_pin_set(dev, PIN, (int)1);
|
gpio_pin_set(dev, PIN, (int)1);
|
||||||
printk("Button 0 (=infected) pressed at %" PRIu32 "\n", k_cycle_get_32());
|
printk("Button 0 (=infected) pressed at %" PRIu32 "\n", k_cycle_get_32());
|
||||||
}
|
}
|
||||||
|
|
||||||
void button_1_pressed(struct device *dev, struct gpio_callback *cb, u32_t pins){
|
void button_1_pressed(struct device *dev, struct gpio_callback *cb, uint32_t pins){
|
||||||
set_infection(false);
|
set_infection(false);
|
||||||
gpio_pin_set(dev, PIN, (int)0);
|
gpio_pin_set(dev, PIN, (int)0);
|
||||||
printk("Button 1 (=healthy) pressed at %" PRIu32 "\n", k_cycle_get_32());
|
printk("Button 1 (=healthy) pressed at %" PRIu32 "\n", k_cycle_get_32());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user