コード例 #1
0
ファイル: LCSC_Sensor.c プロジェクト: linan0827/ble_csc
/*********************************************************************
 * @fn      sensorMeasNotify
 *
 * @brief   Prepare and send a CSC measurement notification
 *
 * @return  none
 */
static void sensorMeasNotify( void )
{
  uint8 *p = sensorMeas.value;
  uint8 flags = sensorFlags[sensorFlagsIdx];

  // Build CSC measurement structure from simulated values
  // Flags simulate the isPresent bits.
  *p++ = flags;

  // If present, add Speed data into measurement
  if (flags & CSC_FLAGS_SPEED)
  {
    *p++ = BREAK_UINT32(cummWheelRevs, 0);
    *p++ = BREAK_UINT32(cummWheelRevs, 1);
    *p++ = BREAK_UINT32(cummWheelRevs, 2);
    *p++ = BREAK_UINT32(cummWheelRevs, 3);

    *p++ = LO_UINT16(lastWheelEvtTime);
    *p++ = HI_UINT16(lastWheelEvtTime);

    // Update simulated values (simulate in the reverse direction)
 /*   if (cummWheelRevs < WHEEL_REV_INCREMENT) //don't allow revolutions to roll over
    {
      cummWheelRevs = 0;
    }
    else
    {
      cummWheelRevs -= WHEEL_REV_INCREMENT;
    }

    lastWheelEvtTime += WHEEL_EVT_INCREMENT;   */
  }

  // If present, add Cadence data into measurement
  if (flags & CSC_FLAGS_CADENCE)
  {
    *p++ = LO_UINT16(cummCrankRevs);
    *p++ = HI_UINT16(cummCrankRevs);

    *p++ = LO_UINT16(lastCrankEvtTime);
    *p++ = HI_UINT16(lastCrankEvtTime);

    // Update Simualted Values
   /* cummCrankRevs += CRANK_REV_INCREMENT;
    lastCrankEvtTime += CRANK_EVT_INCREMENT; */
  }

  // Get length
  sensorMeas.len = (uint8) (p - sensorMeas.value);

  // Send to service to send the notification
  Cycling_MeasNotify( gapConnHandle, &sensorMeas );
}
コード例 #2
0
/*********************************************************************
 * @fn      sensorMeasNotify
 *
 * @brief   Prepare and send a CSC measurement notification
 *
 * @return  none
 */
static void sensorMeasNotify( void )
{
  attHandleValueNoti_t sensorMeas;
  
  sensorMeas.pValue = GATT_bm_alloc( gapConnHandle, ATT_HANDLE_VALUE_NOTI,
                                     CSC_MEAS_LEN, NULL );
  if ( sensorMeas.pValue != NULL )
  {
    uint8 *p = sensorMeas.pValue;
    uint8 flags = sensorFlags[sensorFlagsIdx];

    // Build CSC measurement structure from simulated values
    // Flags simulate the isPresent bits.
    *p++ = flags;

    // If present, add Speed data into measurement
    if (flags & CSC_FLAGS_SPEED)
    {
      *p++ = BREAK_UINT32(cummWheelRevs, 0);
      *p++ = BREAK_UINT32(cummWheelRevs, 1);
      *p++ = BREAK_UINT32(cummWheelRevs, 2);
      *p++ = BREAK_UINT32(cummWheelRevs, 3);

      *p++ = LO_UINT16(lastWheelEvtTime);
      *p++ = HI_UINT16(lastWheelEvtTime);

      // Update simulated values (simulate in the reverse direction)
      if (cummWheelRevs < WHEEL_REV_INCREMENT) //don't allow revolutions to roll over
      {
        cummWheelRevs = 0;
      }
      else
      {
        cummWheelRevs -= WHEEL_REV_INCREMENT;
      }

      lastWheelEvtTime += WHEEL_EVT_INCREMENT;
    }

    // If present, add Cadence data into measurement
    if (flags & CSC_FLAGS_CADENCE)
    {
      *p++ = LO_UINT16(cummCrankRevs);
      *p++ = HI_UINT16(cummCrankRevs);

      *p++ = LO_UINT16(lastCrankEvtTime);
      *p++ = HI_UINT16(lastCrankEvtTime);

      // Update Simualted Values
      cummCrankRevs += CRANK_REV_INCREMENT;
      lastCrankEvtTime += CRANK_EVT_INCREMENT;
    }

    // Get length
    sensorMeas.len = (uint8) (p - sensorMeas.pValue);

    // Send to service to send the notification
    if ( Cycling_MeasNotify( gapConnHandle, &sensorMeas ) != SUCCESS )
    {
      GATT_bm_free( (gattMsg_t *)&sensorMeas, ATT_HANDLE_VALUE_NOTI );
    }
  }
}