void htpc_unpack_temp(struct htpc_env_tag *htpc_env, uint8_t *packed_temp, uint8_t length, uint8_t flag_stable_meas) { // Cursor used to read parameter in the packed temperature value uint8_t cursor = 0; // Checked the length of the received value if (length >= HTPC_PACKED_TEMP_MIN_LEN) { // Prepare the message to send to the application struct htpc_temp_ind *ind = KE_MSG_ALLOC(HTPC_TEMP_IND, htpc_env->con_info.appid, htpc_env->con_info.prf_id, htpc_temp_ind); // Connection handle ind->conhdl = gapc_get_conhdl(htpc_env->con_info.conidx); // Unpack Temp Measurement ind->temp_meas.flags = *(packed_temp + cursor); cursor += 1; ind->temp_meas.temp = co_read32p(packed_temp + cursor); cursor += 4; // Time Flag Set if ((ind->temp_meas.flags & HTPT_FLAG_TIME) == HTPT_FLAG_TIME) { cursor += prf_unpack_date_time(packed_temp+cursor, &(ind->temp_meas.time_stamp)); } // Type Flag set if ((ind->temp_meas.flags & HTPT_FLAG_TYPE) == HTPT_FLAG_TYPE) { ind->temp_meas.type = *(packed_temp + cursor); } // Stable or intermediary type of temperature ind->flag_stable_meas = flag_stable_meas; //Send request to ATT ke_msg_send(ind); } }
/** **************************************************************************************** * @brief Handles reception of the @ref GATT_HANDLE_VALUE_NTF message. * @param[in] msgid Id of the message received (probably unused). * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (probably unused). * @param[in] src_id ID of the sending task instance. * @return If the message was consumed or not. **************************************************************************************** */ static int gatt_handle_value_ntf_handler(ke_msg_id_t const msgid, struct gatt_handle_value_notif const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { // Get the address of the environment struct cscpc_env_tag *cscpc_env = PRF_CLIENT_GET_ENV(dest_id, cscpc); if (cscpc_env != NULL) { // Offset uint8_t offset = CSCP_CSC_MEAS_MIN_LEN; // CSC Measurement value has been received struct cscpc_value_ind *ind = KE_MSG_ALLOC(CSCPC_VALUE_IND, cscpc_env->con_info.appid, cscpc_env->con_info.prf_id, cscpc_value_ind); // Connection Handle ind->conhdl = param->conhdl; // Attribute code ind->att_code = CSCPC_NTF_CSC_MEAS; /*---------------------------------------------------- * Unpack Measurement -------------------------------- *----------------------------------------------------*/ // Flags ind->value.csc_meas.flags = param->value[0]; // Cumulative Wheel Revolutions // Last Wheel Event Time if ((param->value[0] & CSCP_MEAS_WHEEL_REV_DATA_PRESENT) == CSCP_MEAS_WHEEL_REV_DATA_PRESENT) { // Cumulative Wheel Revolutions ind->value.csc_meas.cumul_wheel_rev = co_read32p(¶m->value[offset]); offset += 4; // Last Wheel Event Time ind->value.csc_meas.last_wheel_evt_time = co_read16p(¶m->value[offset]); offset += 2; } // Cumulative Crank Revolutions // Last Crank Event Time if ((param->value[0] & CSCP_MEAS_CRANK_REV_DATA_PRESENT) == CSCP_MEAS_CRANK_REV_DATA_PRESENT) { // Cumulative Crank Revolutions ind->value.csc_meas.cumul_crank_rev = co_read16p(¶m->value[offset]); offset += 2; // Last Crank Event Time ind->value.csc_meas.last_crank_evt_time = co_read16p(¶m->value[offset]); } ke_msg_send(ind); } // else ignore the message return (KE_MSG_CONSUMED); }