|
|
@@ -9,8 +9,8 @@
|
|
|
|
|
|
volatile int32_t flag_data_received = -1;
|
|
|
|
|
|
-NbusCommunicator::NbusCommunicator(UART_HandleTypeDef* uartUbus) {
|
|
|
- _packet_tx = new DataFrame (_data_packet_tx, sizeof(_data_packet_tx), TYPE_PLAIN, CRC_ON);
|
|
|
+NbusCommunicator::NbusCommunicator(UART_HandleTypeDef* uartUbus, UART_HandleTypeDef *uartMaster) {
|
|
|
+ _packet_tx = new DataFrame(_data_packet_tx, sizeof(_data_packet_tx), TYPE_PLAIN, CRC_ON);
|
|
|
if(_packet_tx == NULL)
|
|
|
{
|
|
|
while(1){
|
|
|
@@ -18,7 +18,7 @@ NbusCommunicator::NbusCommunicator(UART_HandleTypeDef* uartUbus) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- _packet_rx = new DataFrame (_data_packet_rx, sizeof(_data_packet_rx), TYPE_PLAIN, CRC_ON);\
|
|
|
+ _packet_rx = new DataFrame(_data_packet_rx, sizeof(_data_packet_rx), TYPE_PLAIN, CRC_OFF);\
|
|
|
if(_packet_rx == NULL)
|
|
|
{
|
|
|
while(1){
|
|
|
@@ -27,14 +27,21 @@ NbusCommunicator::NbusCommunicator(UART_HandleTypeDef* uartUbus) {
|
|
|
}
|
|
|
|
|
|
if(uartUbus == NULL)
|
|
|
- {
|
|
|
- while(1){
|
|
|
- __NOP();
|
|
|
- }
|
|
|
+ {
|
|
|
+ while(1){
|
|
|
+ __NOP();
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
_uart_nbus = uartUbus;
|
|
|
|
|
|
+ if(uartMaster == NULL)
|
|
|
+ {
|
|
|
+ while(1){
|
|
|
+ __NOP();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _uart_master = uartMaster;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
NbusCommunicator::~NbusCommunicator() {
|
|
|
@@ -50,9 +57,11 @@ void NbusCommunicator::_receive(){
|
|
|
|
|
|
while(flag_data_received < 0 && HAL_GetTick() < stop_receive);
|
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
|
|
|
+
|
|
|
_packet_rx->Init();
|
|
|
if(flag_data_received > 0){
|
|
|
- _packet_rx->AddArray(_data_packet_comm, flag_data_received);
|
|
|
+// _packet_rx->AddArray(_data_packet_comm, flag_data_received);
|
|
|
+ _packet_rx->FromArray(_data_packet_comm, flag_data_received);
|
|
|
}
|
|
|
_packet_rx->Commit();
|
|
|
|
|
|
@@ -76,7 +85,7 @@ DataFrame* NbusCommunicator::send(Nbus_pdu *pdu, uint8_t *data, uint8_t data_len
|
|
|
int length = _packet_tx->Commit();
|
|
|
|
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
|
|
|
- HAL_UART_Transmit(_uart_nbus, _packet_tx->GetFrame(), length, 100);
|
|
|
+ HAL_UART_Transmit_DMA(_uart_nbus, _packet_tx->GetFrame(), length);
|
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
|
|
|
|
|
|
this->_receive();
|
|
|
@@ -84,6 +93,11 @@ DataFrame* NbusCommunicator::send(Nbus_pdu *pdu, uint8_t *data, uint8_t data_len
|
|
|
|
|
|
}
|
|
|
|
|
|
+void NbusCommunicator::sendToMaster(DataFrame *master_frame){
|
|
|
+ HAL_UART_Transmit_DMA(_uart_master, master_frame->GetFrame(), master_frame->GetLength());
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// Application callbacks
|
|
|
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
|
|
|
flag_data_received = Size;
|