//********************************************************************** public void executeGo1(CmdLineCmd aCmd) { string tString = aCmd.argString(1); bool tPass = MyFunctions.IsValidIPAddress(tString); Prn.print(0, "{0} {1}", tString, tPass); }
//********************************************************************** //********************************************************************** //********************************************************************** // Receive message handlers public override void processRxMsg(ByteContent aMsg) { BaseMsg tRxMsg = (BaseMsg)aMsg; // Message jump table based on message type. // Calls corresponding specfic message handler method. switch (tRxMsg.mMessageType) { case MsgIdT.cTestMsg: processRxMsg((TestMsg)tRxMsg); break; case MsgIdT.cStatusRequestMsg: processRxMsg((StatusRequestMsg)tRxMsg); break; case MsgIdT.cStatusResponseMsg: processRxMsg((StatusResponseMsg)tRxMsg); break; case MsgIdT.cDataMsg: processRxMsg((DataMsg)tRxMsg); break; default: Prn.print(Prn.ThreadRun1, "NetworkThread.processRxMsg UNKNOWN"); break; } }
//********************************************************************** //********************************************************************** //********************************************************************** // Configure the socket. public void configure(BaseMsgMonkeyCreator aMonkeyCreator, String aAddress, int aPort) { mMonkey = aMonkeyCreator.createNew(); mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); mIPEndPoint = new IPEndPoint(IPAddress.Parse(aAddress), aPort); Prn.print(Prn.SocketInit2, "UdpTxMsgSocket $ {0,16} : {1}", mIPEndPoint.Address.ToString(), mIPEndPoint.Port); }
//********************************************************************** //********************************************************************** //********************************************************************** // Configure the socket. public void configure(BaseMsgMonkeyCreator aMonkeyCreator, String aAddress, int aPort) { mMonkey = aMonkeyCreator.createNew(); mUdpClient = new UdpClient(aPort); mIPEndPoint = new IPEndPoint(IPAddress.Parse(aAddress), aPort); Prn.print(Prn.SocketInit2, "UdpRxMsgSocket $ {0,16} : {1}", mIPEndPoint.Address.ToString(), mIPEndPoint.Port); }
//********************************************************************** //********************************************************************** //********************************************************************** // Launch thread. public void start() { Prn.print(Prn.View11, "TIMER START"); // Create new thread object using thread run function mThread = new Thread(new ThreadStart(threadRun)); // Start the thread mThread.Start(); }
public static void show(TestMsg aMsg) { Prn.print(Prn.ThreadRun1, "ProtoComm.TestMsg"); Prn.print(Prn.ThreadRun1, "Code1 {0}", aMsg.mCode1); Prn.print(Prn.ThreadRun1, "Code2 {0}", aMsg.mCode2); Prn.print(Prn.ThreadRun1, "Code3 {0}", aMsg.mCode3); Prn.print(Prn.ThreadRun1, "Code4 {0}", aMsg.mCode4); }
public static void show(DataRecord aMsg) { Prn.print(Prn.ThreadRun1, "ProtoCommMsg.DataRecord"); Prn.print(Prn.ThreadRun1, "Code1 {0}", aMsg.mCode1); Prn.print(Prn.ThreadRun1, "Code2 {0}", aMsg.mCode2); Prn.print(Prn.ThreadRun1, "Code3 {0}", aMsg.mCode3); Prn.print(Prn.ThreadRun1, "Code4 {0}", aMsg.mCode4); }
//********************************************************************** //********************************************************************** //********************************************************************** // Thread run function. public void threadRun() { while (!mTerminate) { Thread.Sleep(1000); Prn.print(Prn.View11, "TIMER {0}", mCount++); } }
public static void show(StatusRequestMsg aMsg) { Prn.print(Prn.ThreadRun1, "ProtoCommMsg.StatusMsg"); Prn.print(Prn.ThreadRun1, "Code1 {0}", aMsg.mCode1); Prn.print(Prn.ThreadRun1, "Code2 {0}", aMsg.mCode2); Prn.print(Prn.ThreadRun1, "Code3 {0}", aMsg.mCode3); Prn.print(Prn.ThreadRun1, "Code4 {0}", aMsg.mCode4); for (int i = 0; i < aMsg.mNumOfWords; i++) { Prn.print(Prn.ThreadRun1, "Words {0} {1}", 1, aMsg.mWords[i]); aMsg.mWords[i] = 101 + i; } }
public static void show(DataMsg aMsg) { Prn.print(Prn.ThreadRun1, "ProtoCommMsg.DataMsg"); Console.WriteLine("UChar {0:X}", aMsg.mUChar); Console.WriteLine("UShort {0:X}", aMsg.mUShort); Console.WriteLine("UInt {0:X}", aMsg.mUInt); Console.WriteLine("Unit64 {0:X}", aMsg.mUInt64); Console.WriteLine("Char {0:X}", aMsg.mChar); Console.WriteLine("Short {0:X}", aMsg.mShort); Console.WriteLine("Int {0:X}", aMsg.mInt); Console.WriteLine("Int64 {0:X}", aMsg.mInt64); Console.WriteLine("Float {0}", aMsg.mFloat); Console.WriteLine("Double {0}", aMsg.mDouble); Console.WriteLine("Bool {0}", aMsg.mBool); Console.WriteLine("String {0}", aMsg.mString1); Console.WriteLine("String {0}", aMsg.mString2); Console.WriteLine(""); show(aMsg.mDataRecord); Console.WriteLine(""); }
//********************************************************************** //********************************************************************** //********************************************************************** // Send message to the socket. public void sendMsg(ByteContent aMsg) { //------------------------------------------------------------------ // Create byte buffer. ByteBuffer tBuffer = new ByteBuffer(mMonkey.getMaxBufferSize()); // Copy message to buffer. mMonkey.putMsgToBuffer(tBuffer, aMsg); //------------------------------------------------------------------ // Send buffer to socket. byte[] tTxBytes = tBuffer.getBaseAddress(); int tTxLength = tBuffer.getPosition(); try { int tSent = mSocket.SendTo(tTxBytes, tTxLength, SocketFlags.None, mIPEndPoint); Prn.print(Prn.SocketRun2, "UdpTxSocket tx message {0}", tSent); } catch { Prn.print(Prn.SocketRun2, "UdpTxSocket Send ERROR"); } }
//********************************************************************** //********************************************************************** //********************************************************************** // Shutdown thread. public void stop() { mTerminate = true; Prn.print(Prn.View11, "TIMER STOP"); }
public void Show() { // Amp A. Prn.print(0, " Factory Test Settings************************************"); Prn.print(0, "CommPort {0}", CommPort); }
public static void show(FirstMessageMsg aMsg) { Prn.print(Prn.ThreadRun1, "ProtoComm.FirstMessageMsg"); Prn.print(Prn.ThreadRun1, "Code1 {0}", aMsg.mCode1); }
//********************************************************************** public void executeGo2(CmdLineCmd aCmd) { Prn.print(0, "TESTING"); }
//****************************************************************************** // Rx message handler - StatusResponseMsg void processRxMsg(StatusResponseMsg aMsg) { Prn.print(Prn.ThreadRun1, "NetworkThread.processRxMsg_StatusResponseMsg"); Helper.show(aMsg); }
//********************************************************************** public void executeGo3(CmdLineCmd aCmd) { Console.WriteLine("PrintView2.exe stopping"); Prn.print(0, "PRINTVIEW_SHUTDOWN"); }
//********************************************************************** public void executeGo2(CmdLineCmd aCmd) { Prn.print(0, "GO2****************************************************"); }
//********************************************************************** //********************************************************************** //********************************************************************** // Receive message from socket. public ByteContent receiveMsg() { //------------------------------------------------------------------ // Guard if (mUdpClient == null) { return(null); } //------------------------------------------------------------------ // Receive bytes from socket byte[] tRxBytes = null; try { tRxBytes = mUdpClient.Receive(ref mIPEndPoint); } catch { Prn.print(Prn.SocketRun1, "UdpRxSocket Receive EXCEPTION"); return(null); } //------------------------------------------------------------------ // Guard. if (tRxBytes != null) { Prn.print(Prn.SocketRun2, "UdpRxSocket rx message {0}", tRxBytes.Length); } else { Prn.print(Prn.SocketRun1, "UdpRxSocket ERROR"); return(null); } //------------------------------------------------------------------ // Create byte buffer. ByteBuffer tBuffer = new ByteBuffer(tRxBytes); tBuffer.setCopyFrom(); tBuffer.setLength(tRxBytes.Length); //------------------------------------------------------------------ // Copy from the receive buffer into the message parser object // and validate the header mMonkey.extractMessageHeaderParms(tBuffer); // If the header is not valid then error if (!mMonkey.mHeaderValidFlag) { Prn.print(Prn.SocketRun1, "UdpRxSocket Receive FAIL INVALID HEADER"); return(null); } Prn.print(Prn.SocketRun3, "UdpRxSocket Receive Header {0}", mMonkey.mHeaderLength); //------------------------------------------------------------------ // At this point the buffer contains the complete message. // Extract the message from the byte buffer into a new message // object and return it. tBuffer.rewind(); ByteContent tRxMsg = mMonkey.getMsgFromBuffer(tBuffer); if (tRxMsg == null) { Prn.print(Prn.SocketRun1, "UdpRxSocket FAIL INVALID MESSAGE"); return(null); } // Returning true means socket was not closed // Returning false means socket was closed mRxCount++; return(tRxMsg); }
//****************************************************************************** // Rx message handler - DataMsg void processRxMsg(DataMsg aMsg) { Prn.print(Prn.ThreadRun1, "NetworkThread.processRxMsg_DataMsg"); Helper.show(aMsg); }
//********************************************************************** public void executeGo1(CmdLineCmd aCmd) { Prn.print(Prn.View11, "TESTING"); }