Ejemplo n.º 1
0
 /// <summary>
 /// Takes command packet's arguments and parses them to their appropriate types, returning a list of objects containing the command's arguments
 /// </summary>
 /// <param name="cmd"></param>
 /// <param name="bitArray"></param>
 /// <returns></returns>
 public static List <object> CommandPacketArgumentBitArrayToListObject(commandPacket cmd)
 {
     int[] argumentLength = Program.db.commands.Where(x => x.Key == cmd.commandID).Select(x => x.Value.argumentLengths).FirstOrDefault().ToArray();
     //helps parsing argument data into correct variable types. 1 is boolean, 2 is string 3 is integer
     byte[] argumentTypes = Program.db.commands.Where(x => x.Key == cmd.commandID).Select(x => x.Value.argumentTypes).FirstOrDefault().ToArray();
     return(BitArrayToListObject(cmd.arguments, argumentLength, argumentTypes));
 }
Ejemplo n.º 2
0
        public static void printCommandPacket(commandPacket cmd)
        {
            Console.WriteLine("\n=== PRINTING COMMAND PACKET ===\n");
            Console.WriteLine("ID: " + cmd.commandID + "\nArguments: ");

            List <object> arguments = new List <object>();

            arguments = CommandPacketArgumentBitArrayToListObject(cmd);

            foreach (object arg in arguments)
            {
                Console.WriteLine(arg.GetType() + ": " + arg.ToString());
            }
            Console.WriteLine("\n=== END OF PRINT ===\n");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Used to parse bit array data to command object
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public static commandPacket BitArrayToCommandPacket(BitArray bitArray)
        {
            //command ID always 32 bits
            int commandIDLength = 32;

            commandPacket cmd = new commandPacket();
            //ID of command to look arguments for in db
            BitArray commandIDToBits = new BitArray(commandIDLength);

            for (int k = 0; k < commandIDLength; k++)
            {
                commandIDToBits[k] = bitArray[k];
            }

            //convert sequence of bits representing command ID to int
            cmd.commandID = BitConverter.ToInt32(BitArrayToByteArray(commandIDToBits), 0);
            cmd.arguments = new BitArray(bitArray.Length - commandIDLength);
            for (int k = 0; k < cmd.arguments.Length; k++)
            {
                cmd.arguments[k] = bitArray[k + 32];
            }

            return(cmd);
        }