Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FT8 transmit dies with segmentation fault. #7

Closed
wb2osz opened this issue Aug 3, 2022 · 7 comments
Closed

FT8 transmit dies with segmentation fault. #7

wb2osz opened this issue Aug 3, 2022 · 7 comments

Comments

@wb2osz
Copy link

wb2osz commented Aug 3, 2022

The builtin FT8 receive works great but I have not been able to transmit.

Power supply is 20A. Transmit power 10W.
Antenna tuner was adjusted for low SWR using antenna analyzer before connecting to sBitx.
The application was updated today.

I entered my callsign and grid square.

Clicking a station calling CQ and using the reply button, causes the application to terminate.
Same thing happens if I try using the FT8 CQ button.

This is what gdb has to say about the situation:

[Detaching after fork from child process 4266]
Sample rate 12000 Hz, 180000 samples, 15.000 seconds
Block size = 1920
Subblock size = 960
N_FFT = 3840
Max magnitude: -11.6 dB
Decoded 14 messages
[Detaching after fork from child process 4269]
Sample rate 12000 Hz, 180000 samples, 15.000 seconds
Block size = 1920
Subblock size = 960
N_FFT = 3840
Max magnitude: -11.5 dB
Decoded 14 messages
[Detaching after fork from child process 4271]
Sample rate 12000 Hz, 180000 samples, 15.000 seconds
Block size = 1920
Subblock size = 960
N_FFT = 3840
Max magnitude: -10.8 dB
Decoded 15 messages
transmitting on 753
[Detaching after fork from child process 4273]
Packed data: e6 ed ee e7 38 a9 a1 1f aa 48

FSK tones: 3140652716447647142536160317463333253140652204551215173603670207123617723140652

Thread 1 "sbitx" received signal SIGSEGV, Segmentation fault.
0xb5e9cd80 in __GI__IO_fread (buf=0x90adc <ft8_tx_buff>, size=4, count=180000, fp=0x0) at iofread.c:37
37 iofread.c: No such file or directory.
(gdb)

(gdb) backtrace
#0 0xb5e9cd80 in __GI__IO_fread (buf=0x90adc <ft8_tx_buff>, size=4, count=180000, fp=0x0) at iofread.c:37
#1 0x000250a4 in ft8_tx (message=0xbeffeafc "WA4KBM WB2OSZ -10 ", freq=2140) at modems.c:261
#2 0x0001d718 in do_macro (f=0x56410 <main_controls+93016>, gfx=0x0, event=4, a=22, b=421) at sbitx_gtk.c:2224
#3 0x0001ef84 in on_mouse_press (widget=0x3898b0, event=0x394c80, data=0x0) at sbitx_gtk.c:2618
#4 0xb6936b8c in () at /usr/lib/arm-linux-gnueabihf/libgtk-3.so.0
(gdb)

@wb2osz
Copy link
Author

wb2osz commented Aug 3, 2022

Here's the problem, in modems.c:

The FT8 audio file is generated with:

sprintf(cmd, "/home/pi/ft8_lib/gen_ft8 "%s" /tmp/ft_tx.wav %d",
...

A little later, it is trying to read a different file which does not exist:

pf = fopen("/home/pi/sbitx/ft8tx_float.raw", "r");

There is no check for NULL so the following fread dies.

FIX PART 1:

Check for failed fopen and produce an error message rather than crashing the application:


-       pf = fopen("/home/pi/sbitx/ft8tx_float.raw", "r");
-       ft8_tx_nsamples = fread(ft8_tx_buff, sizeof(float), 180000, pf);
-       fclose(pf);
+       pf = fopen("/dev/shm/ft_tx.wav", "r");
+  if (pf != NULL) {
+         ft8_tx_nsamples = fread(ft8_tx_buff, sizeof(float), 180000, pf);
+         fclose(pf);
+  }
+  else {
+    write_console(FONT_LOG_TX, "ERROR - Could not open ft8 tx audio file.\n");
+  }

FIX PART 2:

Read the same file that gen_ft8 produces. Included in above.

Closer but it's still not right.

When transmitting, horrible noises come out of the speaker.
Somewhat random yellow blocks go flashing in the upper right region.

FIX PART 3:

I threw another improvement in there.
/tmp resides on the SD memory card.
I used /dev/shm to hold the temporary file instead.
This is a RAM disk so we are not beating on the SD memory card as much and shortening its lifespan.

This would be even more important for /tmp/ftrx.raw.

@afarhan
Copy link
Owner

afarhan commented Aug 4, 2022 via email

@wb2osz
Copy link
Author

wb2osz commented Aug 6, 2022

A modular architecture has advantages. Components can be tested separately or even replaced with a different implementation.

For example, I ran the ft8 audio file generator, without sbitx being involved, and examined the file it created. It creates a .wav format file with 16 bit integer samples. the modems.c code is written like it is expecting a file with floating point values. (It also did not use binary mode read.) I wrote a little function to read the .wav format file and produce an array of floating point values as expected by the code. It now transmits (something) but never returns to receive. This needs more work to switch back to receive.

Another problem we have is that the FT8 transmit audio file is a full 15 seconds. It should be less than 13 so we are back into receive mode in time to hear stations that start sending a second too early for their time slot. See https://github.com/wb2osz/technightradio/blob/master/poc/WSJT-X-Transmit-with-DDS.docx for my earlier research into this. the next step would be to find out why the audio file is too long. Hopefully it will just be extra silence appended to the end. That should be easy to fix.

@afarhan
Copy link
Owner

afarhan commented Aug 6, 2022 via email

@wb2osz
Copy link
Author

wb2osz commented Aug 6, 2022

(1,2) I don't know the code well enough yet to have an informed opinion.
(3) IMHO, responding on the same frequency is not the best approach. Imagine the mess if everyone who heard the CQ responded on the same frequency at the same time! More experienced FT8 operators taught me to watch the waterfall for a couple cycles and manually set the TX frequency to an unused spot. I was under the assumption that the red line was the FT8 transmit frequency.

@afarhan
Copy link
Owner

afarhan commented Aug 6, 2022 via email

@afarhan
Copy link
Owner

afarhan commented Aug 8, 2022

I have rewritten this entirely to directly use the ft8_lib. Do a git pull to get the latest build

@afarhan afarhan closed this as completed Apr 29, 2023
laluha pushed a commit to laluha/sbitx-oz7bx that referenced this issue Aug 15, 2024
updated eq functions added enable/bypass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants