b3nn0 / stratux

Fork of the original cyoung/stratux with multiple patches for flying in europe
BSD 3-Clause "New" or "Revised" License
144 stars 63 forks source link

flexbile UART baudrate setting for GPS module (Feature request ?) #207

Closed rush0815 closed 1 year ago

rush0815 commented 1 year ago
  1. Stratux version: stratux-v1.6r1-eu028-32d5e58b.img

  2. Stratux config:

    SDR

    • [ ] single
    • [X] dual

    GPS

    AHRS

    • [ ] yes
    • [X] no

    power source: 3A 5.2V Adapter (original Raspberry Pi adapter)

  3. EFB app and version: (FroeFlight)

  4. Description of your issue:

I am trying to get the NEO-M9N module working on the raspberry UART pins. Looking at gps.go line 317, every GPS module connected to the UART will be treated as an u-blox 8 module.

  1. issue here: These modules are set to a baudrate of 38400 by default but stratux looks at /dev/ttypAMA0 at 9600 as default baud rate.
  2. issue "writeUblox8ConfigCommands" will be executed on the modules that is different than "writeUblox9ConfigCommands"

Since the GPS module is located on the dev board, the native USB port is made plugable so I can change the baudrate of the GPS module to 9600 to bring it up in stratux. Btw. line 319 in gps.go says:

log.Printf("ublox 8 detected\n")

where to find this log message? I assumend it should be written in stratux.log but I cant find that line.

So back to the workaround: Setting the baudrate via u-center is tricky when I use a OEM module because there is not hardware "around it" to which I connect.

The question / feature request is:

What about implementing a flexible baudrate setting and GPS Module setting into the web UI ? (only for handling UART connected modules) to make it possible to handle u-blox modules connected to UART equal to the same one connected to USB port

b3nn0 commented 1 year ago

There is already logic in there to automatically detect the baud rate. It will open the port at different baud rates, read for a bit, and check if we got some useful NMEA. See e.g. here how it is used: https://github.com/b3nn0/stratux/blob/e2b60736c41e60498bbe93d6309d25307096e8ee/main/gps.go#L245 The code will then trial all baud rates in that array. Feel free to create a PR using the same logic for UART GPS to try the most common ones (e.g. 9600, 38400, 57600 and 115200 or something) - I'll happily merge it if that works for you.

EDIT: Looks like detection is done after trying to send commands to it, assuming that we initially know the baud rate.. Feel free to change that a bit.

rush0815 commented 1 year ago

Thanks for your respond... so that will be the point where I will introduce myself into golang and github usage (not only download) :-D

I checked the line you referred to and got a bit confused now:

  1. GPS_TYPE_SERIAL is only used in combination with SoftRF/Flarm? Is that correct ? see gps.go line 1703
  2. you said that the detection is done after trying to send commands: I don't think so, see line 419-439. Or did you mean another routine ?

Since I am new to Go, can you please give me a hint where I can find the variable assignment for the values that are shown on the webUI, for example {{ConnectState}}, please?

VirusPilot commented 1 year ago

I would try the two following changes:

b3nn0 commented 1 year ago

change line 311 to: if (globalStatus.GPS_detected_type == GPS_TYPE_UBX9) || (globalStatus.GPS_detected_type == GPS_TYPE_UART) { change line 317 to: } else if globalStatus.GPS_detected_type == GPS_TYPE_UBX8 {

Not for the PR though.. I think Ublox 8 is still much more dominant than 9 - and I don't want to break it for existing users. We are not able to detect if it's 8 or 9 via UART (at least not in a simple way). So for the upstream code base, this should stay at 8, at least for now.

after line 252 insert: baudrates = []int{115200, 57600, 38400, 9600}

This is the only change required to make it work. However, in line 264, the serial port is opened with baudrates[0] for configuration (including potentially changing the baud rate of the connected device). Later, in line 403 it is then re-opened with auto detection.

I'd recommend potentially changing like 264 to auto-detection as well, so your GPS will be configured properly.

b3nn0 commented 1 year ago

Since I am new to Go, can you please give me a hint where I can find the variable assignment for the values that are shown on the webUI, for example {{ConnectState}}, please?

This is handled by angularJS in the UI itself. Check the plates-subidirectory. Each "plate" has it's HTML and its JS file providing the values of the template variables.

rush0815 commented 1 year ago

What is the root password to connect via ssh to stratux? I am always getting a Permission denied

b3nn0 commented 1 year ago

It is a normal RaspiOS, so no root password is set. Use sudo to set one. Login with pi/raspberry.

rush0815 commented 1 year ago

ok, setting root password worked. But installint the GO Pack on stratux fails with that:

image

Any ideas ?

Trying to run go env directly on stratux results in:

root@stratux:~/go/bin# /root/go/bin/go env -bash: /root/go/bin/go: cannot execute binary file: Exec format error

For me it looks like VSC tries to install an x64 environment and not ARM EDIT: I accidently installed the AMD not ARM version :-/ trying again ...

b3nn0 commented 1 year ago

See here for a proper dev setup https://github.com/b3nn0/stratux/wiki/Developing-Stratux

rush0815 commented 1 year ago

I changed the order of GPS init to first detect the correct baud rate and then reprogram the module and committed the changes already. But I cant see any Pull Request on github. Any idea what I am doing wrong?

Btw: where does log.Printf("ublox 9 detected\n") print to? Any logfile? I could not find all the printings anywhere....

b3nn0 commented 1 year ago

To create a Pull Request, you need to

Here the long version...: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests

I changed the order of GPS init to first detect the correct baud rate and then reprogram the module

Keep in mind that auto-detection needs to happen before and after reconfiguration, because Stratux tries to change the baud-rate for some GPS devices. And they should always connect, even if reconfiguration fails for some reason.

Btw: where does log.Printf("ublox 9 detected\n") print to

The normal log file when you click on logs in the web interface. This particular one is inside an if globalSettings.DEBUG. So it will only print if you enable debug logging in the settings. And of course only if an Ublox 9 is actually detected - and detection only works via USB, so you will not see that for now.

b3nn0 commented 1 year ago

Solved by #209