/* */ // global variable to keep the results from onReceive() #include #include #define buffersize 50 #define baudrate 9600 // The Modbus RTU standard prescribes a silent period corresponding to 3.5 characters between each // message, to be able to figure out where one message ends and the next one starts. #define modbusRxTimeoutLimit 4 //PWM Definitions #define SW_versionMajor 0x01 #define SW_versionMinor 0x01 #define LEDC_CHANNEL_0 0 #define LEDC_TIMER_13_BIT 13 #define LEDC_BASE_FREQ 5000 #define LED_PIN 2 #define Timer_pending_cyclic_maxvalue 1000 #define Timer_timeout_Maxvalue 3000 #define HEXCODE_BIT1_READ_SENSOR_1 0x31 #define HEXCODE_BIT1_READ_SENSOR_2 0x32 #define HEXCODE_BIT1_READ_SENSOR_3 0x33 #define HEXCODE_BIT1_WRITE_CHANNEL_1 0x31 #define HEXCODE_BIT1_WRITE_CHANNEL_2 0x32 #define HEXCODE_BIT1_WRITE_CHANNEL_3 0x33 #define HEXCODE_BIT1_READ_DEBUG 0xFF #define HEXCODE_BIT1_WRITE_DEBUG 0xFF #define HEXCODE_BIT1_WRITE_NAME 0xFE uint8_t length_of_name = 0; uint8_t BT_rx_buffer[buffersize]; uint8_t uart_buffer[buffersize]; uint16_t timer_pending = 0; uint16_t timer_timeout = 0; bool pendingSend = false; bool isChipPendingActive = false; bool IsBTDebugOn = false; String deviceName = "BT_Radio_66"; BluetoothSerial SerialBT; // UART_RX_IRQ will be executed as soon as data is received by the UART and an RX Timeout occurs // This is a callback function executed from a high priority monitor task // All data will be buffered into RX Buffer, which may have its size set to whatever necessary void fill_UART_RX_Buffer() { uint8_t i=0; while (Serial.available()) { uart_buffer[i]=(uint8_t)Serial.read(); i=i+1; } i=0; } void fill_BT_RX_Buffer() { uint8_t tempCnt = 0; while (SerialBT.available()) { BT_rx_buffer[tempCnt]= SerialBT.read(); tempCnt = tempCnt +1; } tempCnt=0; } void sendDebugOutput(String text) { if(IsBTDebugOn) { int i; for (i=0;i=Timer_pending_cyclic_maxvalue)) { /*reset bit so in next cycle the pending messase is send after Timer_pending_cyclic */ pendingSend = false; timer_pending=0; }else{ timer_pending++; } }else { timer_pending=0; } if(isChipPendingActive == true) { if( (timer_timeout >=Timer_timeout_Maxvalue)) { SerialBT.write(0x7F); SerialBT.write(UDS_ROUTING); SerialBT.write(UDS_NRC_uploadDownloadNotAccepted); timer_timeout=0; isChipPendingActive=false; }else{ timer_timeout++; } }else { timer_timeout=0; } } void loop() { // String is filled by the UART Callback whenever data is received and RX Timeout occurs fill_BT_RX_Buffer(); //analyse_uart_Protocol(uart_buffer); analyse_BT_Protocol(BT_rx_buffer); delete_BT_UART_buffer(); updateTimer(); delay(1); }