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;
        }
    }
}
Esempio n. 2
0
extern void HidSendInputReport(uint16 ucid, uint8 report_id, uint8 *report)
{
    switch(report_id)
    {
        case HID_INPUT_REPORT_ID:
        {
            uint16 data_length = ATTR_LEN_HID_INPUT_REPORT;

            /* If boot mode is enabled, change the length of the report */
            if(!hid_data.report_mode)
            {
                data_length = ATTR_LEN_HID_BOOT_INPUT_REPORT;
            }
            GattCharValueNotification(ucid,
                              hid_data.input_report_handle,
                              data_length,
                              report);
        }
        break;
    
        /* More cases can be added if the mouse supports more types of
         * reports.
         */
    }
}
extern void HeartRateSendMeasValue(uint16 ucid, uint8 hrm_length, 
                                   uint8 *p_hr_meas)
{
int i = 0;
     
    /*if(credits < 8)
        return;
        
    meas_report[1] = test++;

    uint16 testy  =  AioRead((aio_select) 1);
    meas_report[1] = testy;
    uint16* add = &testy;
    add++;
    meas_report[2] = *add;*/    

    
    
    for (i = 0; i < 1; i++) {
       /*DebugWriteString("\n\rTransmit.."); */
       GattCharValueNotification(ucid, 
              HANDLE_EEG_MEASUREMENT, 
              (uint16)16, 
              meas_report);   
       credits--;
    }
    /*credits = 0;*/

}
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);
        }
    }
}
extern void HeartRateSendMeasValue(uint16 ucid, uint8 hrm_length, 
                                   uint8 *p_hr_meas)
{
    /*  Send a notification of the HR Measurement value */
    GattCharValueNotification(ucid, 
                              HANDLE_HEART_RATE_MEASUREMENT, 
                              (uint16)hrm_length, 
                              p_hr_meas);  /* heart rate */
}
extern void ScanParamRefreshNotify(uint16 ucid)
{
    uint8 value = SERVER_REQUIRES_REFRESH;

    if(scan_param_data.refresh_client_config & gatt_client_config_notification)
    {
        GattCharValueNotification(ucid, 
                              HANDLE_SCAN_REFRESH, 
                              1, &value);
    }

}
/*-----------------------------------------------------------------------------*
 *  NAME
 *      OtaHandleAccessWrite
 *
 *  DESCRIPTION
 *      Handle write-access requests from the Host where the characteristic
 *      handle falls within the range of the OTAU Application Service.
 *
 *  PARAMETERS
 *      p_ind [in]              Write request data
 *
 *  RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
void OtaHandleAccessWrite(GATT_ACCESS_IND_T *p_ind)
{
    sys_status  rc = gatt_status_write_not_permitted;
                                    /* Function status */
        
    switch (p_ind->handle)
    {
        case HANDLE_CSR_OTA_CURRENT_APP:
        {
            /* Set the index of the current application */
            const uint8 app_id = p_ind->value[0];
                                            /* New application index */
#if defined(USE_STATIC_RANDOM_ADDRESS) || defined(USE_RESOLVABLE_RANDOM_ADDRESS)
            BD_ADDR_T   bd_addr;            /* Bluetooth Device address */

            GapGetRandomAddress(&bd_addr);
#endif /* USE_STATIC_RANDOM_ADDRESS || USE_RESOLVABLE_RANDOM_ADDRESS */
            
            rc = OtaWriteCurrentApp(app_id,
                                    IS_BONDED,
                                    &(CONN_HOST_ADDR),
                                    LINK_DIVERSIFIER,
#if defined(USE_STATIC_RANDOM_ADDRESS) || defined(USE_RESOLVABLE_RANDOM_ADDRESS)
                                    &bd_addr,
#else
                                    NULL,
#endif
                                    CONNECTION_IRK,
                                    GattServiceChangedIndActive());
            if (rc != sys_status_success)
            {
                /* Sanitise the result. If OtaWriteCurrentApp fails it will be
                 * because one or more of the supplied parameters was invalid.
                 */
                rc = gatt_status_invalid_param_value;
            }
        }
            break;
            
        case HANDLE_CSR_OTA_READ_CS_BLOCK:
            /* Set the offset and length of a block of CS to read */
            
            /* Validate input (expecting uint16[2]) */
            if (p_ind->size_value == WORDS_TO_BYTES(sizeof(uint16[2])))
            {
                const uint16 offset = BufReadUint16(&p_ind->value);
                
                data_transfer_data_length = (uint8)BufReadUint16(&p_ind->value);
            
                rc = readCsBlock(offset,
                                 data_transfer_data_length,
                                 data_transfer_memory);
            }
            else
            {
                rc = gatt_status_invalid_length;
            }
            break;
            
        case HANDLE_CSR_OTA_DATA_TRANSFER_CLIENT_CONFIG:
        {
            /* Modify the Data Transfer Client Characteristic Configuration
             * Descriptor
             */
            const uint16 client_config = BufReadUint16(&p_ind->value);
                                            /* Requested descriptor value */

            if((client_config == gatt_client_config_notification) ||
               (client_config == gatt_client_config_none))
            {
                data_transfer_configuration[0] = client_config;
                rc = sys_status_success;
            }
            else
            {
                /* INDICATION or RESERVED */

                /* Return error as only notifications are supported */
                rc = gatt_status_desc_improper_config;
            }
        }
            break;
            
        default:
            /* Writing to this characteristic is not permitted */
            break;
    }
 
    GattAccessRsp(p_ind->cid, p_ind->handle, rc, 0, NULL);
    
    /* Perform any follow-up actions */
    if (rc == sys_status_success)
    {
        switch (p_ind->handle)
        {
            case HANDLE_CSR_OTA_READ_CS_BLOCK:
                /* If this write action was to trigger a CS key read and
                 * notifications have been enabled send the result now.
                 */
                if (data_transfer_configuration[0] ==
                                                gatt_client_config_notification)
                {
                    GattCharValueNotification(CONNECTION_CID, 
                                              HANDLE_CSR_OTA_DATA_TRANSFER, 
                                              data_transfer_data_length,
                                              data_transfer_memory);
                }
                break;

            case HANDLE_CSR_OTA_CURRENT_APP:
                /* If a new application index has been requested disconnect from
                 * the Host and reset the device to run the new application.
                 */
                
                /* Record that the GATT database may be different after the
                 * device has reset.
                 */
                GattOnOtaSwitch();
                
                /* When the disconnect confirmation comes in, call OtaReset() */
                g_ota_reset_required = TRUE;

                /* Disconnect from the Host */
                GattDisconnectReq(CONNECTION_CID);
                break;

            default:
                /* No follow up action necessary */
                break;
        }
    }
}