コード例 #1
0
ファイル: GPSTimeTests.cs プロジェクト: nanwnagnanfeng/Rinex
        public void GPS_Test_3(int Year, int Month, int Date, int Hour, int Minute, int Second, int GPSWeek, int GPSSeconds)
        {
            string   s = "(1952-194766) 6/6/2017:6:6:6)";
            IGPSTime t = new GPSTime(GPSWeek, GPSSeconds);

            Assert.AreEqual(s, t.ToString());
        }
コード例 #2
0
ファイル: GPSTimeTests.cs プロジェクト: nanwnagnanfeng/Rinex
        public void GPS_Test_5(int Year, int Month, int Date, int Hour, int Minute, int Second, int GPSWeek, int GPSSeconds)
        {
            string   s = "(335-153243) 9/6/1986:18:34:3)";
            IGPSTime t = new GPSTime(GPSWeek, GPSSeconds);

            Assert.AreEqual(s, t.ToString());
        }
コード例 #3
0
        public async Task <ActionResult <IEnumerable <IEnumerable <double> > > > GetDatas(string tableName, int?fromWeek, int?toWeek, double?fromT, double?toT)
        {
            try
            {
                GPSTime from = null, to = null;
                if (fromWeek != null || fromT != null)
                {
                    from = new GPSTime(fromWeek.Value, fromT.Value);
                }
                if (toWeek != null || toT != null)
                {
                    to = new GPSTime(toWeek.Value, toT.Value);
                }

                var Datas = (await datas.GetAllAsync(tableName, from, to)).ToList();
                var All   = new List <List <double> >();
                foreach (var data in Datas)
                {
                    All.Add(new List <double>()
                    {
                        data.WEEK, data.T, data.AX, data.AY, data.AZ, data.Temp.Value
                    });
                }
                return(All);
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                return(StatusCode(501));
            }
        }
コード例 #4
0
ファイル: GPSTimeTests.cs プロジェクト: nanwnagnanfeng/Rinex
        public void GPS_Test_4(int Year, int Month, int Date, int Hour, int Minute, int Second, int GPSWeek, int GPSSeconds)
        {
            IGPSTime t  = new GPSTime(GPSWeek, GPSSeconds);
            IGPSTime t1 = new GPSTime(Year, Month, Date, Hour, Minute, Second);

            Assert.AreEqual(t, t1);
        }
コード例 #5
0
        public async Task <ActionResult <IEnumerable <double> > > GetCount(string tableName, int?week, double?t)
        {
            if (week == null || t == null)
            {
                return(NotFound());
            }

            try
            {
                int    currentWeek = week.Value;
                double currentT    = t.Value;
                var    HistData    = new List <double>();
                for (int i = 1; i <= 24; i++)
                {
                    var from = new GPSTime(currentWeek, currentT);
                    nextHour(ref currentWeek, ref currentT);
                    var to = new GPSTime(currentWeek, currentT - 0.001);

                    var    count   = datas.GetCount(tableName, from, to);
                    double percent = (double)count / (double)dataCountPerHour * 100.0;

                    HistData.Add(percent);
                }

                return(HistData);
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                return(StatusCode(501));
            }
        }
コード例 #6
0
ファイル: GPSTimeTests.cs プロジェクト: nanwnagnanfeng/Rinex
        public void GPS_Test_1(int Year, int Month, int Date, int Hour, int Minute, int Second, int GPSWeek, int GPSSeconds)
        {
            DateTime t1 = new DateTime(Year, Month, Date, Hour, Minute, Second);
            IGPSTime t  = new GPSTime(t1);

            Assert.AreEqual(GPSWeek, t.GPSWeek);
            Assert.AreEqual(GPSSeconds, t.GPSSeconds);
        }
コード例 #7
0
ファイル: GPSTimeTests.cs プロジェクト: nanwnagnanfeng/Rinex
        public void GPS_Test_2(int Year, int Month, int Date, int Hour, int Minute, int Second, int GPSWeek, int GPSSeconds)
        {
            IGPSTime t = new GPSTime(GPSWeek, GPSSeconds);

            Assert.AreEqual(Year, t.RegularDateTime.Year);
            Assert.AreEqual(Month, t.RegularDateTime.Month);
            Assert.AreEqual(Date, t.RegularDateTime.Day);
            Assert.AreEqual(Hour, t.RegularDateTime.Hour);
            Assert.AreEqual(Minute, t.RegularDateTime.Minute);
            Assert.AreEqual(Second, t.RegularDateTime.Second);
        }
コード例 #8
0
        /// <summary>
        /// Calculates from the GPS second the GPS time given at the GPS time structure.
        /// </summary>
        /// <param name="GPS_Second">GPS second, which has to be converted in the GPS time structure.</param>
        /// <returns>GPS time structure.</returns>
        public static GPSTime getGPSWeekSecondFromGPSSeconds(long GPS_Second)
        {
            GPSTime GPSWS = new GPSTime();

            GPSWS.SecondofWeek = (int)(GPS_Second % (86400 * 7));
            GPSWS.Day          = (int)Math.Floor(GPSWS.SecondofWeek / 86400.0);
            GPSWS.Week         = (int)((GPS_Second - (long)GPSWS.SecondofWeek) / (long)(86400 * 7));
            GPSWS.Rollover     = (int)Math.Floor((double)(GPSWS.Week + 1) / 1024.0);

            if (GPSWS.Rollover > 0)
            {
                GPSWS.Week -= GPSWS.Rollover * 1024;
            }

            return(GPSWS);
        }
コード例 #9
0
        void parse_GPS_msg()
        {
            string temp = currentMsg.ToString();
            string[] tempArray = new string[100];
            tempArray = temp.Split(delims);

            switch (tempArray[0])
            {
                case "$GPGGA":
                    try
                    {
                        if (tempArray[9] == "")
                            tempArray[9] = "0";
                        if (tempArray[7] == "")
                            tempArray[7] = "0";
                        time = new GPSTime(tempArray[1]);
                        lastFix = fix;
                        fix = (tempArray[6] != "0");
                        altitude = Convert.ToDouble(tempArray[9]);

                        lastLatitude = latitude;
                        lastLongitude = longitude;

                        latitude = Math.Round(((Convert.ToDouble(tempArray[2].Remove(0, 2)) / 60) + (Convert.ToDouble(tempArray[2].Remove(2)))), 6);
                        longitude = Math.Round(((Convert.ToDouble(tempArray[4].Remove(0, 3)) / 60) + (Convert.ToDouble(tempArray[4].Remove(3)))), 6);

                        if (tempArray[3] == "S")
                            latitude = -latitude;
                        if (tempArray[5] == "W")
                            longitude = -longitude;
                    }
                    catch
                    {

                    }
                    if(lastLongitude != longitude)
                        OnPositionChange(new PositionChangeEventArgs(latitude, longitude));
                    else if(lastLatitude != latitude)
                        OnPositionChange(new PositionChangeEventArgs(latitude, longitude));
                    if(lastFix != fix)
                        OnPositionFixChange(new PositionFixChangeEventArgs(fix));

                    break;
                case "$GPGSA":

                    break;
                case "$GPGSV":

                    break;
                case "$GPRMC":
                    try
                    {
                        if (tempArray[7] == "")
                            tempArray[7] = "0";
                        if (tempArray[8] == "")
                            tempArray[8] = "0";
                        if (tempArray[9] == "")
                            tempArray[9] = "0";
                        date = new GPSDate(tempArray[9]);
                        velocity = (Convert.ToDouble(tempArray[7]))/0.5399568;
                        heading = Convert.ToDouble(tempArray[8]);
                    }
                    catch { }
                    break;
                case "$GPVTG":

                    break;
                case "$GPGLL":

                    break;
                default:
                    break;
            }
        }
コード例 #10
0
 ///<exclude/>
 public bool Equals(GPSTime other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other._Sec.Equals(_Sec) && other._Msec.Equals(_Msec);
 }
コード例 #11
0
 /// <summary>
 /// Determines the GPS second by using the GPS time structure of the week, rollover and sekond of the week.
 /// </summary>
 /// <param name="GPSWS">GPS time structure</param>
 /// <returns>The calculated GPS second.</returns>
 public static long getGPSSecondFromGPSWeekSecond(GPSTime GPSWS)
 {
     return((((long)GPSWS.Week + ((long)GPSWS.Rollover * 1024)) * 86400 * 7) + (long)GPSWS.SecondofWeek);
 }
コード例 #12
0
        /// <summary>
        /// 取得指定[縣市],[路線名稱]的公車動態定點資料(A2)[批次更新]
        /// </summary>
        /// <param name="city">縣市</param>
        /// <param name="routeName">路線</param>
        /// <param name="top">筆數</param>
        /// <returns></returns>
        public void BusA2DataGet(string city, string routeName, string filter)
        {
            //appID 與 appKey
            //L1
            const string appID  = "de9846031af54c0e95cd3f0c68e6c9e9";
            const string appKey = "VVnz4vQe5Lsu4qtmUJAr79uVLRQ";
            //L2
            //const string appID = "9d23cca661e34c60a27da4102820cdca";
            //const string appKey = "szVA8s6nvxAqwzbZSQkiMVA2fyM";



            //Use RestSharp Call API
            //var client = new RestClient($"http://ptx.transportdata.tw/MOTC/v2/Bus/RealTimeNearStop/City/{city}/{routeName}?%top={top}&$format=JSON");
            //client = new RestClient($"http://ptx.transportdata.tw/MOTC/v2/Bus/RealTimeNearStop/City/{city}/{routeName}?%filter={filter}&$format=JSON");
            var client = new RestClient($"http://ptx.transportdata.tw/MOTC/v2/Bus/RealTimeNearStop/City/{city}/{routeName}?$format=JSON");


            var request = new RestRequest(Method.GET);



            string gmtStr    = DateTime.UtcNow.ToString("r");
            string signature = HMACSHA1Text(@"x-date: " + gmtStr, appKey);


            string Authorization = @"hmac  username=""" + appID + @""", algorithm=""hmac-sha1"", headers=""x-date"", signature=""" + signature + @"""";


            request.AddHeader("Accept", "application/json");
            request.AddHeader("Authorization", Authorization);
            request.AddHeader("x-date", gmtStr);
            request.AddHeader("Accept-Encoding", "gzip, deflate");


            IRestResponse response = client.Execute(request);

            string Result = "";

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var APIResult = JsonConvert.DeserializeObject <List <BusA2Data> >(response.Content);

                if (APIResult != null && APIResult.Count > 0)
                {
                    string   PlateNumb, RouteID, Direction, StopID, StopName;
                    int      DutyStatus, BusStatus, MessageType, StopSequence, A2EventType;
                    DateTime GPSTime;
                    string   CreateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                    foreach (BusA2Data PTXData in APIResult)
                    {
                        GetA2 = GetA2 + 1;

                        PlateNumb    = PTXData.PlateNumb;
                        RouteID      = PTXData.RouteID;
                        Direction    = PTXData.Direction;
                        StopID       = PTXData.StopID;
                        StopName     = PTXData.StopName.Zh_tw;
                        StopSequence = PTXData.StopSequence;
                        A2EventType  = PTXData.A2EventType;

                        DutyStatus  = PTXData.DutyStatus;
                        BusStatus   = PTXData.BusStatus;
                        MessageType = PTXData.MessageType;
                        GPSTime     = PTXData.GPSTime;

                        Result = Result + "IF NOT EXISTS(SELECT PlateNumb FROM A2Data WHERE PlateNumb='" + PlateNumb + "' AND A2EventType=" + A2EventType +
                                 " AND GPSTime='" + GPSTime.ToString("yyyy/MM/dd HH:mm:ss") + "')" +
                                 "BEGIN " +
                                 "INSERT INTO A2Data(PlateNumb, RouteID, Direction, StopID, StopName,DutyStatus, BusStatus, MessageType, StopSequence, A2EventType,GPSTime, CreateTime)" +
                                 "VALUES(" +
                                 " '" + PlateNumb + "' " +
                                 ",'" + RouteID + "' " +
                                 ",'" + Direction + "' " +
                                 ",'" + StopID + "' " +
                                 ",'" + StopName + "' " +
                                 ", " + DutyStatus + " " +
                                 ", " + BusStatus + " " +
                                 ", " + MessageType + " " +
                                 ", " + StopSequence + " " +
                                 ", " + A2EventType + " " +
                                 ",'" + GPSTime.ToString("yyyy/MM/dd HH:mm:ss") + "' " +
                                 ",'" + CreateTime + "' " +
                                 ") END ;";
                    }
                }
            }


            //寫入資料
            if (Result != "")
            {
                SqlConnection connnew = new SqlConnection(strconnection);

                try
                {
                    connnew.Open();
                    SqlCommand cmmdnew = new SqlCommand(Result, connnew);
                    cmmdnew.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("A2Data error ");
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    connnew.Close();
                }
            }
        }
コード例 #13
0
ファイル: GPS.cs プロジェクト: YakNazim/launch-tower
        void parse_GPS_msg()
        {
            string temp = currentMsg.ToString();

            string[] tempArray = new string[100];
            tempArray = temp.Split(delims);

            switch (tempArray[0])
            {
            case "$GPGGA":
                try
                {
                    if (tempArray[9] == "")
                    {
                        tempArray[9] = "0";
                    }
                    if (tempArray[7] == "")
                    {
                        tempArray[7] = "0";
                    }
                    time     = new GPSTime(tempArray[1]);
                    lastFix  = fix;
                    fix      = (tempArray[6] != "0");
                    altitude = Convert.ToDouble(tempArray[9]);

                    lastLatitude  = latitude;
                    lastLongitude = longitude;

                    latitude  = Math.Round(((Convert.ToDouble(tempArray[2].Remove(0, 2)) / 60) + (Convert.ToDouble(tempArray[2].Remove(2)))), 6);
                    longitude = Math.Round(((Convert.ToDouble(tempArray[4].Remove(0, 3)) / 60) + (Convert.ToDouble(tempArray[4].Remove(3)))), 6);

                    if (tempArray[3] == "S")
                    {
                        latitude = -latitude;
                    }
                    if (tempArray[5] == "W")
                    {
                        longitude = -longitude;
                    }
                }
                catch
                {
                }
                if (lastLongitude != longitude)
                {
                    OnPositionChange(new PositionChangeEventArgs(latitude, longitude));
                }
                else if (lastLatitude != latitude)
                {
                    OnPositionChange(new PositionChangeEventArgs(latitude, longitude));
                }
                if (lastFix != fix)
                {
                    OnPositionFixChange(new PositionFixChangeEventArgs(fix));
                }

                break;

            case "$GPGSA":

                break;

            case "$GPGSV":

                break;

            case "$GPRMC":
                try
                {
                    if (tempArray[7] == "")
                    {
                        tempArray[7] = "0";
                    }
                    if (tempArray[8] == "")
                    {
                        tempArray[8] = "0";
                    }
                    if (tempArray[9] == "")
                    {
                        tempArray[9] = "0";
                    }
                    date     = new GPSDate(tempArray[9]);
                    velocity = (Convert.ToDouble(tempArray[7])) / 0.5399568;
                    heading  = Convert.ToDouble(tempArray[8]);
                }
                catch { }
                break;

            case "$GPVTG":

                break;

            case "$GPGLL":

                break;

            default:
                break;
            }
        }