示例#1
0
        //Writer : Junsuk Park
        //Function : panel1_MouseDown
        //Print the angle to display (Actually, the angle in reading from the gimbal has weird value. (Not solved..)
        private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Update the mouse path with the mouse information
            Point mouseDownLocation = new Point(e.X, e.Y);

            angle = SerialProtocol.getAngle();

            switch (e.Button)
            {
            case MouseButtons.Left:
                if (angle[1] > 360)
                {
                    //angle[1] = angle[1] - 360;
                }
                this.label8.Text = "Pitch: " + angle[1].ToString();
                if (angle[2] > 360)
                {
                    // angle[2] = angle[2] - 360;
                }
                this.label7.Text = "Yaw: " + angle[2].ToString();
                break;

            default:
                break;
            }


            panel1.Focus();
            panel1.Invalidate();
        }
示例#2
0
    static public void Main(string[] args)
    {
        // Load default file.
        Database    database    = new Database();
        DefaultFile defaultFile = new DefaultFile();

        defaultFile.LoadFromDefaultFile();
        database.Buffer = defaultFile.DefaultBuffer;
        database.Decode();
        // Tell user to physically set up the radio.
        Console.WriteLine("Connect the radio to the computer and put it in ADMS mode, then press ENTER.");
        Console.ReadLine();
        Console.WriteLine("Waiting 30 secs. because that seems to make it more likely that the transfer will not have errors:");
        for (int i = 0; i < 30; i++)
        {
            Thread.Sleep(1000);
            Console.Write(".");
        }
        Console.WriteLine();
        // Create and open serial port and receiving protocol.
        SerialPort     serialPort     = new SerialPort("/dev/ttyACM0");
        SerialProtocol serialProtocol = new SerialProtocol(serialPort, database, false);

        serialProtocol.PortOpen();
        // Read in data from radio.
        Console.WriteLine("With the radio still in ADMS mode, press the BAND button on the top-right corner of the buttons.");
        serialProtocol.Run();
        // Close connection.
        serialProtocol.PortClose();
        // Decode recieved data.
        database.Decode();
        File.WriteAllBytes("data.db", database.Buffer);
    }
        public BCCentralManager(string serialPath)
        {
            SerialPath = serialPath ?? throw new ArgumentNullException(nameof(serialPath));

            // Hookup serial protocol
            _protocol = new SerialProtocol();
            _protocol.CommandResponseReceived += (sender, responsePdu) => _responsePdu = responsePdu;
            _protocol.EventReceived           += (sender, eventPdu) => _eventPdu = eventPdu;
            _protocol.ProtocolError           += (sender, error) => _protocolError = error;
        }
        public void StartScan()
        {
            try {
                if (IsScanning)
                {
                    return;
                }

                // Check if serial is setup serial
                if (_serial == null)
                {
                    InitSerial();
                }
                if (!_serial.IsOpen)
                {
                    _serial.Open();
                }

                // Send StopScan command in case it was previously left in a scanning state
                IsScanning = true;
                SendCommand(SerialProtocol.CreateStopScanCommand());
                GetResponse(); // The actual response doesn't matter in this case, just consuming it

                // Read MAC Address (Public Bluetooth Address) of BLE Scanner
                SendCommand(SerialProtocol.CreateReadBluetoothAddressCommand());
                var response = GetResponse();
                var code     = response.ResponseCode;
                if (code != CommandResponseCode.Ack)
                {
                    throw new Exception($"Response code: {code}");
                }
                CentralBluetoothAddress = response.As <ReadBluetoothAddressCommandResponse>()?.BluetoothAddress;

                var macString = DataConverter.ByteArrayToHexString(CentralBluetoothAddress, true, ":");
                Console.WriteLine($"Staring scanning with BLE Scanner [ port={SerialPath}, mac={macString} ]");

                // Send StartScan command
                SendCommand(SerialProtocol.CreateStartScanCommand());
                response = GetResponse();
                if (response.ResponseCode != CommandResponseCode.Ack)
                {
                    throw new Exception($"Received response code: {response.ResponseCode}");
                }

                // Start polling for events in background
                _scanCancellationSource = new CancellationTokenSource();
                var cancelToken = _scanCancellationSource.Token;
                StartParsingInBackground(cancelToken);
            }
            catch {
                IsScanning = false;
            }
        }
        public void StopScan()
        {
            if (!IsScanning)
            {
                return;
            }
            if (!_scanCancellationSource.IsCancellationRequested)
            {
                _scanCancellationSource.Cancel();
            }

            // Send StopScan command to USB BLE Sniffer
            SendCommand(SerialProtocol.CreateStopScanCommand());
            var response = GetResponse();

            if (response.ResponseCode != CommandResponseCode.Ack)
            {
                throw new Exception($"Responded with: {response.ResponseCode}");
            }
            IsScanning = false;
        }
示例#6
0
            // This method will be called when the thread is started.
            public void DoWork()
            {
                while (!_shouldStop)
                {
                    //일정시간동안 setAngle()을 호출한다.
                    // 1 per 5ms, 200Hz
                    if (p != null)
                    { //한 쓰레드에 걸리는 시간 - 한 쓰레드에서 Sleep 빼고 돌아가는 시간  = 한 쓰레드의 Sleep 시간
                        long tmp = 0;
                        QueryPerformanceCounter(ref tmp);
                        SerialProtocol.setAngle(0, mouseY, mouseX, ref cCmd);

                        QueryPerformanceCounter(ref ctr);
                        herz = (double)(ctr - tmp) / (double)freq;
                    }
                    double elapsedTime = (1.0 / herz) * 1000;
                    if ((int)elapsedTime < 5)
                    {
                        Thread.Sleep(5 - (int)elapsedTime); //1 per 5ms
                    }
                }
                Console.WriteLine("worker thread: terminating gracefully.");
            }
示例#7
0
 public AdapterProtocol(string portName)
 {
     Lower = new SerialProtocol(portName);
 }