Exemple #1
0
        public static int GetMinCommandLength(CommandCodes command)
        {
            switch (command)
            {
            case CommandCodes.Ping:             return(2);

            case CommandCodes.QuerySetting:     return(2);

            case CommandCodes.UpdateSetting:    return(2);

            case CommandCodes.Swap:             return(2);

            case CommandCodes.ReadRect:         return(3);

            case CommandCodes.WriteRect:        return(3);

            case CommandCodes.CopyRect:         return(4);

            case CommandCodes.FillRect:         return(5);

            case CommandCodes.ReadMemory:       return(3);

            case CommandCodes.WriteMemory:      return(3);

            case CommandCodes.PlayFromBookmark: return(3);
            }
            throw new NotImplementedException("Unimplemented CommandCode length! (" + command + ")");
        }
Exemple #2
0
        public static int GetFullCommandLength(CommandCodes command, byte[] buffer, int offset)
        {
            switch (command)
            {
            case CommandCodes.UpdateSetting:
            {
                SettingValue setting = (SettingValue)(buffer[offset] & 0xF);
                return(GetSettingUpdateLength(setting));
            }

            case CommandCodes.WriteRect:
            {
                Target      targetBuffer;
                PixelFormat format;
                byte        x, y;
                byte        width, height;
                byte        bufferLength;
                int         headerLen = BadgeCommands.DecodeWriteRect(buffer, offset, out targetBuffer, out format, out x, out y, out width, out height, out bufferLength);
                return(headerLen + bufferLength);
            }

            case CommandCodes.WriteMemory:
            {
                byte  numDWords;
                short address;
                byte  bufferLength;
                int   headerLen = BadgeCommands.DecodeWriteMemory(buffer, offset, out address, out numDWords, out bufferLength);
                return(headerLen + bufferLength);
            }

            default: return(GetMinCommandLength(command));
            }
        }
Exemple #3
0
 /// <summary>
 /// Initialises a new instance of the <see cref="CommandData"/> class.
 /// </summary>
 /// <param name="commandCode">
 /// 16-bit command code. Must be defined in <see cref="CommandCodes"/>.
 /// </param>
 public CommandData(ushort commandCode)
 {
     if (!Enum.IsDefined(typeof(CommandCodes), (int)commandCode))
     {
         throw new Exception("Invalid command code.");
     }
     CommandCode = (CommandCodes)commandCode;
 }
Exemple #4
0
 /// <summary>
 /// Initialises a new instance of the <see cref="CommandData"/> class.
 /// </summary>
 /// <param name="commandCode">
 /// 16-bit command code. Must be defined in <see cref="CommandCodes"/>.
 /// </param>
 public CommandData(ushort commandCode)
 {
     if (!Enum.IsDefined(typeof(CommandCodes), (int)commandCode))
     {
         throw new Exception("Invalid command code.");
     }
     CommandCode = (CommandCodes)commandCode;
 }
 /// <summary>
 /// Constructs an encoded command frame.
 /// </summary>
 /// <param name="commandCode">
 /// Command code. See <see cref="CommandCodes"/>.
 /// </param>
 /// <returns>
 /// Constructed and encoded command frame.
 /// </returns>
 public static byte[] ConstructCommandFrame(CommandCodes commandCode)
 {
     byte[] decodedFrame = new byte[12] {
         (byte)FrameStart.Sart1, (byte)FrameStart.Start2, (byte)commandCode, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)FrameStop.Stop1, (byte)FrameStop.Stop2
     };
     decodedFrame = InsertChecksum(decodedFrame);
     return(FrameEncoding.EncodeFrame(decodedFrame));
 }
 /// <summary>
 /// Constructs an encoded command packet.
 /// </summary>
 /// <param name="commandCode">
 /// Command code. See <see cref="CommandCodes"/>.
 /// </param> 
 /// <returns>
 /// Constructed and encoded command packet.
 /// </returns> 
 public static byte[] ConstructCommandPacket(CommandCodes commandCode)
 {
     byte[] decodedPacket = new byte[] { (byte)PacketHeaders.Command,
                                         (byte)((ushort)commandCode >> 8),
                                         (byte)commandCode,
                                         0};
     decodedPacket = InsertChecksum(decodedPacket);
     return PacketEncoding.EncodePacket(decodedPacket);
 }
Exemple #7
0
 /// <summary>
 /// Constructs an encoded command packet.
 /// </summary>
 /// <param name="commandCode">
 /// Command code. See <see cref="CommandCodes"/>.
 /// </param>
 /// <returns>
 /// Constructed and encoded command packet.
 /// </returns>
 public static byte[] ConstructCommandPacket(CommandCodes commandCode)
 {
     byte[] decodedPacket = new byte[] { (byte)PacketHeaders.Command,
                                         (byte)((ushort)commandCode >> 8),
                                         (byte)commandCode,
                                         0 };
     decodedPacket = InsertChecksum(decodedPacket);
     return(PacketEncoding.EncodePacket(decodedPacket));
 }
Exemple #8
0
        public SignText(string text, string label = "A", Position position = Position.Fill, Mode mode = Mode.NormalAutoMode, bool priority = false)
        {
            Label    = label;
            Mode     = mode;
            Position = position;
            Text     = text;

            var modeField = $"{PacketConstants.ESC}{position.ToCode()}{Mode.ToCode()}";

            var content = Text != null
                ? $"{CommandCodes.WRITE_TEXT}{(priority ? "0" : Label)}{modeField}{Text}"
                : $"{CommandCodes.WRITE_TEXT}{(priority ? "0" : Label)}";

            _packet = new Packet(content);
        }
        private void UnpackMessage(byte [] data)
        {
            List <byte> args           = new List <byte> ();
            List <byte> status         = new List <byte> ();
            bool        separatorFound = false;

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (data.Length < 5)
            {
                throw new InvalidDataException();
            }

            if (data [0] != MARKER_START)
            {
                throw new InvalidDataException();
            }

            receivedCommand = (CommandCodes)data [3];
            for (int i = 4; i < data.Length; i++)
            {
                if (data [i] == MARKER_ARGS_END)
                {
                    break;
                }

                if (data [i] == MARKER_ARGS_SEPARATOR && !separatorFound)
                {
                    separatorFound = true;
                    continue;
                }

                if (separatorFound)
                {
                    status.Add(data [i]);
                }
                else
                {
                    args.Add(data [i]);
                }
            }

            receivedArguments = args.ToArray();
            ParseStatus(status.ToArray());
        }
        protected virtual void FMReportByNumbers(CommandCodes command, int start, int end)
        {
            start = Math.Min(start, 9999);
            start = Math.Max(start, 0);

            end = Math.Min(end, 9999);
            end = Math.Max(end, 0);

            int validStart     = Math.Min(end, start);
            int validEnd       = Math.Max(end, start);
            NumberFormatInfo n = new NumberFormatInfo {
                NumberDecimalSeparator = ".", NumberGroupSeparator = string.Empty
            };

            SendMessage(command, defaultEnc.GetBytes(
                            string.Format("{0},{1}", validStart.ToString(n), validEnd.ToString(n))));
        }
 /// <summary>
 /// Sends a basic command to the device
 /// </summary>
 /// <param name="Command">The command op-code as an enum</param>
 /// <param name="Data">Any data that goes with the command</param>
 void SendCommand(CommandCodes Command, byte[] Data = null)
 {
     byte[] Packet;
     if (Data == null)
     {
         Packet = new byte[1] {
             (byte)Command
         }
     }
     ;
     else
     {
         Packet    = new byte[1 + Data.Length];
         Packet[0] = (byte)Command;
         Array.Copy(Data, 0, Packet, 1, Data.Length);
     }
     SendPacket(PIDs.CommandPacket, Packet);
 }
 protected void SendMessage(CommandCodes command, params byte [] commandArgs)
 {
     SendMessage((byte)command, commandArgs);
 }
Exemple #13
0
 /// <summary>
 /// Initialises a new instance of the <see cref="CommandData"/> class.
 /// </summary>
 /// <param name="commandCode">
 /// Command code. See <see cref="CommandCodes"/>.
 /// </param>
 public CommandData(CommandCodes commandCode)
     : this((ushort)commandCode)
 {
 }
        private void ParseMessage(byte[] Message)
        {
            int offset, strLen;

            if (Message == null)
            {
                return;
            }

            if (Message.Count() == 0)
            {
                return;
            }

            //Log.WriteLog(Log.LogLevelType.Comm, "CommandInterface::ParseMessage(): " +
            //    "[" + m_Connection.Address + ":" + m_Connection.Port + "] " +
            //     "Found Message of " + Message.Length.ToString() + " bytes");
            // Log.HexDump(Log.LogLevelType.Comm, Message);

            offset = 0;
            while (offset < Message.Length)
            {
                CommandCodes Command = (CommandCodes)Message[0];
                offset++;   //skip past Command

                if (offset == Message.Length)
                {
                    break;
                }

                switch (Command)
                {
                case CommandCodes.COMMAND_FAILURE:
                    var ResponseErrorArgs = new CommandInterfaceResponseErrorEventArgs();
                    strLen  = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseErrorArgs.ErrorText = System.Text.Encoding.ASCII.GetString(Message, offset, strLen);
                    offset += strLen;

                    //Log.WriteLog(Log.LogLevelType.Error, "CommandInterface::ParseMessage(): " +
                    //    "[" + m_Connection.Address + ":" + m_Connection.Port + "] " +
                    //    "COMMAND_FAILURE: " + ResponseErrorArgs.ErrorText);

                    OnResponseError(ResponseErrorArgs);
                    break;

                case CommandCodes.GET_ID:
                case CommandCodes.V2_GET_ID:
                    var ResponseGetIDArgs = new CommandInterfaceResponseGetIDEventArgs();

                    strLen  = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseGetIDArgs.Name = System.Text.Encoding.ASCII.GetString(Message, offset, strLen);
                    offset += strLen;

                    ResponseGetIDArgs.ID = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseGetIDArgs.Format = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseGetIDArgs.Use        = 0;
                    ResponseGetIDArgs.ParamCount = 0;

                    if (Command == CommandCodes.V2_GET_ID)
                    {
                        ResponseGetIDArgs.Use = BitConverter.ToInt16(Message, offset);
                        offset += sizeof(Int16);

                        ResponseGetIDArgs.ParamCount = BitConverter.ToInt16(Message, offset);
                        offset += sizeof(Int16);
                    }

                    //Log.WriteLog(Log.LogLevelType.Comm, "CommandInterface::ParseMessage(): " +
                    //    "[" + m_Connection.Address + ":" + m_Connection.Port + "] " +
                    //    "GET_ID: " + ResponseGetIDArgs.Name +
                    //    " = " + ResponseGetIDArgs.ID + " (0x" + ResponseGetIDArgs.ID.ToString("X2") + ")" +
                    //   " Format: " + ResponseGetIDArgs.Format +
                    //    " Use: " + ResponseGetIDArgs.Use +
                    //   " ParamCount: " + ResponseGetIDArgs.ParamCount);

                    OnResponseGetID(ResponseGetIDArgs);
                    break;

                case CommandCodes.RUN_GET:
                case CommandCodes.V2_RUN_GET:
                    var ResponseRunGetArgs = new CommandInterfaceResponseRunGetEventArgs();

                    ResponseRunGetArgs.TransactionID = 0;

                    if (Command == CommandCodes.V2_RUN_GET)
                    {
                        ResponseRunGetArgs.TransactionID = BitConverter.ToInt16(Message, offset);
                        offset += sizeof(Int16);
                    }

                    ResponseRunGetArgs.ID = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseRunGetArgs.Param = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseRunGetArgs.Length = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseRunGetArgs.Value = Message.Skip(offset).Take(ResponseRunGetArgs.Length).ToArray();
                    offset += ResponseRunGetArgs.Length;

                    //Log.WriteLog(Log.LogLevelType.Comm, "CommandInterface::ParseMessage(): " +
                    //    "[" + m_Connection.Address + ":" + m_Connection.Port + "] " +
                    //    "RUN_GET: ID: " + ResponseRunGetArgs.ID + " (0x" + ResponseRunGetArgs.ID.ToString("X2") + ")" +
                    //    " Param: " + ResponseRunGetArgs.Param +
                    //    " Length: " + ResponseRunGetArgs.Length +
                    //    " Transaction: " + ResponseRunGetArgs.TransactionID);

                    OnResponseRunGet(ResponseRunGetArgs);
                    break;

                case CommandCodes.RUN_SET:
                case CommandCodes.V2_RUN_SET:
                    var ResponseRunSetArgs = new CommandInterfaceResponseRunSetEventArgs();

                    ResponseRunSetArgs.TransactionID = 0;

                    if (Command == CommandCodes.V2_RUN_SET)
                    {
                        ResponseRunSetArgs.TransactionID = BitConverter.ToInt16(Message, offset);
                        offset += sizeof(Int16);
                    }

                    ResponseRunSetArgs.ID = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseRunSetArgs.Param = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    ResponseRunSetArgs.Length = BitConverter.ToInt16(Message, offset);
                    offset += sizeof(Int16);

                    //Log.WriteLog(Log.LogLevelType.Comm, "CommandInterface::ParseMessage(): " +
                    //     "[" + m_Connection.Address + ":" + m_Connection.Port + "] " +
                    //    "RUN_SET: ID: " + ResponseRunSetArgs.ID + " (0x" + ResponseRunSetArgs.ID.ToString("X2") + ")" +
                    //    " Param: " + ResponseRunSetArgs.Param +
                    //     " Length: " + ResponseRunSetArgs.Length +
                    //    " Transaction: " + ResponseRunSetArgs.TransactionID);

                    OnResponseRunSet(ResponseRunSetArgs);
                    break;

                default:
                    var InvalidCommandErrorArgs = new CommandInterfaceResponseErrorEventArgs();

                    InvalidCommandErrorArgs.ErrorText = "Unimplemented Command: " + Command.ToString("X2");

                    //Log.WriteLog(Log.LogLevelType.Error, "CommandInterface::ParseMessage(): " +
                    //    "[" + m_Connection.Address + ":" + m_Connection.Port + "] " +
                    //    "INVALID_COMMAND: " + InvalidCommandErrorArgs.ErrorText);

                    OnResponseError(InvalidCommandErrorArgs);
                    break;
                }
            }
        }
Exemple #15
0
 /// <summary>
 /// Initialises a new instance of the <see cref="CommandData"/> class.
 /// </summary>
 /// <param name="commandCode">
 /// Command code. See <see cref="CommandCodes"/>.
 /// </param>
 public CommandData(CommandCodes commandCode)
     : this((ushort)commandCode)
 {
 }
Exemple #16
0
 public Command(CommandCodes code)
 {
     Channel = (byte)code;
     Value   = 0;
 }
Exemple #17
0
 /// <summary>
 /// Sends command packet.
 /// </summary>
 /// <param name="commandCode">
 /// Command data to be sent.
 /// </param> 
 public void SendCommandPacket(CommandCodes commandCode)
 {
     SendByteArray(PacketConstruction.ConstructCommandPacket(commandCode));
     PacketsWrittenCounter.CommandPackets++;
 }
 /// <summary>
 /// Sends command frame.
 /// </summary>
 /// <param name="commandCode">
 /// Command data to be sent.
 /// </param>
 public void SendCommandFrame(CommandCodes commandCode)
 {
     // TODO : ajouter la commande dans la FILE pour ACK + timer
     AddTrameOut(FrameConstruction.ConstructCommandFrame(commandCode));
     //FramesWrittenCounter.CommandFrames++;
 }
Exemple #19
0
 public void SendCommandFrame(CommandCodes commandCode)
 {
     Pss.SendCommandFrame(commandCode);
 }
Exemple #20
0
 /// <summary>
 /// Sends command packet.
 /// </summary>
 /// <param name="commandCode">
 /// Command data to be sent.
 /// </param>
 public void SendCommandPacket(CommandCodes commandCode)
 {
     SendByteArray(PacketConstruction.ConstructCommandPacket(commandCode));
     PacketsWrittenCounter.CommandPackets++;
 }