简体   繁体   English

发送数据包到UBX协议

[英]send packet to UBX protocol

lately I have been working on a GPS reciever that supports both UBX and NEMA protocols. 最近,我一直在研究同时支持UBX和NEMA协议的GPS接收器。 I am using serial programing on C++. 我在C ++上使用串行编程。 I am trying to use UBX protocol, but it seems that I only recieve from NEMA. 我正在尝试使用UBX协议,但看来我只从NEMA收到。 I downloaded the driver and I think I need to send a package first to recieve through UBX. 我下载了驱动程序,我想我需要先发送软件包才能通过UBX接收。 Does anyone know a link or could tell me how could I send these packages the method I developed is stated below I think I need a small command before I start reading the data. 有谁知道链接或可以告诉我如何将我开发的方法发送给这些软件包,如下所述。我认为在开始读取数据之前,我需要一个小的命令。 Please someone help me here :D 请有人在这里帮助我:D

void read_port(void)
{
    unsigned char c='D';


     while (c!='q')
    {
            if (read(fd, UBX_buffer, sizeof(UBX_buffer))>0)      
            {
                data = read(fd, UBX_buffer, sizeof(UBX_buffer));

            //  write(fd,&UBX_buffer,1);  // if new data is available on the serial port, print it out

      cout<<"Data on the port =  ";
      for (unsigned i =0; i< sizeof(UBX_buffer) ;i++){
        cout<<&UBX_buffer[i];  


    }
    cout<<" "<<endl;
     for (int i=0; i<fd; i++)  // Process bytes received
{

     switch(UBX_step)     //we start from zero and increment as we go through the cases
  {
  case 0:  
    if(data==0xB5)  UBX_step++;  break; // UBX sync char 1 //check for the first data packet and go to next byte


  case 1:  if(data==0x62) UBX_step++;// UBX sync char 2 //check for the second data packet and go to the next byte

    else    UBX_step=0; break;  //if first and second packets are not correct then go back and check again     

  case 2:   UBX_class=data; checksum(UBX_class); UBX_step++;  break;

  case 3:   UBX_id=data;  checksum(UBX_id);  UBX_step++; break;

  case 4:   UBX_payload_length_hi=data; checksum(UBX_payload_length_hi);  UBX_step++;  break;

  case 5:   UBX_payload_length_lo=data; checksum(UBX_payload_length_lo);  UBX_step++; break;

  case 6:         // Payload data read...
  if (UBX_payload_counter < UBX_payload_length_hi)  // We stay in this state until we reach the payload_length
    {
      UBX_buffer[UBX_payload_counter] = data;
      checksum(data);
      UBX_payload_counter++;
    }
    else
      UBX_step++; 
    break;
  case 7:   ck_a=data;  UBX_step++; break;      // First checksum byte
  case 8:   ck_b=data;                           // Second checksum byte

    // We end the GPS read...

    if((ck_a= ck_a)&&(ck_b= ck_a))   // Verify the received checksum with the generated checksum.. 
          parse_ubx_gps();               // Parse new GPS packet...


    UBX_step=0;
    UBX_payload_counter=0;
    ck_a=0;
    ck_b=0;
    GPS_timer=0; //Restarting timer...
    break;
      }
  }

            if (read(STDIN_FILENO,&c,1)>0) write(fd,&c,1);  // if new data is available on the console, send it to the serial port

    }

    close(fd);



  } // End Switch
} // End For

At the ublox Homepage you can Download the ublox protocoll specification. 在ublox主页上,您可以下载ublox协议规范。 There, look at the cfg messages. 在那里,查看cfg消息。 For test purposes, you also can enable the ubx protocol via the tool u-Center . 为了进行测试,您还可以通过工具u-Center启用ubx协议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM