|
1 | 1 | #include "CanVendorSystec.h" |
2 | 2 |
|
| 3 | +#include <algorithm> |
3 | 4 | #include <time.h> |
4 | 5 | #include <LogIt.h> |
5 | 6 | #include <iomanip> |
| 7 | +#include <vector> |
6 | 8 |
|
7 | 9 | std::mutex CanVendorSystec::m_handles_lock; |
8 | 10 | std::unordered_map<int, tUcanHandle> CanVendorSystec::m_handle_map; |
@@ -104,43 +106,40 @@ CanReturnCode CanVendorSystec::vendor_close() noexcept { |
104 | 106 | erase_module_handle(m_module_number); |
105 | 107 | m_receive_thread_flag = false; |
106 | 108 | if (m_SystecRxThread.joinable()) m_SystecRxThread.join(); |
107 | | - UcanDeinitCanEx (m_UcanHandle, (BYTE)m_channel_number); |
| 109 | + UcanDeinitCanEx (m_UcanHandle, (BYTE) m_channel_number); |
108 | 110 | LOG(Log::DBG, CanLogIt::h()) << __FUNCTION__ << " closed successfully"; |
109 | 111 | return CanReturnCode::success; |
110 | 112 | }; |
111 | 113 |
|
112 | 114 | CanReturnCode CanVendorSystec::vendor_send(const CanFrame& frame) noexcept { |
113 | | - bool rtr = frame.is_remote_request(); |
114 | 115 | uint32_t len = frame.length(); |
115 | | - char *message = frame.message().data(); |
116 | | - short cobID = frame.id(); |
117 | | - |
118 | | - LOG(Log::DBG, CanLogIt::h()) << "Sending message: [" << ( message == 0 ? "" : (const char *) message) << "], cobID: [" << cobID << "], Message Length: [" << static_cast<int>(len) << "]"; |
| 116 | + std::vector<char> message = frame.message(); |
119 | 117 |
|
120 | 118 | tCanMsgStruct can_msg_to_send; |
121 | 119 | BYTE Status; |
122 | 120 |
|
123 | | - can_msg_to_send.m_dwID = cobID; |
| 121 | + can_msg_to_send.m_dwID = frame.id(); |
124 | 122 | can_msg_to_send.m_bDLC = len; |
125 | 123 | can_msg_to_send.m_bFF = 0; |
126 | | - if (rtr) { |
127 | | - can_msg_to_send.m_bFF = USBCAN_MSG_FF_RTR; |
| 124 | + if (frame.is_remote_request()) { |
| 125 | + can_msg_to_send.m_bFF = USBCAN_MSG_FF_RTR; |
128 | 126 | } |
129 | 127 | int message_length_to_process; |
130 | 128 | //If there is more than 8 characters to process, we process 8 of them in this iteration of the loop |
131 | 129 | if (len > 8) { |
132 | | - message_length_to_process = 8; |
133 | | - LOG(Log::DBG, CanLogIt::h()) << "The length is more then 8 bytes, adjust to 8, ignore >8. len= " << len; |
| 130 | + message_length_to_process = 8; |
| 131 | + LOG(Log::DBG, CanLogIt::h()) << "The length is more than 8 bytes, adjust to 8, ignore > 8. len = " << len; |
134 | 132 | } else { |
135 | | - //Otherwise if there is less than 8 characters to process, we process all of them in this iteration of the loop |
136 | | - message_length_to_process = len; |
137 | | - if (len < 8) { |
138 | | - LOG(Log::DBG, CanLogIt::h())<< "The length is less then 8 bytes, process only. len= " << len; |
139 | | - } |
| 133 | + //Otherwise if there is less than 8 characters to process, we process all of them in this iteration of the loop |
| 134 | + message_length_to_process = len; |
| 135 | + if (len < 8) { |
| 136 | + LOG(Log::DBG, CanLogIt::h())<< "The length is less than 8 bytes, process only. len = " << len; |
| 137 | + } |
140 | 138 | } |
141 | 139 | can_msg_to_send.m_bDLC = message_length_to_process; |
142 | | - memcpy(can_msg_to_send.m_bData, message, message_length_to_process); |
143 | | - // MLOG(TRC,this) << "Channel Number: [" << m_channel_number << "], cobID: [" << can_msg_to_send.m_dwID << "], Message Length: [" << static_cast<int>(can_msg_to_send.m_bDLC) << "]"; |
| 140 | + if (message_length_to_process) |
| 141 | + std::copy(message.begin(), message.begin() + message_length_to_process, can_msg_to_send.m_bData); |
| 142 | + |
144 | 143 | Status = UcanWriteCanMsgEx(m_UcanHandle, m_channel_number, &can_msg_to_send, NULL); |
145 | 144 | if (Status != USBCAN_SUCCESSFUL) { |
146 | 145 | LOG(Log::ERR, CanLogIt::h()) << "There was a problem when sending a message: " |
@@ -225,7 +224,7 @@ int CanVendorSystec::SystecRxThread() |
225 | 224 | tCanMsgStruct read_can_message; |
226 | 225 | LOG(Log::DBG, CanLogIt::h()) << "SystecRxThread Started. m_receive_thread_flag = [" << m_receive_thread_flag <<"]"; |
227 | 226 | while (m_receive_thread_flag) { |
228 | | - status = UcanReadCanMsgEx(m_UcanHandle, (BYTE *)&m_channel_number, &read_can_message, NULL); |
| 227 | + status = UcanReadCanMsgEx(m_UcanHandle, (BYTE *) &m_channel_number, &read_can_message, NULL); |
229 | 228 | switch (status) { |
230 | 229 | case USBCAN_WARN_SYS_RXOVERRUN: [[ fallthrough ]]; |
231 | 230 | case USBCAN_WARN_DLL_RXOVERRUN: [[ fallthrough ]]; |
|
0 commit comments