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; } }
private bool SendPacket(ARCPO_Packet pP) { bool vSentSuccess = false; //for (int i = 0; !vSentSuccess && i < 3; i++) //{ vSentSuccess = mConnector.SendPacket(pP); //} return(vSentSuccess); }
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)); } }
private void FrmTokenPlaylistEditor_Load(object sender, EventArgs e) { ARCPO_Packet vP = FrmMain.sUNIQUE_INSTANCE.LatestReceivedPacket; if (vP != null) { txbLastToken.Text = vP.ContentString; } ReadCommandsFromXML(); MakeListItems(); }
/// <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); } }
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"; } }
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); }
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); }
/// <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); } }
/// <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); } }
/// <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)); }
/// <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)); }
/// <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; }