248 lines
8.3 KiB
Python
248 lines
8.3 KiB
Python
|
|
import os
|
||
|
|
R = r"C:\Projects\CMSCore"
|
||
|
|
def w(rel, txt):
|
||
|
|
p = os.path.join(R, rel)
|
||
|
|
os.makedirs(os.path.dirname(p), exist_ok=True)
|
||
|
|
with open(p, "w", encoding="utf-8", newline="\r\n") as f:
|
||
|
|
f.write(txt.lstrip("\n"))
|
||
|
|
print(f" OK: {rel}")
|
||
|
|
|
||
|
|
# ============================================================================
|
||
|
|
# 1. anscloud-common/include/anscloud/common/types.h
|
||
|
|
# ============================================================================
|
||
|
|
w("anscloud-common/include/anscloud/common/types.h", r'''#pragma once
|
||
|
|
// ==========================================================================
|
||
|
|
// ANSCloud SDK - Common Types
|
||
|
|
// ANSCENTER Pty Ltd - Cloud Messaging Protocol Types
|
||
|
|
// ==========================================================================
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
#include <functional>
|
||
|
|
#include <cstdint>
|
||
|
|
#include <chrono>
|
||
|
|
|
||
|
|
namespace anscloud {
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Protocol version
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
constexpr const char* PROTOCOL_VERSION = "1.0.0";
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Exchange names (must match RabbitMQ broker topology)
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
namespace exchange {
|
||
|
|
constexpr const char* DEVICE_TELEMETRY = "ex.device.telemetry";
|
||
|
|
constexpr const char* DEVICE_STATUS = "ex.device.status";
|
||
|
|
constexpr const char* DEVICE_EVENTS = "ex.device.events";
|
||
|
|
constexpr const char* COMMAND = "ex.command";
|
||
|
|
constexpr const char* COMMAND_RESPONSE = "ex.command.response";
|
||
|
|
constexpr const char* BROADCAST = "ex.broadcast";
|
||
|
|
}
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Queue name builders
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
namespace queue {
|
||
|
|
inline std::string device_command(const std::string& device_id) { return "q.cmd." + device_id; }
|
||
|
|
inline std::string device_broadcast(const std::string& device_id){ return "q.broadcast." + device_id; }
|
||
|
|
// Gateway-side queues (shared)
|
||
|
|
constexpr const char* TELEMETRY_INGEST = "q.telemetry.ingest";
|
||
|
|
constexpr const char* EVENTS_PROCESSOR = "q.events.processor";
|
||
|
|
constexpr const char* STATUS_TRACKER = "q.status.tracker";
|
||
|
|
constexpr const char* COMMAND_RESPONSES = "q.command.responses";
|
||
|
|
}
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Device Status
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
enum class DeviceStatus {
|
||
|
|
Unknown = 0,
|
||
|
|
Online,
|
||
|
|
Offline,
|
||
|
|
Connecting,
|
||
|
|
Error
|
||
|
|
};
|
||
|
|
const char* to_string(DeviceStatus s);
|
||
|
|
DeviceStatus device_status_from_string(const std::string& s);
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Command Types
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
enum class CommandType {
|
||
|
|
Custom = 0,
|
||
|
|
GetSystemInfo,
|
||
|
|
GetConfig,
|
||
|
|
SetConfig,
|
||
|
|
GetCameraList,
|
||
|
|
AddCamera,
|
||
|
|
RemoveCamera,
|
||
|
|
UpdateCamera,
|
||
|
|
GetCameraSnapshot,
|
||
|
|
StartStream,
|
||
|
|
StopStream,
|
||
|
|
RestartService,
|
||
|
|
RebootDevice,
|
||
|
|
UpdateFirmware,
|
||
|
|
RunDiagnostics,
|
||
|
|
GetLogs,
|
||
|
|
SetSchedule,
|
||
|
|
GetSchedule
|
||
|
|
};
|
||
|
|
const char* to_string(CommandType t);
|
||
|
|
CommandType command_type_from_string(const std::string& s);
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Event Types
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
enum class EventType {
|
||
|
|
Custom = 0,
|
||
|
|
Alert,
|
||
|
|
DetectionLPR,
|
||
|
|
DetectionFace,
|
||
|
|
DetectionObject,
|
||
|
|
DetectionMotion,
|
||
|
|
LineCrossing,
|
||
|
|
Intrusion,
|
||
|
|
Loitering,
|
||
|
|
CameraDisconnected,
|
||
|
|
CameraReconnected,
|
||
|
|
StorageWarning,
|
||
|
|
SystemError
|
||
|
|
};
|
||
|
|
const char* to_string(EventType t);
|
||
|
|
EventType event_type_from_string(const std::string& s);
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Command Status
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
enum class CommandStatus {
|
||
|
|
Success = 0,
|
||
|
|
Failed,
|
||
|
|
Timeout,
|
||
|
|
Rejected,
|
||
|
|
Pending,
|
||
|
|
PartialSuccess
|
||
|
|
};
|
||
|
|
const char* to_string(CommandStatus s);
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Data structures
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
struct SystemMetrics {
|
||
|
|
double cpu_usage_percent = 0.0;
|
||
|
|
double ram_usage_percent = 0.0;
|
||
|
|
uint64_t ram_total_mb = 0;
|
||
|
|
uint64_t ram_used_mb = 0;
|
||
|
|
double gpu_usage_percent = 0.0;
|
||
|
|
double gpu_memory_percent = 0.0;
|
||
|
|
double gpu_temperature_c = 0.0;
|
||
|
|
double disk_usage_percent = 0.0;
|
||
|
|
uint64_t disk_total_gb = 0;
|
||
|
|
uint64_t disk_used_gb = 0;
|
||
|
|
double cpu_temperature_c = 0.0;
|
||
|
|
uint32_t process_count = 0;
|
||
|
|
double network_rx_mbps = 0.0;
|
||
|
|
double network_tx_mbps = 0.0;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct CameraInfo {
|
||
|
|
std::string camera_id;
|
||
|
|
std::string name;
|
||
|
|
std::string rtsp_url;
|
||
|
|
std::string status; // "online", "offline", "error"
|
||
|
|
int width = 0;
|
||
|
|
int height = 0;
|
||
|
|
double fps = 0.0;
|
||
|
|
std::string codec;
|
||
|
|
std::string ai_models; // comma-separated model names
|
||
|
|
bool recording = false;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct InferenceMetrics {
|
||
|
|
uint32_t active_models = 0;
|
||
|
|
double avg_latency_ms = 0.0;
|
||
|
|
double total_fps = 0.0;
|
||
|
|
uint64_t total_detections = 0;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Heartbeat {
|
||
|
|
std::string device_id;
|
||
|
|
std::string timestamp; // ISO 8601
|
||
|
|
DeviceStatus status = DeviceStatus::Online;
|
||
|
|
uint64_t uptime_seconds = 0;
|
||
|
|
std::string firmware_version;
|
||
|
|
std::string ansvis_version;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct DeviceTelemetry {
|
||
|
|
std::string device_id;
|
||
|
|
std::string timestamp;
|
||
|
|
SystemMetrics metrics;
|
||
|
|
std::vector<CameraInfo> cameras;
|
||
|
|
InferenceMetrics inference;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Command {
|
||
|
|
std::string command_id; // UUID
|
||
|
|
std::string device_id; // target device
|
||
|
|
CommandType type = CommandType::Custom;
|
||
|
|
std::string type_name; // string name for Custom commands
|
||
|
|
std::string params_json; // JSON string with command parameters
|
||
|
|
std::string correlation_id; // for RPC matching
|
||
|
|
std::string reply_to; // reply queue/routing key
|
||
|
|
int timeout_seconds = 30;
|
||
|
|
std::string timestamp;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct CommandResponse {
|
||
|
|
std::string command_id;
|
||
|
|
std::string device_id;
|
||
|
|
CommandStatus status = CommandStatus::Success;
|
||
|
|
std::string result_json; // JSON string with results
|
||
|
|
std::string error_message;
|
||
|
|
std::string correlation_id;
|
||
|
|
double execution_time_ms = 0.0;
|
||
|
|
std::string timestamp;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct DeviceEvent {
|
||
|
|
std::string event_id; // UUID
|
||
|
|
std::string device_id;
|
||
|
|
EventType type = EventType::Custom;
|
||
|
|
std::string type_name;
|
||
|
|
std::string camera_id; // optional, which camera
|
||
|
|
std::string data_json; // event payload
|
||
|
|
std::string thumbnail_base64;// optional snapshot
|
||
|
|
std::string timestamp;
|
||
|
|
int severity = 0; // 0=info, 1=warning, 2=critical
|
||
|
|
};
|
||
|
|
|
||
|
|
struct DeviceStatusMessage {
|
||
|
|
std::string device_id;
|
||
|
|
DeviceStatus status = DeviceStatus::Unknown;
|
||
|
|
std::string timestamp;
|
||
|
|
std::string firmware_version;
|
||
|
|
std::string ansvis_version;
|
||
|
|
std::string ip_address;
|
||
|
|
std::string message;
|
||
|
|
};
|
||
|
|
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
// Callback types
|
||
|
|
// --------------------------------------------------------------------------
|
||
|
|
using CommandCallback = std::function<CommandResponse(const Command&)>;
|
||
|
|
using TelemetryCallback = std::function<void(const DeviceTelemetry&)>;
|
||
|
|
using HeartbeatCallback = std::function<void(const Heartbeat&)>;
|
||
|
|
using EventCallback = std::function<void(const DeviceEvent&)>;
|
||
|
|
using StatusCallback = std::function<void(const DeviceStatusMessage&)>;
|
||
|
|
using ConnectionCallback = std::function<void(bool connected, const std::string& info)>;
|
||
|
|
using ErrorCallback = std::function<void(int code, const std::string& message)>;
|
||
|
|
using BroadcastCallback = std::function<void(const std::string& message_json)>;
|
||
|
|
|
||
|
|
} // namespace anscloud
|
||
|
|
''')
|
||
|
|
|
||
|
|
print(" [1/15] types.h done")
|