예제 #1
0
        public void StartMessageSendingLoop()
        {
            thrdMessageSend = new Thread(
                () =>
            {
                Stopwatch sw = Stopwatch.StartNew();
                while (!bKillSwitch)
                {
                    areMessageSend.WaitOne();
                    for (int i = 0; (i < isource.GetCount()) || isource.GetCount() == -1; i++)
                    {
                        sw.Restart();
                        areMessageSend.WaitOne(TimeSpan.FromMilliseconds(SettingsHolder.Instance.SendFreq));
                        SixMsg omsg = isource.GetMessage();
                        SendSingleMessage(omsg);
                        sw.Stop();
                        double d = (double)sw.ElapsedTicks / Stopwatch.Frequency * 1000;
                        evSentMessage.Raise(omsg.ToString());

                        if (bStopSending)
                        {
                            break;
                        }
                    }
                    isource.Reset();
                }
            });
            thrdMessageSend.IsBackground = true;
            thrdMessageSend.Name         = "UDP six msg sender";
            thrdMessageSend.Start();
        }
예제 #2
0
        public SixMsg GetMessage()
        {
            SixMsg oMsg = lstSixMsgs[iCurrentPos];

            iCurrentPos++;
            iCurrentPos = iCurrentPos % (lstSixMsgs.Count);
            return(oMsg);
        }
예제 #3
0
        private void SendSingleMessage(SixMsg oSixMsg)
        {
            //byte[] by1SixMsg_ = lstSixMsg.MakeByteArrayMarshal();
            byte[] by1SixMsg = oSixMsg.MakeByteArray();

            Buffer.BlockCopy(new byte[4], 0, by1SixMsg, by1SixMsg.Length - sizeof(int), sizeof(int));

            uint uiCheckSum = crc.ComputeCheckSum(by1SixMsg, Common.CRC32.CSMethod.Checksum);

            Buffer.BlockCopy(BitConverter.GetBytes(uiCheckSum), 0, by1SixMsg, by1SixMsg.Length - sizeof(int), sizeof(int));

            oComm.UDPSendMessage(by1SixMsg);
        }
예제 #4
0
        public SixMsg GetMessage()
        {
            SixMsg oMsg = new SixMsg();

            oMsg.Header       = 0xAA55;
            oMsg.MSGCounter   = iCountPos++;
            oMsg.Object_X     = SettingsForManualSend.Instance.Six_obj_X;
            oMsg.Object_Y     = SettingsForManualSend.Instance.Six_obj_Y;
            oMsg.Object_Y     = SettingsForManualSend.Instance.Six_obj_Z;
            oMsg.Object_Pitch = SettingsForManualSend.Instance.Six_obj_Pitch;
            oMsg.Object_Roll  = SettingsForManualSend.Instance.Six_obj_Roll;
            oMsg.Object_Yaw   = SettingsForManualSend.Instance.Six_obj_Yaw;
            oMsg.Object_model = iCountPos % SettingsForManualSend.Instance.Six_obj_blink;
            oMsg.Smoke        = SettingsForManualSend.Instance.Six_obj_Smoke;
            return(oMsg);
        }
예제 #5
0
        public bool Parse(string file)
        {
            lstSixMsgs.Clear();
            bool bRes = false;

            try
            {
                Regex           rgxBody   = new Regex(@"^[^#].*", RegexOptions.Multiline);
                Regex           rgxHeader = new Regex(@"^#.*", RegexOptions.Multiline);
                MatchCollection matches;
                int             iNumOfColumns = 0;
                using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (StreamReader sw = new StreamReader(fs))
                    {
                        string sAll = sw.ReadToEnd();
                        //oScriptSettings.Checksum = sAll.ComputeCRC();
                        matches = rgxBody.Matches(sAll);
                        Match matchesHeader = rgxHeader.Match(sAll);
                        int   iColsFound    = matchesHeader.Value
                                              .Split(new char[] { ',', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length;
                        if (iColsFound > 0)
                        {
                            iNumOfColumns = iColsFound;
                        }
                    }
                foreach (Match match in matches)
                {
                    string[] parts = match.Value.Split(new char[] { ',', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == iNumOfColumns)
                    {
                        var msg = new SixMsg();
                        msg.Header       = int.Parse(parts[0], NumberStyles.HexNumber, CultureInfo.CurrentCulture);
                        msg.Sender_ID    = (int)double.Parse(parts[1]);
                        msg.Target_ID    = (int)double.Parse(parts[2]);
                        msg.MSGCounter   = (int)double.Parse(parts[3]);
                        msg.Time         = double.Parse(parts[4]);
                        msg.Object_X     = double.Parse(parts[5]);
                        msg.Object_Y     = double.Parse(parts[6]);
                        msg.Object_Z     = double.Parse(parts[7]);
                        msg.Object_Roll  = double.Parse(parts[8]);
                        msg.Object_Pitch = double.Parse(parts[9]);
                        msg.Object_Yaw   = double.Parse(parts[10]);
                        msg.Smoke        = (int)double.Parse(parts[11]);
                        msg.Object_model = (int)double.Parse(parts[12]);
                        msg.Spare        = (int)double.Parse(parts[13]);
                        msg.CheckSum     = int.Parse(parts[14], NumberStyles.HexNumber, CultureInfo.CurrentCulture);
                        lstSixMsgs.Add(msg);
                        bRes = true;
                    }
                    else
                    {
                        bRes = false;
                    }
                }
            }
            catch (Exception e)
            {
                bRes = false;
            }
            return(bRes);
        }