1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_BLECSC_SENSOR_ 21 #define H_BLECSC_SENSOR_ 22 23 #include "modlog/modlog.h" 24 #include "nimble/ble.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* Cycling Speed and Cadence configuration */ 31 #define GATT_CSC_UUID 0x1816 32 #define GATT_CSC_MEASUREMENT_UUID 0x2A5B 33 #define GATT_CSC_FEATURE_UUID 0x2A5C 34 #define GATT_SENSOR_LOCATION_UUID 0x2A5D 35 #define GATT_SC_CONTROL_POINT_UUID 0x2A55 36 /* Device Information configuration */ 37 #define GATT_DEVICE_INFO_UUID 0x180A 38 #define GATT_MANUFACTURER_NAME_UUID 0x2A29 39 #define GATT_MODEL_NUMBER_UUID 0x2A24 40 41 /*CSC Measurement flags*/ 42 #define CSC_MEASUREMENT_WHEEL_REV_PRESENT 0x01 43 #define CSC_MEASUREMENT_CRANK_REV_PRESENT 0x02 44 45 /* CSC feature flags */ 46 #define CSC_FEATURE_WHEEL_REV_DATA 0x01 47 #define CSC_FEATURE_CRANK_REV_DATA 0x02 48 #define CSC_FEATURE_MULTIPLE_SENSOR_LOC 0x04 49 50 /* Sensor location enum */ 51 #define SENSOR_LOCATION_OTHER 0 52 #define SENSOR_LOCATION_TOP_OF_SHOE 1 53 #define SENSOR_LOCATION_IN_SHOE 2 54 #define SENSOR_LOCATION_HIP 3 55 #define SENSOR_LOCATION_FRONT_WHEEL 4 56 #define SENSOR_LOCATION_LEFT_CRANK 5 57 #define SENSOR_LOCATION_RIGHT_CRANK 6 58 #define SENSOR_LOCATION_LEFT_PEDAL 7 59 #define SENSOR_LOCATION_RIGHT_PEDAL 8 60 #define SENSOR_LOCATION_FROT_HUB 9 61 #define SENSOR_LOCATION_REAR_DROPOUT 10 62 #define SENSOR_LOCATION_CHAINSTAY 11 63 #define SENSOR_LOCATION_REAR_WHEEL 12 64 #define SENSOR_LOCATION_REAR_HUB 13 65 #define SENSOR_LOCATION_CHEST 14 66 #define SENSOR_LOCATION_SPIDER 15 67 #define SENSOR_LOCATION_CHAIN_RING 16 68 69 /* SC Control Point op codes */ 70 #define SC_CP_OP_SET_CUMULATIVE_VALUE 1 71 #define SC_CP_OP_START_SENSOR_CALIBRATION 2 72 #define SC_CP_OP_UPDATE_SENSOR_LOCATION 3 73 #define SC_CP_OP_REQ_SUPPORTED_SENSOR_LOCATIONS 4 74 #define SC_CP_OP_RESPONSE 16 75 76 /*SC Control Point response values */ 77 #define SC_CP_RESPONSE_SUCCESS 1 78 #define SC_CP_RESPONSE_OP_NOT_SUPPORTED 2 79 #define SC_CP_RESPONSE_INVALID_PARAM 3 80 #define SC_CP_RESPONSE_OP_FAILED 4 81 82 /* CSC simulation configuration */ 83 #define CSC_FEATURES (CSC_FEATURE_WHEEL_REV_DATA | \ 84 CSC_FEATURE_CRANK_REV_DATA |\ 85 CSC_FEATURE_MULTIPLE_SENSOR_LOC) 86 87 struct ble_csc_measurement_state { 88 uint32_t cumulative_wheel_rev; 89 uint16_t last_wheel_evt_time; 90 uint16_t cumulative_crank_rev; 91 uint16_t last_crank_evt_time; 92 }; 93 94 extern uint16_t csc_measurement_handle; 95 extern uint16_t csc_control_point_handle; 96 97 int gatt_svr_init(struct ble_csc_measurement_state * csc_measurement_state); 98 int gatt_svr_chr_notify_csc_measurement(uint16_t conn_handle); 99 void gatt_svr_set_cp_indicate(uint8_t indication_status); 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif 106