glidernet / ogn-tracker

OGN prototype tracker
15 stars 10 forks source link

GPS automatic baud rate detection #4

Open pjalocha opened 9 years ago

pjalocha commented 9 years ago

could be done by switching between several standard rates as long as no valid NMEA frames are detected. Once the NMEA frames start arriving the speed should stay. Algorithm is easy and should achieve correct speed within 10-20 seconds.

It can be very convenient, as one needs not to check eveyr time if the GPS speed matched the configured tracker speed.

pyrog commented 7 years ago

Could use one of following algorithms:

STM32 boot loader baud rate detection

"Bootloader measures the signal length between rising edge of first 1 bit in 0x7F to the falling edge of the last 1 bit in 0x7F to deduce the baudrate value"

Source: STM32 microcontroller system memory boot mode

First character received by the STM32 boot loader: 0111 11110x7F _<------>

First NMEA sentence sended by the GPS $GPGGA,184155.422,,,,,0,00,,,M,0.0,M,,0000*5E

0010 01000x24$ __<--->__

The pattern to measure could be 0010 01000x24$ 0100 01110x47G 0101 00000x50P 0100 01110x47G 0100 01110x47G 0100 00010x41A

0010 0100 0100 0111 0101 0000 0100 0111 0100 0111 0100 0001

Detect a pattern sended at differents speed

// s is the first string received at 115200

switch (s) {
case 'OGN':
  baudrate = 115200;
  break;
case '`b#ƒ':
  baudrate = 57600;
  break;
case '`sÌrÈ':
  baudrate = 38400;
  break;
…
}

b#ƒ ¤‡…á§Çäb!ᧁ„†§@ó$ †¦󆦥æ¥ÆÆÆÄ楄ÆFƆ‡FÆƄ„‡@ó$ †ÆÆÆÆÆÆÆæb$ "†󆆦¥æ¥ÆÁÆÆÆ楅„¤ÆfƇEó$ †¦󆦥æ¥ÆÆÆÄ楄ÆFƆ‡FÆƄ„‡Aó$ †ÆÆÆÆÆÆÆæb$ "†󆆦¥æ¥ÆÁ

GPS Autobaud algorithm on Arduino

https://github.com/rob42/FreeboardPLC_v1_2/blob/master/Gps.cpp#L89-L148