diff --git a/code/b-parasite/Makefile b/code/b-parasite/Makefile index 9947a86..c0be3b9 100644 --- a/code/b-parasite/Makefile +++ b/code/b-parasite/Makefile @@ -308,3 +308,7 @@ SDK_CONFIG_FILE := ../config/sdk_config.h CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar sdk_config: java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE) + +.PHONY: flash_loop +flash_loop: + while [ 1 ]; do make flash && break; done \ No newline at end of file diff --git a/code/b-parasite/config/prst_config.h b/code/b-parasite/config/prst_config.h index 036f684..e8e1f01 100644 --- a/code/b-parasite/config/prst_config.h +++ b/code/b-parasite/config/prst_config.h @@ -15,15 +15,18 @@ #define PRST_ADC_DEBUG 0 // BLE. -#define PRST_BLE_ADV_NAME "prst" // Prints out BLE debug info, such as the final encoded advertisement packet. #define PRST_BLE_DEBUG 0 +#define PRST_BLE_MAC_ADDR_LSB0 0xaa +#define PRST_BLE_MAC_ADDR_LSB1 0xbb +#define PRST_BLE_ADV_TIME_IN_MS 200 +#define PRST_BLE_ADV_NAME "prst aabb" // PWM. #define PRST_PWM_PIN NRF_GPIO_PIN_MAP(0, 5) #define PRST_FAST_DISCH_PIN NRF_GPIO_PIN_MAP(1, 10) // SHT3C temp/humidity sensor. -#define PRST_SHT3C_DEBUG 1 +#define PRST_SHT3C_DEBUG 0 #endif // _PRST_CONFIG_H_ \ No newline at end of file diff --git a/code/b-parasite/src/main.c b/code/b-parasite/src/main.c index f916d94..6b12d1a 100644 --- a/code/b-parasite/src/main.c +++ b/code/b-parasite/src/main.c @@ -71,7 +71,7 @@ static void rtc_callback() { temp_humi.humidity, soil_read.relative); NRF_LOG_FLUSH(); prst_adv_start(); - nrf_delay_ms(200); + nrf_delay_ms(PRST_BLE_ADV_TIME_IN_MS); prst_adv_stop(); nrf_gpio_pin_clear(PRST_LED_PIN); NRF_LOG_FLUSH(); diff --git a/code/b-parasite/src/prst/ble.c b/code/b-parasite/src/prst/ble.c index 29e6041..b465cdb 100644 --- a/code/b-parasite/src/prst/ble.c +++ b/code/b-parasite/src/prst/ble.c @@ -23,7 +23,7 @@ #define NON_CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(100, UNIT_0_625_MS) // Sensor data payload that will go into the advertisement message. -#define SERVICE_DATA_LEN 16 +#define SERVICE_DATA_LEN 12 static uint8_t service_data[SERVICE_DATA_LEN]; // Stores the encoded advertisement data. As per BLE spec, 31 bytes max. @@ -61,6 +61,17 @@ static uint8_t adv_handle_ = BLE_GAP_ADV_SET_HANDLE_NOT_SET; // Advertisement parameters. static ble_gap_adv_params_t adv_params_; +// Stores the MAC address & type. +// We're using a random static MAC address, which has the following constraints: +// 1. Two most significant bits are set to 1; +// 2. The remaining bits should not _all_ be set to 0; +// 2. The remaining bits should not _all_ be set to 1; +static const ble_gap_addr_t gap_addr_ = { + .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC, + // Least significant bytes first. + .addr = {PRST_BLE_MAC_ADDR_LSB0, PRST_BLE_MAC_ADDR_LSB1, 0xca, 0xf0, 0xca, + 0xf0}}; + static void init_advertisement_data() { // We'll just broadcast our data, so we disallow connections and scan // requests. @@ -81,6 +92,8 @@ static void init_advertisement_data() { uint32_t err_code = sd_ble_gap_adv_set_configure(&adv_handle_, &gap_adv_data_, &adv_params_); APP_ERROR_CHECK(err_code); + + APP_ERROR_CHECK(sd_ble_gap_addr_set(&gap_addr_)); } void prst_ble_init() { diff --git a/code/b-parasite/src/prst/shtc3.c b/code/b-parasite/src/prst/shtc3.c index 4d81f36..0836a0e 100644 --- a/code/b-parasite/src/prst/shtc3.c +++ b/code/b-parasite/src/prst/shtc3.c @@ -6,6 +6,8 @@ #include #include +#include "prst_config.h" + static const nrf_drv_twi_t twi_ = NRF_DRV_TWI_INSTANCE(0); static nrf_drv_twi_config_t twi_config_ = NRF_DRV_TWI_DEFAULT_CONFIG; @@ -54,9 +56,9 @@ prst_shtc3_read_t prst_shtc3_read() { .humidity = humi}; #if PRST_SHT3C_DEBUG NRF_LOG_INFO("[sht3c] Read temp: " NRF_LOG_FLOAT_MARKER " oC", - NRF_LOG_FLOAT((float)temp_humi.temp_millicelcius / 1000.0)); + NRF_LOG_FLOAT((float)ret.temp_millicelcius / 1000.0)); NRF_LOG_INFO("[sht3c] Read humi: " NRF_LOG_FLOAT_MARKER " %%", - NRF_LOG_FLOAT(100.0 * temp_humi.humidity / (1 << 16))); + NRF_LOG_FLOAT(100.0 * ret.humidity / (1 << 16))); #endif return ret; } \ No newline at end of file