Skip to content

Commit

Permalink
simplify send_lan_message
Browse files Browse the repository at this point in the history
- drop artificial (and not needed) restrictions of line length
- move common code (append NL and send it to lan) to end
- drop empty cases
  • Loading branch information
dl1jbe committed Oct 9, 2024
1 parent 9ad23a5 commit 1294d1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 50 deletions.
60 changes: 11 additions & 49 deletions src/lancode.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,62 +269,24 @@ static int lan_send(char *lanbuffer) {

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

#define MAX_MESSAGE_LEN 98

void send_lan_message(int opcode, char *message) {
char sendbuffer[102];
char sendbuffer[MAX_MESSAGE_LEN + 4]; /* + node + opcode + NL + \0 */

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

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

if (opcode == TLFSPOT) {
sendbuffer[82] = '\0';
strcat(sendbuffer, "\n");
lan_send(sendbuffer);
}
if (opcode == TLFMSG) {
sendbuffer[82] = '\0';
strcat(sendbuffer, "\n");
lan_send(sendbuffer);
}
if (opcode == FREQMSG) {
strcat(sendbuffer, "\n");
lan_send(sendbuffer);
}
if (opcode == INCQSONUM) {
strcat(sendbuffer, "\n");
lan_send(sendbuffer);
}
if (opcode == TIMESYNC) {
strcat(sendbuffer, "\n");
sendbuffer[14] = '\0';
lan_send(sendbuffer);
}
if (opcode == QTCRENTRY) {
strcat(sendbuffer, "\n");
sendbuffer[94] = '\0';
lan_send(sendbuffer);
}
if (opcode == QTCSENTRY) {
strcat(sendbuffer, "\n");
sendbuffer[100] = '\0';
lan_send(sendbuffer);
}
if (opcode == QTCFLAG) {
strcat(sendbuffer, "\n");
lan_send(sendbuffer);
}
strcat(sendbuffer, "\n");
lan_send(sendbuffer);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_lancode.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ void test_lan_send_message_all_codes(void **state) {

void test_lan_send_message_inhibit_cluster(void **state) {
cl_send_inhibit = true;

send_lan_message(CLUSTERMSG, "DX de ...");
assert_int_equal(sendto_call_count, 0);
assert_null(sendto_last_message);

send_lan_message(LOGENTRY, "160....");
assert_int_equal(sendto_call_count, 1);
check_line_format(LOGENTRY, "160....");

}


Expand Down

0 comments on commit 1294d1e

Please sign in to comment.