From ee5516b8aca5c23d53af7bcaf760964485d27f8a Mon Sep 17 00:00:00 2001 From: nishi Date: Thu, 13 Jun 2024 05:39:17 +0000 Subject: [PATCH] working git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@291 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- HEADER | 1 + RemoteClient/hayes.c | 21 ++++++++++++++++++--- RemoteClient/rcli.c | 11 +++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 HEADER diff --git a/HEADER b/HEADER new file mode 100644 index 0000000..6a61b9f --- /dev/null +++ b/HEADER @@ -0,0 +1 @@ +DataWorks - Simple DBMS diff --git a/RemoteClient/hayes.c b/RemoteClient/hayes.c index b5f4a49..897fc5b 100644 --- a/RemoteClient/hayes.c +++ b/RemoteClient/hayes.c @@ -43,7 +43,7 @@ extern int argc; extern char** argv; int port = -1; -bool connected; +bool connected = false; bool option(const char* str, const char* shortopt, const char* longopt); @@ -171,13 +171,13 @@ int rcli_init(void) { } if(__dw_strcaseequ(resp, "CONNECT")) { printf("Connected\n"); + connected = true; break; } } return 0; } - disconnect(0); - return 1; + return 0; } void disconnect(int sock) { @@ -187,3 +187,18 @@ void disconnect(int sock) { while(inp(get_ioport() + 6) & (1 << 7)) outp(get_ioport() + 4, 0); connected = false; } + +char* readline_sock(void) { + char* resp = modem_response(); + if(__dw_strcaseequ(resp, "NO CARRIER")) { + connected = false; + free(resp); + } + return connected ? resp : NULL; +} + +void writeline(const char* str) { + char* w = __dw_strcat(str, "\r\n"); + write_serial(w); + free(w); +} diff --git a/RemoteClient/rcli.c b/RemoteClient/rcli.c index 7efbe4d..39e9067 100644 --- a/RemoteClient/rcli.c +++ b/RemoteClient/rcli.c @@ -39,6 +39,8 @@ int argc; char** argv; int rcli_init(void); +char* readline_sock(void); +void writeline(const char*); bool option(const char* str, const char* shortopt, const char* longopt) { char* dos_shortopt = __dw_strcat("/", shortopt); @@ -55,4 +57,13 @@ int main(int _argc, char** _argv) { argv = _argv; int st = rcli_init(); if(st != 0) return st; + while(1) { + char* resp = readline_sock(); + if(resp == NULL) { + break; + } + printf("!%s!\n", resp); + free(resp); + } + return 0; } -- 2.43.0