加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

寻找健壮的Delphi NMEA解析器

发布时间:2020-12-15 04:13:11 所属栏目:大数据 来源:网络整理
导读:我正在寻找生产级的开源Delphi NMEA解析器. 如果它可以满足关键任务要求就好了(我在开玩笑!我相信使用Win32系统是不可能实现的). 到目前为止,我已经使用基本的Windows API(NMEA 0183)通过串口使用手腕GPS(Garmin Foretrex 101)的基本接口. 我还探索了一个开
我正在寻找生产级的开源Delphi NMEA解析器.

如果它可以满足关键任务要求就好了(我在开玩笑!我相信使用Win32系统是不可能实现的).

到目前为止,我已经使用基本的Windows API(NMEA 0183)通过串口使用手腕GPS(Garmin Foretrex 101)的基本接口.

我还探索了一个开源VCL组件来处理与航空模型GPS(Garmin Gpsmap 196)的实验性串行通信.

谢谢.

解决方法

我最终使用开源 TComPort软件包中的TComPort和TComDataPacket.

ComPort设置:

object ComPort: TComPort
    BaudRate = br4800
    Port = 'COM1'
    Parity.Bits = prNone
    StopBits = sbTwoStopBits
    DataBits = dbEight
    Events = [evRxChar,evTxEmpty,evRxFlag,evRing,evBreak,evCTS,evDSR,evError,evRLSD,evRx80Full]
    FlowControl.OutCTSFlow = False
    FlowControl.OutDSRFlow = False
    FlowControl.ControlDTR = dtrDisable
    FlowControl.ControlRTS = rtsDisable
    FlowControl.XonXoffOut = False
    FlowControl.XonXoffIn = False
    SyncMethod = smWindowSync
    OnAfterOpen = ComPortAfterOpen
    OnAfterClose = ComPortAfterClose
    Left = 904
    Top = 192
  end

ComDataPacket设置:

object ComDataPacket: TComDataPacket
    ComPort = ComPort
    StartString = '$'
    StopString = '*'
    OnPacket = ComDataPacketPacket
    Left = 808
    Top = 240
  end

摘录类型使用

type
  // NMEA 0185's messages used
  TMsgGP = (
    msgGP,// Unknown message
    msgGPGGA,// Global Positioning System Fix Data
    msgGPGLL,// Geographic position,Latitude and Longitude
    msgGPGSV,// Satellites in view
    msgGPRMA,// Recommended minimum specific GPS/Transit data Loran C
    msgGPRMC,// Recommended minimum specific GPS/Transit data
    msgGPZDA  // Date and time
    );

  // Satellite properties
  TSatellite = record
    Identification: ShortInt;
    Elevation: 0..90;
    Azimut: Smallint;
    SignLevel: Smallint;
  end;
  // Array of satellites referenced
  TSatellites = array[1..MAX_SATS] of TSatellite;

  // GPS status informations
  TGPSDatas = record
    Latitude: Double;
    Longitude: Double;
    HeightAboveSea: Double;
    Speed: Double;
    UTCTime: TDateTime;
    Valid: Boolean;
    NbrSats: Shortint;
    NbrSatsUsed: Shortint;
  end;

ComDataPacketPacket事件处理程序:

procedure TForm1.ComDataPacketPacket(Sender: TObject; const Str: string);
var
  Resultat: TStringList;
  MsgCorrect,TypeMsg: string;
  i: Integer;
begin
  Resultat := TStringList.Create;
  try

    // Split the message into different parts.
    MsgCorrect := AnsiReplaceStr('$'+Str,',');
    Resultat.Text := AnsiReplaceStr(LeftStr(MsgCorrect,Length(MsgCorrect) - 1),#13#10);

    // Get the message type
    TypeMsg := AnsiMidStr(Resultat[0],4,3);

    case IndexMsgGP(TypeMsg) of
      msgGPGGA:
        begin
        end;
      msgGPGLL:
        begin
        end;
      msgGPGSV:
        begin
          // If there are satellites referenced in the frame
          if Resultat.Count < 4 then
            FGPSDatas.NbrSats := 0
          else
            FGPSDatas.NbrSats := StrToInteger(Resultat[3]);

          if Resultat[2] = '1' then
          begin
            FSatRef := 0;

            // Initiate satellites values
            for i := 1 to 12 do
              with FSatellites[i] do
              begin
                Identification := 0;
                Elevation := 0;
                Azimut := 0;
                SignLevel := 0;
              end;
          end;

          i := 4;

          // For each referenced satellites
          while (i + 4) <= (Resultat.Count) do
          begin
            with FSatellites[FSatRef + 1] do
            begin
              Identification := StrToInteger(Resultat[i]);
              Elevation := StrToInteger(Resultat[i + 1]);
              Azimut := StrToInteger(Resultat[i + 2]);
              if Resultat[i + 3] <> '' then
                SignLevel := StrToInteger(Resultat[i + 3])
              else
                SignLevel := 0;
            end;
            Inc(i,4);
            Inc(FSatRef);
          end;
        end;
      msgGPRMA:
        begin
        end;
      msgGPRMC:
        begin
        end;
      msgGPZDA:
        begin
        end;
      else
    end;
  finally
    Resultat.Free;
  end;
end;

NMEA处理发生在事件处理程序中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读