Пример #1
0
extern void BatteryUpdateLevel(uint16 ucid)
{
    uint8 old_vbat;
    uint8 cur_bat_level;

    /* Read the battery level */
    cur_bat_level = readBatteryLevel();

    old_vbat = (g_batt_data.level);

    /* If the current and old battery level are not same, update the 
     * connected host if notifications are configured.
     */
    if(old_vbat != cur_bat_level)
    {
        if((ucid != GATT_INVALID_UCID) &&
           (g_batt_data.level_client_config & gatt_client_config_notification))
        {

            GattCharValueNotification(ucid, 
                                      HANDLE_BATT_LEVEL, 
                                      1, &cur_bat_level);
            
            /* Update Battery Level characteristic in database */
            g_batt_data.level = cur_bat_level;
        }
    }
}
extern void BatteryUpdateLevel(uint16 ucid)
{
    uint8 old_vbat;
    uint8 cur_bat_level;

    /* Read the battery level and status */
    cur_bat_level = readBatteryLevel();

    old_vbat = (g_batt_data.level);

    /* check if the current and old battery level are same or not. Notify 
     * battery level only if they are different.
     */
    if(old_vbat != cur_bat_level)
    {

        if((ucid != GATT_INVALID_UCID) && AppIsLinkEncrypted() &&
          (g_batt_data.level_client_config == gatt_client_config_notification))
        {

            /* Update battery level characteristic in database */
            g_batt_data.level = cur_bat_level;

            GattCharValueNotification(ucid, 
                                      HANDLE_BATT_LEVEL, 
                                      1, &cur_bat_level);
        }
    }
}
Пример #3
0
extern void BatteryHandleAccessRead(GATT_ACCESS_IND_T *p_ind)
{
    uint16 length = 0;
    uint8 value[2];
    uint8 *p_val = NULL;
    sys_status rc = sys_status_success;

    switch(p_ind->handle)
    {
        /* Battery level is being read */
        case HANDLE_BATT_LEVEL:
        {
            /* Reading battery level */
            length = 1; /* One Octet */

            g_batt_data.level = readBatteryLevel();

            value[0] = g_batt_data.level;
        }
        break;

        /* Client Characteristic Configuration for the Battery Level 
         * Characteristic is being read 
         */
        case HANDLE_BATT_LEVEL_C_CFG:
        {
            length = 2; /* Two Octets */
            p_val = value;

            BufWriteUint16((uint8 **)&p_val, g_batt_data.level_client_config);
        }
        break;

        default:
            /* No more IRQ characteristics */
            rc = gatt_status_read_not_permitted;
        break;

    }

    /* Send Access response */
    GattAccessRsp(p_ind->cid, p_ind->handle, rc,
                  length, value);

}
Пример #4
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      BatteryHandleAccessRead
 *
 *  DESCRIPTION
 *      This function handles read operations on Battery Service attributes
 *      maintained by the application and responds with the GATT_ACCESS_RSP
 *      message.
 *
 *  PARAMETERS
 *      p_ind [in]              Data received in GATT_ACCESS_IND message.
 *
 *  RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
extern void BatteryHandleAccessRead(GATT_ACCESS_IND_T *p_ind)
{
    uint16 length = 0;                  /* Length of attribute data, octets */
    uint8  value[2];                    /* Attribute value */
    uint8 *p_val = NULL;                /* Pointer to attribute value */
    sys_status rc = sys_status_success; /* Function status */

    switch(p_ind->handle)
    {

        case HANDLE_BATT_LEVEL:
        {
            /* Read the battery level */
            length = 1; /* One Octet */

            g_batt_data.level = readBatteryLevel();

            value[0] = g_batt_data.level;
        }
        break;

        case HANDLE_BATT_LEVEL_C_CFG:
        {
            /* Read the client configuration descriptor for the battery level
             * characteristic.
             */
            length = 2; /* Two Octets */
            p_val = value;

            BufWriteUint16((uint8 **)&p_val, g_batt_data.level_client_config);
        }
        break;

        default:
            /* No more IRQ characteristics */
            rc = gatt_status_read_not_permitted;
        break;

    }

    /* Send ACCESS RESPONSE */
    GattAccessRsp(p_ind->cid, p_ind->handle, rc, length, value);

}