Exemplo n.º 1
0
        /// <summary>
        /// разбивает данные по формату входящего файла
        /// </summary>
        /// <param name="input">Все строки которые были в файле</param>
        /// <returns>Возвращает Receivers и список тремени сигналов</returns>
        public (Receivers receivers, List <SignalTime> signalTimes) Parse(string input)
        {
            Receivers         receivers;
            List <SignalTime> signalTimes = new List <SignalTime>();

            var stringsCoords = input.Split("\r\n,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            double[] coords = new double[stringsCoords.Length];

            for (int i = 0; i < stringsCoords.Length; i++)
            {
                coords[i] = Convert.ToDouble(stringsCoords[i]);
            }

            receivers.A = new Radio.Receiver(new Point(coords[0], coords[1]));
            receivers.B = new Radio.Receiver(new Point(coords[2], coords[3]));
            receivers.C = new Radio.Receiver(new Point(coords[4], coords[5]));

            for (int i = 6; i < coords.Length - 2; i += 3)
            {
                SignalTime signalTime = new SignalTime(coords[i], coords[i + 1], coords[i + 2]);
                signalTimes.Add(signalTime);
            }
            return(receivers, signalTimes);
        }
Exemplo n.º 2
0
        private void TimerElapsed(object sender, TimerElapsedEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            try
            {
                m_Timer.Stop();

                SignalTime = e.SignalTime;

                TaskStarting(this, new BeforeTaskStartedEventArgs(TaskId, SignalTime.GetValueOrDefault()));

                LastStartDateUtc = m_DateTimeProvider.GetUtcNow();
                IsRunning        = true;

                m_Task.Run();

                LastSuccessDateUtc = LastEndDateUtc = m_DateTimeProvider.GetUtcNow();

                TaskEnded(this, new AfterTaskEndedEventArgs(TaskId, LastStartDateUtc, LastEndDateUtc));

                if (RunOnlyOnce)
                {
                    Dispose();
                }
                else
                {
                    m_Timer.Start();
                }
            }
            catch (Exception ex)
            {
                if (StopOnError)
                {
                    Enabled = false;
                    Stop();
                }

                OnTaskError(this, new OnTaskErrorEventArgs(TaskId, LastStartDateUtc, LastEndDateUtc, ex));
            }
            finally
            {
                IsRunning = false;
            }
        }
Exemplo n.º 3
0
    private void SetParametersFromBeacon(Beacon b)
    {
        int major = b.major - 1;
        int minor = b.minor - 1;

        int sig = Mathf.FloorToInt(major * 0.01f);
        int pay = major - sig * 100;

        int min = Mathf.FloorToInt(minor * 0.01f);
        int sec = minor - min * 100;

        Diglbug.Log("Translating beacon into Signal: maj:" + b.major + ", min:" + b.minor + " == sig:" + sig + ", pay:" + pay + ", minute:" + min + ", second:" + sec);
        signature = (Signature)sig;
        payload   = (Payload)pay;
        time      = new SignalTime(min, sec);
    }
Exemplo n.º 4
0
    public static int GetSignalTimeOffset(SignalTime s)
    {
        //New method. Presumes gap is less that 30 minutes.

        DateTime ours = Variables.Instance.GetCurrentTimeWithOffset();

        int ourMinute   = ours.Minute;
        int ourSecond   = ours.Second;
        int theirMinute = s.minute;
        int theirSecond = s.second;


//		Debug.Log ("Testing GetSignalOffsetTime: " + ourMinute + ", " + ourSecond + ", " + theirMinute + ", " + theirSecond);

        if (ourMinute == theirMinute)
        {
            // Happy days, we'll just grab the difference. Limit to min 0 - we can't skip backwards. Yet...
            return(Mathf.Max(ourSecond - theirSecond, 0));
        }
        // else, someone is ahead of the other.

        // Cheap abs
        int minuteDiff = (ourMinute > theirMinute ? ourMinute - theirMinute : theirMinute - ourMinute);

        if (minuteDiff > 30)
        {
            // Someone has ticked the hour.
            if (ourMinute < theirMinute)
            {
                // We are ahead, and have ticked the hour
                return(GetTimeDifferenceBetweenDifferentHours(ourMinute, ourSecond, theirMinute, theirSecond));
            }
            else
            {
                // They are ahead, and have ticked the hour
                return(0);               // We min at 0 for now. // GetTimeDifferenceBetweenDifferentHours(theirMinute, theirSecond, ourMinute, ourSecond);
            }
        }
        else
        {
            // We are within the same hour
            if (ourMinute > theirMinute)
            {
                // We are ahead
                return(GetTimeDifferenceWithinSameHour(ourMinute, ourSecond, theirMinute, theirSecond));
            }
            else
            {
                // They are ahead
                return(0);               // We min at 0 for now.
            }
        }

        // Old method below. Presumes gap less than 60 minutes. Presumes receiver has a larger time than sender.

        /*
         * DateTime now = Variables.Instance.GetCurrentTimeWithOffset ();
         *
         * int timeSecond = now.Second;
         * int timeMinute = now.Minute;
         *
         * int nowMinute = timeMinute;
         * int prevMinute = s.minute;
         *
         * // If the current minute is smaller than the previous one, we must have ticked an hour
         * if (nowMinute < prevMinute) {
         *      nowMinute += 60;
         * }
         *
         * int minuteDifference = nowMinute - prevMinute;
         * if (minuteDifference == 0) {
         *      return timeSecond - s.second;
         * } else {
         *      int ret = (60 - s.second) + timeSecond + 60 * (Mathf.Max (minuteDifference - 1, 0));
         *      return ret;
         * }*/
    }
Exemplo n.º 5
0
 // ONLY USE THIS FOR RECOVERY - it has a pre-set time.
 public Signal(Signature s, Payload p, int minute, int second)
 {
     SetSignature(s);
     SetPayload(p);
     time = new SignalTime(minute, second);
 }
Exemplo n.º 6
0
 public Signal(Signature s, Payload p)
 {
     SetSignature(s);
     SetPayload(p);
     time = SignalUtils.GetSignalTime();
 }