Update car monitor asset reload and telemetry

This commit is contained in:
seo committed 2026-08-12 21:35:21 +09:00
1 parent 6f965f8f3e
commit 5d75ad81bd
8 files changed
+4334 -4366

No files matched your search

+66 -66
View File
@@ -44,37 +44,37 @@ if (($params['log'] ?? '') == '1') {
$cmdRequested = $params['cmd'] ?? 'se';
$cmd = normalize_cmd($cmdRequested);
if ($cmd === 'se') {
$latest = db_latest($pdo);
if (!$latest) {
if ($cmd === 'se') {
$latest = db_latest($pdo);
if (!$latest) {
json_exit([
'request_id' => $requestId,
'error' => 'no_latest_data'
], 500);
}
$ageSeconds = max(0, time() - strtotime((string)$latest['ts']));
$latestUsage = db_latest_usage($pdo);
$staleReason = null;
if ($ageSeconds > 30 && $latestUsage && (int)$latestUsage['tcp_ok'] === 0) {
$staleReason = (string)($latestUsage['tcp_error'] ?? 'tcp_failed');
}
json_exit([
'request_id' => $requestId,
'cmd_requested' => 'se',
'cmd' => $latest['cmd'],
'ts' => $latest['ts'],
'meta' => [
'age_seconds' => $ageSeconds,
'stale' => $ageSeconds > 30,
'stale_reason' => $staleReason,
'latest_tcp' => $latestUsage,
],
'raw_full' => $latest['raw_full'],
'raw_trim' => $latest['raw_trim'],
], 500);
}
$ageSeconds = max(0, time() - strtotime((string)$latest['ts']));
$latestUsage = db_latest_usage($pdo);
$staleReason = null;
if ($ageSeconds > 30 && $latestUsage && (int)$latestUsage['tcp_ok'] === 0) {
$staleReason = (string)($latestUsage['tcp_error'] ?? 'tcp_failed');
}
json_exit([
'request_id' => $requestId,
'cmd_requested' => 'se',
'cmd' => $latest['cmd'],
'ts' => $latest['ts'],
'meta' => [
'age_seconds' => $ageSeconds,
'stale' => $ageSeconds > 30,
'stale_reason' => $staleReason,
'latest_tcp' => $latestUsage,
],
'raw_full' => $latest['raw_full'],
'raw_trim' => $latest['raw_trim'],
'data' => [
'boundary' => (int)$latest['boundary'],
@@ -110,26 +110,26 @@ if ($requestMethod !== 'POST') {
], 405);
}
$tcpMs = 0;
$connectMs = 0;
$readMs = 0;
$tcpError = '';
$trimError = '';
$sentBytes = 0;
$receivedBytes = 0;
$rawFull = tcp_request(
$cmd,
$tcpMs,
$connectMs,
$readMs,
$tcpError,
'api_control',
$requestId,
$sentBytes,
$receivedBytes
);
$execMs = (int)round((microtime(true) - $tsStart) * 1000);
$tcpMs = 0;
$connectMs = 0;
$readMs = 0;
$tcpError = '';
$trimError = '';
$sentBytes = 0;
$receivedBytes = 0;
$rawFull = tcp_request(
$cmd,
$tcpMs,
$connectMs,
$readMs,
$tcpError,
'api_control',
$requestId,
$sentBytes,
$receivedBytes
);
$execMs = (int)round((microtime(true) - $tsStart) * 1000);
if ($rawFull === '') {
json_exit([
@@ -141,16 +141,16 @@ if ($rawFull === '') {
'client_ip' => $clientIp,
'ua' => $userAgent,
'tcp_ok' => 0,
'tcp_ms' => $tcpMs,
'connect_ms' => $connectMs,
'read_ms' => $readMs,
'sent_bytes' => $sentBytes,
'received_bytes' => $receivedBytes,
'total_bytes' => $sentBytes + $receivedBytes,
'tcp_error' => ($tcpError !== '' ? $tcpError : 'timeout_or_empty'),
'error' => 'CONTROL_CMD_SEND_FAILED'
], 502);
}
'tcp_ms' => $tcpMs,
'connect_ms' => $connectMs,
'read_ms' => $readMs,
'sent_bytes' => $sentBytes,
'received_bytes' => $receivedBytes,
'total_bytes' => $sentBytes + $receivedBytes,
'tcp_error' => ($tcpError !== '' ? $tcpError : 'timeout_or_empty'),
'error' => 'CONTROL_CMD_SEND_FAILED'
], 502);
}
$rawTrim = make_trim($rawFull, $trimError);
$data = ($rawTrim !== '') ? parse_trim($rawTrim) : null;
@@ -174,16 +174,16 @@ json_exit([
'client_ip' => $clientIp,
'ua' => $userAgent,
'tcp_ok' => 1,
'tcp_ms' => $tcpMs,
'connect_ms' => $connectMs,
'read_ms' => $readMs,
'sent_bytes' => $sentBytes,
'received_bytes' => $receivedBytes,
'total_bytes' => $sentBytes + $receivedBytes,
'tcp_error' => $tcpError,
'tcp_ms' => $tcpMs,
'connect_ms' => $connectMs,
'read_ms' => $readMs,
'sent_bytes' => $sentBytes,
'received_bytes' => $receivedBytes,
'total_bytes' => $sentBytes + $receivedBytes,
'tcp_error' => $tcpError,
'accepted' => true,
'ack_only' => ($rawTrim === ''),
'raw_full' => $rawFull,
'raw_trim' => $rawTrim,
'data' => $data
]);
]);