You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.4 KiB
JavaScript

5 months ago
// Constants
const AN_DEVICE_DFU_DATA = "00006387-3C17-D293-8E48-14FE2E4DA212"; // 在接受响应上写
const AN_DEVICE_FIRMWARE_UPDATE_CHAR = "00006487-3C17-D293-8E48-14FE2E4DA212"; // 接受控制指令的通道 写/通知
// DFU Opcode
const OPCODE_DFU_START_DFU = 0x01;
const OPCODE_DFU_RECEIVE_FW_IMAGE = 0x02;
const OPCODE_DFU_VALIDATE_FW_IMAGE = 0x03;
const OPCODE_DFU_ACTIVE_IMAGE_RESET = 0x04;
const OPCODE_DFU_RESET_SYSTEM = 0x05;
const OPCODE_DFU_REPORT_RECEIVED_IMAGE_INFO = 0x06;
const OPCODE_DFU_PACKET_RECEIPT_NOTIFICATION_REQUEST = 0x07;
const OPCODE_DFU_RESPONSE_CODE = 0x10;
const OPCODE_DFU_PACKET_RECEIPT_NOTIFICATION = 0x11;
// Error Codes
const ERROR_STATE_SUCCESS = 0x01;
const ERROR_STATE_OPCODE_NOT_SUPPORTED = 0x02;
const ERROR_STATE_INVALID_PARA = 0x03;
const ERROR_STATE_OPERATION_FAILED = 0x04;
const ERROR_STATE_DATA_SIZE_EXCEEDS = 0x05;
const ERROR_STATE_CRC_ERROR = 0x06;
// Structures and data definitions
function DEF_RESPONSE_HEADER(opcode, reqOpcode, rspValue) {
this.Opcode = opcode;
this.ReqOpcode = reqOpcode;
this.RspValue = rspValue;
}
function DFU_START_DFU(opcode, offset, signature, version, checksum, length, otaFlag, reserved8, reservedForAes) {
this.Opcode = opcode;
this.Offset = offset;
this.Signature = signature;
this.Version = version;
this.Checksum = checksum;
this.Length = length;
this.OtaFlag = otaFlag;
this.Reserved8 = reserved8;
this.ReservedForAes = reservedForAes;
}
function DFU_START_DFU_RESPONSE(opcode, reqOpcode, rspValue) {
this.Opcode = opcode;
this.ReqOpcode = reqOpcode;
this.RspValue = rspValue;
}
function RECEIVE_FW_IMAGE(opcode, nSignature, nImageUpdateOffset) {
this.Opcode = opcode;
this.NSignature = nSignature;
this.NImageUpdateOffset = nImageUpdateOffset;
}
function RECEIVE_FW_IMAGE_RESPONSE(opcode, reqOpcode, rspValue) {
this.Opcode = opcode;
this.ReqOpcode = reqOpcode;
this.RspValue = rspValue;
}
function VALIDATE_FW_IMAGE(opcode, nSignature) {
this.Opcode = opcode;
this.NSignature = nSignature;
}
function VALIDATE_FW_IMAGE_RESPONSE(opcode, reqOpcode, rspValue) {
this.Opcode = opcode;
this.ReqOpcode = reqOpcode;
this.RspValue = rspValue;
}
function ACTIVE_IMAGE_RESET(opcode) {
this.Opcode = opcode;
}
function RESET_SYSTEM(opcode) {
this.Opcode = opcode;
}
function REPORT_RECEIVED_IMAGE_INFO(opcode, nSignature) {
this.Opcode = opcode;
this.NSignature = nSignature;
}
function REPORT_RECEIVED_IMAGE_INFO_RESPONSE(opcode, reqOpcode, rspValue, originalFWVersion, nImageUpdateOffset) {
this.Opcode = opcode;
this.ReqOpcode = reqOpcode;
this.RspValue = rspValue;
this.OriginalFWVersion = originalFWVersion;
this.NImageUpdateOffset = nImageUpdateOffset;
}
function DFU_FW_IMAGE_INFO(FWImageSize, FWVersion, OriginalVersion, ImageUpdateOffset) {
this.FWImageSize = FWImageSize;
this.FWVersion = FWVersion;
this.OriginalVersion = OriginalVersion;
this.ImageUpdateOffset = ImageUpdateOffset;
}
function DFU_DATA_INFO(flag, curInfo, imgInfo) {
this.Flag = flag;
this.CurInfo = curInfo;
this.ImgInfo = imgInfo;
}
function IMAGE_HEADER(offset, signature, version, checksum, length, otaFlag, reserved8) {
this.Offset = offset;
this.Signature = signature;
this.Version = version;
this.Checksum = checksum;
this.Length = length;
this.OtaFlag = otaFlag;
this.Reserved8 = reserved8;
}