Ejemplo n.º 1
0
/*********************************************************************
 * @fn      heartRateMeasNotify
 *
 * @brief   Prepare and send a heart rate measurement notification
 *
 * @return  none
 */
static void heartRateMeasNotify(void)
{
  // Heart rate measurement value stored in this structure
  attHandleValueNoti_t heartRateMeas;

  heartRateMeas.pValue = GATT_bm_alloc( gapConnHandle, ATT_HANDLE_VALUE_NOTI,
                                        HR_MEAS_LEN, NULL );
  if ( heartRateMeas.pValue != NULL )
  {
    uint8 *p = heartRateMeas.pValue;
    uint8 flags = heartRateFlags[heartRateFlagsIdx];
    
    // build heart rate measurement structure from simulated values
    *p++ = flags;
    *p++ = heartRateBpm;
    
    if (flags & HEARTRATE_FLAGS_FORMAT_UINT16)
    {
      // additional byte for 16 bit format
      *p++ = 0;
    }
    
    if (flags & HEARTRATE_FLAGS_ENERGY_EXP)
    {
      *p++ = LO_UINT16(heartRateEnergy);
      *p++ = HI_UINT16(heartRateEnergy);
    }
    
    if (flags & HEARTRATE_FLAGS_RR)
    {
      *p++ = LO_UINT16(heartRateRrInterval1);
      *p++ = HI_UINT16(heartRateRrInterval1);  
      *p++ = LO_UINT16(heartRateRrInterval2);
      *p++ = HI_UINT16(heartRateRrInterval2);  
    }
    
    heartRateMeas.len = (uint8) (p - heartRateMeas.pValue);
    
    if ( HeartRate_MeasNotify( gapConnHandle, &heartRateMeas ) != SUCCESS )
    {
      GATT_bm_free( (gattMsg_t *)&heartRateMeas, ATT_HANDLE_VALUE_IND );
    }
    
    // update simulated values 
    heartRateEnergy += ENERGY_INCREMENT;
    if (++heartRateBpm == BPM_MAX)
    {
      heartRateBpm = BPM_DEFAULT;
    }
    
    heartRateRrInterval1 = heartRateRrInterval2 = HEARTRATE_BPM_TO_RR(heartRateBpm);
  }
}
Ejemplo n.º 2
0
/*********************************************************************
 * @fn      HeartRate_measNotify
 *
 * @brief   Prepare and send a heart rate measurement notification.
 *
 * @return  none
 */
static void HeartRate_measNotify(void)
{
  attHandleValueNoti_t heartRateMeas;

  heartRateMeas.pValue = GATT_bm_alloc(gapConnHandle, ATT_HANDLE_VALUE_NOTI,
                                       HEARTRATE_MEAS_LEN, NULL);
  if (heartRateMeas.pValue != NULL)
  {
    uint8_t *p = heartRateMeas.pValue;
    uint8_t flags = heartRateflags[flagsIdx];
    
    // Build heart rate measurement structure from simulated values.
    *p++ = flags;
    *p++ = heartRateBpm;
    
    if (flags & HEARTRATE_FLAGS_FORMAT_UINT16)
    {
      // Additional byte for 16 bit format.
      *p++ = 0;
    }
    
    if (flags & HEARTRATE_FLAGS_ENERGY_EXP)
    {
      *p++ = LO_UINT16(heartRateEnergyLvl);
      *p++ = HI_UINT16(heartRateEnergyLvl);
    }
    
    if (flags & HEARTRATE_FLAGS_RR)
    {
      *p++ = LO_UINT16(heartRateRrInterval);
      *p++ = HI_UINT16(heartRateRrInterval);  
      *p++ = LO_UINT16(heartRateRrInterval2);
      *p++ = HI_UINT16(heartRateRrInterval2);  
    }
    
    heartRateMeas.len = (uint8)(p - heartRateMeas.pValue);
    
    // Send notification.
    if (HeartRate_MeasNotify(gapConnHandle, &heartRateMeas) != SUCCESS)
    {
      GATT_bm_free((gattMsg_t *)&heartRateMeas, ATT_HANDLE_VALUE_NOTI);
    }
    
    // Update simulated values.
    heartRateEnergyLvl += HEARTRATE_ENERGY_INCREMENT;
    if (++heartRateBpm == HEARTRATE_BPM_MAX)
    {
      heartRateBpm = HEARTRATE_BPM_DEFAULT;
    }
    
    heartRateRrInterval = heartRateRrInterval2 = HEARTRATE_BPM2RR(heartRateBpm);
  }
}
Ejemplo n.º 3
0
/*********************************************************************
 * @fn      heartRateMeasNotify
 *
 * @brief   Prepare and send a heart rate measurement notification
 *
 * @return  none
 */
static void heartRateMeasNotify(void)
{
  uint8 *p = heartRateMeas.value;
  uint8 flags = heartRateFlags[heartRateFlagsIdx];
  
  // build heart rate measurement structure from simulated values
  *p++ = flags;
  *p++ = heartRateBpm;
  if (flags & HEARTRATE_FLAGS_FORMAT_UINT16)
  {
    // additional byte for 16 bit format
    *p++ = 0;
  }
  if (flags & HEARTRATE_FLAGS_ENERGY_EXP)
  {
    *p++ = LO_UINT16(heartRateEnergy);
    *p++ = HI_UINT16(heartRateEnergy);
  }
  if (flags & HEARTRATE_FLAGS_RR)
  {
    *p++ = LO_UINT16(heartRateRrInterval1);
    *p++ = HI_UINT16(heartRateRrInterval1);  
    *p++ = LO_UINT16(heartRateRrInterval2);
    *p++ = HI_UINT16(heartRateRrInterval2);  
  }
  heartRateMeas.len = (uint8) (p - heartRateMeas.value);
  HeartRate_MeasNotify( gapConnHandle, &heartRateMeas );
  
  // update simulated values 
  heartRateEnergy += ENERGY_INCREMENT;
  if (++heartRateBpm == BPM_MAX)
  {
    heartRateBpm = BPM_DEFAULT;
  }
  heartRateRrInterval1 = heartRateRrInterval2 = HEARTRATE_BPM_TO_RR(heartRateBpm);
}