Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
EMM
meteorolog
Commits
95f610b1
Commit
95f610b1
authored
Jun 01, 2017
by
Nelso Jost
Browse files
DEVEL: reestructuring repl files and usage
parent
1bab7777
Changes
8
Show whitespace changes
Inline
Side-by-side
esplogger/Makefile
View file @
95f610b1
...
@@ -14,9 +14,13 @@ install-platformio:
...
@@ -14,9 +14,13 @@ install-platformio:
sudo
python get-pip.py
&&
rm
get-pip.py
sudo
python get-pip.py
&&
rm
get-pip.py
sudo
pip
install
platformio
sudo
pip
install
platformio
firmware
:
firmware
:
build upload monitor
build
:
@
echo
"
$$
PIO_BUILD"
| sh
@
echo
"
$$
PIO_BUILD"
| sh
@
$(MAKE)
monitor
upload
:
cd
$(PIODIR)
&&
platformio run
-t
upload
monitor
:
monitor
:
platformio device monitor
platformio device monitor
...
@@ -83,6 +87,6 @@ define PIO_BUILD
...
@@ -83,6 +87,6 @@ define PIO_BUILD
rm
-rf
$(PIODIR)/src
rm
-rf
$(PIODIR)/src
platformio
init
--board
$(PIOBOARD)
-d
$(PIODIR)
platformio
init
--board
$(PIOBOARD)
-d
$(PIODIR)
cp
-rf
$(PIOPROJ)/*
$(PIODIR)/src/
cp
-rf
$(PIOPROJ)/*
$(PIODIR)/src/
cd
$(PIODIR)
&&
platformio
run
-t
upload
cd
$(PIODIR)
&&
platformio
run
endef
endef
export
PIO_BUILD
export
PIO_BUILD
esplogger/firmware/esplogger/esplogger.ino
View file @
95f610b1
...
@@ -5,47 +5,21 @@
...
@@ -5,47 +5,21 @@
*---------------------------------------------------------------------------*/
*---------------------------------------------------------------------------*/
#include <Arduino.h>
#include <Arduino.h>
#include "repl.h"
#include "repl.h"
#include "repl_gpio.h"
#include "repl_sdcard.h"
#include "wifi.h"
#include "wifi.h"
#include "blinker.h"
#include "sdcard.h"
#define BUILTIN_LED 2
Blinker
blinker
(
BUILTIN_LED
);
Ticker
alog_ticker
;
bool
LOGGING
=
true
;
void
REPL_WIFISCAN
(
String
command
);
void
REPL_WIFISCAN
(
String
command
);
void
REPL_BLINK
(
String
command
);
void
REPL_DWRITE
(
String
command
);
void
REPL_AREAD
(
String
command
);
void
REPL_ALOG
(
String
command
);
void
REPL_SDCARDINFO
(
String
command
);
REPL_COMMAND
commands
[]
=
\
REPL_COMMAND
commands
[]
=
\
{
{
{
"wifiscan"
,
REPL_WIFISCAN
,
ALLCMD_REPL_GPIO
,
"wifiscan"
,
ALLCMD_REPL_SDCARD
,
{
"wifiscan"
,
REPL_WIFISCAN
,
"wifiscan"
,
"List all availables SSID in range for connection."
},
"List all availables SSID in range for connection."
},
{
"blink"
,
REPL_BLINK
,
"blink <interval>"
,
{
NULL
}
"Blink builtin led (pin 2) with given <interval> in seconds (int|float). "
"Use
\"
blink 0
\"
to stop it."
},
{
"dwrite"
,
REPL_DWRITE
,
"dwrite <pin> <value>"
,
"Digital write <value> (number|high|low) on <pin>. "
},
{
"aread"
,
REPL_AREAD
,
"aread <pin>"
,
"Read analogic pin and print out the value."
},
{
"alog"
,
REPL_ALOG
,
"alog <pin> <interval>"
,
"Start datalog on analogic pin with given interval."
},
{
"sdcardinfo"
,
REPL_SDCARDINFO
,
"sdcardinfo"
,
"Show a summary of the SD card info."
},
{
NULL
,
NULL
}
};
};
REPL
repl
(
commands
);
REPL
repl
(
commands
);
...
@@ -62,112 +36,11 @@ void loop()
...
@@ -62,112 +36,11 @@ void loop()
}
}
void
REPL_WIFISCAN
(
String
command
)
void
REPL_WIFISCAN
(
REPL
*
repl
)
{
{
wifiscan
();
wifiscan
();
}
}
void
REPL_BLINK
(
String
command
)
{
float
interval
=
get_arg
(
command
,
1
).
toFloat
();
if
(
interval
==
0
)
{
blinker
.
deactivate
();
if
(
LOGGING
)
{
Serial
.
print
(
"
\n
[INFO] Deactivated blink builtin led (pin 2)."
);
}
}
else
{
blinker
.
activate
(
interval
);
if
(
LOGGING
)
{
Serial
.
print
(
"
\n
[INFO] Activated blink builtin led (pin 2) with "
);
Serial
.
print
(
interval
);
Serial
.
print
(
" s interval."
);
}
}
}
void
REPL_DWRITE
(
String
command
)
{
String
arg_pin
=
get_arg
(
command
,
1
);
String
arg_value
=
get_arg
(
command
,
2
);
int
pin
=
arg_pin
.
toInt
();
int
value
=
!
arg_value
.
toInt
();
if
(
arg_pin
==
"led"
)
pin
=
BUILTIN_LED
;
if
(
arg_value
==
"high"
)
value
=
0
;
if
(
arg_value
==
"low"
)
value
=
1
;
pinMode
(
pin
,
OUTPUT
);
digitalWrite
(
pin
,
value
);
if
(
LOGGING
)
{
Serial
.
print
(
"
\n
[INFO] Pin "
);
Serial
.
print
(
pin
);
Serial
.
print
(
" was set to "
);
Serial
.
print
(
value
?
"HIGH"
:
"LOW"
);
}
}
void
REPL_AREAD
(
String
command
)
{
int
pin
=
get_arg
(
command
,
1
).
toInt
();
if
(
LOGGING
)
{
Serial
.
print
(
"
\n
[INFO] Reading analog pin "
);
Serial
.
print
(
pin
);
Serial
.
println
(
":"
);
}
Serial
.
print
(
analogRead
(
pin
));
}
void
alog_update
(
int
pin
)
{
repl
.
log
(
"a"
+
String
(
pin
)
+
":"
+
String
(
analogRead
(
pin
)));
}
void
REPL_ALOG
(
String
command
)
{
int
pin
=
get_arg
(
command
,
1
).
toInt
();
int
interval
=
get_arg
(
command
,
2
).
toInt
();
if
(
interval
==
0
)
{
alog_ticker
.
detach
();
if
(
LOGGING
)
{
Serial
.
print
(
"
\n
[INFO] Deactivated datalog on analog pin "
);
Serial
.
print
(
pin
);
Serial
.
print
(
"."
);
}
}
else
{
alog_ticker
.
attach
(
interval
,
alog_update
,
pin
);
if
(
LOGGING
)
{
Serial
.
print
(
"
\n
[INFO] Activated datalog on analog pin "
);
Serial
.
print
(
pin
);
Serial
.
print
(
" with "
);
Serial
.
print
(
interval
);
Serial
.
print
(
" s interval."
);
}
}
}
void
REPL_SDCARDINFO
(
String
command
)
{
print_sdcard_info
();
}
esplogger/firmware/esplogger/repl.cpp
View file @
95f610b1
/*-----------------------------------------------------------------------------
/*-----------------------------------------------------------------------------
* Author: Nelso G. Jost (nelsojost@gmail.com)
* Author: Nelso G. Jost (nelsojost@gmail.com)
* License: GPLv2
* License: GPLv2
* Purpose:
Read-Eval-Print-Loop functionality
* Purpose:
Provide basic GPIO control commands for the REPL.
*---------------------------------------------------------------------------*/
*---------------------------------------------------------------------------*/
#include <Arduino.h>
#include <Arduino.h>
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
REPL
::
REPL
(
REPL_COMMAND
*
command_map
)
REPL
::
REPL
(
REPL_COMMAND
*
command_map
)
{
{
this
->
_fp_map
=
command_map
;
this
->
_fp_map
=
command_map
;
this
->
_history
[
0
]
=
""
;
}
}
...
@@ -31,25 +32,25 @@ void REPL::run(void)
...
@@ -31,25 +32,25 @@ void REPL::run(void)
else
if
(
c
==
'['
)
else
if
(
c
==
'['
)
this
->
_history_previous
();
this
->
_history_previous
();
else
if
(
c
==
'
[
'
)
else
if
(
c
==
'
]
'
)
this
->
_history_next
();
this
->
_history_next
();
else
else
{
{
this
->
_command
+=
c
;
this
->
_command
_buffer
+=
c
;
if
(
c
!=
13
)
Serial
.
write
(
c
);
if
(
c
!=
13
)
Serial
.
write
(
c
);
}
}
//Serial.println(int(c));
//Serial.println(int(c));
if
(
this
->
_command
.
indexOf
(
"
\r
"
)
!=
-
1
||
if
(
this
->
_command
_buffer
.
indexOf
(
"
\r
"
)
!=
-
1
||
this
->
_command
.
indexOf
(
"
\n
"
)
!=
-
1
)
this
->
_command
_buffer
.
indexOf
(
"
\n
"
)
!=
-
1
)
{
{
this
->
_command
.
trim
();
this
->
_command
_buffer
.
trim
();
if
(
this
->
_command
==
"help"
)
this
->
print_help
();
if
(
this
->
_command
_buffer
==
"help"
)
this
->
print_help
();
else
if
(
this
->
_command
!=
""
)
this
->
_execute_command
();
else
if
(
this
->
_command
_buffer
!=
""
)
this
->
_execute_command
();
if
(
c
!=
13
)
Serial
.
print
(
this
->
prompt
+
" "
);
if
(
c
!=
13
)
Serial
.
print
(
this
->
prompt
+
" "
);
this
->
_command
=
""
;
this
->
_command
_buffer
=
""
;
}
}
Serial
.
flush
();
Serial
.
flush
();
}
}
...
@@ -62,36 +63,68 @@ void REPL::_clear_line(void)
...
@@ -62,36 +63,68 @@ void REPL::_clear_line(void)
" "
" "
"
\r
"
);
"
\r
"
);
Serial
.
print
(
"> "
);
Serial
.
print
(
"> "
);
this
->
_command
=
""
;
this
->
_command
_buffer
=
""
;
}
}
void
REPL
::
_backspace
(
void
)
void
REPL
::
_backspace
(
void
)
{
{
if
(
this
->
_command
.
length
()
!=
0
)
if
(
this
->
_command
_buffer
.
length
()
!=
0
)
{
{
Serial
.
write
(
8
);
Serial
.
write
(
8
);
Serial
.
write
(
32
);
Serial
.
write
(
32
);
Serial
.
write
(
8
);
Serial
.
write
(
8
);
this
->
_command
.
remove
(
this
->
_command
.
length
()
-
1
);
this
->
_history_index
=
0
;
this
->
_command_buffer
.
remove
(
this
->
_command_buffer
.
length
()
-
1
);
}
}
}
}
void
REPL
::
_history_previous
(
void
)
void
REPL
::
_history_previous
(
void
)
{
{
if
(
this
->
_history_index
<
HISTORY_MAX
-
1
&&
\
this
->
_history
[
this
->
_history_index
]
!=
""
)
{
this
->
_command_buffer
=
this
->
_history
[
this
->
_history_index
];
this
->
_history_index
++
;
Serial
.
print
(
"
\r
\r
"
);
Serial
.
print
(
this
->
prompt
+
" ["
+
this
->
_history_index
+
"] "
);
Serial
.
print
(
this
->
_command_buffer
);
}
//this->log("history previous" + String(this->_history_index));
}
}
void
REPL
::
_history_next
(
void
)
void
REPL
::
_history_next
(
void
)
{
{
if
(
this
->
_history_index
>
0
&&
\
this
->
_history
[
this
->
_history_index
]
!=
""
)
{
this
->
_command_buffer
=
this
->
_history
[
this
->
_history_index
];
this
->
_history_index
--
;
Serial
.
print
(
"
\r
\r
"
);
Serial
.
print
(
this
->
prompt
+
" ["
+
this
->
_history_index
+
"] "
);
Serial
.
print
(
this
->
_command_buffer
);
}
//this->log("history next" + String(this->_history_index));
}
void
REPL
::
_history_save
(
void
)
{
this
->
_history_index
=
0
;
if
(
this
->
_history
[
0
]
!=
this
->
_command_buffer
)
{
for
(
int
i
=
0
;
i
<
HISTORY_MAX
-
2
;
i
++
)
{
this
->
_history
[
i
+
1
]
=
this
->
_history
[
i
];
}
this
->
_history
[
0
]
=
this
->
_command_buffer
;
}
}
}
int
REPL
::
_execute_command
(
void
)
int
REPL
::
_execute_command
(
void
)
{
{
String
command_name
=
get_arg
(
this
->
_command
,
0
);
String
command_name
=
get_arg
(
this
->
_command
_buffer
,
0
);
bool
show_help
=
false
;
bool
show_help
=
false
;
if
(
command_name
.
endsWith
(
"?"
))
if
(
command_name
.
endsWith
(
"?"
))
...
@@ -118,7 +151,8 @@ int REPL::_execute_command(void)
...
@@ -118,7 +151,8 @@ int REPL::_execute_command(void)
Serial
.
println
(
rc
->
help
);
Serial
.
println
(
rc
->
help
);
return
0
;
return
0
;
}
}
rc
->
func
(
this
->
_command
);
rc
->
func
(
this
);
this
->
_history_save
();
return
0
;
return
0
;
}
}
rc
++
;
rc
++
;
...
@@ -153,9 +187,9 @@ void REPL::print_help(void)
...
@@ -153,9 +187,9 @@ void REPL::print_help(void)
void
REPL
::
log
(
String
msg
)
void
REPL
::
log
(
String
msg
)
{
{
Serial
.
print
(
"
\n
[LOG] "
+
msg
+
"
\n
"
+
this
->
prompt
+
" "
);
Serial
.
print
(
"
\n
[LOG] "
+
msg
+
"
\n
"
+
this
->
prompt
+
" "
);
if
(
this
->
_command
.
length
()
>
0
)
if
(
this
->
_command
_buffer
.
length
()
>
0
)
{
{
Serial
.
print
(
this
->
_command
);
Serial
.
print
(
this
->
_command
_buffer
);
}
}
}
}
...
...
esplogger/firmware/esplogger/repl.h
View file @
95f610b1
...
@@ -6,11 +6,14 @@
...
@@ -6,11 +6,14 @@
#ifndef REPL_H
#ifndef REPL_H
#define REPL_H
#define REPL_H
#define HISTORY_MAX 10
class
REPL
{};
typedef
struct
typedef
struct
{
{
const
char
*
name
;
const
char
*
name
;
void
(
*
func
)(
String
);
void
(
*
func
)(
REPL
*
);
const
char
*
prototype
;
const
char
*
prototype
;
const
char
*
help
;
const
char
*
help
;
}
REPL_COMMAND
;
}
REPL_COMMAND
;
...
@@ -26,20 +29,22 @@ public:
...
@@ -26,20 +29,22 @@ public:
void
run
(
void
);
void
run
(
void
);
void
print_help
(
void
);
void
print_help
(
void
);
void
log
(
String
msg
);
void
log
(
String
msg
);
String
get_arg
(
int
index
);
private:
private:
REPL_COMMAND
*
_fp_map
;
REPL_COMMAND
*
_fp_map
;
String
_command
=
""
;
String
_command_buffer
=
""
;
String
_history
[
HISTORY_MAX
];
int
_history_index
=-
1
;
void
_backspace
(
void
);
void
_backspace
(
void
);
void
_clear_line
(
void
);
void
_clear_line
(
void
);
void
_history_previous
(
void
);
void
_history_previous
(
void
);
void
_history_next
(
void
);
void
_history_next
(
void
);
void
_history_save
(
void
);
int
_execute_command
(
void
);
int
_execute_command
(
void
);
};
};
String
get_arg
(
String
command
,
int
index
);
#endif
#endif
esplogger/firmware/esplogger/repl_gpio.cpp
0 → 100644
View file @
95f610b1
/*-----------------------------------------------------------------------------
* Author: Nelso G. Jost (nelsojost@gmail.com)
* License: GPLv2
* Purpose: Read-Eval-Print-Loop functionality
*---------------------------------------------------------------------------*/
#include <Arduino.h>
#include "repl.h"
#include "blinker.h"
#define BUILTIN_LED 2
Blinker
blinker
(
BUILTIN_LED
);
Ticker
alog_ticker
;
void
REPL_DWRITE
(
REPL
*
repl
)
{
String
arg_pin
=
repl
->
get_arg
(
1
);
String
arg_value
=
repl
->
get_arg
(
2
);
int
pin
=
arg_pin
.
toInt
();
int
value
=
!
arg_value
.
toInt
();
if
(
arg_pin
==
"led"
)
pin
=
BUILTIN_LED
;
if
(
arg_value
==
"high"
)
value
=
0
;
if
(
arg_value
==
"low"
)
value
=
1
;
pinMode
(
pin
,
OUTPUT
);
digitalWrite
(
pin
,
value
);
repl
->
log
(
"
\n
[INFO] Pin "
+
String
(
pin
)
+
" was set to "
+
value
?
"HIGH"
:
"LOW"
);
}
void
REPL_AREAD
(
REPL
*
repl
)
{
int
pin
=
repl
->
get_arg
(
1
).
toInt
();
repl
.
log
(
"
\n
[INFO] Read analog pin "
+
String
(
pin
)
+
" value:"
+
String
(
analogRead
(
pin
));
}
void
alog_callback
(
int
pin
,
REPL
*
repl
)
{
repl
.
log
(
"a"
+
String
(
pin
)
+
":"
+
String
(
analogRead
(
pin
)));
}
void
REPL_ALOG
(
REPL
*
repl
)
{
int
pin
=
get_arg
(
1
).
toInt
();
int
interval
=
get_arg
(
2
).
toInt
();
if
(
interval
==
0
)
{
alog_ticker
.
detach
();
repl
->
log
(
"
\n
[INFO] Deactivated datalog on analog pin "
+
String
(
pin
)
+
"."
);
}
else
{
alog_ticker
.
attach
(
interval
,
alog_callback
,
pin
,
repl
);
repl
->
log
(
"
\n
[INFO] Activated datalog on analog pin "
+
String
(
pin
)
+
" with "
+
String
(
interval
)
+
" s interval."
);
}
}
void
REPL_BLINK
(
REPL
*
repl
)
{
float
interval
=
repl
->
get_arg
(
1
).
toFloat
();
if
(
interval
==
0
)
{
blinker
.
deactivate
();
repl
->
log
(
"
\n
[INFO] Deactivated blink builtin led (pin 2)."
);
}
else
{
blinker
.
activate
(
interval
);
repl
->
log
(
"
\n
[INFO] Activated blink builtin led (pin 2) with "
String
(
interval
)
+
" s interval."
);
}
}
esplogger/firmware/esplogger/repl_gpio.h
0 → 100644
View file @
95f610b1
/*-----------------------------------------------------------------------------
* Author: Nelso G. Jost (nelsojost@gmail.com)
* License: GPLv2
* Purpose: Provide basic GPIO control commands for the REPL.
*---------------------------------------------------------------------------*/
#ifndef REPL_GPIO_H
#define REPL_GPIO_H
#define CMD_REPL_BLINK {\
"blink", REPL_BLINK, "blink <interval>", \
"Blink builtin led (pin 2) with given <interval> in seconds (int|float). " \
"Use \"blink 0\" to stop it."}
#define CMD_REPL_DWRITE {\
"dwrite", REPL_DWRITE, "dwrite <pin> <value>",\
"Digital write <value> (number|high|low) on <pin>. "}
#define CMD_REPL_AREAD {\
"aread", REPL_AREAD, "aread <pin>", \
"Read analogic pin and print out the value."}
#define CMD_REPL_ALOG {\
"alog", REPL_ALOG, "alog <pin> <interval>", \
"Start datalog on analogic pin with given interval."}
#define ALLCMD_REPL_GPIO\
CMD_REPL_BLINK,\
CMD_REPL_DWRITE,\
CMD_REPL_AREAD,\
CMD_REPL_ALOG
void
REPL_BLINK
(
REPL
*
repl
);
void
REPL_DWRITE
(
REPL
*
repl
);
void
REPL_AREAD
(
REPL
*
repl
);
void
REPL_ALOG
(
REPL
*
repl
);
#endif
esplogger/firmware/esplogger/repl_sdcard.cpp
0 → 100644
View file @
95f610b1
/*-----------------------------------------------------------------------------
* Author: Nelso G. Jost (nelsojost@gmail.com)
* License: GPLv2
* Purpose: Provide basic SD card management commands for the REPL.
*---------------------------------------------------------------------------*/
#include <Arduino.h>
#include "repl.h"
#include "sdcard.h"
void
REPL_SDCARDINFO
(
REPL
*
repl
)