Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
ShellTask.h
Go to the documentation of this file.
1
22
#ifndef SHELL_TASK_H
23
#define SHELL_TASK_H
24
25
#include <
Scheduler.h
>
26
#include "
Trace.h
"
27
28
namespace
ShellTask
{
29
30
const
size_t
BUF_MAX
= 64;
31
static
char
*
buf
= NULL;
32
33
void
setup
()
34
{
35
TRACE
(
"stack="
);
36
Serial.println(
Scheduler
.
stack
());
37
}
38
39
void
loop
()
40
{
41
// Check for buffer allocation
42
if
(buf == NULL) {
43
buf = (
char
*) malloc(BUF_MAX);
44
TRACE
(
"malloc:buf=0x"
);
45
Serial.println((
int
) buf, HEX);
46
if
(buf == NULL) {
47
delay(1000);
48
return
;
49
}
50
}
51
52
// Read line and yield while waiting for characters
53
// Capture wait time and number of yields
54
char
* bp =
buf
;
55
unsigned
long
yields = 0;
56
unsigned
long
start = millis();
57
int
c;
58
TRACE
(
"stack="
);
59
Serial.println(
Scheduler
.
stack
());
60
while
((c = Serial.read()) !=
'\n'
) {
61
if
(c > 0)
62
*bp++ = c;
63
else
{
64
yields += 1;
65
yield
();
66
}
67
}
68
*bp = 0;
69
70
// Print wait time, number of yields and line
71
unsigned
long
stop = millis();
72
unsigned
long
ms = stop - start;
73
TRACE
(
"yields="
);
74
Serial.print(yields);
75
Serial.print(F(
",ms="
));
76
Serial.print(ms);
77
Serial.print(F(
",buf="
));
78
Serial.println(buf);
79
80
// Check for buffer free command
81
if
(!strcmp_P(buf, (
const
char
*) F(
"free"
))) {
82
TRACE
(
"free:buf=0x"
);
83
Serial.println((
int
) buf, HEX);
84
free(buf);
85
delay(500);
86
buf = NULL;
87
}
88
}
89
};
90
#endif
Trace.h
ShellTask::loop
void loop()
Definition:
ShellTask.h:39
ShellTask::buf
static char * buf
Definition:
ShellTask.h:31
ShellTask
Definition:
ShellTask.h:28
ShellTask::setup
void setup()
Definition:
ShellTask.h:33
SchedulerClass::stack
static size_t stack()
Definition:
Scheduler.cpp:127
Scheduler
SchedulerClass Scheduler
Definition:
Scheduler.cpp:53
ShellTask::BUF_MAX
const size_t BUF_MAX
Definition:
ShellTask.h:30
yield
void yield(void)
Definition:
Scheduler.cpp:153
TRACE
#define TRACE(msg)
Definition:
Trace.h:25
Scheduler.h
examples
SchedulerDemoNamespaces
ShellTask.h
Generated on Thu Aug 31 2017 12:52:30 for Arduino-Scheduler by
1.8.11