Ejemplo n.º 1
0
        public override void Interprete(ARCPO_Packet pPacket)
        {
            char vKey = this.GetPacketKey(pPacket);

            switch (vKey)
            {
            case 'N':
                RunNotepad();
                break;

            case 'X':
                RunCalculatrice();
                break;

            case 'C':
                RunCmd();
                break;

            case 'Z':
                RunCharmap();
                break;

            default:
                //is it a known custom command?
                if (this.CommandRunDict.ContainsKey(vKey.ToString()))
                {
                    RunCustom(pPacket);
                }
                break;
            }
        }
Ejemplo n.º 2
0
        private bool SendPacket(ARCPO_Packet pP)
        {
            bool vSentSuccess = false;

            //for (int i = 0; !vSentSuccess && i < 3; i++)
            //{
            vSentSuccess = mConnector.SendPacket(pP);
            //}

            return(vSentSuccess);
        }
Ejemplo n.º 3
0
        public override void Interprete(ARCPO_Packet pPacket)
        {
            //is it a known custom command?
            if (this.CommandRunDict.ContainsKey(this.GetPacketKey(pPacket).ToString()))
            {
                CommandRun vCR = this.CommandRunDict[this.GetPacketKey(pPacket).ToString()];

                //Idea: use name (dictionnary of known values) and fallback interpretes ... later.
                this.SendWMAppCommand(Convert.ToInt32(vCR.mCommand));
            }
        }
Ejemplo n.º 4
0
        private void FrmTokenPlaylistEditor_Load(object sender, EventArgs e)
        {
            ARCPO_Packet vP = FrmMain.sUNIQUE_INSTANCE.LatestReceivedPacket;

            if (vP != null)
            {
                txbLastToken.Text = vP.ContentString;
            }

            ReadCommandsFromXML();

            MakeListItems();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Runs a custom command (dispatch to submethods according packet type)
        /// </summary>
        /// <param name="commandRun"></param>
        private void RunCustom(ARCPO_Packet pPacket)
        {
            CommandRun vCR = this.CommandRunDict[this.GetPacketKey(pPacket).ToString()];

            if (vCR.IsExtended)
            {
                this.RunExtendedCommand(vCR, pPacket);
            }
            else
            {
                this.RunCustom(vCR);
            }
        }
Ejemplo n.º 6
0
        private void SendPacket(ARCPO_Packet pP)
        {
            bool vSentSuccess = false;

            for (int i = 0; !vSentSuccess && i < 3; i++)
            {
                textBox1.Text += ">>Sent message " + pP.mID + " : ";

                vSentSuccess = mConnector.SendPacket(pP);

                textBox1.Text += vSentSuccess + "\r\n";
            }
        }
Ejemplo n.º 7
0
        private void SendPacket(string pContent, byte pType, byte pSubType)
        {
            ARCPO_Packet vP        = new ARCPO_Packet();
            int          vPacketId = mPacketCounter;

            vP.mType              = pType;
            vP.mID                = (byte)(mPacketCounter++ % 256);
            vP.mSubType           = pSubType;
            vP.mExpectAcknowledge = ckbAck.Checked;;
            vP.ContentString      = pContent;

            this.SendPacket(vP);
        }
Ejemplo n.º 8
0
        private void SendPacketLed(int pLed)
        {
            ARCPO_Packet vP        = new ARCPO_Packet();
            int          vPacketId = mPacketCounter;

            vP.mType              = 199;
            vP.mID                = (byte)(mPacketCounter++ % 256);
            vP.mSubType           = (byte)pLed;
            vP.mExpectAcknowledge = ckbAck.Checked;;
            vP.ContentString      = "Led : " + pLed;

            this.SendPacket(vP);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Prepares a packet based on parameters
        /// </summary>
        /// <param name="pContent"></param>
        /// <param name="pType"></param>
        /// <param name="pSubType"></param>
        /// <returns></returns>
        private ARCPO_Packet MakePacket(string pContent, byte pType, byte pSubType)
        {
            ARCPO_Packet vP        = new ARCPO_Packet();
            int          vPacketId = mPacketCounter;

            vP.mType = pType;
            //dont allow packet id to be 0!!
            vP.mID                = (byte)((mPacketCounter++ % (256 - 1)) + 1);
            vP.mSubType           = pSubType;
            vP.mExpectAcknowledge = true;
            vP.ContentString      = pContent;

            return(vP);
        }
 /// <summary>
 /// Returns the key to use to identify the intepreter
 /// </summary>
 /// <param name="pPacket"></param>
 /// <returns></returns>
 protected char GetPacketKey(ARCPO_Packet pPacket)
 {
     //is a ardTouch packet ?
     if (pPacket.mType == Constants.ARDTOUCH_TYPE && pPacket.mSubType == Constants.ARDTOUCH_SUBTYPE)
     {
         //ardTouch packet : the key is the first char of the body
         return(pPacket.mContent != null && pPacket.mContent.Length > 0 ? pPacket.ContentString[0] : (char)0);
     }
     else
     {
         //generic, use type
         return((char)pPacket.mType);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Runs an extended command, where the action is not defined only by the command type, but by also other data within the packet
        /// </summary>
        /// <param name="pPacket"></param>
        private void RunExtendedCommand(CommandRun pCR, ARCPO_Packet pPacket)
        {
            //search for the matching commandExt
            CommandRunExt vCRE = null;

            foreach (CommandRunExt vIter in pCR.mSubCommands)
            {
                if (
                    (string.IsNullOrEmpty(vIter.mPacketSubtype) || vIter.mPacketSubtype[0] == (char)pPacket.mSubType)
                    &&
                    (string.IsNullOrEmpty(vIter.mPacketBody) || vIter.mPacketBody == pPacket.ContentString)
                    )
                {
                    //found
                    vCRE = vIter;
                    break;
                }
            }

            if (vCRE != null)
            {
                RunCustom(vCRE);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// DEBUG purpose :Sends a packet and returns as string whatever is answered by arduino
        /// </summary>
        /// <param name="pPacket"></param>
        /// <returns></returns>
        public string DEBUG_SendPacketAndReturnLineContent(string pContent, byte pType, byte pSubType)
        {
            ARCPO_Packet vP = this.MakePacket(pContent, pType, pSubType);

            return(this.mConnector.DEBUG_SendPacketAndReturnLineContent(vP));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Sends a packet on the line
        /// </summary>
        /// <param name="pContent"></param>
        /// <param name="pType"></param>
        /// <param name="pSubType"></param>
        /// <returns></returns>
        private bool SendPacket(string pContent, byte pType, byte pSubType)
        {
            ARCPO_Packet vP = this.MakePacket(pContent, pType, pSubType);

            return(this.SendPacket(vP));
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Logs a message
 /// </summary>
 /// <param name="pTime"></param>
 /// <param name="pReceivedOrSent">true received, false sent</param>
 /// <param name="pPacket"></param>
 public void LogMessage(DateTime pTime, bool pReceivedOrSent, ARCPO_Packet pPacket)
 {
     txbLog.Text = (pReceivedOrSent ? "[>I N] " : "[<OUT] ") + pTime.ToLongTimeString() + " : " + pPacket.ToString() + "\r\n" + txbLog.Text;
 }