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