Esempio n. 1
0
            public static sAdbMessage Parse(byte[] data)
            {
                sAdbMessage msg    = new sAdbMessage();
                int         offset = 0;

                msg.command    = (UInt32)(data[offset++] + (data[offset++] << 8) + (data[offset++] << 16) + (data[offset++] << 24));
                msg.arg0       = (UInt32)(data[offset++] + (data[offset++] << 8) + (data[offset++] << 16) + (data[offset++] << 24));
                msg.arg1       = (UInt32)(data[offset++] + (data[offset++] << 8) + (data[offset++] << 16) + (data[offset++] << 24));
                msg.dataLength = (UInt32)(data[offset++] + (data[offset++] << 8) + (data[offset++] << 16) + (data[offset++] << 24));
                msg.dataCheck  = (UInt32)(data[offset++] + (data[offset++] << 8) + (data[offset++] << 16) + (data[offset++] << 24));
                msg.magic      = (UInt32)(data[offset++] + (data[offset++] << 8) + (data[offset++] << 16) + (data[offset++] << 24));
                return(msg);
            }
Esempio n. 2
0
        static void AdbListening()
        {
            int    count      = 0;
            string datastring = "";

            Debug.Print("Inside AdbListening");
            // Read every bInterval
            while (true)
            {
                Thread.Sleep(adbInPipe.PipeEndpoint.bInterval);

                try
                {
                    count = adbInPipe.TransferData(adbData, 0, adbData.Length);
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.ToString());
                }

                if (count == 24)
                {
                    adbInMsg = sAdbMessage.Parse(adbData);
                    switch (adbInMsg.command)
                    {
                    case A_CNXN:
                        Debug.Print("In << CNXN " + adbInMsg.arg0.ToString() + "," + adbInMsg.arg1.ToString());
                        break;

                    case A_OPEN:
                        Debug.Print("In << OPEN " + adbInMsg.arg0.ToString() + "," + adbInMsg.arg1.ToString());
                        break;

                    case A_OKAY:
                        Debug.Print("In << OKAY " + adbInMsg.arg0.ToString() + "," + adbInMsg.arg1.ToString());
                        busyWrite = false;
                        break;

                    case A_CLSE:
                        Debug.Print("In << CLSE " + adbInMsg.arg0.ToString() + "," + adbInMsg.arg1.ToString());
                        SendAdbMessage(A_OKAY, adbInMsg.arg1, adbInMsg.arg0);
                        break;

                    case A_WRTE:
                        Debug.Print("In << WRTE " + adbInMsg.arg0.ToString() + "," + adbInMsg.arg1.ToString());
                        SendAdbMessage(A_OKAY, adbInMsg.arg1, adbInMsg.arg0);
                        break;

                    default:
                        datastring = ByteArrayToString(adbData);
                        Debug.Print("In << (" + count.ToString() + ") " + datastring);
                        break;
                    }
                }
                else if (count > 0)
                {
                    adbData[count] = 0;
                    datastring     = ByteArrayToString(adbData);
                    Debug.Print("In << (" + count.ToString() + ") " + datastring);
                    switch (datastring)
                    {
                    case "device::":
                        SendAdbMessage(A_OPEN, 1, 0, portName);
                        break;

                    default:
                        string[] cmds = datastring.Split(';');
                        for (int i = 0; i < cmds.Length; i++)
                        {
                            string[] cmd = cmds[i].Split(':');
                            if (cmd.Length == 2)
                            {
                                switch (cmd[0])
                                {
                                case "x":
                                    servo1.SetPosition((byte)int.Parse(cmd[1]));
                                    break;

                                case "y":
                                    servo2.SetPosition((byte)int.Parse(cmd[1]));
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
                else if (count == 0)
                {
                    float value = myRanger.GetDistance_cm();

                    Debug.Print("myRanger reading is: " + value.ToString());
                    SendAdbMessage(A_WRTE, 1, 25, "a0:" + value.ToString() + ";");
                    Thread.Sleep(10);
                }
            }
        }