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.

1577 lines
39 KiB

​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
4 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "deviceNodeSensor.h"
  2. #include "../../components/object/objectSystemAnchor.h"
  3. #include "kernelPrototype.h"
  4. // Communication timing: slow replies, timeouts and a one-minute summary (see txTimingReport)
  5. // #define DEBUG_COMMUNICATION // timing logs (see the commit "Debug: log communication timing ...")
  6. #ifndef LGS_SLOW_REPLY_MS
  7. #define LGS_SLOW_REPLY_MS 500 // replies slower than this are logged one by one
  8. #endif
  9. #define LGS_TIMING_REPORT_MS 60000
  10. #include <time.h>
  11. static uint64_t nsNowMs(void)
  12. {
  13. struct timespec ts;
  14. clock_gettime(CLOCK_MONOTONIC, &ts);
  15. return (uint64_t) ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
  16. }
  17. #define LOG(X) deviceNode::m_pLog->Log("NODSEN", this, X)
  18. #define LOG_ERROR(X) deviceNode::m_pLog->Log("NODSEN", this, _LOG_ERROR, X)
  19. /*
  20. USER.INI
  21. AUTORESET_ENABLE=0
  22. AUTORESET_INTERLEAVE=2000
  23. AUTORESET_TIMEOUT=-5536
  24. BOARD_TEMPERATURE=20
  25. BOARD_ZEROSHIFT=0
  26. BOARD_ENCODERSTEPS=6
  27. BOARD_GEARRATIO=61
  28. SWITCHER_TABLE=27,55,82
  29. SWITCHER_REPLY_TIMEOUT=100
  30. SWITCHER_COMMAND_TIMEOUT=500
  31. SWITCHER_AUTO_MODE=0
  32. SWITCHER_AUTO_ENTER_TIMEOUT=60
  33. SWITCHER_AUTO_SWITCH_TIMEOUT=3
  34. */
  35. /*
  36. "ADDRESS",
  37. "CAMERA_TYPE",
  38. "CAMERA_SHIFT",
  39. "CAMERA_AUTO",
  40. "CAMERA_DELAY",
  41. "RELAY_NC",
  42. "RELAY_AUTO",
  43. "RELAY_DELAY",
  44. "VOLTAGE_CONTROL",
  45. "MASTER_DISABLED",
  46. "SLAVE_DISABLED",
  47. */
  48. /*
  49. typedef struct S_DBC_LRF_INI{
  50. uint16_t _AUTO_RESET_ENABLE;
  51. uint16_t _AUTO_RESET_INTERLEAVE;
  52. uint16_t _AUTO_RESET_TIMEOUT;
  53. uint16_t _BOARD_TEMPERATURE;
  54. uint16_t _BOARD_ZEROSHIFT;
  55. uint16_t _BOARD_SPEED;
  56. uint16_t _RUN_DIR;
  57. uint16_t _NO_BLACK_TARGETS;
  58. uint16_t _JUST_MOVING_TARGETS;
  59. uint16_t _JUST_MOVING_RADIAL;
  60. uint16_t _JUST_MOVING_DISTANCE;
  61. uint16_t _FREEZ_FIRST_TH;
  62. uint16_t _SAVE_FIRST_TH;
  63. }DBC_LRF_INI;
  64. */
  65. #define __INI_FILE_ENTRIES_CNT__ 13
  66. const CSTR settings_user_ini_fields[__INI_FILE_ENTRIES_CNT__] = {"AUTORESET_ENABLE", "AUTORESET_INTERLEAVE", "AUTORESET_TIMEOUT", "BOARD_TEMPERATURE", "BOARD_ZEROSHIFT", "BOARD_SPEED", "RUN_DIR", "NO_BLACK_TARGETS", "JUST_MOVING_TARGETS",
  67. "JUST_MOVING_RADIAL", "JUST_MOVING_DISTANCE", "FREEZ_FIRST_TH", "SAVE_FIRST_TH"};
  68. /*
  69. LPCTSTR m_pSetting[] =
  70. {
  71. { "SN" },
  72. { "ADDRESS" },
  73. { "CAMERA_TYPE" },
  74. { "CAMERA_SHIFT" },
  75. { "CAMERA_AUTO" },
  76. { "CAMERA_DELAY" },
  77. { "RELAY_NC" },
  78. { "RELAY_AUTO" },
  79. { "RELAY_DELAY" },
  80. { "VOLTAGE_CONTROL" },
  81. { "MASTER_DISABLED" },
  82. { "SLAVE_DISABLED" },
  83. { "AUTORESET_ENABLE" },
  84. { "AUTORESET_INTERLEAVE" },
  85. { "AUTORESET_TIMEOUT" },
  86. { "BOARD_TEMPERATURE" },
  87. { "BOARD_ZEROSHIFT" },
  88. { "BOARD_ENCODERSTEPS" },
  89. { "BOARD_GEARRATIO" },
  90. { "BOARD_MAXRANGE" },
  91. { "BOARD_SPEED" },
  92. { "RUN_DIR" },
  93. { "SWITCHER_TABLE" },
  94. { "SWITCHER_REPLY_TIMEOUT" },
  95. { "SWITCHER_COMMAND_TIMEOUT" },
  96. { "SWITCHER_AUTO_MODE" },
  97. { "SWITCHER_AUTO_ENTER_TIMEOUT" },
  98. { "SWITCHER_AUTO_SWITCH_TIMEOUT" },
  99. { "NO_BLACK_TARGETS" },
  100. { "JUST_MOVING_TARGETS" },
  101. { "JUST_MOVING_RADIAL" },
  102. { "JUST_MOVING_DISTANCE" },
  103. { "BLIND_ZONE_START_ANGLE" },
  104. { "BLIND_ZONE_END_ANGLE" },
  105. { "BLIND_ZONE_START_RANGE" },
  106. { "BLIND_ZONE_END_RANGE" },
  107. { "BLIND_ZONE_WIDTH" },
  108. { "BLIND_ZONE_DEPTH" },
  109. { "BLIND_ZONE_ANGLE" },
  110. { "BLIND_ZONE_RANGE" }
  111. #ifdef STORE_FIRST_SAF
  112. ,{ "FREEZ_FIRST_TH" }
  113. ,( "SAVE_FIRST_TH" )
  114. #endif
  115. };
  116. */
  117. LRF_WORK_STAGE operator++(LRF_WORK_STAGE & id, int)
  118. {
  119. LRF_WORK_STAGE currentID = id;
  120. if (LRF_WS_COUNT < id + 1)
  121. {
  122. id = LRF_WS_COUNT;
  123. }
  124. else
  125. {
  126. id = static_cast<LRF_WORK_STAGE>(id + 1);
  127. };
  128. return (currentID);
  129. }
  130. void deviceNodeSensor::transactionResetResult(void)
  131. {
  132. m_mPPModeProtector.lock();
  133. m_ePPMODE = STG_PUSH;
  134. m_mPPModeProtector.unlock();
  135. }
  136. void deviceNodeSensor::transactionSetResult(bool ACK)
  137. {
  138. m_mPPModeProtector.lock();
  139. bool tWasWaiting = (m_ePPMODE == STG_WAIT);
  140. m_ePPMODE = (ACK) ? STG_POOL : STG_PUSH;
  141. m_mPPModeProtector.unlock();
  142. if (tWasWaiting)
  143. {
  144. txTimingDone(ACK);
  145. };
  146. }
  147. void deviceNodeSensor::transactionWaitResult(void)
  148. {
  149. m_mPPModeProtector.lock();
  150. m_ePPMODE = STG_WAIT;
  151. m_mPPModeProtector.unlock();
  152. m_nTxStartMs = nsNowMs();
  153. if (m_nTxFirstMs == 0)
  154. {
  155. m_nTxFirstMs = m_nTxStartMs; // a retry keeps the time of the first attempt
  156. };
  157. }
  158. /*
  159. A reply ended the wait of the running request: reply time from the request, and from the first
  160. attempt when the command needed retries.
  161. */
  162. void deviceNodeSensor::txTimingDone(bool ok)
  163. {
  164. if (m_nTxStartMs == 0)
  165. {
  166. return;
  167. };
  168. uint64_t tNow = nsNowMs();
  169. uint64_t tReply = tNow - m_nTxStartMs;
  170. uint64_t tTotal = (m_nTxFirstMs != 0) ? tNow - m_nTxFirstMs : tReply;
  171. m_nTxCount++;
  172. m_nTxSumMs += tReply;
  173. if (tReply > m_nTxMaxMs)
  174. {
  175. m_nTxMaxMs = tReply;
  176. };
  177. #ifdef DEBUG_COMMUNICATION
  178. if (tReply > LGS_SLOW_REPLY_MS || tTotal > tReply || ! ok)
  179. {
  180. m_nTxSlow++;
  181. char tB[192];
  182. snprintf(tB, sizeof(tB), "COMM: %s WM 0x%02X STG 0x%02X reply %llu ms%s (wait %u ms per attempt)", ok ? "reply" : "NACK", (unsigned) getWM(), (unsigned) getStage(),
  183. (unsigned long long) tReply, (tTotal > tReply) ? ", command needed retries" : "", (unsigned) m_nTOCounterBase * 100);
  184. LOG(tB);
  185. if (tTotal > tReply)
  186. {
  187. snprintf(tB, sizeof(tB), "COMM: command done %llu ms after its first attempt", (unsigned long long) tTotal);
  188. LOG(tB);
  189. };
  190. };
  191. #else
  192. (void) ok;
  193. (void) tTotal;
  194. #endif
  195. m_nTxStartMs = 0;
  196. m_nTxFirstMs = 0;
  197. txTimingReport(false);
  198. }
  199. void deviceNodeSensor::txTimingReport(bool force)
  200. {
  201. #ifdef DEBUG_COMMUNICATION
  202. uint64_t tNow = nsNowMs();
  203. if (! force && tNow - m_nTxStatStartMs < LGS_TIMING_REPORT_MS)
  204. {
  205. return;
  206. };
  207. char tB[256];
  208. snprintf(tB, sizeof(tB), "COMM stats %llu s: %u replies, avg %llu ms, max %llu ms, %u slow (> %d ms) | %u attempts timed out (%u ms each), %u commands failed",
  209. (unsigned long long) ((tNow - m_nTxStatStartMs) / 1000), m_nTxCount, (unsigned long long) (m_nTxCount ? m_nTxSumMs / m_nTxCount : 0),
  210. (unsigned long long) m_nTxMaxMs, m_nTxSlow, LGS_SLOW_REPLY_MS, m_nTxAttemptTO, (unsigned) m_nTOCounterBase * 100, m_nTxFailed);
  211. LOG(tB);
  212. m_nTxCount = m_nTxSlow = m_nTxAttemptTO = m_nTxFailed = 0;
  213. m_nTxSumMs = m_nTxMaxMs = 0;
  214. m_nTxStatStartMs = tNow;
  215. #else
  216. if (force)
  217. {
  218. force = false;
  219. };
  220. #endif
  221. }
  222. STAGE_PP_CONDITION deviceNodeSensor::getPPStatus()
  223. {
  224. STAGE_PP_CONDITION rv;
  225. m_mPPModeProtector.lock();
  226. rv = m_ePPMODE;
  227. m_mPPModeProtector.unlock();
  228. return rv;
  229. }
  230. deviceNodeSensor::deviceNodeSensor(uint32_t id) :
  231. deviceNode(id),
  232. m_oPosition()
  233. {
  234. m_nCommErrorsCounter = 0;
  235. m_nTOCounterBase = LGS_DEFAULT_TO_COUNTER;
  236. m_nTxStartMs = m_nTxFirstMs = 0;
  237. m_nTxCount = m_nTxSlow = m_nTxAttemptTO = m_nTxFailed = 0;
  238. m_nTxSumMs = m_nTxMaxMs = 0;
  239. m_nTxStatStartMs = nsNowMs();
  240. m_ePPMODE = STG_INIT;
  241. m_bValidationSkipCounter = DAFAULT_VALIDATION_SKIP_COUNTER;
  242. m_nCommErrorsStatTO = COMMUNICATION_ERROR_STATISTIC_HARVEST_INTERVAL_IN_SECONDS;
  243. m_pTargetPipeLine = NULL;
  244. m_pEventHeap = basicEventHeap::getInstance();
  245. //m_bInitialSyncIsDone = false;
  246. switch (m_sNodeData.type)
  247. {
  248. case ARGUS_CLD_SENSOR : m_eEventClass = EVT_CLASS_SENSOR_CLD; break;
  249. case ARGUS_LGS_SENSOR : m_eEventClass = EVT_CLASS_SENSOR_LGS; break;
  250. case ARGUS_ALS_SENSOR : m_eEventClass = EVT_CLASS_SENSOR_ALS; break;
  251. case ARGUS_LFS_SENSOR : m_eEventClass = EVT_CLASS_SENSOR_LFS; break;
  252. case ARGUS_PLS_200_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_PLS_210; break;
  253. case ARGUS_PLS_360_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_PLS_360; break;
  254. case ARGUS_3D_SENSOR : m_eEventClass = EVT_CLASS_SENSOR_3D; break;
  255. default : m_eEventClass = EVT_CLASS_SYSTEM; break;
  256. };
  257. setWM(LRF_WM_INIT);
  258. memset(&m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
  259. if (m_pDBC)
  260. {
  261. DBC_LRF_DATA * tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id);
  262. if (tDATA != NULL)
  263. {
  264. memcpy(&m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA));
  265. free(tDATA);
  266. m_pDBC->updateLRFUnfinishedUploads(m_sNodeData.aux_id);
  267. m_pTargetPipeLine = new targetPipeLine(m_sNodeData.node_id, m_sLRF_DATA.prefered_camera_id);
  268. #ifdef DEBUG
  269. }
  270. else
  271. {
  272. LOG_ERROR("No Sensor DATA !!");
  273. #endif
  274. };
  275. };
  276. // m_pTargetFilter = NULL;
  277. systemAnchor * SA = systemAnchor::getInstance();
  278. if (SA)
  279. {
  280. if (SA->beLocal())
  281. {
  282. LOG_ERROR("Local Coords!");
  283. m_oPosition.setPositionXYZ(m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z);
  284. m_oPosition.setOrientationDeg(m_sLRF_DATA.x_rot, m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot);
  285. }
  286. else
  287. {
  288. LOG_ERROR("WGS Coords!");
  289. C3D_DECART LD = SA->getXYZ();
  290. char tZ[256];
  291. sprintf( tZ, "SX:%f SY:%f SZ:%f LX:%f LY:%f LZ:%f SH:%d Zone:%d", LD.x, LD.y, LD.z, m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z, SA->getSH(), SA->getUTMZone() );
  292. LOG(tZ);
  293. m_oPosition.setPositionXYZ(LD.x + m_sLRF_DATA.x, LD.y + m_sLRF_DATA.y, LD.z + m_sLRF_DATA.z, SA->getSH(), SA->getUTMZone() );
  294. m_oPosition.setOrientationDeg(m_sLRF_DATA.x_rot, m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot);
  295. };
  296. }
  297. else
  298. {
  299. LOG_ERROR("No System Anchor Object - Using Local Binding!");
  300. m_oPosition.setPositionXYZ(m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z);
  301. m_oPosition.setOrientationDeg(m_sLRF_DATA.x_rot, m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot);
  302. };
  303. m_oPosition.updateMatrix();
  304. #ifdef DEBUG
  305. char tB[128];
  306. sprintf(tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt());
  307. LOG(tB);
  308. sprintf(tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ());
  309. LOG(tB);
  310. sprintf(tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg());
  311. LOG(tB);
  312. #endif
  313. LOG("Finish Construct!");
  314. }
  315. deviceNodeSensor::deviceNodeSensor(DBC_NODE_DATA * Data) :
  316. deviceNode(Data),
  317. m_oPosition()
  318. {
  319. m_nCommErrorsCounter = 0;
  320. m_nTOCounterBase = LGS_DEFAULT_TO_COUNTER;
  321. m_nTxStartMs = m_nTxFirstMs = 0;
  322. m_nTxCount = m_nTxSlow = m_nTxAttemptTO = m_nTxFailed = 0;
  323. m_nTxSumMs = m_nTxMaxMs = 0;
  324. m_nTxStatStartMs = nsNowMs();
  325. m_ePPMODE = STG_INIT;
  326. m_bValidationSkipCounter = DAFAULT_VALIDATION_SKIP_COUNTER;
  327. m_nCommErrorsStatTO = COMMUNICATION_ERROR_STATISTIC_HARVEST_INTERVAL_IN_SECONDS;
  328. m_pEventHeap = basicEventHeap::getInstance();
  329. //m_bInitialSyncIsDone = false;
  330. memset(&m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
  331. m_pTargetPipeLine = NULL;
  332. if (m_pDBC)
  333. {
  334. reloadDeviceNodeFromDB();
  335. m_pDBC->updateLRFUnfinishedUploads(m_sLRF_DATA.id);
  336. m_pTargetPipeLine = new targetPipeLine(m_sNodeData.node_id, m_sLRF_DATA.prefered_camera_id);
  337. };
  338. setWM(LRF_WM_INIT);
  339. LOG("Finish Data Construct!");
  340. }
  341. deviceNodeSensor::~deviceNodeSensor()
  342. {
  343. // m_vTargetFilters.clear();
  344. if (m_pTargetPipeLine)
  345. {
  346. delete(m_pTargetPipeLine);
  347. }
  348. }
  349. /*
  350. bool deviceNodeSensor::filterTargetData( TARGET_DATA *ptr ){
  351. bool RetVal = false;
  352. if ( m_vTargetFilters.size() ) {
  353. for (vectorKernelEventFilters::iterator idx = m_vTargetFilters.begin(); idx != m_vTargetFilters.end(); idx++) {
  354. if( (*idx)->isActive() ) {
  355. if( (*idx)->validateTarget( m_sNodeData.node_id, ptr ) ) {
  356. RetVal = true;
  357. break;
  358. };
  359. };
  360. };
  361. };
  362. return RetVal;
  363. };
  364. */
  365. bool deviceNodeSensor::reloadDeviceNodeFromDB()
  366. {
  367. if (m_pDBC)
  368. {
  369. DBC_LRF_DATA * tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id);
  370. if (tDATA != NULL)
  371. {
  372. memcpy(&m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA));
  373. free(tDATA);
  374. };
  375. }
  376. else
  377. {
  378. return false;
  379. }
  380. systemAnchor * SA = systemAnchor::getInstance();
  381. if (SA)
  382. {
  383. if (SA->beLocal())
  384. {
  385. m_oPosition.setPositionXYZ(m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z, 0); // SA->getUTMZone() );
  386. m_oPosition.setOrientationDeg(m_sLRF_DATA.x_rot, m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot);
  387. }
  388. else
  389. {
  390. C3D_DECART LD = SA->getXYZ();
  391. m_oPosition.setPositionXYZ(LD.x + m_sLRF_DATA.x, LD.y + m_sLRF_DATA.y, LD.z + m_sLRF_DATA.z, SA->getUTMZone());
  392. m_oPosition.setOrientationDeg(m_sLRF_DATA.x_rot, m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot);
  393. };
  394. }
  395. else
  396. {
  397. m_oPosition.setPositionXYZ(m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z);
  398. m_oPosition.setOrientationDeg(m_sLRF_DATA.x_rot, m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot);
  399. };
  400. /// @todo Valgrind tells us something in this next call to updateMatrix() is leaked
  401. m_oPosition.updateMatrix();
  402. #ifdef DEBUG_EXTRA
  403. char tB[128];
  404. LOG("Reload Data From DB!");
  405. sprintf(tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt());
  406. LOG(tB);
  407. sprintf(tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ());
  408. LOG(tB);
  409. sprintf(tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg());
  410. LOG(tB);
  411. #endif
  412. return true;
  413. }
  414. bool deviceNodeSensor::validate()
  415. {
  416. if (m_bValidationSkipCounter)
  417. {
  418. m_bValidationSkipCounter--;
  419. }
  420. else
  421. {
  422. if (m_pDBC == NULL)
  423. {
  424. return false;
  425. }
  426. bool RetVal = true;
  427. DBC_LRF_DATA * tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id);
  428. if (tDATA != NULL)
  429. {
  430. if (RetVal && (tDATA->uart_id != m_sLRF_DATA.uart_id))
  431. {
  432. RetVal = false;
  433. }
  434. if (RetVal && (tDATA->device_id != m_sLRF_DATA.device_id))
  435. {
  436. RetVal = false;
  437. }
  438. if (RetVal && (tDATA->max_range != m_sLRF_DATA.max_range))
  439. {
  440. RetVal = false;
  441. }
  442. if (RetVal && (tDATA->base_shift != m_sLRF_DATA.base_shift))
  443. {
  444. RetVal = false;
  445. }
  446. if (RetVal && (tDATA->auto_draw != m_sLRF_DATA.auto_draw))
  447. {
  448. RetVal = false;
  449. }
  450. free(tDATA);
  451. }
  452. else
  453. {
  454. RetVal = false;
  455. }
  456. m_bValidationSkipCounter = DAFAULT_VALIDATION_SKIP_COUNTER;
  457. #ifdef DEBUG
  458. if (! RetVal)
  459. {
  460. LOG("Validation of Device Failure!");
  461. }
  462. #endif
  463. return RetVal;
  464. };
  465. return true;
  466. }
  467. #define SKIP_LINE_PIXELS 28
  468. #define HEIGHT 512
  469. #define WIDTH 1024
  470. #ifdef GEN_DRAW_IMAGE
  471. // scale factor -> 4/9
  472. uint8_t * deviceNodeSensor::create2dDraw(uint32_t * out_size, uint32_t * th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum)
  473. {
  474. uint8_t * RetVal = NULL;
  475. *out_size = 0;
  476. #ifdef DEBUG_EXTRA
  477. LOG("C2DD");
  478. #endif
  479. if (th_data != NULL && th_size != 0)
  480. {
  481. if (fileExist(tpl))
  482. {
  483. LOG(tpl);
  484. cv::Mat tImage = cv::imread(tpl, cv::IMREAD_UNCHANGED);
  485. int psize = th_size / (sizeof(uint32_t));
  486. float stp = 2.0f * (M_PI / (float) psize);
  487. // float MR = m_sLRF_DATA.max_range;
  488. float S = (M_PI / 3000.0f) * (float) radial_shift;
  489. int x0 = (tImage.cols >> 1);
  490. int y0 = (tImage.rows >> 1);
  491. float maxR = ((float) x0) * 0.98f;
  492. #ifdef DEBUG_EXTRA
  493. LOG("C2DD - Start");
  494. #endif
  495. cv::Point pts[(psize << 1)];
  496. cv::Point ptt[(psize + 2)];
  497. const cv::Point * ppt[1];
  498. int npp[1];
  499. const cv::Point * ppz[1];
  500. int npz[1];
  501. float rst;
  502. int rpt;
  503. uint16_t RANGE = 0;
  504. ptt[0].x = x0;
  505. ptt[0].y = y0;
  506. rst = maxR / ((float) (max_digital + 1));
  507. rpt = 1;
  508. for (int i = 0; i < psize; i++)
  509. {
  510. if (byMinimum)
  511. {
  512. RANGE = (th_data[i] >> 16) & 0xFFFF;
  513. }
  514. else
  515. {
  516. RANGE = th_data[i] & 0xFFFF;
  517. };
  518. float ca = 0.0 - (S + i * stp);
  519. if (RANGE > 0)
  520. {
  521. pts[psize + i].x = x0 + maxR * cosf(ca);
  522. pts[psize + i].y = y0 + maxR * sinf(ca);
  523. if (RANGE > max_digital)
  524. {
  525. pts[i].x = pts[psize + i].x;
  526. pts[i].y = pts[psize + i].y;
  527. }
  528. else
  529. {
  530. float cr = (rst * RANGE);
  531. pts[i].x = x0 + cr * cosf(ca);
  532. pts[i].y = y0 + cr * sinf(ca);
  533. };
  534. }
  535. else
  536. {
  537. ptt[rpt].x = pts[psize + i].x = pts[i].x = x0 + maxR * cosf(ca);
  538. ptt[rpt].y = pts[psize + i].y = pts[i].y = y0 + maxR * sinf(ca);
  539. rpt++;
  540. };
  541. };
  542. ppt[0] = pts;
  543. npp[0] = (psize << 1);
  544. ppz[0] = ptt;
  545. npz[0] = (rpt - 1);
  546. #ifdef DEBUG_EXTRA
  547. LOG("C2DD -> draw finish");
  548. #endif
  549. cv::Mat ttMOMO = cv::imread(tpl, cv::IMREAD_UNCHANGED);
  550. #ifdef DEBUG_EXTRA
  551. LOG("C2DD -> read tpl2 finish");
  552. #endif
  553. cv::fillPoly(ttMOMO, ppt, npp, 1, cv::Scalar(0, 128, 255, 50), cv::LINE_8);
  554. #ifdef DEBUG_EXTRA
  555. LOG("C2DD -> poly1 finish");
  556. #endif
  557. // try {
  558. // cv::fillPoly(ttMOMO, ppz, npz, 1, cv::Scalar(0, 0, 0, 100), cv::LINE_8);
  559. // LOG("C2DD -> poly2 finish");
  560. // } catch ( cv::Exception& e ) {
  561. // LOG("C2DD -> poly2 Error!");
  562. // LOG( e.what() );
  563. // };
  564. cv::addWeighted(tImage, 0.5, ttMOMO, 0.5, 0.0, tImage);
  565. #ifdef DEBUG_EXTRA
  566. LOG("C2DD -> add img finish");
  567. #endif
  568. ttMOMO.release();
  569. #ifdef DEBUG_EXTRA
  570. LOG("C2DD -> img release finish");
  571. #endif
  572. vector<int> compression_params;
  573. compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
  574. compression_params.push_back(9);
  575. vector<uchar> buf;
  576. cv::imencode(".png", tImage, buf, compression_params);
  577. tImage.release();
  578. #ifdef DEBUG_EXTRA
  579. LOG("C2DD -> compress finish");
  580. #endif
  581. *out_size = buf.size();
  582. RetVal = (uint8_t *) malloc(*out_size);
  583. if (RetVal)
  584. {
  585. memcpy(RetVal, buf.data(), *out_size);
  586. }
  587. else
  588. {
  589. *out_size = 0;
  590. }
  591. buf.clear();
  592. };
  593. };
  594. return RetVal;
  595. }
  596. #endif // GEN_DRAW_IMAGE
  597. #ifndef LRF_PROXY_ONLY
  598. #include <opencv2/opencv.hpp>
  599. #endif
  600. bool deviceNodeSensor::handleDeviceDraw(uint8_t kID, void * th_data, size_t th_size, bool byMinimum)
  601. {
  602. if ( byMinimum ) byMinimum = true;
  603. if (th_data == NULL)
  604. {
  605. return false;
  606. }
  607. if (th_size == 0)
  608. {
  609. return false;
  610. }
  611. if (m_pDBC == NULL)
  612. {
  613. return false;
  614. }
  615. switch (getNodeType())
  616. {
  617. case ARGUS_ALS_SENSOR:
  618. case ARGUS_LFS_SENSOR:
  619. case ARGUS_PLS_200_SENSOR:
  620. case ARGUS_PLS_360_SENSOR:
  621. case ARGUS_NET_PLS_200:
  622. {
  623. // apply Base Shift to 2D draw
  624. if (m_sLRF_DATA.base_shift != 0)
  625. {
  626. int16_t cnt = (th_size >> 2);
  627. uint32_t * ttData = (uint32_t *) malloc(th_size);
  628. int16_t data_shift = (int16_t) (((float) m_sLRF_DATA.base_shift) * (((float) cnt) / 360.0f));
  629. for (uint16_t i = 0; i < cnt; i++)
  630. {
  631. ttData[i] = ((uint32_t *) th_data)[(cnt + i + data_shift) % cnt];
  632. };
  633. memcpy(th_data, ttData, th_size);
  634. };
  635. break;
  636. };
  637. default: break;
  638. };
  639. #ifdef DEBUG_EXTRA
  640. LOG("DATA DD TO DATABASE");
  641. #endif
  642. m_pDBC->addDeviceDraw(getNodeID(), DRAW_MODE_RAW_DATA, kID, th_data, th_size);
  643. /*
  644. //Clear Old Draw
  645. CSTR old = m_pDBC->getLRFDraw( getNodeID() );
  646. if ( old ) {
  647. // delete old draw
  648. char filename[256];
  649. sprintf( filename, "data/device_draws/%s_100.png", old );
  650. if( fileExist( filename ) ){
  651. unlink( filename );
  652. };
  653. sprintf( filename, "data/device_draws/%s_50.png", old );
  654. if( fileExist( filename ) ){
  655. unlink( filename );
  656. };
  657. sprintf( filename, "data/device_draws/%s_25.png", old );
  658. if( fileExist( filename ) ){
  659. unlink( filename );
  660. };
  661. sprintf( filename, "data/device_draws/%s_12.png", old );
  662. if( fileExist( filename ) ){
  663. unlink( filename );
  664. };
  665. sprintf( filename, "data/device_draws/%s_map.png", old );
  666. if( fileExist( filename ) ){
  667. unlink( filename );
  668. };
  669. free( old );
  670. };
  671. */
  672. #ifndef SAVE_DRAW_RAW_ONLY
  673. CSTR uid = getUniqID_MD5();
  674. if (uid == NULL)
  675. {
  676. return false;
  677. }
  678. switch (getNodeType())
  679. {
  680. case ARGUS_ALS_SENSOR:
  681. case ARGUS_LFS_SENSOR:
  682. case ARGUS_PLS_200_SENSOR:
  683. case ARGUS_PLS_360_SENSOR:
  684. case ARGUS_NET_PLS_200:
  685. {
  686. #ifdef GEN_DRAW_IMAGE // 2D Sensors does not need Image to be created
  687. #ifdef DEBUG_EXTRA
  688. LOG("DEV DRAW");
  689. #endif
  690. LOG( uid );
  691. uint32_t tSize;
  692. uint8_t *tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 1024, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_100.png" );
  693. if ( tBuff ) {
  694. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_100, kID, tBuff, tSize );
  695. free( tBuff );
  696. };
  697. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 512, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_50.png" );
  698. if ( tBuff ) {
  699. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_50, kID, tBuff, tSize );
  700. free( tBuff );
  701. };
  702. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 256, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_25.png" );
  703. if ( tBuff ) {
  704. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_25, kID, tBuff, tSize );
  705. free( tBuff );
  706. };
  707. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 128, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_12.png" );
  708. if ( tBuff ) {
  709. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_12, kID, tBuff, tSize );
  710. free( tBuff );
  711. };
  712. tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 1024, m_sLRF_DATA.base_shift, "data/assets/images/2d_MAP.png" );
  713. if ( tBuff ) {
  714. m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_MAP, kID, tBuff, tSize );
  715. free( tBuff );
  716. };
  717. #ifdef DEBUG_EXTRA
  718. LOG(" DD FINISH!");
  719. #endif
  720. #endif // GEN_DRAW_IMAGE
  721. break;
  722. };
  723. case ARGUS_3D_SENSOR:
  724. {
  725. #ifndef LRF_PROXY_ONLY
  726. char * emptyBG = "data/assets/images/empty_3d.png";
  727. thresholdNode * ptr = (thresholdNode *) th_data;
  728. if (fileExist(emptyBG))
  729. {
  730. cv::Mat tImage = cv::imread(emptyBG, cv::IMREAD_UNCHANGED);
  731. if (tImage.rows != 512 || tImage.cols != 1024)
  732. {
  733. LOG_ERROR("Background Image wrong size (should be 1024x512)!");
  734. free(uid);
  735. return false;
  736. };
  737. uint8_t * tMemory = tImage.data;
  738. thresholdNode * cNode = NULL;
  739. uint8_t * cPixel = NULL;
  740. int pix = 0;
  741. int mem = 0;
  742. bool s_bit = false;
  743. bool no_data = false;
  744. float tVal;
  745. bool master = (kID < 16);
  746. for (int idx = 0; idx < (TH_SIZE_NODES << 2); idx++)
  747. { // tik-tak
  748. if ((idx % 4) == 0)
  749. {
  750. mem++;
  751. if (master)
  752. {
  753. cNode = ptr + TH_SIZE_NODES - mem - 1;
  754. }
  755. else
  756. {
  757. cNode = ptr + mem - 1;
  758. };
  759. if (! s_bit)
  760. {
  761. s_bit = cNode->values.sbit;
  762. }
  763. if (! no_data)
  764. {
  765. no_data = (cNode->values.cnt == 0);
  766. }
  767. if (! s_bit && ! no_data)
  768. {
  769. if (byMinimum)
  770. {
  771. tVal = ((float) cNode->values.min) / 4096.f;
  772. }
  773. else
  774. {
  775. tVal = ((float) cNode->values.max) / 4096.f;
  776. };
  777. };
  778. };
  779. if ((idx % 9) == 0)
  780. {
  781. if (mem > (SKIP_LINE_PIXELS * TH_LINE_NODES))
  782. {
  783. cPixel = tMemory + (pix << 2);
  784. pix++;
  785. if (s_bit)
  786. { // Set Red
  787. cPixel[0] = 0x00;
  788. cPixel[1] = 0x00;
  789. cPixel[2] = 0xff;
  790. cPixel[3] = 0xff;
  791. }
  792. else
  793. {
  794. if (no_data)
  795. { // Set Blue
  796. cPixel[0] = 0xff;
  797. cPixel[1] = 0x00;
  798. cPixel[2] = 0x00;
  799. cPixel[3] = 0xff;
  800. }
  801. else
  802. {
  803. uint32_t tColor;
  804. tColor = interpolate(0x000000ff, 0xffffffff, tVal);
  805. cPixel[0] = (tColor >> 24) & 0xFF;
  806. cPixel[1] = (tColor >> 16) & 0xFF;
  807. cPixel[2] = (tColor >> 8) & 0xFF;
  808. cPixel[3] = tColor & 0xFF;
  809. };
  810. };
  811. s_bit = false;
  812. no_data = false;
  813. };
  814. };
  815. };
  816. char filename[256];
  817. sprintf(filename, "data/device_draws/%s_100.png", uid);
  818. // int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
  819. vector<int> compression_params;
  820. compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
  821. compression_params.push_back(9);
  822. if (! cv::imwrite(filename, tImage, compression_params))
  823. {
  824. tImage.release();
  825. free(uid);
  826. return false;
  827. };
  828. tImage.release();
  829. #ifdef DEBUG_EXTRA
  830. LOG("Draw Saved!");
  831. #endif
  832. cv::Mat tMap(Q_SCAN_COUNT, TH_LINE_NODES, CV_8UC4);
  833. #ifdef DEBUG_EXTRA
  834. LOG("Map Creating");
  835. #endif
  836. tMemory = tMap.data;
  837. for (int j = 0; j < Q_SCAN_COUNT; j++)
  838. {
  839. for (int i = 0; i < TH_LINE_NODES; i++)
  840. {
  841. // cNode = ptr+(j*i);
  842. // cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
  843. int ids = 0;
  844. int idd = 0;
  845. if (master)
  846. {
  847. // cNode = ptr+makeIds( i, j , true );
  848. // cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  849. ids = makeIds(i, j, true);
  850. idd = 4 * makeIds(i, j, false);
  851. // cNode = ptr + ( i * j );
  852. // cPixel = tMemory + ( cSpace * i * j );
  853. }
  854. else
  855. {
  856. // cNode = ptr+makeIds( i, j , false );
  857. // cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  858. ids = makeIds(i, j, false);
  859. idd = 4 * makeIds(i, j, false);
  860. };
  861. cNode = ptr + ids;
  862. cPixel = tMemory + idd;
  863. if (0)
  864. { // Monochrome
  865. #ifdef CHECK_SUN_BIT
  866. if (cNode->values.sbit)
  867. {
  868. cPixel[0] = 0;
  869. }
  870. else
  871. {
  872. cPixel[0] = (uint8_t) ((((float) cNode->values.min) * 255.f) / 4096.f);
  873. };
  874. #else
  875. cPixel[0] = (uint8_t) ((((float) cNode->values.min) * 255.f) / 4096.f);
  876. #endif
  877. }
  878. else
  879. {
  880. #ifdef CHECK_SUN_BIT
  881. if (cNode->values.sbit)
  882. {
  883. // Set Red
  884. cPixel[0] = 0x00;
  885. cPixel[1] = 0x00;
  886. cPixel[2] = 0xff;
  887. cPixel[3] = 0xff;
  888. }
  889. else
  890. {
  891. if (cNode->values.cnt == 0)
  892. {
  893. // Set Blue
  894. cPixel[0] = 0xff;
  895. cPixel[1] = 0x00;
  896. cPixel[2] = 0x00;
  897. cPixel[3] = 0xff;
  898. }
  899. else
  900. {
  901. uint32_t tColor;
  902. float tVal = ((float) cNode->values.min) / 4096.f;
  903. tColor = interpolate(0x000000ff, 0xffffffff, tVal);
  904. cPixel[0] = (tColor >> 24) & 0xFF;
  905. cPixel[1] = (tColor >> 16) & 0xFF;
  906. cPixel[2] = (tColor >> 8) & 0xFF;
  907. cPixel[3] = tColor & 0xFF;
  908. };
  909. };
  910. #else
  911. if (cNode->values.cnt == 0)
  912. {
  913. // Set Blue
  914. cPixel[0] = 0xff;
  915. cPixel[1] = 0x00;
  916. cPixel[2] = 0x00;
  917. cPixel[3] = 0xff;
  918. }
  919. else
  920. {
  921. uint32_t tColor;
  922. float tVal = ((float) cNode->values.min) / 4096.f;
  923. tColor = interpolate(0x000000ff, 0xffffffff, tVal);
  924. cPixel[0] = (tColor >> 24) & 0xFF;
  925. cPixel[1] = (tColor >> 16) & 0xFF;
  926. cPixel[2] = (tColor >> 8) & 0xFF;
  927. cPixel[3] = tColor & 0xFF;
  928. };
  929. #endif
  930. };
  931. };
  932. };
  933. sprintf(filename, "data/device_draws/%s_map.png", uid);
  934. LOG(filename);
  935. if (! cv::imwrite(filename, tMap, compression_params))
  936. {
  937. tMap.release();
  938. free(uid);
  939. return false;
  940. };
  941. tMap.release();
  942. m_pDBC->addDeviceDraw(getNodeID(), DRAW_MODE_MAP, kID, (void *) uid, 0);
  943. // m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true );
  944. }
  945. else
  946. {
  947. LOG_ERROR("Background Image is Not Found!");
  948. free(uid);
  949. return false;
  950. };
  951. #endif //!LRF_PROXY_ONLY
  952. break;
  953. };
  954. default: break;
  955. };
  956. free(uid);
  957. #endif // !SAVE_DRAW_RAW_ONLY
  958. return true;
  959. }
  960. /*
  961. #define STB_IMAGE_IMPLEMENTATION
  962. #include "../data/stbi/stb_image.h"
  963. #define STB_IMAGE_WRITE_IMPLEMENTATION
  964. #include "../data/stbi/stb_image_write.h"
  965. #undef STB_IMAGE_WRITE_IMPLEMENTATION
  966. #undef STB_IMAGE_IMPLEMENTATION
  967. bool argus3DLIDAR::saveTHPicture( thresholdNode *ptr, CSTR uid, bool master, bool byMinimum, bool monochrome ){
  968. uint8_t *tMemory = NULL;
  969. thresholdNode *cNode = NULL;
  970. uint8_t *cPixel = NULL;
  971. int cSpace;
  972. int x, y;
  973. tMemory = stbi_load( "data/assets/images/empty_3d.png", &x, &y, &cSpace, STBI_default );
  974. if( tMemory == NULL ){
  975. LOG_ERROR("Draw Memory Alloc Eror!");
  976. return false;
  977. };
  978. if( x != 1024 || y != 512 ){
  979. LOG("Wrong IMG Size!");
  980. free( tMemory );
  981. return NULL;
  982. };
  983. int pix = 0;
  984. int mem = 0;
  985. bool s_bit = false;
  986. bool no_data = false;
  987. float tVal;
  988. for ( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
  989. if( ( idx % 4 ) == 0 ){
  990. mem++;
  991. if ( master ) {
  992. cNode = ptr + TH_SIZE_NODES - mem - 1;
  993. } else {
  994. cNode = ptr + mem - 1;
  995. };
  996. if( !s_bit ) s_bit = cNode->values.sbit;
  997. if( !no_data ) no_data = ( cNode->values.cnt == 0 );
  998. if( !s_bit && !no_data ){
  999. if( byMinimum ) {
  1000. tVal = ((float)cNode->values.min) / 4096.f;
  1001. } else {
  1002. tVal = ((float)cNode->values.max) / 4096.f;
  1003. };
  1004. };
  1005. };
  1006. if( ( idx % 9 ) == 0 ){
  1007. if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
  1008. cPixel = tMemory + (pix << 2);
  1009. pix++;
  1010. if( s_bit ) { // Set Red
  1011. cPixel[0] = 0x00; cPixel[1] = 0xff; cPixel[2] = 0x00; cPixel[3] = 0xff;
  1012. } else {
  1013. if( no_data ) { // Set Blue
  1014. cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
  1015. } else {
  1016. uint32_t tColor;
  1017. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  1018. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  1019. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  1020. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  1021. cPixel[3] = tColor & 0xFF;
  1022. };
  1023. };
  1024. s_bit = false;
  1025. no_data = false;
  1026. }
  1027. };
  1028. };
  1029. char filename[256];
  1030. sprintf( filename, "data/device_draws/%s_100.png", uid );
  1031. int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
  1032. free( tMemory );
  1033. if( RetVal == 0 ) return false;
  1034. if( monochrome ) {
  1035. cSpace = 1;
  1036. } else {
  1037. cSpace = 4;
  1038. };
  1039. tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace );
  1040. if( tMemory == NULL ){
  1041. LOG_ERROR("Map Memory Alloc Eror!");
  1042. return false;
  1043. };
  1044. for (int j = 0; j < Q_SCAN_COUNT; j++) {
  1045. for ( int i = 0; i < TH_LINE_NODES; i++ ) {
  1046. //cNode = ptr+(j*i);
  1047. //cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
  1048. int ids = 0;
  1049. int idd = 0;
  1050. if ( master ) {
  1051. //cNode = ptr+makeIds( i, j , true );
  1052. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  1053. ids = makeIds( i, j , true );
  1054. idd = cSpace * makeIds( i, j , false );
  1055. //cNode = ptr + ( i * j );
  1056. //cPixel = tMemory + ( cSpace * i * j );
  1057. } else {
  1058. //cNode = ptr+makeIds( i, j , false );
  1059. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  1060. ids = makeIds( i, j , false );
  1061. idd = cSpace * makeIds( i, j , false );
  1062. };
  1063. cNode = ptr + ids ;
  1064. cPixel = tMemory + idd;
  1065. if( monochrome ) {
  1066. #ifdef CHECK_SUN_BIT
  1067. if( cNode->values.sbit ) {
  1068. cPixel[0] = 0;
  1069. } else {
  1070. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  1071. };
  1072. #else
  1073. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  1074. #endif
  1075. } else {
  1076. #ifdef CHECK_SUN_BIT
  1077. if( cNode->values.sbit ) {
  1078. // Set Red
  1079. cPixel[0] = 0x00;
  1080. cPixel[1] = 0xff;
  1081. cPixel[2] = 0x00;
  1082. cPixel[3] = 0xff;
  1083. } else {
  1084. if( cNode->values.cnt == 0 ) {
  1085. // Set Blue
  1086. cPixel[0] = 0x00;
  1087. cPixel[1] = 0x00;
  1088. cPixel[2] = 0xff;
  1089. cPixel[3] = 0xff;
  1090. } else {
  1091. uint32_t tColor;
  1092. float tVal = ((float) cNode->values.min ) / 4096.f;
  1093. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  1094. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  1095. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  1096. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  1097. cPixel[3] = tColor & 0xFF;
  1098. };
  1099. };
  1100. #else
  1101. if( cNode->values.cnt == 0 ) {
  1102. // Set Blue
  1103. cPixel[0] = 0x00;
  1104. cPixel[1] = 0x00;
  1105. cPixel[2] = 0xff;
  1106. cPixel[3] = 0xff;
  1107. } else {
  1108. uint32_t tColor;
  1109. float tVal = ((float) cNode->values.min ) / 4096.f;
  1110. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  1111. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  1112. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  1113. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  1114. cPixel[3] = tColor & 0xFF;
  1115. };
  1116. #endif
  1117. };
  1118. };
  1119. };
  1120. sprintf( filename, "data/device_draws/%s_map.png", uid );
  1121. RetVal = stbi_write_png( filename, TH_LINE_NODES, Q_SCAN_COUNT, cSpace, tMemory, TH_LINE_NODES * cSpace );
  1122. free( tMemory );
  1123. if( RetVal == 0 ) return false;
  1124. return true;
  1125. };
  1126. */
  1127. void deviceNodeSensor::broadcastFlip(uint16_t flipCount)
  1128. {
  1129. EVENT_CONTAINER * bEVT = NULL;
  1130. if( flipCount ) bEVT = NULL;
  1131. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_FLIP, NULL, NULL, NULL);
  1132. if (bEVT != NULL)
  1133. {
  1134. m_pEventHeap->broadcast(bEVT);
  1135. }
  1136. }
  1137. void deviceNodeSensor::broadcastConnected(void)
  1138. {
  1139. EVENT_CONTAINER * bEVT = NULL;
  1140. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_CONNECTED, NULL, NULL, NULL);
  1141. if (bEVT != NULL)
  1142. {
  1143. m_pEventHeap->broadcast(bEVT);
  1144. }
  1145. }
  1146. void deviceNodeSensor::broadcastDisconnected(void)
  1147. {
  1148. EVENT_CONTAINER * bEVT = NULL;
  1149. bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_DISCONNECTED, NULL, NULL, NULL);
  1150. if (bEVT != NULL)
  1151. {
  1152. m_pEventHeap->broadcast(bEVT);
  1153. }
  1154. }
  1155. void deviceNodeSensor::startWaitDeviceOnline(LRF_WORK_MODE wm, LRF_WORK_STAGE stg)
  1156. {
  1157. m_SP_WM = wm;
  1158. m_SP_STAGE = stg;
  1159. setWM(LRF_WM_WAIT_ONLINE_SPECIAL);
  1160. }
  1161. uint8_t deviceNodeSensor::getSensStatus()
  1162. {
  1163. return m_sLRF_DATA.data_status;
  1164. }
  1165. void deviceNodeSensor::updateDataStatus(uint8_t ds, uint8_t ns)
  1166. {
  1167. if (m_pDBC == NULL)
  1168. {
  1169. return;
  1170. }
  1171. if (m_sNodeData.node_id)
  1172. {
  1173. if (ds < ARGUS_DS_CONNECTING)
  1174. {
  1175. m_pDBC->setNodeOffline(m_sNodeData.node_id);
  1176. }
  1177. else
  1178. {
  1179. m_pDBC->setNodeOnline(m_sNodeData.node_id, ns);
  1180. };
  1181. };
  1182. if (m_sLRF_DATA.id)
  1183. {
  1184. m_sLRF_DATA.data_status = ds;
  1185. m_pDBC->setLRFDataStatus(m_sLRF_DATA.id, ds);
  1186. };
  1187. }
  1188. void deviceNodeSensor::waitStateFunction(LRF_WORK_STAGE boboStage)
  1189. {
  1190. #ifdef DEBUG_EXTRA
  1191. LOG("WaitState");
  1192. uint8_t cwm = getWM();
  1193. uint8_t cst = getStage();
  1194. char tB[128];
  1195. sprintf(tB, "WM: 0x%02X STG: 0x%02X", cwm, cst);
  1196. LOG(tB);
  1197. #endif
  1198. if (m_bTimeOutCounter)
  1199. {
  1200. m_bTimeOutCounter--;
  1201. DELAY_10MS(LGS_DEFAULT_WS_TIME);
  1202. }
  1203. else
  1204. {
  1205. if (m_bOpRetryCnt)
  1206. {
  1207. #ifdef DEBUG_EXTRA
  1208. LOG("ATTEMPT RECOVER");
  1209. #endif
  1210. m_nTxAttemptTO++;
  1211. #ifdef DEBUG_COMMUNICATION
  1212. {
  1213. char tB[160];
  1214. snprintf(tB, sizeof(tB), "COMM: no reply - WM 0x%02X STG 0x%02X attempt %d/%d timed out after %llu ms", (unsigned) getWM(), (unsigned) getStage(),
  1215. LGS_CMD_RETRY_COUNT - m_bOpRetryCnt + 1, LGS_CMD_RETRY_COUNT + 1, (unsigned long long) (m_nTxStartMs ? nsNowMs() - m_nTxStartMs : 0));
  1216. LOG(tB);
  1217. }
  1218. #endif
  1219. m_bOpRetryCnt--;
  1220. m_bTimeOutCounter = m_nTOCounterBase;
  1221. registerCommError(false);
  1222. LRF_WORK_STAGE pS = getPrevStage();
  1223. if (pS != LRF_WS_INIT)
  1224. {
  1225. #ifdef DEBUG_EXTRA
  1226. LOG("Set Prev Stage");
  1227. #endif
  1228. setStage(pS, false);
  1229. }
  1230. else
  1231. {
  1232. if (boboStage != LRF_WS_INIT)
  1233. {
  1234. #ifdef DEBUG_EXTRA
  1235. LOG("Set Desired Stage");
  1236. #endif
  1237. setStage(boboStage, false);
  1238. }
  1239. else
  1240. {
  1241. #ifdef DEBUG_EXTRA
  1242. LOG("Set Connection Stage");
  1243. #endif
  1244. setWM(LRF_WM_CONNECTION);
  1245. return;
  1246. };
  1247. };
  1248. }
  1249. else
  1250. {
  1251. LOG_ERROR("Communication Wait State TO!");
  1252. m_nTxFailed++;
  1253. #ifdef DEBUG_COMMUNICATION
  1254. {
  1255. char tB[192];
  1256. snprintf(tB, sizeof(tB), "COMM: command failed - WM 0x%02X STG 0x%02X, %d attempts of %u ms, %llu ms since the first attempt", (unsigned) getWM(), (unsigned) getStage(),
  1257. LGS_CMD_RETRY_COUNT + 1, (unsigned) m_nTOCounterBase * 100, (unsigned long long) (m_nTxFirstMs ? nsNowMs() - m_nTxFirstMs : 0));
  1258. LOG(tB);
  1259. }
  1260. txTimingReport(true);
  1261. #endif
  1262. m_nTxStartMs = 0;
  1263. m_nTxFirstMs = 0;
  1264. registerCommError(true);
  1265. // setStage( boboStage );
  1266. setWM(LRF_WM_CONNECTION);
  1267. return;
  1268. };
  1269. DELAY_10MS(LGS_DEFAULT_WS_TIME);
  1270. transactionResetResult();
  1271. };
  1272. }
  1273. void deviceNodeSensor::poolStateFunction()
  1274. {
  1275. goNextStage();
  1276. transactionResetResult();
  1277. }
  1278. bool deviceNodeSensor::initWModeFunction(uint8_t wm)
  1279. {
  1280. if (getOWM() != wm)
  1281. {
  1282. setWM(wm);
  1283. setWM(wm);
  1284. setStage(LRF_WS_INIT);
  1285. transactionResetResult();
  1286. m_nTxStartMs = 0; // a new work mode: no command running
  1287. m_nTxFirstMs = 0;
  1288. m_bOpRetryCnt = LGS_CMD_RETRY_COUNT;
  1289. return true;
  1290. };
  1291. return false;
  1292. }
  1293. void deviceNodeSensor::m_fThreadProc(void)
  1294. {
  1295. time_t tTimeT_Current;
  1296. time_t tTimeT_Old = time(NULL);
  1297. m_bThreadStatus = TH_WORKING;
  1298. setWM(LRF_WM_INIT);
  1299. pthread_setname_np( pthread_self(), "NodeSensor" );
  1300. while (m_bThreadStatus < TH_ENDED)
  1301. {
  1302. tTimeT_Current = time(NULL);
  1303. if (tTimeT_Old != tTimeT_Current)
  1304. {
  1305. tTimeT_Old = tTimeT_Current;
  1306. if (m_nCommErrorsStatTO)
  1307. {
  1308. m_nCommErrorsStatTO--;
  1309. }
  1310. else
  1311. {
  1312. /**
  1313. * Update Communication Status!
  1314. */
  1315. m_nCommErrorsStatTO = COMMUNICATION_ERROR_STATISTIC_HARVEST_INTERVAL_IN_SECONDS;
  1316. m_pDBC->updateLRFComStat(m_sNodeData.aux_id, m_nCommErrorsCounter);
  1317. m_nCommErrorsCounter = 0;
  1318. };
  1319. proceedDBCommands();
  1320. };
  1321. if (getWM() > LRF_WM_CONNECTION)
  1322. {
  1323. if (! validateCommunicationRessource())
  1324. {
  1325. setWM(LRF_WM_CONNECTION);
  1326. DELAY_10MS(200);
  1327. };
  1328. };
  1329. switch (getWM())
  1330. {
  1331. case LRF_WM_INIT:
  1332. reloadDeviceNodeFromDB();
  1333. setWM(LRF_WM_CONNECTION);
  1334. break;
  1335. case LRF_WM_CONNECTION : connectMode(); break;
  1336. case LRF_WM_HANDSHAKE : handshakeMode(); break;
  1337. case LRF_WM_SYNC_UP : readMode(); break;
  1338. case LRF_WM_SYNC_DOWN : syncMode(); break;
  1339. case LRF_WM_BORDER : drawMode(); break;
  1340. case LRF_WM_FULL_BORDER : fullDrawMode(); break;
  1341. case LRF_WM_FILE : getfileMode(); break;
  1342. case LRF_WM_FILE_TF : fileTransferMode(); break;
  1343. case LRF_WM_ALARM : alarmMode(); break;
  1344. case LRF_WM_IDLE : idleMode(); break;
  1345. case LRF_WM_STATUS_MASK : maskMode(); break;
  1346. case LRF_WM_SAVE_HW : save_ini(); break;
  1347. case LRF_WM_SAVE_DETECTION : save_detection(); break;
  1348. case LRF_WM_SAVE_EPROM : save_eprom(); break;
  1349. case LRF_WM_SAVE_MASKS : save_masks(); break;
  1350. case LRF_WM_WAIT_ONLINE_SPECIAL: wait_device(); break;
  1351. case LRF_WM_WAIT_CHANNEL : wait_channel(); break;
  1352. default : LOG("WM NOT REG"); setWM(LRF_WM_IDLE);
  1353. };
  1354. };
  1355. LOG("Stop Dev Thread");
  1356. }
  1357. void deviceNodeSensor::setStage(LRF_WORK_STAGE st, bool update_old_stage)
  1358. {
  1359. m_mStageProtector.lock();
  1360. if (update_old_stage)
  1361. {
  1362. m_eOldWorkingStage = m_eWorkingStage;
  1363. }
  1364. m_eWorkingStage = st;
  1365. m_mStageProtector.unlock();
  1366. }
  1367. void deviceNodeSensor::goNextStage(bool update_old_stage)
  1368. {
  1369. m_mStageProtector.lock();
  1370. if (m_eWorkingStage < LRF_WS_COUNT)
  1371. {
  1372. if (update_old_stage)
  1373. {
  1374. m_eOldWorkingStage = m_eWorkingStage;
  1375. }
  1376. m_eWorkingStage++;
  1377. };
  1378. m_mStageProtector.unlock();
  1379. }
  1380. LRF_WORK_STAGE deviceNodeSensor::getStage()
  1381. {
  1382. LRF_WORK_STAGE rV;
  1383. m_mStageProtector.lock();
  1384. rV = m_eWorkingStage;
  1385. m_mStageProtector.unlock();
  1386. return rV;
  1387. }
  1388. LRF_WORK_STAGE deviceNodeSensor::getPrevStage()
  1389. {
  1390. LRF_WORK_STAGE rV;
  1391. m_mStageProtector.lock();
  1392. rV = m_eOldWorkingStage;
  1393. m_mStageProtector.unlock();
  1394. return rV;
  1395. }
  1396. bool deviceNodeSensor::generateIniFile(uint8_t i)
  1397. {
  1398. if (m_pDBC == NULL)
  1399. {
  1400. return false;
  1401. }
  1402. DBC_LRF_INI * tData = m_pDBC->getINIData(m_sNodeData.aux_id);
  1403. if (tData)
  1404. {
  1405. }
  1406. else
  1407. {
  1408. LOG("No Data From DB! ---> Set Defaults!");
  1409. tData = (DBC_LRF_INI *) malloc(sizeof(DBC_LRF_INI));
  1410. if (tData)
  1411. {
  1412. memset(tData, 0, sizeof(DBC_LRF_INI));
  1413. tData->_AUTO_RESET_ENABLE = 0;
  1414. tData->_BOARD_SPEED = 4;
  1415. tData->_BOARD_TEMPERATURE = 1;
  1416. tData->_RUN_DIR = 2;
  1417. };
  1418. };
  1419. if (tData)
  1420. {
  1421. CSTR tMD5 = getUniqID_MD5();
  1422. if (tMD5)
  1423. {
  1424. sprintf(m_pTGENFILENAMES[i], "%s", tMD5);
  1425. free(tMD5);
  1426. char tB[256];
  1427. sprintf(tB, "data/uploads/%s", m_pTGENFILENAMES[i]);
  1428. FILE * fd = fopen(tB, "wb+");
  1429. if (fd)
  1430. {
  1431. uint16_t * tpP = (uint16_t *) tData;
  1432. for (int idx = 0; idx < __INI_FILE_ENTRIES_CNT__; idx++)
  1433. {
  1434. fprintf(fd, "%s=%d\r\n", settings_user_ini_fields[idx], tpP[idx]);
  1435. };
  1436. fclose(fd);
  1437. return true;
  1438. };
  1439. };
  1440. free(tData);
  1441. }
  1442. return false;
  1443. }
  1444. void deviceNodeSensor::registerCommError(bool withEvent)
  1445. {
  1446. m_nCommErrorsCounter++;
  1447. if (withEvent)
  1448. {
  1449. EVENT_CONTAINER * bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_COMMUNICATION_JAMED, NULL, NULL, NULL);
  1450. if (bEVT != NULL)
  1451. {
  1452. m_pEventHeap->broadcast(bEVT);
  1453. };
  1454. };
  1455. }
  1456. bool deviceNodeSensor::generateRestartFile(uint8_t i)
  1457. {
  1458. if (m_pDBC == NULL)
  1459. {
  1460. return false;
  1461. }
  1462. CSTR tMD5 = getUniqID_MD5();
  1463. if (tMD5)
  1464. {
  1465. sprintf(m_pTGENFILENAMES[i], "%s", tMD5);
  1466. free(tMD5);
  1467. char tB[256];
  1468. sprintf(tB, "data/uploads/%s", m_pTGENFILENAMES[i]);
  1469. FILE * fd = fopen(tB, "wb+");
  1470. if (fd)
  1471. {
  1472. fprintf(fd, "copy *.exe c:\r\ncopy *.ini c:\r\ncopy *.txt c:\r\n");
  1473. fclose(fd);
  1474. return true;
  1475. };
  1476. };
  1477. return false;
  1478. }
  1479. #undef LOG
  1480. #undef LOG_ERROR