Browse Source

un squelette de gestion de param's

phyto 1 year ago
parent
commit
0a83be585a
3 changed files with 70 additions and 6 deletions
  1. 16
    5
      simulator/rdtemp/cli.ino
  2. 8
    0
      simulator/rdtemp/rdtemp.ino
  3. 46
    1
      simulator/rdtemp/storage.ino

+ 16
- 5
simulator/rdtemp/cli.ino View File

@@ -70,7 +70,11 @@ prtln("");
70 70
 static void clihelp()
71 71
 {
72 72
  prtln("x\texit cli");
73
- prtln("I\tinit storage"); 
73
+ prtln("I\tinit storage");
74
+ prtln("d\tdisplay config");
75
+ prtln("r\tread config");
76
+ prtln("w\twrite config");
77
+ prtln("H\thexdump config");
74 78
 }
75 79
 /* --------------------------------------------------------------- */
76 80
 void phytocli(void)
@@ -87,15 +91,22 @@ prtln("entering cli, '?' to help, 'x' to quit.");
87 91
 do  {
88 92
   prt(" + ");
89 93
   ret = readline(line,TLINE);
90
-#if DEBUG
94
+#if DEBUG > 1
91 95
   hexdump((unsigned char *)line, ret);
92 96
 #endif
93 97
   key = *(sptr = strtok(line, " "));
94 98
 
95 99
   switch(key) {
96
-    case 'x':  flag_exit=1;                     break;
97
-    case '?':  clihelp();                       break;
98
-    case 'I':  init_storage();                  break;
100
+    case 'x':  flag_exit=1;                            break;
101
+    case '?':  clihelp();                              break;
102
+    case 'I':  init_storage();                         break;
103
+    case 'd':  display_config(&parametres);            break;
104
+    case 'r':  read_config(0, &parametres);            break;
105
+    case 'w':  write_config(0, &parametres);           break;
106
+    case 'H':  hexdump((unsigned char *)&parametres,
107
+                            sizeof(Global));           break;
108
+
109
+    default:    prtln("gni ?");                        break;
99 110
     }
100 111
   
101 112
   } while (!flag_exit);

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

@@ -7,6 +7,14 @@
7 7
 #define NBVAL   4
8 8
 #define DELAI   1000
9 9
 
10
+typedef struct {
11
+  unsigned short    magic;
12
+  char              tag[4];
13
+  short             delai;
14
+  } Global;
15
+
16
+Global parametres;
17
+
10 18
 /* -------------------------------------------------- */
11 19
 void setup() {
12 20
   Serial.begin(9600);

+ 46
- 1
simulator/rdtemp/storage.ino View File

@@ -1,14 +1,59 @@
1 1
 /* --------------------------------------------------------------- */
2 2
 #include <EEPROM.h>
3 3
 /* --------------------------------------------------------------- */
4
-int init_storage(void)
4
+short init_storage(void)
5 5
 {
6
+short     foo;
7
+
6 8
 Serial.println(__func__);
7 9
 
8 10
 Serial.print("eeprom length: ");
9 11
 Serial.println(EEPROM.length());
12
+Serial.print("global length: ");
13
+Serial.println(sizeof(Global));
14
+
15
+}
16
+/* --------------------------------------------------------------- */
17
+short read_config(short num, Global *where)
18
+{
19
+#if DEBUG
20
+prtln(">>> read config");
21
+#endif
22
+
23
+
24
+
10 25
 
26
+return -1;
27
+}
28
+/* --------------------------------------------------------------- */
29
+short write_config(short num, Global *from)
30
+{
31
+#if DEBUG
32
+prtln(">>> write config");
33
+#endif
34
+
35
+from->magic = 0xfde9;
36
+memcpy(from->tag, "aaaa", 4);
11 37
 
38
+return -1;
12 39
 }
13 40
 /* --------------------------------------------------------------- */
41
+short display_config(Global *what)
42
+{
43
+char    foo, c;
44
+#if DEBUG
45
+prtln(">>> display config");
46
+#endif
47
+
48
+prt("Magic     : ");    prtln(what->magic);
49
+prt("Id        : ");
50
+for (foo=0; foo<4; foo++) {
51
+  if (isprint(c=what->tag[foo]))  prt(c);
52
+  else                            prt('?');
53
+  }
54
+prtln("");
55
+prt("Delay     : ");    prtln(what->delai);
56
+
57
+return -1;
58
+}
14 59
 /* --------------------------------------------------------------- */

Loading…
Cancel
Save