I recently picked up an old Garmin etrex Vista handheld GPS at a swap meet for a dollar.
I took it home, put some batteries in it, and fired it up.
It took some time to synch up with the satellites. (No surprise.)
The time of day was correct. The date was incorrect.
I remembered the GPS week rollover that happened in 2019 - https://en.wikipedia.org/wiki/GPS_week_number_rollover
After doing some research, I thought I would use gpsbabel to reset the time using:
gpsbabel -i garmin -f /dev/ttyUSB0 -o garmin,resettime -F /dev/ttyUSB0I dug out the USB-to-RS232 adapter I used to use to capture bike rides and hikes to upload to Strava in the days before GPSes were integrated into phones.
The hard part was getting gpsbabel to successfully open /dev/ttyUSB0.
I followed all kinds of instruction to try to get it to work. You probably will at least need to do the following:
sudo chmod 666 /dev/ttyUSB0
ls -l /dev/ttyUSB0
sudo usermod -a -G dialout $USERNot 100% sure about this, but odds are you need this too (it matches the Garmin standard);
stty -F /dev/ttyUSB0 9600 cs8 -cstopb -parenb -echo ixon ixoff -crtsctsI doubt this was necessary (module wasn't running):
sudo rmmod garmin_gpsBut no matter what I tried, I kept getting this:
$ sudo gpsbabel -i garmin -f /dev/ttyUSB0 -o gpx -F /tmp/test.gpx
[ERROR] XSERIAL: Cannot open serial port '/dev/ttyUSB0': Permission denied
[ERROR] Cannot open serial port '/dev/ttyUSB0'
garmin: Can't init /dev/ttyUSB0I put the Garmin aside, and set about diagnosing the serial connection. I installed minicom. minicom had no such trouble. I happened to have two USB-to-RS232 adapters, a null modem cable, and a spare laptop. After installing minicom on the laptop, I was able to verify serial data transfer between the two computers.
At this point, I just couldn't understand why gpsbabel couldn't open the serial port. Neither with nor without sudo.
I decided to have a look at the dmesg output. I noticed some messages which reported my connecting/disconnecting/reconnecting the USB-to-RS232 adapter. And then, ... I saw messages containing apparmor="DENIED" every time I ran gpsbabel:
$ sudo gpsbabel -i garmin -f /dev/ttyUSB0 -o gpx -F /tmp/test.gpx
[ERROR] XSERIAL: Cannot open serial port '/dev/ttyUSB0': Permission denied
[ERROR] Cannot open serial port '/dev/ttyUSB0'
garmin: Can't init /dev/ttyUSB0
gerard@karkand:~$ sudo dmesg | tail -200
.
.
.
[1902124.279578] usb 1-4: USB disconnect, device number 10
[1902124.279996] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0
[1902124.280054] pl2303 1-4:1.0: device disconnected
[1902126.348088] usb 1-4: new full-speed USB device number 11 using xhci_hcd
[1902126.472073] usb 1-4: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 4.00
[1902126.472092] usb 1-4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[1902126.472098] usb 1-4: Product: USB-Serial Controller D
[1902126.472102] usb 1-4: Manufacturer: Prolific Technology Inc.
[1902126.475394] pl2303 1-4:1.0: pl2303 converter detected
[1902126.476893] usb 1-4: pl2303 converter now attached to ttyUSB0
[1902258.415523] kauditd_printk_skb: 2 callbacks suppressed
[1902258.415529] audit: type=1400 audit(1780259665.620:715): apparmor="DENIED" operation="open" class="file" profile="snap.gpsbabel.gpsbabel" name="/dev/ttyUSB0" pid=256590 comm="gpsbabel" requested_mask="wr" denied_mask="wr" fsuid=0 ouid=0I researched that and found that this is a symptom of running the gpsbabel Snap - it is a security restriction. So I removed the gpsbabel Snap and installed with apt install instead:
snap remove gpsbabel
sudo apt update
sudo apt install gpsbabelWith the Garmin still disconnected, I attempted a simple gpsbabel command and got this:
$ sudo gpsbabel -i garmin -f /dev/ttyUSB0 -o gpx -F /tmp/test.gpx
[ERROR] GPS_Packet_Read: Timeout. No data received.
garmin: Can't init /dev/ttyUSB0This was very promising; it shows that gpsbabelcan now open the serial port.
I reconnected the Garmin to the interface cable, powered it on, and ran the full gpsbabelcommand to reset the time:
gpsbabel -i garmin -f /dev/ttyUSB0 -o garmin,resettime -F /dev/ttyUSB0This succeeded. I brought the Garmin outside and left it there for about 30 minutes. I looked at the Main Menu page and now the date was showing correctly. (I did have to adjust the Time->Time Zone to US - Pacific to correctly reflect my location.) Now the time and date are correct!