/** **************************************************************************************** * @brief If the intermediate temperature value is stable, indicate to client and stop notify. * otherwise notify to client. * * To avoid transmitting unnecessary data, the Time Stamp and Temperature Type fields * should not be used in the Intermediate Temperature characteristic. **************************************************************************************** */ void app_interm_temp_notify(void) { int32_t temperature_x10; struct htp_temp_meas temp_meas; temperature_x10 = app_get_imeas_notify_data(&temp_meas); if(app_is_interm_temp_stable(temperature_x10)) { usr_env.is_imeas_send_busy = false; usr_env.is_temp_imeas_config = false; if(usr_env.is_temp_meas_config) { app_temp_meas_indicate(); } if(! usr_env.is_temp_meas_config && usr_env.is_meas_running) { usr_env.is_meas_running = false; ke_timer_clear(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP); } } else { // send the notify usr_env.is_imeas_send_busy = true; app_htpt_temp_send(app_htpt_env->conhdl, &temp_meas, INTERMEDIATE_MEASUREMENT); } }
/** **************************************************************************************** * @brief Send stored measure value, if no data to send, will disconnect **************************************************************************************** */ void app_send_stored_meas(void) { if(usr_env.is_temp_meas_config) { struct htp_temp_meas temp_meas; // if not empty, send the indication if(app_store_meas_fifo_out(&temp_meas)) { usr_env.is_meas_send_busy = true; app_htpt_temp_send(app_htpt_env->conhdl, &temp_meas, TEMPERATURE_MEASUREMENT); } else { // there are two place to disconnect, one is idle connection timeout, // the other is temperature measure send complete usr_env.is_meas_send_busy = false; // set measure send complete if(usr_env.is_idle_connection_overtime && !usr_env.is_imeas_send_busy) // idle connection timeout { QPRINTF("Force disconnect\r\n"); app_gap_discon_req(app_htpt_env->conhdl); } } } }
void app_eaci_data_htps_hdl(uint8_t msg_id, uint8_t param_len, uint8_t const *param) { if (app_htpt_env->enabled == false) return; switch (msg_id) { case EACI_MSG_DATA_REQ_HT_SEND_INTER_VALUE: { uint16_t meas_intv = param[1] << 8 | param[0]; app_htpt_measurement_intv_send(app_htpt_env->conhdl, meas_intv); } break; case EACI_MSG_DATA_REQ_HT_SEND_TEMP_VALUE: { struct htp_temp_meas temp; uint8_t flag_stable_meas = param[0]; temp.flags = param[1]; temp.type = param[2]; temp.temp = (param[6] << 24) | (param[5] << 16) | (param[4] << 8) | param[3]; temp.time_stamp.year = (param[8] << 8) | param[7]; temp.time_stamp.month = param[9]; temp.time_stamp.day = param[10]; temp.time_stamp.hour = param[11]; temp.time_stamp.min = param[12]; temp.time_stamp.sec = param[13]; app_htpt_temp_send(app_htpt_env->conhdl, &temp, flag_stable_meas); } break; default: break; } }
/** **************************************************************************************** * @brief Handles health thermometer timer * * @param[in] msgid Id of the message received. * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (TASK_GAP). * @param[in] src_id ID of the sending task instance. * * @return If the message was consumed or not. **************************************************************************************** */ static int app_ht_timer_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { if (ke_state_get(dest_id) == APP_HT_CONNECTED) { // Random generation of a temperature value uint32_t rand_temp_step; // Sign used to know if the tempererature will be increased or decreased int8_t sign; // Generate temperature step rand_temp_step = (uint32_t)(rand()%20); // Increase or decrease the temperature value sign = (int8_t)(rand_temp_step & 0x00000001); if (!sign) { sign = -1; } app_ht_env.temp_value += sign*rand_temp_step; // Send the new temperature app_htpt_temp_send(); #if (DISPLAY_SUPPORT) app_display_update_temp_val_screen(app_ht_env.temp_value); #endif //DISPLAY_SUPPORT // Reset the Timer (Measurement Interval is not 0 if we are here) ke_timer_set(APP_HT_TIMER, TASK_APP_HT, app_ht_env.htpt_meas_intv*100); } return (KE_MSG_CONSUMED); }