Example #1
0
static void fill_advertising_report_from_packet(advertising_report_t * report, uint8_t *packet){
    int pos = 2;
    report->event_type = packet[pos++];
    report->address_type = packet[pos++];
    memcpy(report->address, &packet[pos], 6);
    pos += 6;
    report->rssi = packet[pos++];
    report->length = packet[pos++];
    report->data = &packet[pos];
    pos += report->length;
    dump_advertising_report(report);
    
    bd_addr_t found_device_addr;
    memcpy(found_device_addr, report->address, 6);
    swapX(found_device_addr, report->address, 6);
}
Example #2
0
void Gauss(int n , double E)
{
    int i; // 用来循环
    int k=0; //记录迭代次数
    double maxE;

    //设置初始值
    double *a = (double *)malloc(sizeof(double)*(n+1));
    for(i=1; i<=n; i++)
    {
        a[i]=0;
        printf("%d :X0=%f ,",k,a[i]);
    }

    printf("\n");
    //存放新的解
    double *temp = (double *)malloc(sizeof(double)*(n+1));
    do
    {
        CalculateG(a,temp);
        k++;
        printf("%d :",k);
        for(i=1; i<=n; i++)
        {
            printf("X%d=%f ,",i,temp[i]);
        }
        printf("\n");
        swapX(temp,a,n);
        maxE = fabs(temp[1]-a[1]);
        for(i=2; i<=n; i++)
        {
            if(maxE<fabs(temp[i]-a[i]))
                maxE = fabs(temp[i]-a[i]);
        }
    } while(maxE	>=E);
    return ;
}
Example #3
0
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
    le_command_status_t status;
    
    if (packet_type != HCI_EVENT_PACKET) return;
    
    switch (packet[0]) {
        case HCI_EVENT_DISCONNECTION_COMPLETE:
            printf("test client - DISCONNECTED\n");
            break;
        case GAP_LE_ADVERTISING_REPORT:
            if (tc_state != TC_W4_SCAN_RESULT) return;
            printf("test client - SCAN ACTIVE\n");
            ad_event_t ad_event;
            int pos = 2;
            ad_event.event_type = packet[pos++];
            ad_event.address_type = packet[pos++];
            memcpy(ad_event.address, &packet[pos], 6);
            
            pos += 6;
            ad_event.rssi = packet[pos++];
            ad_event.length = packet[pos++];
            ad_event.data = &packet[pos];
            pos += ad_event.length;
            dump_ad_event(&ad_event);
            
            test_device_addr_type = ad_event.address_type;
            bd_addr_t found_device_addr;
            
            memcpy(found_device_addr, ad_event.address, 6);
            swapX(ad_event.address, found_device_addr, 6);
            
            if (memcmp(&found_device_addr, &sensor_tag1_addr, 6) == 0
                || memcmp(&found_device_addr, &sensor_tag2_addr, 6) == 0) {
                    
                    tc_state = TC_W4_CONNECT;
                    le_central_stop_scan();
                    le_central_connect(&found_device_addr, test_device_addr_type);
            }
            break;
        case BTSTACK_EVENT_STATE:
            // BTstack activated, get started
            if (packet[2] == HCI_STATE_WORKING) {
                printf("BTstack activated, get started!\n");
                tc_state = TC_W4_SCAN_RESULT;
                le_central_start_scan(); 
            }
            break;
        case HCI_EVENT_LE_META:
            switch (packet[2]) {
                case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: {
                    if (tc_state != TC_W4_CONNECT) return;
                    tc_state = TC_W4_SERVICE_RESULT;
                    printf("\n test client - CONNECTED, query ACC service\n");
                    test_gatt_client_handle = READ_BT_16(packet, 4);
                    gatt_client_start(&test_gatt_client_context, test_gatt_client_handle);
                    
                    // let's start
                    gatt_client_discover_primary_services_by_uuid128(&test_gatt_client_context, acc_service_uuid);
                    break;
                }
                default:
                    break;
            }
            break;
            
        case DAEMON_EVENT_HCI_PACKET_SENT:
            switch(tc_state){
                case TC_W2_WRITE_WITHOUT_RESPONSE:
                    status = gatt_client_write_value_of_characteristic_without_response(&test_gatt_client_context, characteristic.value_handle, 1, chr_short_value);
                    if (status != BLE_PERIPHERAL_OK) break;
                    tc_state = TC_W4_READ_LONG_RESULT;
                    gatt_client_read_long_value_of_characteristic(&test_gatt_client_context, &characteristic);
                default:
                    break;
            } 

        default:
            break;
    }
}