un squelette de gestion de param's

This commit is contained in:
phyto 2019-04-30 16:49:21 +02:00
parent a4104e21f7
commit 0a83be585a
3 changed files with 71 additions and 7 deletions

View File

@ -70,7 +70,11 @@ prtln("");
static void clihelp() static void clihelp()
{ {
prtln("x\texit cli"); prtln("x\texit cli");
prtln("I\tinit storage"); prtln("I\tinit storage");
prtln("d\tdisplay config");
prtln("r\tread config");
prtln("w\twrite config");
prtln("H\thexdump config");
} }
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
void phytocli(void) void phytocli(void)
@ -87,15 +91,22 @@ prtln("entering cli, '?' to help, 'x' to quit.");
do { do {
prt(" + "); prt(" + ");
ret = readline(line,TLINE); ret = readline(line,TLINE);
#if DEBUG #if DEBUG > 1
hexdump((unsigned char *)line, ret); hexdump((unsigned char *)line, ret);
#endif #endif
key = *(sptr = strtok(line, " ")); key = *(sptr = strtok(line, " "));
switch(key) { switch(key) {
case 'x': flag_exit=1; break; case 'x': flag_exit=1; break;
case '?': clihelp(); break; case '?': clihelp(); break;
case 'I': init_storage(); break; case 'I': init_storage(); break;
case 'd': display_config(&parametres); break;
case 'r': read_config(0, &parametres); break;
case 'w': write_config(0, &parametres); break;
case 'H': hexdump((unsigned char *)&parametres,
sizeof(Global)); break;
default: prtln("gni ?"); break;
} }
} while (!flag_exit); } while (!flag_exit);

View File

@ -7,6 +7,14 @@
#define NBVAL 4 #define NBVAL 4
#define DELAI 1000 #define DELAI 1000
typedef struct {
unsigned short magic;
char tag[4];
short delai;
} Global;
Global parametres;
/* -------------------------------------------------- */ /* -------------------------------------------------- */
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);

View File

@ -1,14 +1,59 @@
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
#include <EEPROM.h> #include <EEPROM.h>
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
int init_storage(void) short init_storage(void)
{ {
short foo;
Serial.println(__func__); Serial.println(__func__);
Serial.print("eeprom length: "); Serial.print("eeprom length: ");
Serial.println(EEPROM.length()); Serial.println(EEPROM.length());
Serial.print("global length: ");
Serial.println(sizeof(Global));
} }
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
short read_config(short num, Global *where)
{
#if DEBUG
prtln(">>> read config");
#endif
return -1;
}
/* --------------------------------------------------------------- */
short write_config(short num, Global *from)
{
#if DEBUG
prtln(">>> write config");
#endif
from->magic = 0xfde9;
memcpy(from->tag, "aaaa", 4);
return -1;
}
/* --------------------------------------------------------------- */
short display_config(Global *what)
{
char foo, c;
#if DEBUG
prtln(">>> display config");
#endif
prt("Magic : "); prtln(what->magic);
prt("Id : ");
for (foo=0; foo<4; foo++) {
if (isprint(c=what->tag[foo])) prt(c);
else prt('?');
}
prtln("");
prt("Delay : "); prtln(what->delai);
return -1;
}
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */