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
6a3ae9d0
Commit
6a3ae9d0
authored
3 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
Finishing reader task
parent
aff63ed2
No related branches found
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
+74
-10
74 additions, 10 deletions
CLC-qthing/SiliconTorch/CyanBus.cpp
CLC-qthing/SiliconTorch/CyanBus.hpp
+3
-10
3 additions, 10 deletions
CLC-qthing/SiliconTorch/CyanBus.hpp
with
77 additions
and
20 deletions
CLC-qthing/SiliconTorch/CyanBus.cpp
+
74
−
10
View file @
6a3ae9d0
...
...
@@ -26,6 +26,16 @@ static const char* TAG = "CyanBus";
namespace
SiliconTorch
{
// namespace Impl {
//
// typedef struct {
// bool crcOK;
// uint16_t length;
// uint8_t payload[CyanBus::MTU];
// } CyanData;
//
// }
namespace
CyanBus
{
// CyanBus envelope header
...
...
@@ -85,17 +95,19 @@ namespace SiliconTorch {
rxEN
(
true
);
readerTaskHandle
=
new
SiliconTorch
::
Util
::
LambdaTask
([
&
](){
readerTask
();
});
readerTaskHandle
=
new
Util
::
LambdaTask
([
&
](){
readerTask
();
});
packetQ
=
xQueueCreate
(
3
,
sizeof
(
CyanData
));
callbackTaskHandle
=
new
SiliconTorch
::
Util
::
LambdaTask
([
&
](){
callbackTask
();
});
// packetQ = xQueueCreate(3, sizeof(Impl::CyanData));
packetQ
=
xQueueCreate
(
3
,
4096
);
packetTaskHandle
=
new
Util
::
LambdaTask
([
&
](){
packetTask
();
});
}
void
CyanBus
::
readerTask
()
{
uint32_t
bufLEN
=
MTU
+
32
;
// header[6] + length[2] + payload[MTU] + CRC[4] + some slack…
uint32_t
bufLEN
=
MTU
;
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;
std
::
memset
(
buffer
,
0x00
,
bufLEN
);
...
...
@@ -122,9 +134,12 @@ namespace SiliconTorch {
enum
FSM
{
SearchHeader
,
ReadLength
,
ReadPayload
,
CheckCRC
};
/*
enum FSM { SearchHeader, ReadLength, ReadPayload, CheckCRC };
FSM fsm = SearchHeader;
uint8_t headerLength = std::strlen(HEADER);
uint32_t headerByteNum = 0; */
uart_event_t
event
;
while
(
true
)
{
...
...
@@ -140,26 +155,56 @@ namespace SiliconTorch {
// received plain data
case
UART_DATA
:
{
uint32_t
bytesRead
=
bufPTR
-
buffer
;
if
(
bytesRead
+
event
.
size
>
bufLEN
)
{
ESP_LOGE
(
TAG
,
"Buffer#[ %d ] Overflow: Got %d bytes without a break"
,
bufLEN
,
bytesRead
+
event
.
size
);
if
(
event
.
size
<
bufLEN
)
{
// read into buffer and just start over
uart_read_bytes
((
uart_port_t
)
uartChannel
,
buffer
,
event
.
size
,
portMAX_DELAY
);
bufPTR
=
buffer
;
}
else
{
// kill it with 🔥
uart_flush_input
((
uart_port_t
)
uartChannel
);
bufPTR
=
buffer
;
}
}
else
{
uart_read_bytes
((
uart_port_t
)
uartChannel
,
bufPTR
,
event
.
size
,
portMAX_DELAY
);
bufPTR
+=
event
.
size
;
}
break
;
}
// FIFO overflow
case
UART_FIFO_OVF
:
{
ESP_LOGW
(
TAG
,
"FIFO overflow! 😡"
);
ESP_LOGE
(
TAG
,
"FIFO overflow! 😡"
);
uart_flush_input
((
uart_port_t
)
uartChannel
);
bufPTR
=
buffer
;
break
;
}
// internal buffer full
case
UART_BUFFER_FULL
:
{
ESP_LOGW
(
TAG
,
"Buffer full! 😡"
);
ESP_LOGE
(
TAG
,
"Internal Buffer overflow! 😡"
);
uart_flush_input
((
uart_port_t
)
uartChannel
);
bufPTR
=
buffer
;
break
;
}
// got an RX break signal
case
UART_BREAK
:
{
ESP_LOGI
(
TAG
,
"
BREAK received 🛑"
);
ESP_LOGI
(
TAG
,
"
Received BREAK 🛑 after reading %d bytes"
,
bufPTR
-
buffer
);
// TODO: handle message end!!!
xQueueSendToBack
(
packetQ
,
buffer
,
portMAX_DELAY
);
bufPTR
=
buffer
;
break
;
}
...
...
@@ -180,8 +225,27 @@ namespace SiliconTorch {
delete
buffer
;
}
void
CyanBus
::
callb
ackTask
()
{
void
CyanBus
::
p
ack
et
Task
()
{
ESP_LOGW
(
TAG
,
"TODO: implement callback task!"
);
uint8_t
*
buffer
=
new
uint8_t
[
MTU
];
while
(
true
)
{
if
(
xQueueReceive
(
packetQ
,
buffer
,
(
TickType_t
)
portMAX_DELAY
))
{
// TODO: handle packet!
char
strbuf
[
17
];
strbuf
[
16
]
=
0x00
;
std
::
memcpy
(
strbuf
,
buffer
,
16
);
ESP_LOGI
(
TAG
,
"PACKET DEBUG: Starts with [ %s ]"
,
strbuf
);
// TODO: really handle packet!
}
}
}
void
CyanBus
::
setBaudRate
(
uint32_t
baudRate
)
{
...
...
This diff is collapsed.
Click to expand it.
CLC-qthing/SiliconTorch/CyanBus.hpp
+
3
−
10
View file @
6a3ae9d0
...
...
@@ -25,13 +25,6 @@ namespace SiliconTorch {
extern
const
uint8_t
*
const
HEADER
;
typedef
struct
{
bool
crc
;
uint16_t
length
;
uint8_t
payload
[
MTU
];
}
CyanData
;
class
CyanBus
{
public:
CyanBus
(
uint8_t
tx
,
uint8_t
rx
,
uint8_t
de
,
uint8_t
re
,
uint32_t
baudRate
=
115200
,
uint8_t
uartChannel
=
1
);
...
...
@@ -60,10 +53,10 @@ namespace SiliconTorch {
void
readerTask
();
void
callb
ackTask
();
void
p
ack
et
Task
();
SiliconTorch
::
Util
::
LambdaTask
*
readerTaskHandle
=
NULL
;
SiliconTorch
::
Util
::
LambdaTask
*
callb
ackTaskHandle
=
NULL
;
Util
::
LambdaTask
*
readerTaskHandle
=
NULL
;
Util
::
LambdaTask
*
p
ack
et
TaskHandle
=
NULL
;
};
}
...
...
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