56 lines
2.2 KiB
TypeScript
56 lines
2.2 KiB
TypeScript
import {z} from 'zod'
|
||
|
||
export const DeviceInfoZod = z.object({
|
||
allspace: z.bigint(),
|
||
freespace: z.bigint(),
|
||
name: z.string().max(128, "Device Name too long"),
|
||
size: z.string().describe("设备分辨率, 以x作为分隔符, 宽x高, 例如 360x360"),
|
||
brand: z.string().max(128, "Brand name too long"),
|
||
powerlevel: z.number().min(0, "Power level could not be less then 0").max(100, "Power level could not be more then 100"),
|
||
})
|
||
|
||
export type DeviceInfo = z.infer<typeof DeviceInfoZod>
|
||
|
||
export const ProtocolFrameZod = z.object({
|
||
head: z.number().describe("固定表示传输方向 APP -> BLE = 0xb1, BLE -> APP = 0xb0"),
|
||
type: z.number().describe("表示传输数据对应哪个Event, 与EVENT_TYPES.xxx.code对应"),
|
||
subpageTotal: z.number().describe("代表总的分包大小"),
|
||
curPage: z.number().describe("代表当前分包序号"),
|
||
dataLen: z.number().describe("代表当前数据包字节长度 bytes"),
|
||
data: z.instanceof(ArrayBuffer).describe("数据包内实际二进制字节内容"),
|
||
checksum: z.number().describe("数据包校验字节, 整个数据包中除该字节以外的所有字节数据的单字节和 = (0 - 该字节)"),
|
||
})
|
||
|
||
export type ProtocolFrame = z.infer<typeof ProtocolFrameZod>
|
||
|
||
export const BondingResponseZod = z.object({
|
||
sn: z.string().length(14).describe("设备sn码, 第1位A量产,D售后,E试产,F测试环境,后六位000000-999999,234568位不变,第7位可能根据配置不同变化"),
|
||
success: z.number().describe("绑定成功 = 1, 失败 = 0"),
|
||
})
|
||
|
||
export type BindingResponse = z.infer<typeof BondingResponseZod>
|
||
|
||
export const UnBindResponseZod = z.object({
|
||
success: z.number().describe("解绑成功 = 1, 失败 = 0"),
|
||
})
|
||
|
||
export type UnBindResponse = z.infer<typeof UnBindResponseZod>
|
||
|
||
export const VersionInfoZod = z.object({
|
||
version: z.string().max(128, "Version string too long").describe("设备版本号"),
|
||
})
|
||
|
||
export type VersionInfo = z.infer<typeof VersionInfoZod>
|
||
|
||
export const FileTransferDataZod = z.object({
|
||
data: z.instanceof(ArrayBuffer),
|
||
})
|
||
|
||
export type FileTransferData = z.infer<typeof FileTransferDataZod>
|
||
|
||
export const BindingRequestZod = z.object({
|
||
userId: z.string().length(32).describe('32位长度的user Id'),
|
||
})
|
||
|
||
export type BindingRequest = z.infer<typeof BindingRequestZod>
|