using Newtonsoft.Json; using System.Collections.Generic; namespace XiaoZhiSharp.Models { /// /// OTA(Over The Air:空中下载)更新请求数据模型 /// 用于客户端向服务器请求固件更新时传递设备信息 /// public class OtaRequest { /// /// 应用程序信息 /// 包含应用名称、版本等详细信息 /// [JsonProperty("application")] public ApplicationInfo Application { get; set; } = new ApplicationInfo(); /// /// 设备的MAC地址(可选) /// 用于设备身份识别和网络标识 /// [JsonProperty("mac_address", NullValueHandling = NullValueHandling.Include)] public string? MacAddress { get; set; } /// /// 设备唯一标识符(可选) /// 用于唯一识别设备实例 /// [JsonProperty("uuid", NullValueHandling = NullValueHandling.Include)] public string? Uuid { get; set; } /// /// 芯片型号名称(可选) /// 如:ESP32, ESP8266等 /// [JsonProperty("chip_model_name", NullValueHandling = NullValueHandling.Include)] public string? ChipModelName { get; set; } /// /// 闪存大小(字节,可选) /// 设备的存储容量信息 /// [JsonProperty("flash_size", NullValueHandling = NullValueHandling.Include)] public long? FlashSize { get; set; } /// /// PSRAM大小(字节,可选) /// 外部伪静态随机存储器的容量 /// [JsonProperty("psram_size", NullValueHandling = NullValueHandling.Include)] public long? PsramSize { get; set; } /// /// 分区表信息(可选) /// 描述设备存储分区的结构和布局 /// [JsonProperty("partition_table", NullValueHandling = NullValueHandling.Include)] public List? PartitionTable { get; set; } /// /// 开发板信息 /// 包含板卡型号、制造商等信息 /// [JsonProperty("board")] public BoardInfo Board { get; set; } = new BoardInfo(); /// /// 协议版本号(可选) /// 用于API版本控制和兼容性处理 /// [JsonProperty("version", NullValueHandling = NullValueHandling.Include)] public int? Version { get; set; } /// /// 语言偏好设置(可选) /// 如:zh-CN, en-US等 /// [JsonProperty("language", NullValueHandling = NullValueHandling.Include)] public string? Language { get; set; } /// /// 最小空闲堆大小(字节,可选) /// 设备运行所需的最小内存空间要求 /// [JsonProperty("minimum_free_heap_size", NullValueHandling = NullValueHandling.Include)] public long? MinimumFreeHeapSize { get; set; } /// /// OTA特定信息(可选) /// 包含更新类型、进度等OTA相关数据 /// [JsonProperty("ota", NullValueHandling = NullValueHandling.Include)] public OtaInfo? Ota { get; set; } } /// /// 应用程序信息类 /// 用于存储和序列化应用程序的基本元数据信息 /// public class ApplicationInfo { /// /// 应用程序名称 /// 使用 JsonProperty 特性指定 JSON 序列化时的字段名为 "name" /// NullValueHandling.Include 表示当值为 null 时在序列化中忽略此字段 /// [JsonProperty("name", NullValueHandling = NullValueHandling.Include)] public string? Name { get; set; } = "xiaozhi"; /// /// 应用程序版本号 /// [JsonProperty("version")] public string Version { get; set; } = "1.0.0"; /// /// ELF 文件的 SHA256 哈希值 /// [JsonProperty("elf_sha256")] public string ElfSha256 { get; set; } = ""; /// /// 应用程序编译时间 /// [JsonProperty("compile_time", NullValueHandling = NullValueHandling.Include)] public string? CompileTime { get; set; } /// /// ESP-IDF 开发环境框架版本号 /// 适用于 ESP32 等嵌入式开发 /// [JsonProperty("idf_version", NullValueHandling = NullValueHandling.Include)] public string? IdfVersion { get; set; } } /// /// 分区信息类 /// 用于表示存储设备中的分区元数据信息 /// public class PartitionInfo { /// /// 分区标签或名称 /// 例如: "EFI System Partition", "Basic data partition" /// [JsonProperty("label")] public string Label { get; set; } = ""; /// /// 分区类型标识符 /// 表示分区的总体类型(如:EFI、主分区、扩展分区等) /// [JsonProperty("type")] public int Type { get; set; } /// /// 分区子类型标识符 /// 提供更详细的分区分类信息 /// [JsonProperty("subtype")] public int Subtype { get; set; } /// /// 分区起始地址(偏移量) /// 表示分区在存储设备上的起始位置,通常以字节为单位 /// [JsonProperty("address")] public long Address { get; set; } /// /// 分区大小 /// 表示分区占用的总空间大小,通常以字节为单位 /// [JsonProperty("size")] public long Size { get; set; } } /// /// 开发板信息 /// /// /// 设备板卡信息数据模型类 /// 用于存储和序列化设备的硬件和网络连接信息 /// public class BoardInfo { /// /// 设备类型标识 /// [JsonProperty("type")] public string Type { get; set; } = ""; /// /// 设备名称 /// [JsonProperty("name")] public string Name { get; set; } = ""; /// /// 操作系统名称 /// [JsonProperty("os")] public string OS { get; set; } = ""; /// /// WiFi网络SSID(Service Set Identifier)名称,可为空 /// [JsonProperty("ssid", NullValueHandling = NullValueHandling.Include)] public string? Ssid { get; set; } /// /// WiFi信号强度指示(RSSI(Received Signal Strength Indicator)值,可为空) /// 值越小表示信号越弱,通常为负值(如:-50) /// [JsonProperty("rssi", NullValueHandling = NullValueHandling.Include)] public int? Rssi { get; set; } /// /// WiFi频道(信道)(可为空) /// [JsonProperty("channel", NullValueHandling = NullValueHandling.Include)] public int? Channel { get; set; } /// /// IP地址(可为空) /// [JsonProperty("ip", NullValueHandling = NullValueHandling.Include)] public string? Ip { get; set; } /// /// MAC地址(可为空) /// [JsonProperty("mac", NullValueHandling = NullValueHandling.Include)] public string? Mac { get; set; } /// /// 硬件版本号或修订版本(可为空) /// [JsonProperty("revision", NullValueHandling = NullValueHandling.Include)] public string? Revision { get; set; } /// /// 移动网络运营商信息(可为空) /// [JsonProperty("carrier", NullValueHandling = NullValueHandling.Include)] public string? Carrier { get; set; } /// /// 信号质量指标(CSQ,可为空) /// 通常用于移动网络信号质量测量 /// [JsonProperty("csq", NullValueHandling = NullValueHandling.Include)] public string? Csq { get; set; } /// /// 国际移动设备识别码(IMEI,可为空) /// 移动设备的唯一标识符 /// [JsonProperty("imei", NullValueHandling = NullValueHandling.Include)] public string? Imei { get; set; } /// /// 集成电路卡识别码(ICCID,可为空) /// SIM卡的唯一标识符 /// [JsonProperty("iccid", NullValueHandling = NullValueHandling.Include)] public string? Iccid { get; set; } public BoardInfo() { OS = Global.OS; Ip = Global.LocalIP; } } /// /// OTA 信息实体类 /// 用于表示和传输 OTA (Over-The-Air) 相关的信息数据 /// public class OtaInfo { /// /// 标签文本 /// 用于显示或标识 OTA 信息的描述性文字 /// [JsonProperty("label")] // JSON 序列化特性,指定该属性在 JSON 中的键名为 "label" public string Label { get; set; } = ""; // 字符串属性,初始化为空字符串以避免 null 值 } /// /// OTA(Over The Air:空中下载)响应数据模型类 /// 用于反序列化从OTA服务器返回的JSON响应 /// public class OtaResponse { /// /// 设备激活相关信息 /// 包含设备激活状态、凭证等信息 /// [JsonProperty("activation", NullValueHandling = NullValueHandling.Include)] public ActivationInfo? Activation { get; set; } /// /// MQTT协议配置信息 /// 包含MQTT服务器地址、端口、认证信息等连接参数 /// [JsonProperty("mqtt", NullValueHandling = NullValueHandling.Include)] public MqttInfo? Mqtt { get; set; } /// /// WebSocket协议配置信息 /// 包含WebSocket服务器地址、连接参数等 /// [JsonProperty("websocket", NullValueHandling = NullValueHandling.Include)] public WebSocketInfo? WebSocket { get; set; } /// /// 服务器时间信息 /// 用于设备时间同步,可能包含时间戳、时区等信息 /// [JsonProperty("server_time", NullValueHandling = NullValueHandling.Include)] public ServerTimeInfo? ServerTime { get; set; } /// /// 固件更新信息 /// 包含固件版本、下载地址、校验和、更新说明等 /// [JsonProperty("firmware", NullValueHandling = NullValueHandling.Include)] public FirmwareInfo? Firmware { get; set; } } /// /// 激活信息实体类 /// 用于表示系统激活操作的结果或状态信息 /// public class ActivationInfo { /// /// 激活码或状态代码 /// 通常用于表示激活操作的结果代码(如成功、失败等状态码) /// 或包含具体的激活凭证代码 /// [JsonProperty("code")] // JSON 序列化属性,指定在 JSON 中对应的字段名为 "code" public string Code { get; set; } = ""; // 默认值空字符串,避免 null 值 /// /// 激活结果消息或描述信息 /// 提供激活操作的详细信息,如成功提示、错误原因说明等 /// [JsonProperty("message")] // JSON 序列化属性,指定在 JSON 中对应的字段名为 "message" public string Message { get; set; } = ""; // 默认值空字符串,避免 null 值 } /// /// MQTT 连接配置信息类 /// 用于存储和序列化/反序列化 MQTT 客户端连接所需的配置参数 /// public class MqttInfo { /// /// MQTT 服务器端点地址 /// 格式通常为:mqtt://hostname:port 或 tcp://hostname:port /// [JsonProperty("endpoint")] public string Endpoint { get; set; } = ""; /// /// MQTT 客户端标识符 /// 用于在 MQTT 代理中唯一标识客户端实例 /// 如果为空,某些 MQTT 库会自动生成唯一 ID /// [JsonProperty("client_id")] public string ClientId { get; set; } = ""; /// /// MQTT 连接用户名 /// 用于服务器身份验证(如果服务器要求认证) /// [JsonProperty("username")] public string Username { get; set; } = ""; /// /// MQTT 连接密码 /// 用于服务器身份验证(如果服务器要求认证) /// 注意:MQTT 协议中密码以明文传输,建议使用 TLS 加密 /// [JsonProperty("password")] public string Password { get; set; } = ""; /// /// 默认发布主题 /// 指定客户端发布消息时使用的默认主题名称 /// 主题格式应符合 MQTT 主题命名规范 /// [JsonProperty("publish_topic")] public string PublishTopic { get; set; } = ""; } /// /// WebSocket连接配置信息类 /// 用于存储WebSocket连接的URL和认证令牌信息 /// public class WebSocketInfo { /// /// WebSocket服务器的URL地址 /// 使用JsonProperty特性指定JSON序列化时的字段名称为"url" /// [JsonProperty("url")] public string Url { get; set; } = ""; /// /// 身份验证令牌(Token) /// 用于WebSocket连接时的认证和授权 /// 使用JsonProperty特性指定JSON序列化时的字段名称为"token" /// [JsonProperty("token")] public string Token { get; set; } = ""; } /// /// 服务器时间信息类 /// 用于反序列化包含时间戳、时区和时区偏移量的JSON响应 /// 通常用于API接口返回的时间相关信息 /// public class ServerTimeInfo { /// /// 时间戳(Unix时间戳格式) /// 通常表示自1970年1月1日00:00:00 UTC以来的秒数或毫秒数 /// 具体取决于API的实现方式 /// [JsonProperty("timestamp")] public long Timestamp { get; set; } /// /// 时区名称 /// 例如:"Asia/Shanghai"、"America/New_York"等 /// 使用IANA时区数据库格式 /// [JsonProperty("timezone")] public string Timezone { get; set; } = ""; /// /// 时区偏移量(以秒为单位) /// 表示相对于UTC时间的偏移量 /// 例如:东八区(UTC+8)的偏移量为28800秒(8*3600) /// [JsonProperty("timezone_offset")] public int TimezoneOffset { get; set; } } /// /// 固件信息 /// public class FirmwareInfo { /// /// 版本号 /// [JsonProperty("version")] public string Version { get; set; } = ""; /// /// 固件下载地址 /// [JsonProperty("url")] public string Url { get; set; } = ""; } /// /// OTA错误响应 /// public class OtaErrorResponse { /// /// 错误信息 /// [JsonProperty("error")] public string Error { get; set; } = ""; } /// /// 蓝牙信息 /// public class BluetoothInfo { } }