/* * @filename AppBridge.cpp * * @date Mar 05, 2025 * @author: juraj */ #include #include "AppBridge.h" #include "dataframe.h" #include "NbusBridge.h" #include "NbusCommunicator.h" UART_HandleTypeDef *pUartMasterGlobal; volatile uint32_t flagUartMasterDataReady; uint8_t pMasterUartRx[64]; uint8_t pMasterUartFrame[64]; uint8_t vMasterUartIndex; uint8_t vMasterUartSize; static void init_app(){ HAL_UARTEx_ReceiveToIdle_DMA(pUartMasterGlobal, pMasterUartRx, 64); flagUartMasterDataReady = 0; vMasterUartIndex = 0; vMasterUartSize = 0; } void app(UART_HandleTypeDef *uartNbus, UART_HandleTypeDef *uartMaster){ pUartMasterGlobal = uartMaster; init_app(); NbusCommunicator nc(uartNbus, uartMaster); // boot long blink for(uint32_t i = 0 ; i<64 ; i++){ HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3); HAL_Delay(25); } NbusBridge bridge(&nc); bridge.scan(); DataFrame *frameTX; for(uint32_t i=0; inbus_echo(); bridge.sendResponseToMaster(frameTX); frameTX = bridge.getSlave(i)->nbus_module_info(); bridge.sendResponseToMaster(frameTX); } while(1){ /* for(uint32_t i=0; inbus_get_sensor_count(false) ; k++){ frameTX = bridge.getSlave(i)->nbus_sensor_getData(k); bridge.sendResponseToMaster(frameTX); } } */ if(flagUartMasterDataReady > 0){ HAL_UART_Transmit_DMA(uartMaster, pMasterUartRx, flagUartMasterDataReady); flagUartMasterDataReady = 0; } //HAL_Delay(1); } } // Application callbacks // TODO - toto je zatial nefunkcne void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){ if(huart == pUartMasterGlobal) { HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3); flagUartMasterDataReady = Size; HAL_UARTEx_ReceiveToIdle_DMA(pUartMasterGlobal, pMasterUartRx, 64); uint8_t copy_offset = 0; if(vMasterUartIndex == 0){ vMasterUartSize = pMasterUartRx[0]; vMasterUartIndex++; vMasterUartSize--; copy_offset = 1; } memcpy(&pMasterUartFrame[vMasterUartIndex], &pMasterUartRx[copy_offset], vMasterUartSize); vMasterUartIndex += vMasterUartSize; if(vMasterUartIndex >= vMasterUartSize){ flagUartMasterDataReady = vMasterUartSize; vMasterUartSize = 0; vMasterUartIndex = 0; pMasterUartRx[0] = 0; // uart_timeout = MAX_SYSTICK; } } }