Beispiel #1
0
 /// <summary>
 /// Initialize the instance of AscentPacketHandler held within this class.
 /// </summary>
 /// <param name="destinationIP">Destination IP to communicate to ROCKS via. By default this is
 /// loopback, though an IP can be specified via command line args for Gazebo testing.
 /// </param>
 public static void Initialize(IPAddress destinationIP)
 {
     if (instance == null)
     {
         instance = new AscentPacketHandler(destinationIP);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Get the instance of AscentPacketHandler held within this class. If the instance has not
        /// yet been initialized, this function creates a new instance that communicates on loopback,
        /// updates the class's instance, and returns it.
        /// </summary>
        /// <returns>AscentPacketHandler - the instance of AscentPacketHandler held within this class.
        /// If no such instance exists, this function returns a new instance, using loopback to
        /// communicate.</returns>
        public static AscentPacketHandler GetInstance()
        {
            if (instance == null)
            {
                instance = new AscentPacketHandler(IPAddress.Loopback);
            }

            return(instance);
        }
        /// <summary>
        /// Send a given DriveCommand to ROCKS.
        /// </summary>
        /// <param name="driveCommand">The DriveCommand to be executed.</param>
        /// <returns>bool - If DriveCommand was successfully sent.</returns>
        public static void SendDriveCommand(DriveCommand driveCommand)
        {
            // Form payload for BCL drive command from specified DriveCommand
            byte[] bclPayload = DriveCommandToBclPayload(driveCommand);

            // Send opcode, payload to AscentPacketHandler to send drive packet to ROCKS
            AscentPacketHandler.SendPayloadToROCKS(OPCODE_ALL_WHEEL_SPEED, bclPayload, AscentPacketHandler.ROCKS_AI_SERVICE_ID);

            // For debugging
            Console.WriteLine("left: " + (sbyte)driveCommand.Left + " | right: " + (sbyte)driveCommand.Right);
        }
        public static void SendDebugAIPacket(Status status, string debugMessage)
        {
            List <byte> payload = new List <byte>();

            // if debug message is too long, truncate
            if (debugMessage.Length >= 150)
            {
                debugMessage = debugMessage.Substring(0, 150);
            }

            // convert everything to bytes
            payload.Add((byte)status);
            payload.AddRange(Encoding.ASCII.GetBytes(debugMessage));
            payload.AddRange(new byte[151 - payload.Count]); // zero extend

            AscentPacketHandler.SendPayloadToROCKS(AscentPacketHandler.OPCODE_DEBUG_AI, payload.ToArray(), AscentPacketHandler.ROCKS_AI_SERVICE_ID);
        }
        public bool HandlePacket(byte opcode, byte[] payload)
        {
            if (opcode == AscentPacketHandler.OPCODE_SIMPLE_AI)
            {
                // ACK packet
                if (payload[0] == (byte)Status.AIS_ACK)
                {
                    AscentPacketHandler.GetInstance().receivedAck = true;
                }
            }

            else if (opcode == AscentPacketHandler.OPCODE_DEBUG_AI)
            {
                //TODO
            }

            return(false);
        }
        public static void SendSimpleAIPacket(Status status, byte[] option = null)
        {
            // check whether an additional 8 bytes are specified
            option = option ?? new byte[8];

            // truncate if option is larger than 8 bytes
            if (option.Length > 8)
            {
                option = new byte[8] {
                    option[0], option[1], option[2], option[3], option[4], option[5], option[6], option[7]
                }
            }
            ;

            List <byte> payload = new List <byte>(new byte[] { (byte)status });

            payload.AddRange(option);

            AscentPacketHandler.SendPayloadToROCKS(AscentPacketHandler.OPCODE_SIMPLE_AI, payload.ToArray(), AscentPacketHandler.ROCKS_AI_SERVICE_ID);
        }