You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Kernel loop: move long blocking work out of it Every pass of the mojo kernel loop ran these synchronously; each could stall the loop (and get la_mojo killed by the watchdog): - Report cleanup (validateReports -> deleteReportDate): deleteRDFDir ran "rm -f -R <whole day>" (seconds to minutes on an SD card), daily or every second while the disk is above preserve_empty. The day is now deleted in a background thread (one at a time; calls during it return false). ~sqliteDBC waits for a running deletion (max 60 s). - MediaMTX (validateService -> restart): "systemctl restart" waited for the service to stop and start, every second if the config kept failing validation. Now "systemctl --no-block restart" (only queues the job), at most once per KH_MTX_RESTART_MIN_S (30 s). - IP UART serial provider (hardwareManager::validate -> create_SOL): a blocking connect() to an address that doesn't answer took ~2 min (SYN retries). Now non-blocking with SERIAL_SOL_CONNECT_TIMEOUT_MS (5 s), the socket mode restored afterwards, and the socket closed on failure (it leaked). - Ethernet2UART gateway nodes: hardwareManager::validate (kernel loop) validated and reconnected them again, although the node factory thread does it (deviceNode::validate). Connects of up to 5 s blocked the kernel loop, plus the wait for the node's connection lock. hardwareResource::selfValidating() (default false) is true for deviceETH2UART, and the hardware manager skips such resources. Tested: the connect timeout on its own (extracted unchanged). A peer that drops the SYN failed after 5002 ms ("Connection timed out") instead of ~2 min; refused and accepted connects are immediate; the socket is blocking again in every case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
10 hours ago
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
  1. #ifndef __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
  2. #define __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
  3. #include "../components/base/basicTransport.h"
  4. #include "hardwareResource.h"
  5. #define HALF_DUPLEX
  6. // #define FIO_SELECT_MODE
  7. #ifndef HALF_DUPLEX
  8. #include "../components/base/basicDualThread.h"
  9. #else
  10. #include "../components/base/basicThread.h"
  11. #endif
  12. #include <errno.h> // Error number definitions
  13. #include <fcntl.h> // File control definitions
  14. #include <stdio.h> // standard input / output functions
  15. #include <stdlib.h>
  16. #include <string.h> // string function definitions
  17. #include <sys/select.h>
  18. #include <sys/types.h>
  19. #include <unistd.h>
  20. #ifdef __linux__
  21. #include <termios.h> // POSIX terminal control definitions
  22. #include <unistd.h> // UNIX standard function definitions
  23. #if defined(__arm__) || defined(__aarch64__) || defined(RASPI_HARDWARE)
  24. #define USE_WIRINGX
  25. #include <wiringx.h>
  26. #ifdef __aarch64__
  27. #define WIRINGX_PLATFORM "rock4"
  28. #define RTS_PIN_NUMBER 0
  29. #else
  30. #define WIRINGX_PLATFORM "raspberrypi4"
  31. #define RTS_PIN_NUMBER 0
  32. #endif
  33. #endif
  34. #endif
  35. #ifdef DEBUG_EXTRA
  36. // #define DEBUG_SERIAL_COMMUNICATION
  37. #endif
  38. #ifndef SERIAL_SOL_CONNECT_TIMEOUT_MS
  39. #define SERIAL_SOL_CONNECT_TIMEOUT_MS 5000 // TCP connect to an IP UART (serial over LAN / Internet)
  40. #endif
  41. #if defined( HALF_DUPLEX ) || defined( SERIAL_PING_PONG )
  42. class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicThread
  43. {
  44. #else // ! HALF_DUPLEX SERIAL_PING_PONG
  45. class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicDualThread
  46. {
  47. #endif // ! HALF_DUPLEX SERIAL_PING_PONG
  48. private:
  49. DBC_UART_DATA m_sUartData;
  50. int m_iDeviceFD;
  51. int m_iMasterFD;
  52. #ifdef __linux__
  53. struct termios m_sTTY;
  54. int m_iInFID;
  55. int m_iOutFID;
  56. bool m_bManualRTS;
  57. void setRTS(uint8_t Val);
  58. #else
  59. DCB PortDCB;
  60. HANDLE m_ioFID;
  61. #endif
  62. bool pingDevice();
  63. bool create_SOL();
  64. bool create_HW();
  65. bool closePort();
  66. int sendBlock(unsigned char * Data, int DataSize);
  67. int recptBlock(unsigned char * Buffer, int * BufferLength);
  68. protected:
  69. #ifdef FIO_SELECT_MODE
  70. int m_nSenderSetMax;
  71. int m_nReaderSetMax;
  72. fd_set m_sSenderSet;
  73. fd_set m_sReaderSet;
  74. int m_iControlPipeFD[2];
  75. #endif
  76. #if defined( HALF_DUPLEX ) || defined( SERIAL_PING_PONG )
  77. virtual void m_fThreadProc(void);
  78. Q_SIO_TZ m_qIO;
  79. // Q_SIO_TZ m_qREADY;
  80. #else
  81. U8 m_pInputBuffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; // 100KB
  82. U8 m_pOutputBuffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
  83. int m_nInputBufferSize;
  84. int m_nOutputBufferSize;
  85. virtual void m_fThreadAProc(void);
  86. virtual void m_fThreadBProc(void);
  87. #endif
  88. public:
  89. explicit hardwareResourceSerialProvider(uint32_t dbID);
  90. virtual ~hardwareResourceSerialProvider();
  91. virtual bool create(void);
  92. virtual bool validate(void);
  93. #ifdef SERIAL_PING_PONG
  94. virtual bool sendData(uint8_t * Data, int DataSize, protocolParser *src = NULL );
  95. #else
  96. virtual bool sendData(uint8_t * Data, int DataSize );
  97. #endif
  98. virtual bool reconnect(void);
  99. virtual bool activate( void );
  100. };
  101. #endif