Skip to content

Commit

Permalink
Changed ft8 tx timing to take time_sbitx() instead of time() for sync…
Browse files Browse the repository at this point in the history
…hronization
  • Loading branch information
afarhan committed Aug 1, 2022
1 parent 845f3fd commit 448748b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
24 changes: 12 additions & 12 deletions data/user_settings.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
vfo_a_freq=7100000
vfo_b_freq=7111300
callsign=vu2ese
vfo_a_freq=7074000
vfo_b_freq=7100000
callsign=vu2bvb
grid=Mk97fj
cw_delay=700
data_delay=700
Expand All @@ -9,13 +9,13 @@ current_macro=
sidetone=10
contest_serial=0
sent_exchange=
r1:freq=7100000
r1:volume=88
r1:mode=USB
r1:low=850
r1:high=1250
r1:freq=7074000
r1:volume=85
r1:mode=FT8
r1:low=200
r1:high=2450
r1:agc=OFF
r1:gain=78
r1:gain=15
tx_power=30
tx_gain=24
#split=OFF
Expand All @@ -26,7 +26,7 @@ tx_compress=30
#tx=
#rx=
#record=OFF
#step=100Hz
#step=1KHz
#vfo=A
#span=10KHz
spectrum=7000 KHz
Expand Down Expand Up @@ -58,8 +58,8 @@ mode3=1

[40m]
power=30
freq0=7028000
mode0=1
freq0=7074000
mode0=6
freq1=7038000
mode1=2
freq2=7074000
Expand Down
32 changes: 20 additions & 12 deletions modems.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int ft8_tx_buff_index = 0;
int ft8_tx_nsamples = 0;
int ft8_do_decode = 0;
int ft8_do_tx = 0;
int ft8_pitch = 0;
int ft8_mode = FT8_SEMI;
pthread_t ft8_thread;

Expand All @@ -122,10 +123,17 @@ void ft8_interpret(char *received, char *transmit){
char second_word[100];
char third_word[100];
char fourth_word[100];
int freq;

//reset the transmit buffer
transmit[0]= 0;

//extract the received frequency if any
char *f = received + 17;
if (*f == ' ')
f++;
ft8_pitch = atoi(f);

//move past the prefixes
char *q, *p = received + 25;
while (*p == ' ')
Expand Down Expand Up @@ -161,7 +169,6 @@ void ft8_interpret(char *received, char *transmit){
*q++ = *p++;
*q = 0;


if (!strcmp(first_word, "CQ")){
if (strlen(second_word) == 2 && strlen(fourth_word) > 0){
strcpy(contact_callsign, third_word);
Expand All @@ -174,6 +181,7 @@ void ft8_interpret(char *received, char *transmit){

char grid_square[10];
strcpy(grid_square, mygrid);
strcpy(sent_rst, "-10"); //this is fudged, replace it with the actual value
grid_square[4] = 0;
received_rst[0] = 0;
sprintf(transmit, "%s %s %s", contact_callsign, mycallsign, grid_square);
Expand Down Expand Up @@ -220,25 +228,25 @@ void ft8_tx(char *message, int freq){
char cmd[200], buff[1000];
FILE *pf;


for (int i = 0; i < strlen(message); i++)
message[i] = toupper(message[i]);

//timestamp the packets for display log
time_t rawtime = time_sbitx();
char time_str[20];
// time(&rawtime);
struct tm *t = gmtime(&rawtime);
sprintf(time_str, "%02d%02d%02d ", t->tm_hour, t->tm_min, t->tm_sec);
write_console(FONT_LOG_TX, time_str);
write_console(FONT_LOG_TX, message);
write_console(FONT_LOG_TX, "\n");

//printf("ft8 tx:[%s]\n", message);
//generate the ft8 samples into a temporary file
if (!strncmp(message, "CQ ", 3) || ft8_pitch == 0)
ft8_pitch = freq;

printf("transmitting on %d\n", ft8_pitch);
sprintf(cmd, "/home/pi/ft8_lib/gen_ft8 \"%s\" /tmp/ft_tx.wav %d",
message, freq);
message, ft8_pitch);

pf = popen(cmd, "r");
while(fgets(buff, sizeof(buff), pf))
puts(buff);
Expand Down Expand Up @@ -296,8 +304,9 @@ void *ft8_thread_function(void *ptr){
//is this interesting?
if (ft8_mode != FT8_MANUAL && strstr(buff, mycallsign_upper)){
ft8_interpret(buff, response);
if (ft8_mode && strlen(response))
if (ft8_mode && strlen(response)){
ft8_tx(response, get_pitch());
}
else
set_field("#text_in", response);
}
Expand All @@ -321,7 +330,7 @@ void ft8_rx(int32_t *samples, int count){
for (int i = 0; i < count; i += decimation_ratio)
ft8_rx_buff[ft8_rx_buff_index++] = samples[i];

int now = time(NULL);
int now = time_sbitx();
if (now != wallclock)
wallclock = now;
else
Expand Down Expand Up @@ -964,7 +973,7 @@ void modem_poll(int mode){
int bytes_available = get_tx_data_length();
int tx_is_on = is_in_tx();
int key_status;
time_t now;
time_t t;
char buffer[10000];

if (current_mode != mode){
Expand All @@ -990,8 +999,8 @@ void modem_poll(int mode){

switch(mode){
case MODE_FT8:
now = time_sbitx();
if (now % 15 == 0){
t = time_sbitx();
if ((t % 15) == 0){
if(ft8_tx_nsamples > 0 && !tx_is_on){
tx_on();
}
Expand All @@ -1003,7 +1012,6 @@ void modem_poll(int mode){
case MODE_CWR:
key_status = key_poll();
if (!tx_is_on && (bytes_available || key_status) > 0){
puts("switching cw on");
tx_on();
cw_init();
symbol_memory = key_status;
Expand Down
5 changes: 3 additions & 2 deletions sbitx_gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,6 @@ int do_status(struct field *f, cairo_t *gfx, int event, int a, int b){

if (event == FIELD_DRAW){
time_t now = time_sbitx();
// time(&now);
struct tm *tmp = gmtime(&now);

sprintf(buff, "%s | %s", mycallsign, mygrid);
Expand Down Expand Up @@ -1907,7 +1906,6 @@ int do_text(struct field *f, cairo_t *gfx, int event, int a, int b){
else if ((a =='\n' || a == MIN_KEY_ENTER) && !strcmp(get_field("r1:mode")->value, "FT8")
&& f->value[0] != COMMAND_ESCAPE){
ft8_tx(f->value, atoi(get_field("#rx_pitch")->value));
//write_console(FONT_LOG_TX, f->value);
f->value[0] = 0;
}
else if (a >= ' ' && a <= 127 && strlen(f->value) < f->max-1){
Expand Down Expand Up @@ -2224,6 +2222,7 @@ int do_macro(struct field *f, cairo_t *gfx, int event, int a, int b){
if (!strcmp(mode, "FT8") && strlen(buff)){
//we use the setting of the PITCH control for tx freq
ft8_tx(buff, atoi(get_field("#rx_pitch")->value));
set_field("#text_in", "");
//write_console(FONT_LOG_TX, buff);
}
else if (strlen(buff)){
Expand Down Expand Up @@ -3062,7 +3061,9 @@ void utc_set(char *args){
setenv("TZ", "UTC", 1);
gm_now = mktime(&t);

write_console(FONT_LOG, "UTC time is set\n");
time_delta =(long)gm_now -(long)(millis()/1000l);
printf("time_delta = %ld\n", time_delta);
}

void do_cmd(char *cmd){
Expand Down

0 comments on commit 448748b

Please sign in to comment.