summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@nolonger-other.tetra.james.local>2020-10-27 10:57:41 +0000
committerroot <root@nolonger-other.tetra.james.local>2020-10-27 10:57:41 +0000
commit232cf21c35c79458969fd661d18ca779c5418c2e (patch)
treeda96dac46f43583047f5d0501675a21325c93587
parent59415c62777983cbc8a1096266149fb8f18e94a9 (diff)
downloadgalaxy_sia-232cf21c35c79458969fd661d18ca779c5418c2e.tar.gz
galaxy_sia-232cf21c35c79458969fd661d18ca779c5418c2e.tar.bz2
galaxy_sia-232cf21c35c79458969fd661d18ca779c5418c2e.zip
statics
-rw-r--r--keypad.c79
-rw-r--r--keypad.h2
-rw-r--r--net_keypad.c16
-rw-r--r--serial_keypad.c16
4 files changed, 76 insertions, 37 deletions
diff --git a/keypad.c b/keypad.c
index f9d9b07..78c67a2 100644
--- a/keypad.c
+++ b/keypad.c
@@ -71,11 +71,11 @@ typedef struct {
} GD_LCD;
-WINDOW *win, *dwin = NULL;
-FILE *dfile = NULL;
+static WINDOW *win, *dwin = NULL;
+static FILE *dfile = NULL;
-void debug_print (const char *fmt, ...)
+static void debug_print (const char *fmt, ...)
{
va_list va;
@@ -84,6 +84,7 @@ void debug_print (const char *fmt, ...)
va_start (va, fmt);
vw_printw (dwin, fmt, va);
va_end (va);
+ wrefresh (dwin);
}
if (dfile) {
@@ -126,12 +127,14 @@ static unsigned char checksum (unsigned char *p, size_t l)
}
-void hexdump_pkt (const char *prefix, GD_PKT *p)
+static void hexdump_pkt (const char *prefix, GD_PKT *p)
{
unsigned i, j, k;
unsigned char *d = p->pkt;
size_t l = p->data_len + 2;
+ if (!dwin && !dfile) return;
+
for (i = 0; i < l; i += 16) {
debug_print ("%s %04x ", prefix, i);
@@ -168,7 +171,7 @@ void hexdump_pkt (const char *prefix, GD_PKT *p)
}
-int send_pkt (int fd, GD_PKT *tx)
+static int send_pkt (int fd, GD_PKT *tx)
{
unsigned char buf[GD_MAX_PKT_LEN];
size_t len = tx->data_len + 2;
@@ -187,7 +190,7 @@ int send_pkt (int fd, GD_PKT *tx)
}
-int recv_pkt (int fd, GD_PKT *rx, int timeout)
+static int recv_pkt (int fd, GD_PKT *rx, int timeout)
{
size_t len;
unsigned char sum;
@@ -221,7 +224,7 @@ int recv_pkt (int fd, GD_PKT *rx, int timeout)
}
-int gd_transact (int fd, GD_PKT *tx, GD_PKT *rx, unsigned char rx_addr, unsigned char rx_fn, int timeout)
+static int gd_transact (int fd, GD_PKT *tx, GD_PKT *rx, unsigned char rx_addr, unsigned char rx_fn, int timeout)
{
unsigned tries = 8;
@@ -245,7 +248,7 @@ int gd_transact (int fd, GD_PKT *tx, GD_PKT *rx, unsigned char rx_addr, unsigned
}
-int gd_get_panel_ver (int fd, unsigned char a, int *v)
+static int gd_get_panel_ver (int fd, unsigned char a, int *v)
{
GD_PKT o, i;
@@ -284,7 +287,7 @@ int gd_get_panel_ver (int fd, unsigned char a, int *v)
}
-int gd_fn_05 (int fd, unsigned char a, unsigned char b, unsigned char c)
+static int gd_fn_05 (int fd, unsigned char a, unsigned char b, unsigned char c)
{
GD_PKT o, i;
@@ -304,7 +307,7 @@ int gd_fn_05 (int fd, unsigned char a, unsigned char b, unsigned char c)
}
-int gd_fn_06 (int fd, unsigned char a, unsigned char b, unsigned char c, unsigned char *data, size_t len)
+static int gd_fn_06 (int fd, unsigned char a, unsigned char b, unsigned char c, unsigned char *data, size_t len)
{
GD_PKT o, i;
@@ -324,7 +327,7 @@ int gd_fn_06 (int fd, unsigned char a, unsigned char b, unsigned char c, unsigne
return 0;
}
-void gd_to_ascii (unsigned char *c, size_t l)
+static void gd_to_ascii (unsigned char *c, size_t l)
{
for (; l; l--, c++) {
@@ -337,7 +340,7 @@ void gd_to_ascii (unsigned char *c, size_t l)
-void gd_extract_lcd (GD_PKT *i, GD_LCD *lcd)
+static void gd_extract_lcd (GD_PKT *i, GD_LCD *lcd)
{
memcpy (lcd->line0, &i->data[3], GD_LCD_LINE_LEN);
@@ -364,7 +367,7 @@ void gd_extract_lcd (GD_PKT *i, GD_LCD *lcd)
-int gd_fn_get_lcd (int fd, GD_LCD *lcd)
+static int gd_fn_get_lcd (int fd, GD_LCD *lcd)
{
GD_PKT o, i;
@@ -382,7 +385,7 @@ int gd_fn_get_lcd (int fd, GD_LCD *lcd)
}
-int gd_fn_key (int fd, char key, int dedup, GD_LCD *lcd)
+static int gd_fn_key (int fd, char key, int dedup, GD_LCD *lcd)
{
int tries = 5;
@@ -456,7 +459,7 @@ int gd_fn_key (int fd, char key, int dedup, GD_LCD *lcd)
return 0;
}
-int gd_fn_poll (int fd, GD_LCD *lcd)
+static int gd_fn_poll (int fd, GD_LCD *lcd)
{
GD_PKT o, i;
@@ -474,7 +477,7 @@ int gd_fn_poll (int fd, GD_LCD *lcd)
}
-int gd_fn_key_press (int fd, char key, GD_LCD *lcd)
+static int gd_fn_key_press (int fd, char key, GD_LCD *lcd)
{
static int alternate = 0;
int ret;
@@ -489,7 +492,7 @@ int gd_fn_key_press (int fd, char key, GD_LCD *lcd)
-int gd_init (int fd)
+static int gd_init (int fd)
{
int gv = 0;
@@ -543,17 +546,21 @@ int gd_init (int fd)
if (gd_fn_05 (fd, 0x02, 0xff, 0xff))
return -1;
+#if 0
+
if (gd_fn_key_press (fd, '\e', NULL))
return -1;
if (gd_fn_key_press (fd, '\e', NULL))
return -1;
+#endif
+
return 0;
}
-void curses_init (void)
+static void curses_init (int debug)
{
initscr(); /* Start curses mode */
@@ -587,27 +594,31 @@ void curses_init (void)
box (win, 0, 0);
wrefresh (win);
- timeout (0);
- dwin = newwin (20, 80, 16, 0);
- box (dwin, 0, 0);
- dwin = newwin (18, 78, 17, 1);
- scrollok (dwin, TRUE);
- wrefresh (dwin);
- timeout (0);
+ if (debug) {
+ dwin = newwin (20, 80, 16, 0);
+ box (dwin, 0, 0);
+ wrefresh (dwin);
+
+ dwin = newwin (18, 78, 17, 1);
+ scrollok (dwin, TRUE);
+ wrefresh (dwin);
+
+ }
+ timeout (0);
}
-void curses_end (void)
+static void curses_end (void)
{
endwin();
}
-void curses_show (GD_LCD *lcd)
+static void curses_show (GD_LCD *lcd)
{
wmove (win, 1, 1);
@@ -619,19 +630,27 @@ void curses_show (GD_LCD *lcd)
}
-int gd_keypad (int fd)
+int gd_keypad (int fd, const char *dfn, int debug)
{
GD_LCD l;
int ch;
-// dfile = fopen ("log", "w");
+ if (dfn) {
+ dfile = fopen (dfn, "w");
+
+ if (!dfile) {
+ perror ("open debug log");
+ return -1;
+ }
+ }
+
if (gd_init (fd)) {
printf ("Failed to init comms with panel\n");
return -1;
}
- curses_init();
+ curses_init (debug);
diff --git a/keypad.h b/keypad.h
index c14e2f9..71ebdc6 100644
--- a/keypad.h
+++ b/keypad.h
@@ -1,4 +1,4 @@
#ifndef _keypad_h_
#define _keypad_h_
-extern int gd_keypad(int);
+extern int gd_keypad (int fd,const char *dfn, int debug);
#endif /* _keypad_h_ */
diff --git a/net_keypad.c b/net_keypad.c
index 9169b80..e315704 100644
--- a/net_keypad.c
+++ b/net_keypad.c
@@ -14,7 +14,7 @@
static int usage (const char *name)
{
fprintf (stderr, "Usage:\n");
- fprintf (stderr, "%s -h host [-p port]\n", name);
+ fprintf (stderr, "%s -h host [ -p port ] [ -d debug ] [ -l log_file ]\n", name);
fprintf (stderr, "\n");
return -1;
@@ -26,9 +26,11 @@ int main (int argc, char *argv[])
unsigned opt;
const char *host = NULL;
unsigned port = 10001;
+ const char *log = NULL;
+ int debug = 0;
int fd;
- while ((opt = getopt (argc, argv, "h:p:z:USPRBFTAD")) != -1) {
+ while ((opt = getopt (argc, argv, "h:p:z:dl:")) != -1) {
switch (opt) {
case 'h':
host = optarg;
@@ -38,6 +40,14 @@ int main (int argc, char *argv[])
port = atoi (optarg);
break;
+ case 'd':
+ debug++;
+ break;
+
+ case 'l':
+ log = optarg;
+ break;
+
default: /* '?' */
return usage (argv[0]);
}
@@ -52,5 +62,5 @@ int main (int argc, char *argv[])
return -1;
}
- return gd_keypad (fd);
+ return gd_keypad (fd, log, debug);
}
diff --git a/serial_keypad.c b/serial_keypad.c
index 91939e6..6c92e1b 100644
--- a/serial_keypad.c
+++ b/serial_keypad.c
@@ -14,7 +14,7 @@
static int usage (const char *name)
{
fprintf (stderr, "Usage:\n");
- fprintf (stderr, "%s -p device [ -b baud ]\n", name);
+ fprintf (stderr, "%s -p device [ -b baud ] [ -d debug ] [ -l log_file ]\n", name);
fprintf (stderr, "\n");
return -1;
@@ -25,10 +25,12 @@ int main (int argc, char *argv[])
{
unsigned opt;
const char *port = NULL;
+ const char *log = NULL;
+ int debug = 0;
unsigned baud = 9600;
int fd;
- while ((opt = getopt (argc, argv, "h:p:z:USPRBFTAD")) != -1) {
+ while ((opt = getopt (argc, argv, "h:p:z:dl:")) != -1) {
switch (opt) {
case 'p':
port = optarg;
@@ -38,6 +40,14 @@ int main (int argc, char *argv[])
baud = atoi (optarg);
break;
+ case 'd':
+ debug++;
+ break;
+
+ case 'l':
+ log = optarg;
+ break;
+
default: /* '?' */
return usage (argv[0]);
}
@@ -56,7 +66,7 @@ int main (int argc, char *argv[])
}
- return gd_keypad (fd);
+ return gd_keypad (fd, log, debug);
}