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
151a5bdd
Commit
151a5bdd
authored
2 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
Preparing new approch to data parsing/reading…
parent
187018e4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CLC-qthing/SiliconTorch/CyanBus.cpp
+49
-42
49 additions, 42 deletions
CLC-qthing/SiliconTorch/CyanBus.cpp
CLC-qthing/SiliconTorch/CyanBus.hpp
+1
-1
1 addition, 1 deletion
CLC-qthing/SiliconTorch/CyanBus.hpp
with
50 additions
and
43 deletions
CLC-qthing/SiliconTorch/CyanBus.cpp
+
49
−
42
View file @
151a5bdd
#include
"CyanBus.hpp"
// C++ system level
#include
<cstring>
// memset
#include
<cstring>
// memset
, strncmp
#include
<cstdlib>
// TODO: is this for memcpy?
#include
<cinttypes>
#include
<functional>
...
...
@@ -39,7 +39,7 @@ namespace SiliconTorch {
namespace
CyanBus
{
// CyanBus envelope header
const
uint8_t
*
const
HEADER
=
(
const
uint8_t
*
)
"fxCyan"
;
const
char
*
const
HEADER
=
"fxCyan"
;
CyanBus
::
CyanBus
(
uint8_t
tx
,
uint8_t
rx
,
uint8_t
de
,
uint8_t
re
,
uint32_t
baudRate
,
uint8_t
uartChannel
)
:
tx
(
tx
),
rx
(
rx
),
de
(
de
),
re
(
re
),
uartChannel
(
uartChannel
)
{
...
...
@@ -113,10 +113,13 @@ namespace SiliconTorch {
uart_port_t
_ch
=
(
uart_port_t
)
uartChannel
;
uint32_t
bufLEN
=
MTU
;
const
uint32_t
bufLEN
=
MTU
+
256
;
// MTU + maxEventSize(120) + slack
uint8_t
*
buffer
=
new
uint8_t
[
bufLEN
];
// our packet buffer
uint8_t
*
bufPTR
=
buffer
;
// points inside our buffer; used for envelope parsing…
// uint16_t payloadLEN = 0;
uint16_t
payloadLEN
=
0
;
const
uint8_t
crcLEN
=
4
;
const
uint8_t
headerLEN
=
std
::
strlen
(
HEADER
);
std
::
memset
(
buffer
,
0x00
,
bufLEN
);
...
...
@@ -124,7 +127,6 @@ namespace SiliconTorch {
/* enum FSM { SearchHeader, ReadLength, ReadPayload, CheckCRC };
FSM fsm = SearchHeader;
uint8_t headerLength = std::strlen(HEADER);
uint32_t headerByteNum = 0; */
uart_event_t
event
;
...
...
@@ -149,39 +151,49 @@ namespace SiliconTorch {
// received plain data
case
UART_DATA
:
{
uint32_t
bytesRead
=
bufPTR
-
buffer
;
if
((
bufPTR
-
buffer
)
+
event
.
size
>
bufLEN
)
{
ESP_LOGE
(
TAG
,
"Buffer#[ %d ] Overflow!"
,
bufLEN
);
if
(
bytesRead
+
event
.
size
>
bufLEN
)
{
ESP_LOGE
(
TAG
,
"Buffer#[ %d ] Overflow: Got %d bytes without a break"
,
bufLEN
,
bytesRead
+
event
.
size
);
bufPTR
=
buffer
;
std
::
memset
(
buffer
,
0x00
,
bufLEN
);
// TODO: needed…?
uart_flush_input
(
_ch
);
xQueueReset
(
Q
);
// fsm = SearchHeader;
payloadLEN
=
0
;
}
if
(
event
.
size
<
bufLEN
)
{
// read into buffer and just start over
uart_read_bytes
(
_ch
,
buffer
,
event
.
size
,
portMAX_DELAY
);
bufPTR
=
buffer
;
bufPTR
+=
uart_read_bytes
(
_ch
,
bufPTR
,
event
.
size
,
portMAX_DELAY
);
}
else
{
// kill it with 🔥
if
(
payloadLEN
>
0
&&
(
bufPTR
-
buffer
)
>
headerLEN
+
payloadLEN
+
crcLEN
)
{
// packet complete!
/* char strbuf[65];
strbuf[64] = 0x00;
ESP_LOGE
(
TAG
,
"// kill it with 🔥"
);
uart_flush_input
(
_ch
);
bufPTR
=
buffer
;
std::memcpy(strbuf, buffer, 64); */
ESP_LOGW
(
TAG
,
"PACKET DEBUG: Starts with header[ %s ] and contains data[ %s ]"
,
buffer
,
buffer
+
headerLEN
+
2
)
;
}
}
else
{
/*int32_t _bytes = 0;
do {
_bytes = uart_read_bytes(_ch, bufPTR, 16, 1);
ESP_LOGW(TAG, "_bytes#[ %d ]", _bytes);
if (_bytes < 0) {
ESP_LOGE(TAG, "!! _bytes < 0 !!");
break;
}
bufPTR += _bytes;
} while (_bytes > 0);*/
bufPTR
+=
uart_read_bytes
(
_ch
,
bufPTR
,
event
.
size
,
portMAX_DELAY
);
// TODO: send to queue!
// xQueueSendToBack(Q2, buffer, portMAX_DELAY);
}
else
if
(
payloadLEN
==
0
&&
bufPTR
-
buffer
>=
headerLEN
+
2
)
{
// got enough for header/length parsing
if
(
strncmp
(
reinterpret_cast
<
const
char
*>
(
buffer
),
HEADER
,
headerLEN
)
==
0
)
{
payloadLEN
=
(
buffer
[
headerLEN
]
<<
8
)
|
buffer
[
headerLEN
+
1
];
ESP_LOGW
(
TAG
,
"Found header: payload#[ %d ]"
,
payloadLEN
);
if
(
payloadLEN
>
MTU
)
{
ESP_LOGE
(
TAG
,
"payload#[ %d ] exceeds MTU[ %d ]"
,
payloadLEN
,
MTU
);
bufPTR
=
buffer
;
std
::
memset
(
buffer
,
0x00
,
bufLEN
);
// TODO: needed…?
uart_flush_input
(
_ch
);
xQueueReset
(
Q
);
// fsm = SearchHeader;
payloadLEN
=
0
;
}
}
}
break
;
...
...
@@ -191,20 +203,12 @@ namespace SiliconTorch {
case
UART_BREAK
:
{
ESP_LOGI
(
TAG
,
"Received BREAK 🛑 after reading %d bytes"
,
bufPTR
-
buffer
);
char
strbuf
[
65
];
strbuf
[
64
]
=
0x00
;
std
::
memcpy
(
strbuf
,
buffer
,
64
);
ESP_LOGW
(
TAG
,
"PACKET DEBUG: Starts with [ %s ]"
,
strbuf
);
// xQueueSendToBack(Q2, buffer, portMAX_DELAY);
bufPTR
=
buffer
;
std
::
memset
(
buffer
,
0x00
,
bufLEN
);
// TODO: needed…?
uart_flush_input
(
_ch
);
xQueueReset
(
Q
);
// fsm = SearchHeader;
payloadLEN
=
0
;
break
;
}
...
...
@@ -227,9 +231,12 @@ namespace SiliconTorch {
ESP_LOGE
(
TAG
,
"Unexpected event[ %s ]!"
,
eventName
);
uart_flush_input
(
_ch
);
bufPTR
=
buffer
;
std
::
memset
(
buffer
,
0x00
,
bufLEN
);
std
::
memset
(
buffer
,
0x00
,
bufLEN
);
// TODO: needed…?
uart_flush_input
(
_ch
);
xQueueReset
(
Q
);
// fsm = SearchHeader;
payloadLEN
=
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
CLC-qthing/SiliconTorch/CyanBus.hpp
+
1
−
1
View file @
151a5bdd
...
...
@@ -22,7 +22,7 @@ namespace SiliconTorch {
constexpr
uint32_t
MTU
=
4096
;
// CyanBus envelope header
extern
const
uint8_t
*
const
HEADER
;
extern
const
char
*
const
HEADER
;
class
CyanBus
{
...
...
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