diff --git a/Nordic/nrf51822/Board/pca10001/s110/ble_app_cscs/main.c b/Nordic/nrf51822/Board/pca10001/s110/ble_app_cscs/main.c index b9b5853..0537f3f 100644 --- a/Nordic/nrf51822/Board/pca10001/s110/ble_app_cscs/main.c +++ b/Nordic/nrf51822/Board/pca10001/s110/ble_app_cscs/main.c @@ -62,7 +62,7 @@ #define CONNECTED_LED_PIN_NO LED_1 /**< Is on when device has connected. */ //#define ASSERT_LED_PIN_NO LED_7 /**< Is on when application has asserted. */ -#define DEVICE_NAME "Nordic_CSC" /**< Name of device. Will be included in the advertising data. */ +#define DEVICE_NAME "VC5SEA" /**< Name of device. Will be included in the advertising data. */ #define MANUFACTURER_NAME "NordicSemiconductor" /**< Manufacturer. Will be passed to Device Information Service. */ #define APP_ADV_INTERVAL 40 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 25 ms). */ #define APP_ADV_TIMEOUT_IN_SECONDS 180 /**< The advertising timeout in units of seconds. */ @@ -82,14 +82,14 @@ #define KPH_TO_MM_PER_SEC 278 /**< Constant to convert kilometers per hour into millimeters per second. */ #define MIN_SPEED_KPH 10 /**< Minimum speed in kilometers per hour for use in the simulated measurement function. */ -#define MAX_SPEED_KPH 40 /**< Maximum speed in kilometers per hour for use in the simulated measurement function. */ +#define MAX_SPEED_KPH 80 /**< Maximum speed in kilometers per hour for use in the simulated measurement function. */ #define SPEED_KPH_INCREMENT 1 /**< Value by which speed is incremented/decremented for each call to the simulated measurement function. */ #define DEGREES_PER_REVOLUTION 360 /**< Constant used in simulation for calculating crank speed. */ #define RPM_TO_DEGREES_PER_SEC 6 /**< Constant to convert revolutions per minute into degrees per second. */ #define MIN_CRANK_RPM 20 /**< Minimum cadence in RPM for use in the simulated measurement function. */ -#define MAX_CRANK_RPM 110 /**< Maximum cadence in RPM for use in the simulated measurement function. */ +#define MAX_CRANK_RPM 150 /**< Maximum cadence in RPM for use in the simulated measurement function. */ #define CRANK_RPM_INCREMENT 3 /**< Value by which cadence is incremented/decremented in the simulated measurement function. */ #define MIN_CONN_INTERVAL MSEC_TO_UNITS(500, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.5 seconds). */ @@ -243,7 +243,7 @@ static void csc_sim_measurement(ble_cscs_meas_t * p_measurement) event_time_inc = (1024 * SPEED_AND_CADENCE_MEAS_INTERVAL) / 1000; // Calculate simulated wheel revolution values. - p_measurement->is_wheel_rev_data_present = true; + p_measurement->is_wheel_rev_data_present = false; mm_per_sec = KPH_TO_MM_PER_SEC * ble_sensorsim_measure(&m_speed_kph_sim_state, &m_speed_kph_sim_cfg); @@ -362,15 +362,22 @@ static void timers_init(void) static void gap_params_init(void) { uint32_t err_code; + char deviceaddr_name[16]; ble_gap_conn_params_t gap_conn_params; ble_gap_conn_sec_mode_t sec_mode; + snprintf(&deviceaddr_name,14,"%s-%.4X%.2X\0", + DEVICE_NAME, + NRF_FICR->DEVICEADDR[0], + NRF_FICR->DEVICEADDR[1]); + BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)DEVICE_NAME, strlen(DEVICE_NAME)); + err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)deviceaddr_name, strlen(deviceaddr_name)); + APP_ERROR_CHECK(err_code); - err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR); + err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_CYCLING_CADENCE_SENSOR); APP_ERROR_CHECK(err_code); memset(&gap_conn_params, 0, sizeof(gap_conn_params)); @@ -466,8 +473,11 @@ static void services_init(void) memset(&cscs_init, 0, sizeof(cscs_init)); cscs_init.evt_handler = NULL; - cscs_init.feature = BLE_CSCS_FEATURE_WHEEL_REV_BIT | BLE_CSCS_FEATURE_CRANK_REV_BIT | BLE_CSCS_FEATURE_MULTIPLE_SENSORS_BIT; +// SET CSCS Features to Use + cscs_init.feature = BLE_CSCS_FEATURE_CRANK_REV_BIT; + //cscs_init.feature = BLE_CSCS_FEATURE_WHEEL_REV_BIT | BLE_CSCS_FEATURE_CRANK_REV_BIT | BLE_CSCS_FEATURE_MULTIPLE_SENSORS_BIT; + // Here the sec level for the Cycling Speed and Cadence Service can be changed/increased. BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cscs_init.csc_meas_attr_md.cccd_write_perm); // for the measurement characteristic, only the CCCD write permission can be set by the application, others are mandated by service specification BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cscs_init.csc_feature_attr_md.read_perm); // for the feature characteristic, only the read permission can be set by the application, others are mandated by service specification @@ -481,7 +491,7 @@ static void services_init(void) cscs_init.list_supported_locations = supported_locations; cscs_init.size_list_supported_locations = sizeof(supported_locations) / sizeof(ble_sensor_location_t); - sensor_location = BLE_SENSOR_LOCATION_FRONT_WHEEL; // initializes the sensor location to add the sensor location characteristic. + sensor_location = BLE_SENSOR_LOCATION_LEFT_CRANK; // initializes the sensor location to add the sensor location characteristic. cscs_init.sensor_location = &sensor_location; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cscs_init.csc_sensor_loc_attr_md.read_perm); // for the sensor location characteristic, only the read permission can be set by the application, others are mendated by service specification