I have searched the web and the forum for an answer to the problem I am running into. If I missed something, please direct me to the answer.
I am working on writing a program that will utilize AX25 on a unix system. I have been using a Raspberry Pi but also have a full CentOS7 system. The program is a console application that runs similar to a listening socket server (but more for AX25).
I understand that on a Unix/Linux system, ReadLn transfer information to the variable when a line feed (\n) is received. On a Windows system it is a carriage return and line feed (\r\n). I have also learned that some older mac systems used just carriage return (\r).
When I create a little test program and run it from a terminal, the program runs great. When I put it in and try to work with it through AX25, it no longer behaves correctly. The code below is one of my test programs. When it works over AX25, I have to press the enter key 2 times (which the program receives 2 \r characters) to get it past the ReadLn. Another observation is that if I just continue to perform inputs, the output was one <enter> press behind.
I ran into a site that talked about this problem but used C code. Here is the link:
https://thomask.sdf.org/blog/2015/09/27/ax-25-client-and-server-programming.htmlHere is the modified C code (which does work):
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char *argv[]) {
/* Adjust standard in and out to minimise buffering when using '\r' line endings
* * Line buffering works best for stdin
* * No buffering works best for stdout */
int loop = 1;
size_t size = 32 * sizeof(char);
if (argc != 2) {
fprintf(stderr
, "Usage: %s calling_station\n", argv
[0]); }
while(loop==1) {
/* Display greeting using callsign from command line argument */
/* Read in a line */
if (getdelim(&buffer, &size, '\r', stdin) < 0) {
fprintf(stderr
, "Failed to read line\n"); }
/* Strip carriage return from response */
/* Reply */
printf("Your Input: %s\r", buffer
); if(buffer[0]=='b') {
loop=0;
}
}
return 0;
}
It has been many years since I have programmed in C. While C will produce some very tight and efficient code, FPC is much more easy to deal with strings and still produce fairly tight code (it also depends on my programming skill). I also find FPC very easy to integrate with MariaDB/MySQL.
Can someone point me in a direction that could help me get the ReadLn to work?
Thank you!
Matt
Sample code:
program Project1;
{$mode fpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
sysutils,
Classes;
var
//i: Longint;
callsign: string;
loop: Boolean;
choice: string;
const
prompt = 'L,S,R,K,H,B> ';
begin
if ParamCount<1 then
begin
write('Enter your callsign: ');
ReadLn(callsign);
end
else
begin
callsign:=ParamStr(1);
end;
callsign:=UpperCase(callsign);
writeln(callsign);
loop:=True;
while loop do begin
write(prompt);
flush(output);
ReadLn(choice);
if sizeof(choice) > 0 then begin
if (uppercase(choice)='B') or (uppercase(choice)='BYE') then begin
loop:=False;
end
else if (uppercase(choice)='L') then begin
writeln('This would list messages');
flush(output);
end
else if (uppercase(choice)='H') then begin
writeln('This would list the help commands');
flush(output);
end;
end;
end;
end.