Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CyanLight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
fxk8y
CyanLight
Commits
444dd63f
Commit
444dd63f
authored
2 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
Begin building NVSExplorer's MQTT interface
parent
0205e0df
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CLC-qthing/SiliconTorch/NVSExplorer.cpp
+47
-4
47 additions, 4 deletions
CLC-qthing/SiliconTorch/NVSExplorer.cpp
CLC-qthing/SiliconTorch/NVSExplorer.hpp
+1
-0
1 addition, 0 deletions
CLC-qthing/SiliconTorch/NVSExplorer.hpp
CLC-qthing/device_main.cpp
+24
-7
24 additions, 7 deletions
CLC-qthing/device_main.cpp
with
72 additions
and
11 deletions
CLC-qthing/SiliconTorch/NVSExplorer.cpp
+
47
−
4
View file @
444dd63f
...
...
@@ -2,6 +2,7 @@
// C++ system level
#include
<set>
#include
<vector>
#include
<cstring>
// memset, memcpy, strncmp
// #include <cstdlib>
#include
<cinttypes>
...
...
@@ -14,11 +15,11 @@
// #include "driver/uart.h"
// project specific
//
#include
""
#include
<SpiderLib/Util.hpp>
// qthing stuff
//
#include <qthing>
#include
<qthing>
#include
<qthing/mqtt_common.hpp>
...
...
@@ -36,6 +37,45 @@ namespace SiliconTorch {
ESP_LOGI
(
TAG
,
"Starting NVSExplorer[📡]"
);
nvs_flash_init
();
using
MessageHandler
=
std
::
function
<
void
(
std
::
vector
<
std
::
string
>&
,
qthing
::
multipart_message_t
)
>
;
uint16_t
deviceTopicLEN
=
deviceTopic
(
""
).
length
();
auto
wrapMessageHandler
=
[
deviceTopicLEN
](
MessageHandler
handler
)
{
// TODO: capture handler byVal or byRef ?
return
[
&
](
qthing
::
multipart_message_t
msg
)
{
if
(
msg
.
length
==
msg
.
total_length
&&
msg
.
offset
==
0
)
{
std
::
string
_topic
(
msg
.
topic
.
c_str
()
+
deviceTopicLEN
);
ESP_LOGW
(
TAG
,
"wrapMessageHandler() -> _topic[ %s ]"
,
_topic
.
c_str
());
std
::
vector
<
std
::
string
>
topicParts
=
SpiderLib
::
Util
::
split
(
_topic
,
'/'
);
handler
(
topicParts
,
msg
);
}
else
{
ESP_LOGW
(
TAG
,
"Multipart messages are not supported atm. topic[ %s ]"
,
msg
.
topic
.
c_str
());
}
};
};
MessageHandler
sharp
=
[](
std
::
vector
<
std
::
string
>&
topic
,
qthing
::
multipart_message_t
msg
)
{
ESP_LOGE
(
TAG
,
"sharpyyyyy handler called on topic[ %s ] HÖ HÖ HÖ HÖ HÖÖÖöööö"
,
msg
.
topic
.
c_str
());
};
qthing
::
add_binary_message_callback
(
deviceTopic
(
"#"
),
wrapMessageHandler
(
sharp
));
/* qthing::add_binary_message_callback("+/+/test", [&](qthing::multipart_message_t msg) {
char buf[128];
memset(buf, 0x00, 128);
memcpy(buf, msg.payload, std::min(msg.length, (uint32_t)127));
ESP_LOGW("+/+/test", "topic[ %s ] message[ %s ]", msg.topic.c_str(), buf);
}); */
}
...
...
@@ -99,6 +139,10 @@ namespace SiliconTorch {
}
std
::
string
NVSExplorer
::
deviceTopic
(
const
std
::
string
&
suffix
)
{
return
std
::
string
(
DEVICE_NAMESPACE
+
"NVS/"
)
+
suffix
;
}
std
::
string
toString
(
std
::
set
<
std
::
string
>&
set
,
std
::
string
delimiter
)
{
...
...
@@ -135,6 +179,5 @@ namespace SiliconTorch {
return
std
::
string
(
str
);
}
}
}
This diff is collapsed.
Click to expand it.
CLC-qthing/SiliconTorch/NVSExplorer.hpp
+
1
−
0
View file @
444dd63f
...
...
@@ -38,6 +38,7 @@ namespace SiliconTorch {
std
::
set
<
std
::
string
>
listNamespaces
();
std
::
set
<
std
::
string
>
listKeys
(
std
::
string
&
_namespace
);
std
::
string
deviceTopic
(
const
std
::
string
&
suffix
);
// ⬇⬇ Singleton stuff ⬇⬇
...
...
This diff is collapsed.
Click to expand it.
CLC-qthing/device_main.cpp
+
24
−
7
View file @
444dd63f
...
...
@@ -34,6 +34,8 @@
#include
<algorithm>
SiliconTorch
::
CyanBus
::
CyanBus
*
cyanBus
=
NULL
;
...
...
@@ -60,20 +62,35 @@ void device_main() {
qthing
::
add_binary_message_callback
(
"+/+/test"
,
[
&
](
qthing
::
multipart_message_t
msg
)
{
// if (msg.length != msg.total_length) {
// ESP_LOGD("+/+/test", "multipart messages not supported atm");
// return;
// }
char
buf
[
128
];
memset
(
buf
,
0x00
,
128
);
memcpy
(
buf
,
msg
.
payload
,
msg
.
length
);
memcpy
(
buf
,
msg
.
payload
,
std
::
min
(
msg
.
length
,
(
uint32_t
)
127
));
ESP_LOGW
(
"+/+/test"
,
"topic[ %s ] message[ %s ]"
,
msg
.
topic
.
c_str
(),
buf
);
});
qthing
::
add_binary_message_callback
(
"+/+/+"
,
[](
qthing
::
multipart_message_t
msg
)
{
char
buf
[
128
];
memset
(
buf
,
0x00
,
128
);
memcpy
(
buf
,
msg
.
payload
,
std
::
min
(
msg
.
length
,
(
uint32_t
)
127
));
ESP_LOGE
(
"+/+/test"
,
"HDL_0 topic[ %s ] message[ %s ]"
,
msg
.
topic
.
c_str
(),
buf
);
ESP_LOGW
(
"+/+/+"
,
"topic[ %s ] message[ %s ]"
,
msg
.
topic
.
c_str
(),
buf
);
});
qthing
::
add_binary_message_callback
(
"test/+/+"
,
[](
qthing
::
multipart_message_t
msg
)
{
char
buf
[
128
];
memset
(
buf
,
0x00
,
128
);
memcpy
(
buf
,
msg
.
payload
,
std
::
min
(
msg
.
length
,
(
uint32_t
)
127
));
ESP_LOGW
(
"test/+/+"
,
"topic[ %s ] message[ %s ]"
,
msg
.
topic
.
c_str
(),
buf
);
});
/* qthing::add_binary_message_callback("#", [&](qthing::multipart_message_t msg) {
char buf[128];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment