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
c8754813
Commit
c8754813
authored
3 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
Begin restructuring the whole thing…
parent
98722ea7
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
+61
-60
61 additions, 60 deletions
CLC-qthing/SiliconTorch/CyanBus.cpp
CLC-qthing/SiliconTorch/CyanBus.hpp
+20
-5
20 additions, 5 deletions
CLC-qthing/SiliconTorch/CyanBus.hpp
with
81 additions
and
65 deletions
CLC-qthing/SiliconTorch/CyanBus.cpp
+
61
−
60
View file @
c8754813
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#include
"esp_log.h"
#include
"esp_log.h"
#include
"driver/gpio.h"
#include
"driver/gpio.h"
#include
"driver/uart.h"
#include
"driver/uart.h"
#include
"freertos/queue.h"
// project specific
// project specific
#include
"LambdaTask.hpp"
#include
"LambdaTask.hpp"
...
@@ -31,92 +32,92 @@ namespace SiliconTorch {
...
@@ -31,92 +32,92 @@ namespace SiliconTorch {
namespace
CyanBus
{
namespace
CyanBus
{
CyanBus
::
CyanBus
(
SiliconTorch
::
Impl
::
RS485
reader
)
:
reader
(
reader
)
{
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
)
{
readerTaskHandle
=
new
SiliconTorch
::
Util
::
LambdaTask
([
&
](){
readerTask
();
});
}
uint64_t
bitMask
=
0
;
void
CyanBus
::
readerTask
()
{
const
uint8_t
*
header
=
(
const
uint8_t
*
)
"fxCyan"
;
uint8_t
*
buffer
=
new
uint8_t
[
CyanBusMTU
];
uint8_t
*
bufPTR
=
buffer
;
uint16_t
packetLength
=
0
;
enum
FSM
{
SearchHeader
,
ReadLenght
,
ReadBody
,
CheckCRC
};
bitMask
|=
1
<<
tx
;
FSM
fsm
=
SearchHeader
;
bitMask
|=
1
<<
de
;
bitMask
|=
1
<<
re
;
while
(
true
)
{
gpio_config_t
gpio
=
{
.
pin_bit_mask
=
bitMask
,
.
mode
=
GPIO_MODE_OUTPUT
,
.
pull_up_en
=
GPIO_PULLUP_DISABLE
,
.
pull_down_en
=
GPIO_PULLDOWN_DISABLE
,
.
intr_type
=
GPIO_INTR_DISABLE
,
};
switch
(
fsm
)
{
// configure outputs
case
SearchHeader
:
{
gpio_config
(
&
gpio
);
txrxEN
(
false
);
reader
.
read
(
bufPTR
,
1
);
gpio
.
pin_bit_mask
=
1
<<
rx
;
gpio
.
mode
=
GPIO_MODE_INPUT
;
if
(
bufPTR
[
0
]
==
header
[
bufPTR
-
buffer
])
{
// configure inputs
// got the right char
gpio_config
(
&
gpio
);
bufPTR
++
;
if
(
bufPTR
-
buffer
>=
sizeof
(
header
))
{
fsm
=
ReadLenght
;
}
}
else
{
// start over
bufPTR
=
buffer
;
}
break
;
uart_config_t
uartConfig
=
{
}
.
baud_rate
=
(
int
)
baudRate
,
.
data_bits
=
UART_DATA_8_BITS
,
.
parity
=
UART_PARITY_DISABLE
,
.
stop_bits
=
UART_STOP_BITS_1
,
.
flow_ctrl
=
UART_HW_FLOWCTRL_DISABLE
,
.
rx_flow_ctrl_thresh
=
0
,
.
use_ref_tick
=
false
,
// .source_clk = UART_SCLK_APB,
};
case
ReadLenght
:
{
reader
.
read
(
bufPTR
,
2
)
;
uart_port_t
_ch
=
(
uart_port_t
)
uartChannel
;
packetLength
=
(
bufPTR
[
0
]
<<
8
)
|
bufPTR
[
1
];
uart_driver_install
(
_ch
,
CyanBusMTU
,
0
,
0
,
&
uartEvQ
,
0
);
bufPTR
+=
2
;
uart_param_config
(
_ch
,
&
uartConfig
);
uart_set_pin
(
_ch
,
tx
,
rx
,
UART_PIN_NO_CHANGE
,
UART_PIN_NO_CHANGE
);
uart_set_mode
(
_ch
,
UART_MODE_UART
);
uart_set_rx_timeout
(
_ch
,
0
);
// TODO: timeout…??
ESP_LOGW
(
TAG
,
"Got a packet with length[ %d ]
\\
o/"
,
packetLength
);
// TOOD: receive only ATM!
txEN
(
false
);
rxEN
(
true
);
fsm
=
ReadBody
;
break
;
// readerTaskHandle = new SiliconTorch::Util::LambdaTask([&](){ readerTask(); });
}
case
ReadBody
:
{
}
reader
.
read
(
bufPTR
,
packetLength
+
4
);
// +4 = CRC
fsm
=
CheckCRC
;
void
CyanBus
::
readerTask
()
{
// const uint8_t* header = (const uint8_t*)"fxCyan";
}
break
;
}
case
CheckCRC
:
{
void
CyanBus
::
setBaudRate
(
uint32_t
baudRate
)
{
// TODO: check the CRC!
uart_set_baudrate
((
uart_port_t
)
uartChannel
,
baudRate
);
}
// If it matches: handle packet!
uint32_t
CyanBus
::
getBaudRate
()
{
// But if it not matches?
uint32_t
baudRate
=
0
;
// search whole packet for header? (how would we implement this???)
uart_get_baudrate
((
uart_port_t
)
uartChannel
,
&
baudRate
);
// or just discard? (leads to possible desynchronisation!!!)
return
baudRate
;
}
break
;
}
}
}
delete
buffer
;
void
CyanBus
::
txEN
(
bool
state
)
{
gpio_set_level
((
gpio_num_t
)
de
,
state
);
}
}
void
CyanBus
::
setBaudRate
(
uint32_t
baudR
ate
)
{
void
CyanBus
::
rxEN
(
bool
st
ate
)
{
ESP_LOGE
(
TAG
,
"Operation unsupported: setBaudRate(…)"
);
gpio_set_level
((
gpio_num_t
)
re
,
state
^
1
);
}
}
uint32_t
CyanBus
::
getBaudR
ate
(
)
{
void
CyanBus
::
txrxEN
(
bool
st
ate
)
{
ESP_LOGE
(
TAG
,
"Operation unsupported: getBaudRate()"
);
txEN
(
state
);
r
eturn
1337
;
r
xEN
(
state
)
;
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
CLC-qthing/SiliconTorch/CyanBus.hpp
+
20
−
5
View file @
c8754813
...
@@ -5,8 +5,10 @@
...
@@ -5,8 +5,10 @@
#include
<cinttypes>
#include
<cinttypes>
#include
<functional>
#include
<functional>
// ESP32 specific
#include
"freertos/queue.h"
// project specific
// project specific
#include
"RS485.hpp"
#include
"LambdaTask.hpp"
#include
"LambdaTask.hpp"
...
@@ -16,16 +18,29 @@ namespace SiliconTorch {
...
@@ -16,16 +18,29 @@ namespace SiliconTorch {
class
CyanBus
{
class
CyanBus
{
public:
public:
CyanBus
(
SiliconTorch
::
Impl
::
RS485
reader
);
CyanBus
(
uint8_t
tx
,
uint8_t
rx
,
uint8_t
de
,
uint8_t
re
,
uint32_t
baudRate
=
115200
,
uint8_t
uartChannel
=
1
);
// TODO: How do we wanna set baudRates when we only have a reader?!
// TODO: Elaborate on this topic!
uint32_t
getBaudRate
();
uint32_t
getBaudRate
();
void
setBaudRate
(
uint32_t
baudRate
);
void
setBaudRate
(
uint32_t
baudRate
);
private:
private:
SiliconTorch
::
Impl
::
RS485
reader
;
QueueHandle_t
uartEvQ
;
uint8_t
uartChannel
;
uint8_t
tx
,
rx
,
de
,
re
;
void
txEN
(
bool
state
);
void
rxEN
(
bool
state
);
void
txrxEN
(
bool
state
);
// Receive only ATM! (make public after sound implementation…)
void
write
(
std
::
string
&
data
);
void
write
(
const
uint8_t
*
data
,
uint32_t
length
);
void
readerTask
();
void
readerTask
();
...
...
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