@@ -22,6 +22,10 @@ namespace fw {
22
22
23
23
class FDCanMicroServer : public mjlib ::multiplex::MicroDatagramServer {
24
24
public:
25
+ // Fields in Header::flags
26
+ static constexpr uint32_t kBrsFlag = 0x01 ;
27
+ static constexpr uint32_t kFdcanFlag = 0x02 ;
28
+
25
29
FDCanMicroServer (FDCan* can) : fdcan_(can) {}
26
30
27
31
void AsyncRead (Header* header,
@@ -35,19 +39,28 @@ class FDCanMicroServer : public mjlib::multiplex::MicroDatagramServer {
35
39
36
40
void AsyncWrite (const Header& header,
37
41
const std::string_view& data,
42
+ const Header& query_header,
38
43
const mjlib::micro::SizeCallback& callback) override {
39
44
const auto actual_dlc = RoundUpDlc (data.size ());
40
45
const uint32_t id =
41
46
((header.source & 0xff ) << 8 ) | (header.destination & 0xff );
42
47
48
+ FDCan::SendOptions send_options;
49
+ send_options.bitrate_switch =
50
+ (query_header.flags & kBrsFlag ) ?
51
+ FDCan::Override::kRequire : FDCan::Override::kDisable ;
52
+ send_options.fdcan_frame =
53
+ ((query_header.flags & kFdcanFlag ) ==0 && data.size () <= 8 ) ?
54
+ FDCan::Override::kDisable : FDCan::Override::kRequire ;
55
+
43
56
if (actual_dlc == data.size ()) {
44
- fdcan_->Send (id, data, {} );
57
+ fdcan_->Send (id, data, send_options );
45
58
} else {
46
59
std::memcpy (buf_, data.data (), data.size ());
47
60
for (size_t i = data.size (); i < actual_dlc; i++) {
48
61
buf_[i] = 0x50 ;
49
62
}
50
- fdcan_->Send (id, std::string_view (buf_, actual_dlc), {} );
63
+ fdcan_->Send (id, std::string_view (buf_, actual_dlc), send_options );
51
64
}
52
65
53
66
callback (mjlib::micro::error_code (), data.size ());
0 commit comments