Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sensor System
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Institut für Informatik
QE Research Group
FORTE
Sensor System
Merge requests
!20
Create a simple mock client that sends pseudo random values
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Create a simple mock client that sends pseudo random values
43-create-a-mock-client
into
develop
Overview
0
Commits
1
Pipelines
0
Changes
8
Merged
Zoe Pfister
requested to merge
43-create-a-mock-client
into
develop
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
8
Expand
Closes
#43 (closed)
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
c9ae6e8d
1 commit,
2 years ago
8 files
+
210
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
client/client_mock/src/main.cpp
0 → 100644
+
101
−
0
Options
#include
"ESPNow.hpp"
#include
"MockSensor.hpp"
#include
"NoDataAvailableException.hpp"
#include
"f_deep_sleep.hpp"
#include
<Arduino.h>
static
const
char
*
TAG
=
"MAIN"
;
MockSensor
mock_channel0
;
MockSensor
mock_channel1
;
MockSensor
mock_channel2
;
MockSensor
mock_channel3
;
void
send_msgs
(
const
std
::
__cxx11
::
list
<
Message
>
msgs
)
{
for
(
const
Message
&
msg
:
msgs
)
{
if
(
msg
.
send
()
!=
ESP_OK
)
{
RtcMemory
::
store
(
msg
.
getMessageAsMinifiedJsonString
());
}
unsigned
long
ts
=
millis
();
// it takes ~110ms for receiving an acknowledgement by the host in perfect conditions
uint16_t
message_timeout
=
2000
;
while
(
!
was_msg_received
())
{
if
((
millis
()
-
ts
)
>
message_timeout
)
{
RtcMemory
::
store
(
msg
.
getMessageAsMinifiedJsonString
());
ESP_LOGE
(
TAG
,
"Timeout: Host not available
\n
"
);
break
;
}
}
ESP_LOGD
(
TAG
,
"Time until acknowledgement: %ld"
,
millis
()
-
ts
);
}
}
// one loop takes ~2200 ms
void
setup
()
{
unsigned
long
ts
=
millis
();
Serial
.
begin
(
115200
);
// Set the GPIO which conrtols the step up to OUTPUT
gpio_set_direction
(
GPIO_NUM_32
,
GPIO_MODE_OUTPUT
);
// blinking led for debug
// gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT);
// gpio_set_level(GPIO_NUM_17, 1);
DeepSleep
::
print_wakeup_reason
();
DeepSleep
::
bootCount
++
;
ESP_LOGD
(
TAG
,
"Boot number: %d"
,
DeepSleep
::
bootCount
);
gpio_set_level
(
GPIO_NUM_32
,
1
);
// delay(100);
mock_channel0
.
setup
();
mock_channel1
.
setup
();
mock_channel2
.
setup
();
mock_channel3
.
setup
();
mock_channel0
.
setChannel
(
0
);
mock_channel1
.
setChannel
(
1
);
mock_channel2
.
setChannel
(
2
);
mock_channel3
.
setChannel
(
3
);
ESP_LOGD
(
TAG
,
"Setup took %ld ms"
,
millis
()
-
ts
);
try
{
// FIXME: put me into seperate trys? No data will be sent when 1 exception occurs
ts
=
millis
();
auto
messages0
=
mock_channel0
.
buildMessages
();
auto
messages1
=
mock_channel1
.
buildMessages
();
auto
messages2
=
mock_channel2
.
buildMessages
();
auto
messages3
=
mock_channel3
.
buildMessages
();
// roughly takes 500ms, ~120ms for each adc channel, barely anything for battery monitor
ESP_LOGD
(
TAG
,
"Reading data and building messages took %ld ms"
,
millis
()
-
ts
);
gpio_set_level
(
GPIO_NUM_32
,
0
);
// FIXME: put this outside the try loop?
ts
=
millis
();
espnow_setup
();
ESP_LOGD
(
TAG
,
"EPSNow setup took %ld ms"
,
millis
()
-
ts
);
ts
=
millis
();
send_msgs
(
messages0
);
send_msgs
(
messages1
);
send_msgs
(
messages2
);
send_msgs
(
messages3
);
// roughly takes 3s in ideal conditions
ESP_LOGD
(
TAG
,
"Sending messages took %ld ms"
,
millis
()
-
ts
);
}
catch
(
const
NoDataAvailableException
&
e
)
{
std
::
cerr
<<
e
.
what
()
<<
'\n'
;
}
// just to be safe in case exception happens above
gpio_set_level
(
GPIO_NUM_32
,
0
);
// keep it in deep sleep
gpio_hold_en
((
gpio_num_t
)
GPIO_NUM_32
);
// battery protection: go to deep sleep for unlimited time when voltage less than 3.2V
DeepSleep
::
deep_sleep
(
20
);
}
void
loop
()
{}
\ No newline at end of file
Loading