Browse Source

terminal is working, but expect some bugs...

phyto 6 months ago
parent
commit
54a41cfeb3
6 changed files with 111 additions and 25 deletions
  1. 2
    1
      .gitignore
  2. 7
    0
      serial/serial.c
  3. 12
    7
      simulator/rdtemp/cli.ino
  4. 6
    0
      simulator/rdtemp/rdtemp.ino
  5. 33
    6
      ui/t.c
  6. 51
    11
      ui/terminal.c

+ 2
- 1
.gitignore View File

@@ -28,5 +28,6 @@ viz/*.a
28 28
 audio/t
29 29
 audio/*.wav
30 30
 
31
-hi/log.*
31
+ui/log.*
32
+ui/t
32 33
 

+ 7
- 0
serial/serial.c View File

@@ -10,6 +10,8 @@
10 10
 
11 11
 #include  "serial.h"
12 12
 
13
+extern int		verbosity;
14
+
13 15
 /* -------------------------------------------------------------------- */
14 16
 static int baudrate2const(int bauds)
15 17
 {
@@ -107,6 +109,11 @@ tcsetattr(uart0, TCSANOW, &options);
107 109
 
108 110
 tcflush(uart0, TCIFLUSH);		/* do it again, sam */
109 111
 
112
+if (verbosity) {
113
+	fprintf(stderr, "%s %s uart0 = %d\n",
114
+			__FILE__, __func__, uart0);
115
+	}
116
+
110 117
 return uart0;
111 118
 }
112 119
 /* -------------------------------------------------------------------- */

+ 12
- 7
simulator/rdtemp/cli.ino View File

@@ -18,7 +18,7 @@ if (param->magic != 0xfde9) {
18 18
   return 1;
19 19
   }
20 20
 if (param->delai < 100) {
21
-  prtln("delay too short");
21
+  prt(param->delai); prtln("delay too short");
22 22
   return 2;
23 23
   }
24 24
 delta = param->temp_maxi - param->temp_mini;
@@ -121,16 +121,18 @@ switch(key) {
121 121
 
122 122
 }
123 123
 /* --------------------------------------------------------------- */
124
-
124
+/*
125
+ *  use this function with caution, it can burn your system !
126
+ */
125 127
 void test_relais(short nb) {
126 128
 short foo;
127 129
 prtln("test du relais frigo");
128 130
 
129 131
 for (foo=0; foo<nb; foo++) {    
130
-  digitalWrite(RELAIS_FRIGO, HIGH); 
132
+  controle_frigo(1); 
131 133
   delay(parametres.delai);
132 134
              
133
-  digitalWrite(RELAIS_FRIGO, LOW); 
135
+  controle_frigo(1);  
134 136
   delay(parametres.delai);
135 137
   }
136 138
 }
@@ -189,12 +191,15 @@ do  {
189 191
     case 'h':  hexdump((unsigned char *)&parametres,
190 192
                             sizeof(Global));           break;
191 193
     case 's':  setvalue(line, &parametres);            break;
192
-    case 'T':  test_relais(5);                         break; 
193
-
194
+    
194 195
     case 'v':   validate_config(&parametres);          break;
196
+
195 197
     case '+':   controle_frigo(1);                     break;
196 198
     case '-':   controle_frigo(0);                     break;
197
-       
199
+    case '1':   controle_ventilo(1);                   break;
200
+    case '0':   controle_ventilo(0);                   break;
201
+    case 'T':   test_relais(5);                        break; 
202
+   
198 203
     default:    prtln("gni ?");                        break;
199 204
     }
200 205
   

+ 6
- 0
simulator/rdtemp/rdtemp.ino View File

@@ -125,6 +125,12 @@ void loop() {
125 125
       case '-':           /* eteint le frigo */
126 126
           controle_frigo(0);
127 127
           break;
128
+      case '1':           /* allume le ventilo */
129
+          controle_ventilo(1);
130
+          break;
131
+      case '0':           /* eteint le ventilo */
132
+          controle_ventilo(0);
133
+          break;
128 134
       default:
129 135
           prtln("M bad control code");
130 136
           break;          

+ 33
- 6
ui/t.c View File

@@ -13,8 +13,38 @@
13 13
 
14 14
 int	verbosity;
15 15
 
16
+/* ---------------------------------------------------------------- */
17
+int special_dumper(FILE *fp, unsigned char octet)
18
+{
19
+static int		idx = 0;
20
+static unsigned char	buffer[16];
21
+
22
+int			foo, c;
23
+
24
+#if DEBUG_LEVEL > 1
25
+fprintf(stderr, "%s $%x %c\n", __func__, octet, octet);
26
+#endif
27
+
28
+buffer[idx++] = octet;
29
+
30
+if (idx==16) {
31
+	fprintf(fp, "dmp : ");
32
+	for (foo=0; foo<16; foo++) {
33
+		fprintf(fp, "%02x ", buffer[foo]);
34
+		}
35
+	fprintf(fp, " -  |");
36
+	for (foo=0; foo<16; foo++) {
37
+		c = buffer[foo];
38
+		fprintf(fp, "%c", isprint(c) ? c : ' ');
39
+		}
40
+	fprintf(fp, "|\n");	fflush(fp);
41
+	idx = 0;
42
+	}
16 43
 
44
+return 0;
45
+}
17 46
 /* ---------------------------------------------------------------- */
47
+
18 48
 void help(int k)
19 49
 {
20 50
 puts("options : ");
@@ -31,7 +61,7 @@ int		opt, foo;
31 61
 int		serial_in;
32 62
 char		*device = "/dev/ttyS0";
33 63
 int		K = 0;
34
-char		ligne[100];
64
+// char		ligne[100];
35 65
 
36 66
 while ((opt = getopt(argc, argv, "d:hv")) != -1) {
37 67
 	switch (opt) {
@@ -43,15 +73,12 @@ while ((opt = getopt(argc, argv, "d:hv")) != -1) {
43 73
 		}
44 74
 	}
45 75
 
46
-printf("\n*** compiled %s %s ***\n", __DATE__, __TIME__);
76
+printf("\n*** compiled %s %s\n", __DATE__, __TIME__);
47 77
 printf("*** device: %s\n", device);
48 78
 
49
-sleep(1);
50
-
51 79
 serial_in = prepare_UART(device, 9600);
52 80
 if (serial_in < 0) {
53
-	fprintf(stderr, "\n%s : open device : error %d on %s\n",
54
-				argv[0], serial_in, device);
81
+	fprintf(stderr, "err open %s : %d\n", device, serial_in);
55 82
 	exit(1);
56 83
 	}
57 84
 

+ 51
- 11
ui/terminal.c View File

@@ -6,6 +6,9 @@
6 6
 #include  <string.h>
7 7
 #include <unistd.h>
8 8
 #include <stdlib.h>
9
+#include  <errno.h>
10
+#include  <time.h>
11
+#include <sys/time.h>
9 12
 #include <sys/select.h>
10 13
 
11 14
 #include <ncurses.h>
@@ -15,6 +18,8 @@
15 18
 
16 19
 extern int	verbosity;
17 20
 
21
+int special_dumper(FILE *fp, unsigned char octet);
22
+
18 23
 /* ---------------------------------------------------------------- */
19 24
 static void bordure(WINDOW * w, char *texte, int type)
20 25
 {
@@ -31,11 +36,12 @@ static int interactive(WINDOW *glass, int fd_local, int fd_remote)
31 36
 int		flag_exit = 0;
32 37
 long		tstart, tcur;
33 38
 char		ligne[100];
39
+int		received;
34 40
 
35 41
 /* --- variables for select */
36 42
 struct timeval	tv;
37 43
 fd_set		rfds;
38
-int		retval;
44
+int		retval,mfd;
39 45
 
40 46
 #if DEBUG_LEVEL
41 47
 fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__,
@@ -46,18 +52,51 @@ tstart = time(NULL);
46 52
 
47 53
 wclear(glass);		wrefresh(glass);
48 54
 
55
+mfd = (fd_local>fd_remote ? fd_local : fd_remote) + 1;		/* XXX */
56
+
57
+#if DEBUG_LEVEL
58
+sprintf(ligne, "%s : mfd is %d\n", __func__, mfd);
59
+waddstr(glass, ligne); wrefresh(glass);
60
+#endif
61
+
49 62
 do	{
50 63
 	tcur = time(NULL);
51 64
 
52 65
 	FD_ZERO(&rfds);
53 66
 	FD_SET(fd_local, &rfds);	/* stdin */
54 67
 	FD_SET(fd_remote, &rfds);	/* teletype */
55
-	tv.tv_sec = tv.tv_sec = 0;	/* no timeout */
68
+	tv.tv_sec = tv.tv_usec = 0;	/* no timeout */
69
+
70
+	retval = select(mfd, &rfds, NULL, NULL, &tv);	
71
+	if (-1 == retval) {
72
+		sprintf(ligne, "err select %s\n", strerror(errno));
73
+		waddstr(glass, ligne); wrefresh(glass);
74
+		continue;
75
+		}
56 76
 
57
-	retval = select(2, &rfds, NULL, NULL, &tv);	
77
+	/*** est-ce la liaison serie ? */
78
+	if (FD_ISSET(fd_remote, &rfds)) {
79
+		/* get the incoming byte */
80
+		received = getbyte(fd_remote);
81
+		if (verbosity) {
82
+			special_dumper(stderr, received);
83
+			fflush(stderr);
84
+			}
85
+		waddch(glass, received);
86
+		if ('\n' == received) waddch(glass, '\r');
87
+		}
58 88
 
89
+	/*** est-ce le yuser avec son clavier ? */
90
+	if (FD_ISSET(fd_local, &rfds)) {
91
+		received = getch();
92
+		if (verbosity) {
93
+			sprintf(ligne, " $%02x from yuser\n", received);
94
+			waddstr(glass, ligne);
95
+			}
96
+		putbyte(fd_remote, received);		
97
+		}
59 98
 
60
-	wrefresh(glass);	usleep(155*1000);
99
+	wrefresh(glass);
61 100
 
62 101
 	} while (! flag_exit);
63 102
 
@@ -71,12 +110,12 @@ int run_the_terminal(int fd_serial, char *title, WINDOW *win)
71 110
 WINDOW		*terminal, *ecran;
72 111
 int		wid_term, hei_term, lin_term, col_term;
73 112
 int		foo;
74
-char		ligne[100];
75
-unsigned char	byte;
113
+// char		ligne[100];
114
+// unsigned char	byte;
76 115
 int		fd_stdin;
77 116
 
78 117
 lin_term = col_term = 4;			/* position */
79
-wid_term = 40;
118
+wid_term = 60;
80 119
 hei_term = 25;
81 120
 
82 121
 fd_stdin = fileno(stdin);	/* for select or pool */
@@ -94,13 +133,14 @@ if (verbosity) {
94 133
 #if DEBUG_LEVEL > 1
95 134
 	fprintf(stderr, "in '%s', mvwaddstr -> %d\n", __func__, foo);
96 135
 #endif
97
-	wrefresh(ecran);	sleep(2);
136
+	wrefresh(ecran);	sleep(1);
98 137
 	}
99 138
 
100 139
 foo = interactive(ecran, fd_stdin, fd_serial);
101
-
102
-sleep(1);
103
-
140
+if (foo) {
141
+	fprintf(stderr, "interactive -> %d\n", foo);
142
+	sleep(1);
143
+	}
104 144
 
105 145
 delwin(terminal);
106 146
 touchwin(stdscr);			wrefresh(stdscr);

Loading…
Cancel
Save