/*********************************************************************
* @fn      CcService_setParameter
*
* @brief   Set a Connection Control Profile parameter.
*
* @param   param - Profile parameter ID
* @param   len - length of data to write
* @param   value - pointer to data to write.  This is dependent on
*          the parameter ID and WILL be cast to the appropriate
*          data type (example: data type of uint16_t will be cast to
*          uint16_t pointer).
*
* @return  bStatus_t
*/
bStatus_t CcService_setParameter(uint8_t param, uint8_t len, void *value)
{
  bStatus_t ret = SUCCESS;

  switch (param)
  {
  case CCSERVICE_CHAR1:
    if (len == CCSERVICE_CHAR1_LEN )
    {
      memcpy(ccServiceChar1, value, CCSERVICE_CHAR1_LEN);

      // See if Notification has been enabled
      ret = GATTServApp_ProcessCharCfg( ccDataConfig, ccServiceChar1, FALSE,
                                 ccServiceAttrTbl, 
                                 GATT_NUM_ATTRS( ccServiceAttrTbl ),
                                 INVALID_TASK_ID, ccService_ReadAttrCB);
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

  case CCSERVICE_CHAR2:
    if (len == CCSERVICE_CHAR2_LEN )
    {
      // Should not write to this value other than startup
      memcpy(ccServiceChar2, value, CCSERVICE_CHAR2_LEN);
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

  case CCSERVICE_CHAR3:
    if (len == sizeof(uint8_t))
    {
      // Should not write to this value other than startup
      ccServiceChar3 = *((uint8_t*)value);
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

  default:
    ret = INVALIDPARAMETER;
    break;
  }

  return (ret);
}
Exemple #2
0
/*********************************************************************
 * @fn      ProxReporter_SetParameter
 *
 * @brief   Set a Proximity Reporter parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t ProxReporter_SetParameter(uint8 param, uint8 len, void *value)
{
  bStatus_t ret = SUCCESS;
  
  switch (param)
  {
    case PP_LINK_LOSS_ALERT_LEVEL:
      if ((len == sizeof (uint8)) && 
          ((*((uint8*)value) <= PP_ALERT_LEVEL_HIGH))) 
      {
        llAlertLevel = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    case PP_IM_ALERT_LEVEL:
      if (len == sizeof (uint8)) 
      {
        imAlertLevel = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case PP_TX_POWER_LEVEL:
      if (len == sizeof (int8)) 
      {
        txPwrLevel = *((int8*)value);

        // See if notifications have been enabled.
        GATTServApp_ProcessCharCfg(txPwrLevelConfig, (uint8 *)&txPwrLevel, 
                                   FALSE, txPwrLevelAttrTbl, 
                                   GATT_NUM_ATTRS(txPwrLevelAttrTbl),
                                   INVALID_TASK_ID, ProxReporter_ReadAttrCB);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return (ret);
}
/*********************************************************************
 * @fn      IRTemp_setParameter
 *
 * @brief   Set a parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to write
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16_t will be cast to
 *          uint16_t pointer).
 *
 * @return  bStatus_t
 */
bStatus_t IRTemp_setParameter(uint8_t param, uint8_t len, void *value)
{
  bStatus_t ret = SUCCESS;

  switch (param)
  {
    case SENSOR_DATA:
    if (len == SENSOR_DATA_LEN && memcmp(value, sensorData, len))
    {
      memcpy(sensorData, value, SENSOR_DATA_LEN);
      // See if Notification has been enabled
      ret = GATTServApp_ProcessCharCfg(sensorDataConfig, sensorData, FALSE,
                                 sensorAttrTable, 
                                 GATT_NUM_ATTRS(sensorAttrTable),
                                 INVALID_TASK_ID, sensor_ReadAttrCB);
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

    case SENSOR_CONF:
      if (len == sizeof(uint8_t))
      {
        sensorCfg = *((uint8_t*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SENSOR_PERI:
      if (len == sizeof(uint8_t))
      {
        sensorPeriod = *((uint8_t*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }

  return (ret);
}
Exemple #4
0
/*********************************************************************
 * @fn      Gyro_SetParameter
 *
 * @brief   Set a parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Gyro_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case SENSOR_DATA:
    if ( len == SENSOR_DATA_LEN )
    {
      VOID osal_memcpy( sensorData, value, SENSOR_DATA_LEN );
      // See if Notification has been enabled
      GATTServApp_ProcessCharCfg( sensorDataConfig, sensorData, FALSE,
                                 sensorAttrTable, GATT_NUM_ATTRS( sensorAttrTable ),
                                 INVALID_TASK_ID );
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

    case SENSOR_CONF:
      if ( len == sizeof ( uint8 ) )
      {
        sensorCfg = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SENSOR_PERI:
      if ( len == sizeof ( uint8 ) )
      {
        sensorPeriod = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }

  return ( ret );
}
/*********************************************************************
 * @fn      Accel_SetParameter
 *
 * @brief   Set an Accelrometer parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Accel_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case ACCELEROMETER_DATA:
    if ( len == ACCELEROMETER_DATA_LEN )
    {
      VOID osal_memcpy( accelData, value, ACCELEROMETER_DATA_LEN );
      // See if Notification has been enabled
      GATTServApp_ProcessCharCfg( accelDataConfig, accelData, FALSE,
                                 accelAttrTbl, GATT_NUM_ATTRS( accelAttrTbl ),
                                 INVALID_TASK_ID );
    }
    else
    {
      ret = bleInvalidRange;
    }
    break;

    case ACCELEROMETER_CONF:
      if ( len == sizeof ( uint8 ) )
      {
        accelCfg = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case ACCELEROMETER_PERI:
      if ( len == sizeof ( uint8 ) )
      {
        accPer = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }

  return ( ret );
}
/*********************************************************************
 * @fn      IRTemp_SetParameter
 *
 * @brief   Set a Sensor Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t IRTemp_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case IRTEMPERATURE_DATA:
      if ( len == IRTEMPERATURE_DATA_LEN )
      {
        VOID osal_memcpy( irTempData, value, IRTEMPERATURE_DATA_LEN );
        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( irTempDataConfig, irTempData, FALSE,
                                      irTempAttrTbl, GATT_NUM_ATTRS( irTempAttrTbl ),
                                      INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case IRTEMPERATURE_CONF:
      if ( len == sizeof ( uint8 ) )
      {
        irTempCfg = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
    break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }

  return ( ret );
}
Exemple #7
0
/*********************************************************************
 * @fn      Humidity_SetParameter
 *
 * @brief   Set a Sensor Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Humidity_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case HUMIDITY_DATA:
      if ( len == HUMIDITY_DATA_LEN )
      {
        VOID osal_memcpy( humidData, value, HUMIDITY_DATA_LEN );

        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( humidDataConfig, humidData, FALSE,
                                   humidAttrTbl, GATT_NUM_ATTRS( humidAttrTbl ),
                                   INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case HUMIDITY_CONF:
      if ( len == sizeof ( uint8 ) )
      {
        humidCfg = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }

  return ( ret );
}
Exemple #8
0
/*********************************************************************
 * @fn      Gyro_SetParameter
 *
 * @brief   Set a Sensor Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Gyro_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case GYROSCOPE_DATA:
      if ( len == GYROSCOPE_DATA_LEN )
      {
        VOID osal_memcpy( gyroData, value, GYROSCOPE_DATA_LEN );

        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( gyroDataConfig, gyroData, FALSE,
                                   sensorGyroscopeAttrTbl, GATT_NUM_ATTRS( sensorGyroscopeAttrTbl ),
                                   INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case GYROSCOPE_CONF:
      if(len == sizeof ( uint8 ) )
      {
        gyroCfg = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
        ret = INVALIDPARAMETER;
        break;
  }

  return ( ret );
}
Exemple #9
0
/*********************************************************************
 * @fn      TestProfile_SetParameter
 *
 * @brief   Set a Test Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16 will be cast to
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Test_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case TEST_DATA_ATTR:
      if ( len == TEST_DATA_LEN )
      {
        VOID osal_memcpy( testData, value, TEST_DATA_LEN );
        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( testDataConfig, testData, FALSE,
                                   testAttrTbl, GATT_NUM_ATTRS( testAttrTbl ),
                                   INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case TEST_CONF_ATTR:
      if(len == sizeof ( uint8 ) )
      {
        testConf = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }

  return ( ret );
}
/*********************************************************************
 * @fn      Register_setParameter
 *
 * @brief   Set a parameter.
 *
 * @param   param - Profile parameter ID (only data is applicable)
 * @param   len - length of data to write
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16_t will be cast to
 *          uint16_t pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Register_setParameter(uint8_t param, uint8_t len, void *value)
{
  bStatus_t ret = SUCCESS;

  switch (param)
  {
  case REGISTER_DATA:
    if (len <= REGISTER_DATA_LEN )
    {
      // See if Notification has been enabled
      GATTServApp_ProcessCharCfg( registerDataConfig, registerData, FALSE,
                                 sensorAttrTable, GATT_NUM_ATTRS (sensorAttrTable),
                                 INVALID_TASK_ID, sensor_ReadAttrCB);
    }
    
  default:
    ret = INVALIDPARAMETER;
    break;
  }

  return (ret);
}
Exemple #11
0
/*********************************************************************
 * @fn      TXRX_SetParameter
 *
 * @brief   Set a Simple Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t TXRX_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;
  
  switch ( param )
  {
    case TX_DATA_CHAR:
      if ( len <= 20 ) 
      {
        VOID osal_memcpy( txDataChar, value, len );
        txDataLen = len;
        
        GATTServApp_ProcessCharCfg( txrxServiceChar2Config, txDataChar, FALSE,
                      txrxAttrTbl, GATT_NUM_ATTRS( txrxAttrTbl ),
                      INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case RX_DATA_CHAR:
      if ( len == sizeof ( uint8 ) ) 
      {
        VOID osal_memcpy( rxDataChar, value, len );
        rxDataLen = len;
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    case BAUDRATE_CHAR:
      if ( len == 1 ) 
      {
        VOID osal_memcpy( &Baudrate, value, len );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    case DEV_NAME_CHAR:
      if ( len <= 20 ) 
      {
        VOID osal_memcpy( DevName, value, len );
        DevNameLen = len;
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    case VERSION_CHAR:
      {
        VOID osal_memcpy( Version, value, len );
        VersionLen = len;
      }
      break;
      
    case TX_POWER_CHAR:
      if ( len == 1 ) 
      {
        VOID osal_memcpy( &TxPower, value, len );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return ( ret );
}
/*********************************************************************
 * @fn      SimpleProfile_SetParameter
 *
 * @brief   Set a Simple Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;
  switch ( param )
  {
    case SIMPLEPROFILE_CHAR1:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar1 = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SIMPLEPROFILE_CHAR2:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar2 = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SIMPLEPROFILE_CHAR3:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar3 = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SIMPLEPROFILE_CHAR4:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar4 = *((uint8*)value);
        
        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( simpleProfileChar4Config, &simpleProfileChar4, FALSE,
                                    simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SIMPLEPROFILE_CHAR5:
      if ( len == SIMPLEPROFILE_CHAR5_LEN ) 
      {
        VOID osal_memcpy( simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
      
      case SIMPLEPROFILE_CHAR6:
      if ( len == SIMPLEPROFILE_CHAR6_LEN ) 
      {
        VOID osal_memcpy( simpleProfileChar6, value, SIMPLEPROFILE_CHAR6_LEN );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return ( ret );
}
Exemple #13
0
/*********************************************************************
 * @fn      BlueBasic_ProcessEvent
 *
 * @brief   Blue Basic Application Task event processor.  This function
 *          is called to process all events for the task.  Events
 *          include timers, messages and any other user defined events.
 *
 * @param   task_id  - The OSAL assigned task ID.
 * @param   events - events to process.  This is a bit map and can
 *                   contain more than one event.
 *
 * @return  events not processed
 */
uint16 BlueBasic_ProcessEvent( uint8 task_id, uint16 events )
{
  unsigned char i;

  VOID task_id; // OSAL required parameter that isn't used in this function

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( blueBasic_TaskID )) != NULL )
    {
      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & BLUEBASIC_START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &blueBasic_PeripheralCBs );

#ifdef GAP_BOND_MGR
    // Start Bond Manager
    VOID GAPBondMgr_Register( &blueBasic_BondMgrCBs );
#endif
    // Start monitoring links
    VOID linkDB_Register( blueBasic_HandleConnStatusCB );

#ifdef ENABLE_BLE_CONSOLE
    GATTServApp_InitCharCfg(INVALID_CONNHANDLE, consoleProfileCharCfg);
    GATTServApp_RegisterService(consoleProfile, GATT_NUM_ATTRS(consoleProfile), &consoleProfileCB);
#endif

    // Start Interpreter
    interpreter_setup();

    return ( events ^ BLUEBASIC_START_DEVICE_EVT );
  }

#ifdef ENABLE_BLE_CONSOLE
  if ( events & BLUEBASIC_CONNECTION_EVENT )
  {
    while (io.writein != io.writeout)
    {
      uint8* save = io.writeout;
      if (GATTServApp_ProcessCharCfg(consoleProfileCharCfg, io.write, FALSE, consoleProfile, GATT_NUM_ATTRS(consoleProfile), INVALID_TASK_ID) != SUCCESS)
      {
        io.writeout = save;
        break;
      }
    }
    return ( events ^ BLUEBASIC_CONNECTION_EVENT );
  }
#endif

  if ( events & BLUEBASIC_INPUT_AVAILABLE )
  {
    interpreter_loop();
    return (events ^ BLUEBASIC_INPUT_AVAILABLE);
  }

  if ( events & BLUEBASIC_EVENT_INTERRUPTS )
  {
    for (i = 0; i < OS_MAX_INTERRUPT; i++)
    {
      if (blueBasic_interrupts[i].linenum && (events & (BLUEBASIC_EVENT_INTERRUPT << i)))
      {
        interpreter_run(blueBasic_interrupts[i].linenum, 1);
      }
    }
    return (events ^ (events & BLUEBASIC_EVENT_INTERRUPTS));
  }

  if ( events & BLUEBASIC_EVENT_TIMERS )
  {
    for (i = 0; i < OS_MAX_TIMER; i++)
    {
      if (blueBasic_timers[i].linenum && (events & (BLUEBASIC_EVENT_TIMER << i)))
      {
        interpreter_run(blueBasic_timers[i].linenum, i == DELAY_TIMER ? 0 : 1);
      }
    }
    return (events ^ (events & BLUEBASIC_EVENT_TIMERS));
  }
  
  if ( events & BLUEBASIC_EVENT_SERIAL )
  {
    if (serial[0].onread && Hal_UART_RxBufLen(HAL_UART_PORT_0) > 0)
    {
      interpreter_run(serial[0].onread, 1);
    }
    if (serial[0].onwrite && Hal_UART_TxBufLen(HAL_UART_PORT_0) > 0)
    {
      interpreter_run(serial[0].onwrite, 1);
    }

    return (events ^ BLUEBASIC_EVENT_SERIAL);
  }

  // Discard unknown events
  return 0;
}
/*
 * DataService_SetParameter - Set a DataService parameter.
 *
 *    param - Profile parameter ID
 *    len   - length of data to write
 *    value - pointer to data to write.  This is dependent on
 *            the parameter ID and may be cast to the appropriate
 *            data type (example: data type of uint16_t will be cast to
 *            uint16_t pointer).
 */
bStatus_t DataService_SetParameter( uint8_t param, uint16_t len, void *value )
{
  bStatus_t ret = SUCCESS;
  uint8_t  *pAttrVal;
  uint16_t *pValLen;
  uint16_t valMinLen;
  uint16_t valMaxLen;
  uint8_t sendNotiInd = FALSE;
  gattCharCfg_t *attrConfig;
  uint8_t needAuth;

  switch ( param )
  {
    case DS_STRING_ID:
      pAttrVal  =  ds_StringVal;
      pValLen   = &ds_StringValLen;
      valMinLen =  DS_STRING_LEN_MIN;
      valMaxLen =  DS_STRING_LEN;
      Log_info2("SetParameter : %s len: %d", (IArg)"String", (IArg)len);
      break;

    case DS_STREAM_ID:
      pAttrVal  =  ds_StreamVal;
      pValLen   = &ds_StreamValLen;
      valMinLen =  DS_STREAM_LEN_MIN;
      valMaxLen =  DS_STREAM_LEN;
      sendNotiInd = TRUE;
      attrConfig  = ds_StreamConfig;
      needAuth    = FALSE; // Change if authenticated link is required for sending.
      Log_info2("SetParameter : %s len: %d", (IArg)"Stream", (IArg)len);
      break;

    default:
      Log_error1("SetParameter: Parameter #%d not valid.", (IArg)param);
      return INVALIDPARAMETER;
  }

  // Check bounds, update value and send notification or indication if possible.
  if ( len <= valMaxLen && len >= valMinLen )
  {
    memcpy(pAttrVal, value, len);
    *pValLen = len; // Update length for read and get.

    if (sendNotiInd)
    {
      Log_info2("Trying to send noti/ind: connHandle %x, %s",
                (IArg)attrConfig[0].connHandle,
                (IArg)((attrConfig[0].value==0)?"\x1b[33mNoti/ind disabled\x1b[0m" :
                       (attrConfig[0].value==1)?"Notification enabled" :
                                                "Indication enabled"));
      // Try to send notification.
      GATTServApp_ProcessCharCfg( attrConfig, pAttrVal, needAuth,
                                  Data_ServiceAttrTbl, GATT_NUM_ATTRS( Data_ServiceAttrTbl ),
                                  ds_icall_rsp_task_id,  Data_Service_ReadAttrCB);
    }
  }
  else
  {
    Log_error3("Length outside bounds: Len: %d MinLen: %d MaxLen: %d.", (IArg)len, (IArg)valMinLen, (IArg)valMaxLen);
    ret = bleInvalidRange;
  }

  return ret;
}
/*********************************************************************
 * @fn      SimpleProfile_SetParameter
 *
 * @brief   Set a Simple Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;
  switch ( param )
  {
    case SIMPLEPROFILE_CHAR1:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar1 = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SIMPLEPROFILE_CHAR2:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar2 = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SIMPLEPROFILE_CHAR3:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar3 = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SIMPLEPROFILE_CHAR4:
      if ( len == sizeof ( uint8 ) ) 
      {
        simpleProfileChar4 = *((uint8*)value);
        
        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( simpleProfileChar4Config, &simpleProfileChar4, FALSE,
                                    simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case SIMPLEPROFILE_CHAR5:
      ret = bleInvalidRange;
      break;
      
    case SIMPLEPROFILE_CHAR6:
      //LCD_WRITE_STRING_VALUE( "SetParameter 6 len=", len, 10, HAL_LCD_LINE_1 );
      //if ( len == SIMPLEPROFILE_CHAR6_LEN ) 
      if ( len <= SIMPLEPROFILE_CHAR6_LEN ) 
      {
        VOID osal_memcpy( simpleProfileChar6, value, len );
        simpleProfileChar6Len = len;
        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( simpleProfileChar6Config, simpleProfileChar6, FALSE,
                                    simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    case SIMPLEPROFILE_CHAR7:
    case SIMPLEPROFILE_CHAR8:
    case SIMPLEPROFILE_CHAR9:
    case SIMPLEPROFILE_CHARA:
      ret = bleInvalidRange;
      break;

    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return ( ret );
}
Exemple #16
0
/*********************************************************************
 * @fn      BLECTRL_SetParameter
 *
 * @brief   Set an BLECTRL Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t BLECTRL_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case BLECTRL_STATUS:
      if ( len == 3 * sizeof ( int8 ) ) 
      {  
        VOID osal_memcpy( blectrlStatus, value, len );
        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( blectrlStatusConfig, blectrlStatus,
                                    FALSE, blectrlAttrTbl, GATT_NUM_ATTRS( blectrlAttrTbl ),
                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break; 
        
    case BLECTRL_UNCLS_NOTIF:
      if ( len <= MAX_LEN ) 
      {      
        unclsNotifLength = len;
        VOID osal_memcpy( blectrlUnclsNotif, value, len );
        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( blectrlUnclsNotifConfig, blectrlUnclsNotif,
                                    FALSE, blectrlAttrTbl, GATT_NUM_ATTRS( blectrlAttrTbl ),
                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;  
      
    case BLECTRL_COMMAND:
      if ( len == sizeof ( uint8 ) ) 
        blectrlCommand = *((uint8*)value);
      else
        ret = bleInvalidRange;
      break; 
      
    case BLECTRL_SERV_UUID_LEN:
      if ( len == sizeof ( uint8 ) ) 
        blectrlServUUIDLen = *((uint8*)value);
      else
        ret = bleInvalidRange;
      break;   
      
    case BLECTRL_SERV_UUID:
      if ( len <= 16 * sizeof ( uint8 ) ) 
        VOID osal_memcpy( blectrlServUUID, value, len );
      else
        ret = bleInvalidRange;
      break;
          
    case BLECTRL_SERV_START_HDL:
      if ( len == sizeof ( uint16 ) ) 
        blectrlServStartHdl = *((uint16*)value);
      else
        ret = bleInvalidRange;
      break; 
    
    case BLECTRL_SERV_END_HDL:
      if ( len == sizeof ( uint16 ) ) 
        blectrlServEndHdl = *((uint16*)value);
      else
        ret = bleInvalidRange;
      break; 
      
    case BLECTRL_CHAR_UUID_LEN:
      if ( len == sizeof ( uint8 ) ) 
        blectrlCharUUIDLen = *((uint8*)value);
      else
        ret = bleInvalidRange;
      break;   
      
    case BLECTRL_CHAR_UUID:
      if ( len <= 16 * sizeof ( uint8 ) ) 
        VOID osal_memcpy( blectrlCharUUID, value, len );
      else
        ret = bleInvalidRange;
      break;
   
    case BLECTRL_CHAR_HDL:
      if ( len == sizeof ( uint16 ) ) 
        blectrlCharHdl = *((uint16*)value);
      else
        ret = bleInvalidRange;
      break;
      
    case BLECTRL_DATA_LEN:
      if ( len == sizeof ( uint8 ) ) 
        blectrlDataLen = *((uint8*)value);
      else
        ret = bleInvalidRange;
      break;
      
    case BLECTRL_DATA:
      if ( len <= 16 * sizeof ( uint8 ) ) 
        VOID osal_memcpy( blectrlData, value, len );
      else
        ret = bleInvalidRange;
      break;
      
    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return ( ret );
}
/*********************************************************************
 * @fn      Accel_SetParameter
 *
 * @brief   Set an Accelerometer Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Accel_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;

  switch ( param )
  {
    case ACCEL_ENABLER:
      if ( len == sizeof ( uint8 ) ) 
      {
        accelEnabled = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    case ACCEL_RANGE:
      if ( (len == sizeof ( uint16 )) && ((*((uint8*)value)) <= ACCEL_RANGE_8G) ) 
      {
        accelRange = *((uint16*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    case ACCEL_X_ATTR:
      if ( len == sizeof ( int8 ) ) 
      {      
        accelXCoordinates = *((int8*)value);

        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( accelXConfigCoordinates, (uint8 *)&accelXCoordinates,
                                    FALSE, accelAttrTbl, GATT_NUM_ATTRS( accelAttrTbl ),
                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case ACCEL_Y_ATTR:
      if ( len == sizeof ( int8 ) ) 
      {      
        accelYCoordinates = *((int8*)value);

        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( accelYConfigCoordinates, (uint8 *)&accelYCoordinates,
                                    FALSE, accelAttrTbl, GATT_NUM_ATTRS( accelAttrTbl ),
                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case ACCEL_Z_ATTR:
      if ( len == sizeof ( int8 ) ) 
      {      
        accelZCoordinates = *((int8*)value);

        // See if Notification has been enabled
        GATTServApp_ProcessCharCfg( accelZConfigCoordinates, (uint8 *)&accelZCoordinates,
                                    FALSE, accelAttrTbl, GATT_NUM_ATTRS( accelAttrTbl ),
                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return ( ret );
}
Exemple #18
0
/*********************************************************************
 * @fn      Biscuit_SetParameter
 *
 * @brief   Set a Simple Profile parameter.
 *
 * @param   param - Profile parameter ID
 * @param   len - length of data to right
 * @param   value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate 
 *          data type (example: data type of uint16 will be cast to 
 *          uint16 pointer).
 *
 * @return  bStatus_t
 */
bStatus_t Biscuit_SetParameter( uint8 param, uint8 len, void *value )
{
  bStatus_t ret = SUCCESS;
  switch ( param )
  {
    case VENDOR_NAME_CHAR:
      if ( len == sizeof ( uint8 ) ) 
      {
    //    vendorNameCharValue = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case TX_DATA_CHAR:
      if ( len <= 20 ) 
      {
        //txDataChar = *((uint8*)value);
        VOID osal_memcpy( txDataChar, value, len );
        bLen = len;
        GATTServApp_ProcessCharCfg( simpleProfileChar2Config, txDataChar, FALSE,
                      biscuitAttrTbl, GATT_NUM_ATTRS( biscuitAttrTbl ),
                      INVALID_TASK_ID );

      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case RX_DATA_CHAR:
      if ( len == sizeof ( uint8 ) ) 
      {
        rxDataChar = *((uint8*)value);
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case RESET_WRITE_CHAR:
      if ( len == sizeof ( uint8 ) ) 
      {
        resetWriteChar = *((uint8*)value);
        
        // See if Notification has been enabled
//        GATTServApp_ProcessCharCfg( simpleProfileChar4Config, &resetWriteChar, FALSE,
//                                    biscuitAttrTbl, GATT_NUM_ATTRS( biscuitAttrTbl ),
//                                    INVALID_TASK_ID );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;

    case LIB_VER_CHAR:
      if ( len == 2 ) 
      {
        VOID osal_memcpy( libVerChar, value, 2 );
      }
      else
      {
        ret = bleInvalidRange;
      }
      break;
      
    default:
      ret = INVALIDPARAMETER;
      break;
  }
  
  return ( ret );
}