示例#1
0
        private void WriteControllerInformation(ref byte[] message_bytes, OutputControllerInformation info, uint index)
        {
            message_bytes[index++] = info.slot;
            message_bytes[index++] = info.slot_state;
            message_bytes[index++] = info.device_model;
            message_bytes[index++] = info.connection_type;

            Array.Copy(info.mac_address, 0, message_bytes, index, 6);
            index += 6;

            message_bytes[index++] = info.battery_status;
        }
示例#2
0
        private void SendPortResponseMessage(EndPoint client_endpoint)
        {
            ushort message_size = (ushort)(OutputControllerInformation.size + 1);

            byte[] output = new byte[Header.size + message_size];
            Header header = new Header();

            header.identifier       = "DSUS";
            header.protocol_version = max_protocol_version_supported;
            header.packet_size      = (ushort)(message_size + 4); // Message type is not part of the header
            header.client_id        = _server_id;
            header.message_type     = (uint)MessageType.PortResponse;
            WriteHeader(ref output, header);

            uint index = Header.size;
            OutputControllerInformation controller_information = new OutputControllerInformation();

            controller_information.slot            = 0;
            controller_information.slot_state      = 2;
            controller_information.device_model    = 2;
            controller_information.connection_type = 0;
            controller_information.mac_address     = new byte[6];
            controller_information.battery_status  = 0;
            WriteControllerInformation(ref output, controller_information, index);
            index += OutputControllerInformation.size;

            output[index] = (byte)'\0';

            WriteCrc(ref output);

            try
            {
                _socket.SendTo(output, client_endpoint);
            }
            catch (SocketException)
            {
            }
        }
示例#3
0
        private void SendPadDataResponse(EndPoint client_endpoint, uint packet_number, OpenTrackData data)
        {
            ushort message_size = (ushort)(OutputControllerInformation.size + OutputControllerData.size);

            byte[] output = new byte[Header.size + message_size];
            Header header = new Header();

            header.identifier       = "DSUS";
            header.protocol_version = max_protocol_version_supported;
            header.packet_size      = (ushort)(message_size + 4); // Message type is not part of the header
            header.client_id        = _server_id;
            header.message_type     = (uint)MessageType.PadDataResponse;
            WriteHeader(ref output, header);

            uint index = Header.size;
            OutputControllerInformation controller_information = new OutputControllerInformation();

            controller_information.slot            = 0;
            controller_information.slot_state      = 2;
            controller_information.device_model    = 2;
            controller_information.connection_type = 0;
            controller_information.mac_address     = new byte[6];
            controller_information.battery_status  = 0;
            WriteControllerInformation(ref output, controller_information, index);
            index += OutputControllerInformation.size;

            OutputControllerData controller_data = new OutputControllerData();

            controller_data.controller_connected = 1;
            controller_data.packet_number        = packet_number;
            controller_data.button_data          = 0;
            controller_data.more_button_data     = 0;
            controller_data.share_button         = 0;
            controller_data.ps_button            = 0;
            controller_data.left_stick_x         = 128;
            controller_data.left_stick_y         = 128;
            controller_data.right_stick_x        = 128;
            controller_data.right_stick_y        = 128;
            controller_data.d_pad_left           = 0;
            controller_data.d_pad_down           = 0;
            controller_data.d_pad_right          = 0;
            controller_data.d_pad_up             = 0;
            controller_data.analog_y             = 0;
            controller_data.analog_b             = 0;
            controller_data.analog_a             = 0;
            controller_data.analog_x             = 0;
            controller_data.analog_r1            = 0;
            controller_data.analog_l1            = 0;
            controller_data.analog_r2            = 0;
            controller_data.analog_l2            = 0;

            controller_data.first_touch = new OutputControllerTouchData();
            controller_data.first_touch.is_touch_active = 0;
            controller_data.first_touch.touch_id        = 0;
            controller_data.first_touch.x_pos           = 0;
            controller_data.first_touch.y_pos           = 0;

            controller_data.second_touch = new OutputControllerTouchData();
            controller_data.second_touch.is_touch_active = 0;
            controller_data.second_touch.touch_id        = 0;
            controller_data.second_touch.x_pos           = 0;
            controller_data.second_touch.y_pos           = 0;

            DateTimeOffset date_time_offset = DateTime.UtcNow;

            controller_data.motion_timestamp = date_time_offset.ToUnixTimeMilliseconds() * 1000;
            controller_data.accelerometer_x  = (float)data.x;
            controller_data.accelerometer_y  = (float)data.y;
            controller_data.accelerometer_z  = (float)data.z;
            controller_data.gyro_pitch       = (float)data.pitch;
            controller_data.gyro_yaw         = (float)data.yaw;
            controller_data.gyro_roll        = (float)data.roll;
            WriteControllerData(ref output, controller_data, index);

            WriteCrc(ref output);

            try
            {
                _socket.SendTo(output, client_endpoint);
            }
            catch (SocketException)
            {
            }
        }