Пример #1
0
        protected BgApiEventResponse parseEventResponse(BgApiEventResponse received)
        {
            int idx = SIZE_HEADER;
            BgApiEventResponse res = null;
            int _length = received.Length;
            byte[] buffer = received.Data;

            if(received.IsEvent)
            {
                switch(received.Class)
                {
                    case (byte)ble_classes.ble_cls_system:
                        switch(received.Id)
                        {
                            case (byte)ble_event_ids.ble_evt_system_boot_id:
                                {
                                    ble_msg_system_boot_evt_t s = new ble_msg_system_boot_evt_t();
                                    s.major = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.minor = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.patch = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.build = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.ll_version = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.protocol_version = buffer[idx++];
                                    s.hw = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_system_boot(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_system_debug_id:
                                {
                                    ble_msg_system_debug_evt_t s = new ble_msg_system_debug_evt_t();
                                    s.data = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.data.Length; i++)
                                    {
                                        s.data[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_system_debug(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_system_endpoint_watermark_rx_id:
                                {
                                    ble_msg_system_endpoint_watermark_rx_evt_t s = new ble_msg_system_endpoint_watermark_rx_evt_t();
                                    s.endpoint = buffer[idx++];
                                    s.data = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_system_endpoint_watermark_rx(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_system_endpoint_watermark_tx_id:
                                {
                                    ble_msg_system_endpoint_watermark_tx_evt_t s = new ble_msg_system_endpoint_watermark_tx_evt_t();
                                    s.endpoint = buffer[idx++];
                                    s.data = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_system_endpoint_watermark_tx(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_system_script_failure_id:
                                {
                                    ble_msg_system_script_failure_evt_t s = new ble_msg_system_script_failure_evt_t();
                                    s.address = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.reason = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_system_script_failure(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_flash:
                        switch(received.Id)
                        {
                            case (byte)ble_event_ids.ble_evt_flash_ps_key_id:
                                {
                                    ble_msg_flash_ps_key_evt_t s = new ble_msg_flash_ps_key_evt_t();
                                    s.key = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.value = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.value.Length; i++)
                                    {
                                        s.value[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_flash_ps_key(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_attributes:
                        switch(received.Id)
                        {
                            case (byte)ble_event_ids.ble_evt_attributes_value_id:
                                {
                                    ble_msg_attributes_value_evt_t s = new ble_msg_attributes_value_evt_t();
                                    s.connection = buffer[idx++];
                                    s.reason = buffer[idx++];
                                    s.handle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.offset = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.value = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.value.Length; i++)
                                    {
                                        s.value[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attributes_value(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_attributes_user_read_request_id:
                                {
                                    ble_msg_attributes_user_read_request_evt_t s = new ble_msg_attributes_user_read_request_evt_t();
                                    s.connection = buffer[idx++];
                                    s.handle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.offset = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.maxsize = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attributes_user_read_request(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_attributes_status_id:
                                {
                                    ble_msg_attributes_status_evt_t s = new ble_msg_attributes_status_evt_t();
                                    s.handle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.flags = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attributes_status(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_connection:
                        switch(received.Id)
                        {
                            case (byte)ble_event_ids.ble_evt_connection_status_id:
                                {
                                    ble_msg_connection_status_evt_t s = new ble_msg_connection_status_evt_t();
                                    s.connection = buffer[idx++];
                                    s.flags = buffer[idx++];
                                    s.address = new bd_addr();
                                    for(int i = 0; i < s.address.Length; i++)
                                    {
                                        s.address.Address[i] = buffer[idx++];
                                    }
                                    s.address_type = buffer[idx++];
                                    s.conn_interval = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.timeout = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.latency = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.bonding = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_connection_status(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_connection_version_ind_id:
                                {
                                    ble_msg_connection_version_ind_evt_t s = new ble_msg_connection_version_ind_evt_t();
                                    s.connection = buffer[idx++];
                                    s.vers_nr = buffer[idx++];
                                    s.comp_id = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.sub_vers_nr = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_connection_version_ind(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_connection_feature_ind_id:
                                {
                                    ble_msg_connection_feature_ind_evt_t s = new ble_msg_connection_feature_ind_evt_t();
                                    s.connection = buffer[idx++];
                                    s.features = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.features.Length; i++)
                                    {
                                        s.features[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_connection_feature_ind(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_connection_raw_rx_id:
                                {
                                    ble_msg_connection_raw_rx_evt_t s = new ble_msg_connection_raw_rx_evt_t();
                                    s.connection = buffer[idx++];
                                    s.data = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.data.Length; i++)
                                    {
                                        s.data[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_connection_raw_rx(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_connection_disconnected_id:
                                {
                                    ble_msg_connection_disconnected_evt_t s = new ble_msg_connection_disconnected_evt_t();
                                    s.connection = buffer[idx++];
                                    s.reason = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_connection_disconnected(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_attclient:
                        switch(received.Id)
                        {
                            case (byte)ble_event_ids.ble_evt_attclient_indicated_id:
                                {
                                    ble_msg_attclient_indicated_evt_t s = new ble_msg_attclient_indicated_evt_t();
                                    s.connection = buffer[idx++];
                                    s.attrhandle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attclient_indicated(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_attclient_procedure_completed_id:
                                {
                                    ble_msg_attclient_procedure_completed_evt_t s = new ble_msg_attclient_procedure_completed_evt_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.chrhandle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attclient_procedure_completed(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_attclient_group_found_id:
                                {
                                    ble_msg_attclient_group_found_evt_t s = new ble_msg_attclient_group_found_evt_t();
                                    s.connection = buffer[idx++];
                                    s.start = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.end = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.uuid = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.uuid.Length; i++)
                                    {
                                        s.uuid[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attclient_group_found(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_attclient_attribute_found_id:
                                {
                                    ble_msg_attclient_attribute_found_evt_t s = new ble_msg_attclient_attribute_found_evt_t();
                                    s.connection = buffer[idx++];
                                    s.chrdecl = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.value = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.properties = buffer[idx++];
                                    s.uuid = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.uuid.Length; i++)
                                    {
                                        s.uuid[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attclient_attribute_found(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_attclient_find_information_found_id:
                                {
                                    ble_msg_attclient_find_information_found_evt_t s = new ble_msg_attclient_find_information_found_evt_t();
                                    s.connection = buffer[idx++];
                                    s.chrhandle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.uuid = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.uuid.Length; i++)
                                    {
                                        s.uuid[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attclient_find_information_found(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_attclient_attribute_value_id:
                                {
                                    ble_msg_attclient_attribute_value_evt_t s = new ble_msg_attclient_attribute_value_evt_t();
                                    s.connection = buffer[idx++];
                                    s.atthandle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.type = buffer[idx++];
                                    s.value = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.value.Length; i++)
                                    {
                                        s.value[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attclient_attribute_value(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_attclient_read_multiple_response_id:
                                {
                                    ble_msg_attclient_read_multiple_response_evt_t s = new ble_msg_attclient_read_multiple_response_evt_t();
                                    s.connection = buffer[idx++];
                                    s.handles = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.handles.Length; i++)
                                    {
                                        s.handles[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_attclient_read_multiple_response(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_sm:
                        switch(received.Id)
                        {
                            case (byte)ble_event_ids.ble_evt_sm_smp_data_id:
                                {
                                    ble_msg_sm_smp_data_evt_t s = new ble_msg_sm_smp_data_evt_t();
                                    s.handle = buffer[idx++];
                                    s.packet = buffer[idx++];
                                    s.data = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.data.Length; i++)
                                    {
                                        s.data[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_sm_smp_data(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_sm_bonding_fail_id:
                                {
                                    ble_msg_sm_bonding_fail_evt_t s = new ble_msg_sm_bonding_fail_evt_t();
                                    s.handle = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_sm_bonding_fail(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_sm_passkey_display_id:
                                {
                                    ble_msg_sm_passkey_display_evt_t s = new ble_msg_sm_passkey_display_evt_t();
                                    s.handle = buffer[idx++];
                                    s.passkey = buffer[idx+0] | (buffer[idx+1] << 8) | (buffer[idx+2] << 16) | (buffer[idx+3] << 24); idx+=4;
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_sm_passkey_display(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_sm_passkey_request_id:
                                {
                                    ble_msg_sm_passkey_request_evt_t s = new ble_msg_sm_passkey_request_evt_t();
                                    s.handle = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_sm_passkey_request(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_sm_bond_status_id:
                                {
                                    ble_msg_sm_bond_status_evt_t s = new ble_msg_sm_bond_status_evt_t();
                                    s.bond = buffer[idx++];
                                    s.keysize = buffer[idx++];
                                    s.mitm = buffer[idx++];
                                    s.keys = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_sm_bond_status(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_gap:
                        switch(received.Id)
                        {
                            case (byte)ble_event_ids.ble_evt_gap_scan_response_id:
                                {
                                    ble_msg_gap_scan_response_evt_t s = new ble_msg_gap_scan_response_evt_t();
                                    s.rssi = buffer[idx++];
                                    s.packet_type = buffer[idx++];
                                    s.sender = new bd_addr();
                                    for(int i = 0; i < s.sender.Length; i++)
                                    {
                                        s.sender.Address[i] = buffer[idx++];
                                    }
                                    s.address_type = buffer[idx++];
                                    s.bond = buffer[idx++];
                                    s.data = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.data.Length; i++)
                                    {
                                        s.data[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_gap_scan_response(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_gap_mode_changed_id:
                                {
                                    ble_msg_gap_mode_changed_evt_t s = new ble_msg_gap_mode_changed_evt_t();
                                    s.discover = buffer[idx++];
                                    s.connect = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_gap_mode_changed(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_hardware:
                        switch(received.Id)
                        {
                            case (byte)ble_event_ids.ble_evt_hardware_io_port_status_id:
                                {
                                    ble_msg_hardware_io_port_status_evt_t s = new ble_msg_hardware_io_port_status_evt_t();
                                    s.timestamp = buffer[idx+0] | (buffer[idx+1] << 8) | (buffer[idx+2] << 16) | (buffer[idx+3] << 24); idx+=4;
                                    s.port = buffer[idx++];
                                    s.irq = buffer[idx++];
                                    s.state = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_hardware_io_port_status(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_hardware_soft_timer_id:
                                {
                                    ble_msg_hardware_soft_timer_evt_t s = new ble_msg_hardware_soft_timer_evt_t();
                                    s.handle = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_hardware_soft_timer(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_event_ids.ble_evt_hardware_adc_result_id:
                                {
                                    ble_msg_hardware_adc_result_evt_t s = new ble_msg_hardware_adc_result_evt_t();
                                    s.input = buffer[idx++];
                                    s.value = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    ble_evt_hardware_adc_result(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_test:
                        switch(received.Id)
                        {
                            default:
                                throw new BgApiException(string.Format("Unknown event id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    default:
                        throw new BgApiException(string.Format("Unknown class 0x{0}", buffer[2].ToString("X2")));
                }
            }
            else if(!received.IsEvent)
            {
                switch(received.Class)
                {
                    case (byte)ble_classes.ble_cls_system:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_system_hello_id:
                                {
                                    ble_msg_system_hello_rsp_t s = new ble_msg_system_hello_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_hello(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_address_get_id:
                                {
                                    ble_msg_system_address_get_rsp_t s = new ble_msg_system_address_get_rsp_t();
                                    s.address = new bd_addr();
                                    for(int i = 0; i < s.address.Length; i++)
                                    {
                                        s.address.Address[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_address_get(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_reg_write_id:
                                {
                                    ble_msg_system_reg_write_rsp_t s = new ble_msg_system_reg_write_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_reg_write(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_reg_read_id:
                                {
                                    ble_msg_system_reg_read_rsp_t s = new ble_msg_system_reg_read_rsp_t();
                                    s.address = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.value = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_reg_read(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_get_counters_id:
                                {
                                    ble_msg_system_get_counters_rsp_t s = new ble_msg_system_get_counters_rsp_t();
                                    s.txok = buffer[idx++];
                                    s.txretry = buffer[idx++];
                                    s.rxok = buffer[idx++];
                                    s.rxfail = buffer[idx++];
                                    s.mbuf = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_get_counters(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_get_connections_id:
                                {
                                    ble_msg_system_get_connections_rsp_t s = new ble_msg_system_get_connections_rsp_t();
                                    s.maxconn = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_get_connections(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_read_memory_id:
                                {
                                    ble_msg_system_read_memory_rsp_t s = new ble_msg_system_read_memory_rsp_t();
                                    s.address = buffer[idx+0] | (buffer[idx+1] << 8) | (buffer[idx+2] << 16) | (buffer[idx+3] << 24); idx+=4;
                                    s.data = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.data.Length; i++)
                                    {
                                        s.data[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_read_memory(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_get_info_id:
                                {
                                    ble_msg_system_get_info_rsp_t s = new ble_msg_system_get_info_rsp_t();
                                    s.major = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.minor = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.patch = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.build = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.ll_version = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.protocol_version = buffer[idx++];
                                    s.hw = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_get_info(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_endpoint_tx_id:
                                {
                                    ble_msg_system_endpoint_tx_rsp_t s = new ble_msg_system_endpoint_tx_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_endpoint_tx(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_whitelist_append_id:
                                {
                                    ble_msg_system_whitelist_append_rsp_t s = new ble_msg_system_whitelist_append_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_whitelist_append(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_whitelist_remove_id:
                                {
                                    ble_msg_system_whitelist_remove_rsp_t s = new ble_msg_system_whitelist_remove_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_whitelist_remove(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_whitelist_clear_id:
                                {
                                    ble_msg_system_whitelist_clear_rsp_t s = new ble_msg_system_whitelist_clear_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_whitelist_clear(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_endpoint_rx_id:
                                {
                                    ble_msg_system_endpoint_rx_rsp_t s = new ble_msg_system_endpoint_rx_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.data = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.data.Length; i++)
                                    {
                                        s.data[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_endpoint_rx(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_system_endpoint_set_watermarks_id:
                                {
                                    ble_msg_system_endpoint_set_watermarks_rsp_t s = new ble_msg_system_endpoint_set_watermarks_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_system_endpoint_set_watermarks(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_flash:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_flash_ps_defrag_id:
                                {
                                    ble_msg_flash_ps_defrag_rsp_t s = new ble_msg_flash_ps_defrag_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_flash_ps_defrag(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_flash_ps_dump_id:
                                {
                                    ble_msg_flash_ps_dump_rsp_t s = new ble_msg_flash_ps_dump_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_flash_ps_dump(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_flash_ps_erase_all_id:
                                {
                                    ble_msg_flash_ps_erase_all_rsp_t s = new ble_msg_flash_ps_erase_all_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_flash_ps_erase_all(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_flash_ps_save_id:
                                {
                                    ble_msg_flash_ps_save_rsp_t s = new ble_msg_flash_ps_save_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_flash_ps_save(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_flash_ps_load_id:
                                {
                                    ble_msg_flash_ps_load_rsp_t s = new ble_msg_flash_ps_load_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.value = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.value.Length; i++)
                                    {
                                        s.value[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_flash_ps_load(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_flash_ps_erase_id:
                                {
                                    ble_msg_flash_ps_erase_rsp_t s = new ble_msg_flash_ps_erase_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_flash_ps_erase(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_flash_erase_page_id:
                                {
                                    ble_msg_flash_erase_page_rsp_t s = new ble_msg_flash_erase_page_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_flash_erase_page(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_flash_write_words_id:
                                {
                                    ble_msg_flash_write_words_rsp_t s = new ble_msg_flash_write_words_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_flash_write_words(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_attributes:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_attributes_write_id:
                                {
                                    ble_msg_attributes_write_rsp_t s = new ble_msg_attributes_write_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attributes_write(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attributes_read_id:
                                {
                                    ble_msg_attributes_read_rsp_t s = new ble_msg_attributes_read_rsp_t();
                                    s.handle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.offset = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.value = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.value.Length; i++)
                                    {
                                        s.value[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attributes_read(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attributes_read_type_id:
                                {
                                    ble_msg_attributes_read_type_rsp_t s = new ble_msg_attributes_read_type_rsp_t();
                                    s.handle = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.value = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.value.Length; i++)
                                    {
                                        s.value[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attributes_read_type(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attributes_user_read_response_id:
                                {
                                    ble_msg_attributes_user_read_response_rsp_t s = new ble_msg_attributes_user_read_response_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attributes_user_read_response(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attributes_user_write_response_id:
                                {
                                    ble_msg_attributes_user_write_response_rsp_t s = new ble_msg_attributes_user_write_response_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attributes_user_write_response(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_connection:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_connection_disconnect_id:
                                {
                                    ble_msg_connection_disconnect_rsp_t s = new ble_msg_connection_disconnect_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_disconnect(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_connection_get_rssi_id:
                                {
                                    ble_msg_connection_get_rssi_rsp_t s = new ble_msg_connection_get_rssi_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.rssi = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_get_rssi(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_connection_update_id:
                                {
                                    ble_msg_connection_update_rsp_t s = new ble_msg_connection_update_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_update(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_connection_version_update_id:
                                {
                                    ble_msg_connection_version_update_rsp_t s = new ble_msg_connection_version_update_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_version_update(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_connection_channel_map_get_id:
                                {
                                    ble_msg_connection_channel_map_get_rsp_t s = new ble_msg_connection_channel_map_get_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.map = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.map.Length; i++)
                                    {
                                        s.map[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_channel_map_get(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_connection_channel_map_set_id:
                                {
                                    ble_msg_connection_channel_map_set_rsp_t s = new ble_msg_connection_channel_map_set_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_channel_map_set(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_connection_features_get_id:
                                {
                                    ble_msg_connection_features_get_rsp_t s = new ble_msg_connection_features_get_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_features_get(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_connection_get_status_id:
                                {
                                    ble_msg_connection_get_status_rsp_t s = new ble_msg_connection_get_status_rsp_t();
                                    s.connection = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_get_status(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_connection_raw_tx_id:
                                {
                                    ble_msg_connection_raw_tx_rsp_t s = new ble_msg_connection_raw_tx_rsp_t();
                                    s.connection = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_connection_raw_tx(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_attclient:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_attclient_find_by_type_value_id:
                                {
                                    ble_msg_attclient_find_by_type_value_rsp_t s = new ble_msg_attclient_find_by_type_value_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_find_by_type_value(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_read_by_group_type_id:
                                {
                                    ble_msg_attclient_read_by_group_type_rsp_t s = new ble_msg_attclient_read_by_group_type_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_read_by_group_type(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_read_by_type_id:
                                {
                                    ble_msg_attclient_read_by_type_rsp_t s = new ble_msg_attclient_read_by_type_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_read_by_type(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_find_information_id:
                                {
                                    ble_msg_attclient_find_information_rsp_t s = new ble_msg_attclient_find_information_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_find_information(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_read_by_handle_id:
                                {
                                    ble_msg_attclient_read_by_handle_rsp_t s = new ble_msg_attclient_read_by_handle_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_read_by_handle(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_attribute_write_id:
                                {
                                    ble_msg_attclient_attribute_write_rsp_t s = new ble_msg_attclient_attribute_write_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_attribute_write(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_write_command_id:
                                {
                                    ble_msg_attclient_write_command_rsp_t s = new ble_msg_attclient_write_command_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_write_command(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_indicate_confirm_id:
                                {
                                    ble_msg_attclient_indicate_confirm_rsp_t s = new ble_msg_attclient_indicate_confirm_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_indicate_confirm(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_read_long_id:
                                {
                                    ble_msg_attclient_read_long_rsp_t s = new ble_msg_attclient_read_long_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_read_long(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_prepare_write_id:
                                {
                                    ble_msg_attclient_prepare_write_rsp_t s = new ble_msg_attclient_prepare_write_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_prepare_write(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_execute_write_id:
                                {
                                    ble_msg_attclient_execute_write_rsp_t s = new ble_msg_attclient_execute_write_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_execute_write(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_attclient_read_multiple_id:
                                {
                                    ble_msg_attclient_read_multiple_rsp_t s = new ble_msg_attclient_read_multiple_rsp_t();
                                    s.connection = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_attclient_read_multiple(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_sm:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_sm_encrypt_start_id:
                                {
                                    ble_msg_sm_encrypt_start_rsp_t s = new ble_msg_sm_encrypt_start_rsp_t();
                                    s.handle = buffer[idx++];
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_sm_encrypt_start(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_sm_set_bondable_mode_id:
                                {
                                    ble_msg_sm_set_bondable_mode_rsp_t s = new ble_msg_sm_set_bondable_mode_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_sm_set_bondable_mode(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_sm_delete_bonding_id:
                                {
                                    ble_msg_sm_delete_bonding_rsp_t s = new ble_msg_sm_delete_bonding_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_sm_delete_bonding(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_sm_set_parameters_id:
                                {
                                    ble_msg_sm_set_parameters_rsp_t s = new ble_msg_sm_set_parameters_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_sm_set_parameters(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_sm_passkey_entry_id:
                                {
                                    ble_msg_sm_passkey_entry_rsp_t s = new ble_msg_sm_passkey_entry_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_sm_passkey_entry(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_sm_get_bonds_id:
                                {
                                    ble_msg_sm_get_bonds_rsp_t s = new ble_msg_sm_get_bonds_rsp_t();
                                    s.bonds = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_sm_get_bonds(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_sm_set_oob_data_id:
                                {
                                    ble_msg_sm_set_oob_data_rsp_t s = new ble_msg_sm_set_oob_data_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_sm_set_oob_data(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_gap:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_gap_set_privacy_flags_id:
                                {
                                    ble_msg_gap_set_privacy_flags_rsp_t s = new ble_msg_gap_set_privacy_flags_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_set_privacy_flags(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_set_mode_id:
                                {
                                    ble_msg_gap_set_mode_rsp_t s = new ble_msg_gap_set_mode_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_set_mode(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_discover_id:
                                {
                                    ble_msg_gap_discover_rsp_t s = new ble_msg_gap_discover_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_discover(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_connect_direct_id:
                                {
                                    ble_msg_gap_connect_direct_rsp_t s = new ble_msg_gap_connect_direct_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.connection_handle = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_connect_direct(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_end_procedure_id:
                                {
                                    ble_msg_gap_end_procedure_rsp_t s = new ble_msg_gap_end_procedure_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_end_procedure(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_connect_selective_id:
                                {
                                    ble_msg_gap_connect_selective_rsp_t s = new ble_msg_gap_connect_selective_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.connection_handle = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_connect_selective(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_set_filtering_id:
                                {
                                    ble_msg_gap_set_filtering_rsp_t s = new ble_msg_gap_set_filtering_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_set_filtering(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_set_scan_parameters_id:
                                {
                                    ble_msg_gap_set_scan_parameters_rsp_t s = new ble_msg_gap_set_scan_parameters_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_set_scan_parameters(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_set_adv_parameters_id:
                                {
                                    ble_msg_gap_set_adv_parameters_rsp_t s = new ble_msg_gap_set_adv_parameters_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_set_adv_parameters(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_set_adv_data_id:
                                {
                                    ble_msg_gap_set_adv_data_rsp_t s = new ble_msg_gap_set_adv_data_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_set_adv_data(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_gap_set_directed_connectable_mode_id:
                                {
                                    ble_msg_gap_set_directed_connectable_mode_rsp_t s = new ble_msg_gap_set_directed_connectable_mode_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_gap_set_directed_connectable_mode(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_hardware:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_hardware_io_port_config_irq_id:
                                {
                                    ble_msg_hardware_io_port_config_irq_rsp_t s = new ble_msg_hardware_io_port_config_irq_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_io_port_config_irq(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_set_soft_timer_id:
                                {
                                    ble_msg_hardware_set_soft_timer_rsp_t s = new ble_msg_hardware_set_soft_timer_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_set_soft_timer(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_adc_read_id:
                                {
                                    ble_msg_hardware_adc_read_rsp_t s = new ble_msg_hardware_adc_read_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_adc_read(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_io_port_config_direction_id:
                                {
                                    ble_msg_hardware_io_port_config_direction_rsp_t s = new ble_msg_hardware_io_port_config_direction_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_io_port_config_direction(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_io_port_config_function_id:
                                {
                                    ble_msg_hardware_io_port_config_function_rsp_t s = new ble_msg_hardware_io_port_config_function_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_io_port_config_function(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_io_port_config_pull_id:
                                {
                                    ble_msg_hardware_io_port_config_pull_rsp_t s = new ble_msg_hardware_io_port_config_pull_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_io_port_config_pull(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_io_port_write_id:
                                {
                                    ble_msg_hardware_io_port_write_rsp_t s = new ble_msg_hardware_io_port_write_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_io_port_write(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_io_port_read_id:
                                {
                                    ble_msg_hardware_io_port_read_rsp_t s = new ble_msg_hardware_io_port_read_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.port = buffer[idx++];
                                    s.data = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_io_port_read(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_spi_config_id:
                                {
                                    ble_msg_hardware_spi_config_rsp_t s = new ble_msg_hardware_spi_config_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_spi_config(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_spi_transfer_id:
                                {
                                    ble_msg_hardware_spi_transfer_rsp_t s = new ble_msg_hardware_spi_transfer_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.channel = buffer[idx++];
                                    s.data = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.data.Length; i++)
                                    {
                                        s.data[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_spi_transfer(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_i2c_read_id:
                                {
                                    ble_msg_hardware_i2c_read_rsp_t s = new ble_msg_hardware_i2c_read_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    s.data = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.data.Length; i++)
                                    {
                                        s.data[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_i2c_read(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_i2c_write_id:
                                {
                                    ble_msg_hardware_i2c_write_rsp_t s = new ble_msg_hardware_i2c_write_rsp_t();
                                    s.written = buffer[idx++];
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_i2c_write(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_set_txpower_id:
                                {
                                    ble_msg_hardware_set_txpower_rsp_t s = new ble_msg_hardware_set_txpower_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_set_txpower(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_hardware_timer_comparator_id:
                                {
                                    ble_msg_hardware_timer_comparator_rsp_t s = new ble_msg_hardware_timer_comparator_rsp_t();
                                    s.result = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_hardware_timer_comparator(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    case (byte)ble_classes.ble_cls_test:
                        switch(received.Id)
                        {
                            case (byte)ble_command_ids.ble_cmd_test_phy_tx_id:
                                {
                                    ble_msg_test_phy_tx_rsp_t s = new ble_msg_test_phy_tx_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_test_phy_tx(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_test_phy_rx_id:
                                {
                                    ble_msg_test_phy_rx_rsp_t s = new ble_msg_test_phy_rx_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_test_phy_rx(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_test_phy_end_id:
                                {
                                    ble_msg_test_phy_end_rsp_t s = new ble_msg_test_phy_end_rsp_t();
                                    s.counter = buffer[idx+0] | (buffer[idx+1] << 8); idx+=2;
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_test_phy_end(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_test_phy_reset_id:
                                {
                                    ble_msg_test_phy_reset_rsp_t s = new ble_msg_test_phy_reset_rsp_t();
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_test_phy_reset(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_test_get_channel_map_id:
                                {
                                    ble_msg_test_get_channel_map_rsp_t s = new ble_msg_test_get_channel_map_rsp_t();
                                    s.channel_map = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.channel_map.Length; i++)
                                    {
                                        s.channel_map[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_test_get_channel_map(s);
                                    res = s;
                                }
                                break;
                            case (byte)ble_command_ids.ble_cmd_test_debug_id:
                                {
                                    ble_msg_test_debug_rsp_t s = new ble_msg_test_debug_rsp_t();
                                    s.output = new byte[buffer[idx++]];
                                    for(int i = 0; i < s.output.Length; i++)
                                    {
                                        s.output[i] = buffer[idx++];
                                    }
                                    check(idx, SIZE_HEADER + _length);
                                    //ble_cmd_test_debug(s);
                                    res = s;
                                }
                                break;
                            default:
                                throw new BgApiException(string.Format("Unknown response id 0x{0}", buffer[3].ToString("X2")));
                        }
                        break;
                    default:
                        throw new BgApiException(string.Format("Unknown class 0x{0}", buffer[2].ToString("X2")));
                }
            }
            res.Data = received.Data;
            return res;
        }
Пример #2
0
 protected virtual void ble_evt_attclient_procedure_completed(ble_msg_attclient_procedure_completed_evt_t arg)
 {
     log("ble_evt_attclient_procedure_completed");
 }