private void ReadTimerCallback(object state) { if(IsOpen()) { try { GPSDataRequestParameter reqPara = new GPSDataRequestParameter(); reqPara.LastDataID = lastDataID; reqPara.MaxLines = 10; reqPara.LatestDataOnly = !bIsReplay; reqPara.PathID = pathInfo.ID; reqPara.PathPassword = pathInfo.Password; GPSDownloadData[] receivedDatas = serviceClient.GetGPSData(reqPara); if (receivedDatas != null) { foreach (GPSDownloadData dataItem in receivedDatas) { if (dataItem != null) { // Update the id if (lastDataID < dataItem.ID) lastDataID = dataItem.ID; if (dataItem.NMEASentence.Length == 0) continue; byte[] data = new byte[System.Text.Encoding.Default.GetByteCount(dataItem.NMEASentence)]; data = System.Text.Encoding.Default.GetBytes(dataItem.NMEASentence); // Dispatch the received data. if (data != null) { if (Read != null) Read(this, data); } } } } } catch (System.Exception ) { // Don't exit if failed. } // ToDO - for the replay model, we should use the time tamp of the gps data. try { // There is exception when close the port during receiving process. if (!disposed) readTimer.Change(1000, Timeout.Infinite); // Read data every second } catch (System.Exception) { } } }
public List <GPSDownloadData> GetGPSData(GPSDataRequestParameter para) { List <GPSDownloadData> gpsDataList = new List <GPSDownloadData>(); try { if (para.LatestDataOnly) { var datas = (from item in mGPSDB.PathDetails where (item.ID > para.LastDataID) && (item.PathID == para.PathID) orderby item.ID descending select new GPSDownloadData() { ID = item.ID, NMEASentence = Decode(item.GPSSentence) }).Take(para.MaxLines); gpsDataList.AddRange(datas); gpsDataList.Reverse(); // We must keep the sequence of the data the same as that we received. } else { var datas = (from item in mGPSDB.PathDetails where (item.ID > para.LastDataID) && (item.PathID == para.PathID) orderby item.ID ascending select new GPSDownloadData() { ID = item.ID, NMEASentence = Decode(item.GPSSentence) }).Take(para.MaxLines); gpsDataList.AddRange(datas); } } catch (System.Exception) { } return(gpsDataList); }
private void ReadTimerCallback(object state) { if (IsOpen()) { try { GPSDataRequestParameter reqPara = new GPSDataRequestParameter(); reqPara.LastDataID = lastDataID; reqPara.LastDataIDSpecified = true; reqPara.MaxLines = 10; reqPara.MaxLinesSpecified = true; reqPara.LatestDataOnly = !bIsReplay; reqPara.LatestDataOnlySpecified = true; reqPara.PathID = pathInfo.ID; reqPara.PathIDSpecified = true; reqPara.PathPassword = pathInfo.Password; GPSDownloadData[] receivedDatas = serviceClient.GetGPSData(reqPara); if (receivedDatas != null) { foreach (GPSDownloadData dataItem in receivedDatas) { if (dataItem != null) { // Update the id if (lastDataID < dataItem.ID) { lastDataID = dataItem.ID; } if (dataItem.NMEASentence.Length == 0) { continue; } byte[] data = new byte[System.Text.Encoding.Default.GetByteCount(dataItem.NMEASentence)]; data = System.Text.Encoding.Default.GetBytes(dataItem.NMEASentence); // Dispatch the received data. if (data != null) { if (Read != null) { Read(this, data); } } } } } } catch (System.Exception) { // Don't exit if failed. } // ToDO - for the replay model, we should use the time tamp of the gps data. try { // There is exception when close the port during receiving process. if (!disposed) { readTimer.Change(1000, Timeout.Infinite); // Read data every second } } catch (System.Exception) { } } }
public List<GPSDownloadData> GetGPSData(GPSDataRequestParameter para) { List<GPSDownloadData> gpsDataList = new List<GPSDownloadData>(); try { if(para.LatestDataOnly) { var datas = (from item in mGPSDB.PathDetails where (item.ID > para.LastDataID) && (item.PathID == para.PathID) orderby item.ID descending select new GPSDownloadData() { ID = item.ID, NMEASentence = Decode(item.GPSSentence) }).Take(para.MaxLines); gpsDataList.AddRange(datas); gpsDataList.Reverse(); // We must keep the sequence of the data the same as that we received. } else { var datas = (from item in mGPSDB.PathDetails where (item.ID > para.LastDataID) && (item.PathID == para.PathID) orderby item.ID ascending select new GPSDownloadData() { ID = item.ID, NMEASentence = Decode(item.GPSSentence) }).Take(para.MaxLines); gpsDataList.AddRange(datas); } } catch (System.Exception) { } return gpsDataList; }
/// <summary> /// Return the last 10 sentences at most whose IDs are later than the lastID. /// </summary> /// <param name="path"></param> /// <param name="lastID">if it is -1,qurey from the first sentence</param> /// <returns></returns> public List<GPSDownloadData> GetGPSData(GPSDataRequestParameter para) { // Verify the path info. if (null == para) return null; if (-1 == para.PathID) return null; if (para.MaxLines < 1) return null; // ToDo we need check the id and password. // Get the gps data. return mDataAccesser.GetGPSData(para); //return null; }