Skip to content

Commit

Permalink
Add freq to lanentry (#445)
Browse files Browse the repository at this point in the history
* Fix lan_send of LOGENTRY and FREQMSG

- send with terminating newline
- drop size restrictions in lan_send_message()
- change definition of msg-codes into readable ascii characters
  • Loading branch information
dl1jbe authored Oct 14, 2024
1 parent 54c3410 commit 678adbc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/background_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void *background_process(void *ptr) {
if (lan_message[0] == '\0') {

if (lan_recv() >= 0) {
lan_message[strlen(lan_message) - 1] = '\0';
g_strchomp(lan_message);
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/lancode.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ char lan_message[256];
//--------------------------------------
int bc_socket_descriptor[MAXNODES];
ssize_t bc_sendto_rc;
int cl_send_inhibit = 0;
bool cl_send_inhibit = false;
struct sockaddr_in bc_address[MAXNODES];
/* host names and UDP ports to send notifications to */
char bc_hostaddress[MAXNODES][16];
Expand Down Expand Up @@ -167,7 +167,7 @@ int lan_recv(void) {
errno = 0; /* clear the error */

if (lan_recv_message[1] == CLUSTERMSG)
cl_send_inhibit = 1; // this node does not send cluster info
cl_send_inhibit = true; // this node does not send cluster info

if (lan_recv_rc > 0)
recv_packets++;
Expand Down Expand Up @@ -269,23 +269,22 @@ static int lan_send(char *lanbuffer) {

/* ----------------- send lan message ----------*/

int send_lan_message(int opcode, char *message) {
void send_lan_message(int opcode, char *message) {
char sendbuffer[102];

sendbuffer[0] = thisnode;
sendbuffer[1] = opcode;
sendbuffer[2] = '\0';
strncat(sendbuffer, message, 98);
if (opcode == CLUSTERMSG) {
if (cl_send_inhibit == 0) {
if (!cl_send_inhibit) {
strcat(sendbuffer, "\n");
lan_send(sendbuffer);
}
}

if (opcode == LOGENTRY) {
sendbuffer[82] = '\0';

strcat(sendbuffer, "\n");
lan_send(sendbuffer);
}

Expand All @@ -298,7 +297,7 @@ int send_lan_message(int opcode, char *message) {
lan_send(sendbuffer);
}
if (opcode == FREQMSG) {
sendbuffer[10] = '\0';
strcat(sendbuffer, "\n");
lan_send(sendbuffer);
}
if (opcode == INCQSONUM) {
Expand All @@ -324,7 +323,7 @@ int send_lan_message(int opcode, char *message) {
lan_send(sendbuffer);
}

return 0;
return;
}

/* ----------------- send talk message ----------*/
Expand Down
22 changes: 11 additions & 11 deletions src/lancode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@

#define MAXNODES 8

#define LOGENTRY 49
#define CLUSTERMSG 50
#define TLFSPOT 51
#define TLFMSG 52
#define FREQMSG 53
#define INCQSONUM 54
#define TIMESYNC 55
#define QTCRENTRY 56
#define QTCSENTRY 57
#define QTCFLAG 58
#define LOGENTRY '1'
#define CLUSTERMSG '2'
#define TLFSPOT '3'
#define TLFMSG '4'
#define FREQMSG '5'
#define INCQSONUM '6'
#define TIMESYNC '7'
#define QTCRENTRY '8'
#define QTCSENTRY '9'
#define QTCFLAG ':'

#include <hamlib/rig.h>

Expand All @@ -52,7 +52,7 @@ int lan_recv_close(void);
int lan_recv(void);
int lan_send_init(void);
int lan_send_close(void);
int send_lan_message(int opcode, char *message);
void send_lan_message(int opcode, char *message);
void talk(void);
int send_freq(freq_t freq);
void send_time(void) ;
Expand Down
10 changes: 5 additions & 5 deletions src/log_to_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

pthread_mutex_t disk_mutex = PTHREAD_MUTEX_INITIALIZER;

char lan_logline[81];
char lan_logline[LOGLINELEN + 1];


/* restart band timer if in wpx and qso on new band */
Expand Down Expand Up @@ -106,10 +106,10 @@ void log_to_disk(int from_lan) {

} else { /* qso from lan */

/* LOGENTRY contains 82 characters (node,command and logline */
g_strlcpy(lan_logline, lan_message + 2, 81);
char *fill = g_strnfill(80 - strlen(lan_logline), ' ');
g_strlcat(lan_logline, fill, 81); /* fill with spaces if needed */
/* LOGENTRY contains max. 89 characters (node,command and logline */
g_strlcpy(lan_logline, lan_message + 2, LOGLINELEN);
char *fill = g_strnfill(LOGLINELEN - 1 - strlen(lan_logline), ' ');
g_strlcat(lan_logline, fill, LOGLINELEN); /* add spaces if no frequency data */

if (cqwwm2) { /* mark as coming from other station */
if (lan_message[0] != thisnode)
Expand Down
2 changes: 1 addition & 1 deletion src/makelogline.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ char *makelogline(struct qso_t *qso) {
}
FILL_TO(87);

assert(strlen(logline) == 87);
assert(strlen(logline) == LOGLINELEN - 1);

return logline;
}
Expand Down
8 changes: 4 additions & 4 deletions test/test_lancode.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void test_send_freq_80(void **state) {

assert_int_equal(sendto_call_count, 1);
assert_non_null(sendto_last_message);
assert_string_equal(sendto_last_message, "A5 3567.9");
assert_string_equal(sendto_last_message, "A5 3567.9\n");
}

void test_send_freq_10(void **state) {
Expand All @@ -45,7 +45,7 @@ void test_send_freq_10(void **state) {

assert_int_equal(sendto_call_count, 1);
assert_non_null(sendto_last_message);
assert_string_equal(sendto_last_message, "A528123.5");
assert_string_equal(sendto_last_message, "A528123.5\n");
}

void test_send_freq_80_notrx(void **state) {
Expand All @@ -57,7 +57,7 @@ void test_send_freq_80_notrx(void **state) {

assert_int_equal(sendto_call_count, 1);
assert_non_null(sendto_last_message);
assert_string_equal(sendto_last_message, "A5 80.0");
assert_string_equal(sendto_last_message, "A5 80.0\n");
}

void test_send_freq_10_notrx(void **state) {
Expand All @@ -69,5 +69,5 @@ void test_send_freq_10_notrx(void **state) {

assert_int_equal(sendto_call_count, 1);
assert_non_null(sendto_last_message);
assert_string_equal(sendto_last_message, "A5 10.0");
assert_string_equal(sendto_last_message, "A5 10.0\n");
}

0 comments on commit 678adbc

Please sign in to comment.