| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- const storageAccessProtocol = require('../../protocols/storage-access/index.js')
- const settingsService = require('../../store/settings-store.js')
- const transport = require('../../transport/ble-core.js')
- const {
- createGroupsFromCodeInfo,
- parseCodeInfo
- } = require('../../domain/storage-access/code-info-parser.js')
- const {
- cloneImportedGroup,
- normalizeGroup
- } = require('../../domain/parameter-groups/model.js')
- const {
- bytesToHex
- } = require('../../utils/binary-utils.js')
- const {
- normalizeHexDwordText,
- normalizeHexText,
- normalizeHexWordText,
- parseHexBytes,
- parseHexDword,
- parseHexNumber,
- validateHexDwordText,
- validateHexText,
- validateHexWordText
- } = require('../../utils/validation.js')
- const MEMORY_COMMANDS = [
- { key: 'read', label: '读取', description: '按字节读取内存' },
- { key: 'write', label: '写入', description: '按字节写入内存' }
- ]
- const MEMORY_AREAS = [
- { key: storageAccessProtocol.AREA.ADDR32, label: 'addr32', name: 'ADDR32', addressWidth: 32 },
- { key: storageAccessProtocol.AREA.DATA, label: 'data', name: 'DATA' },
- { key: storageAccessProtocol.AREA.IDATA, label: 'idata', name: 'IDATA' },
- { key: storageAccessProtocol.AREA.XDATA, label: 'xdata', name: 'XDATA' },
- { key: storageAccessProtocol.AREA.CODE, label: 'code', name: 'CODE' }
- ]
- const MEMORY_READ_INDEX = 0
- const MEMORY_WRITE_INDEX = 1
- const CONTROL_COMMANDS = [
- { key: 'reset', label: '复位', op: storageAccessProtocol.CONTROL_OP.RESET },
- { key: 'start', label: '启动', op: storageAccessProtocol.CONTROL_OP.START },
- { key: 'stop', label: '停止', op: storageAccessProtocol.CONTROL_OP.STOP },
- { key: 'controlRef', label: '控制参考值', op: storageAccessProtocol.CONTROL_OP.SET_CONTROL_REF, hidden: true }
- ]
- let syncedDeviceCaps = {
- addressWidth: 0,
- maxPacketLength: 0,
- memoryEndian: ''
- }
- function resolveMaxPacketLength(value) {
- const settings = settingsService.getState()
- const numberValue = Number(value === undefined ? settings.parameterMaxPacketLength : value)
- const deviceMaxPacketLength = Number(syncedDeviceCaps.maxPacketLength || 0)
- const configuredMaxPacketLength = Number.isFinite(numberValue) && Math.round(numberValue) === 0
- ? 0
- : (Number.isFinite(numberValue) && numberValue > 0 ? Math.round(numberValue) : 64)
- if (!Number.isFinite(deviceMaxPacketLength) || deviceMaxPacketLength <= 0) return configuredMaxPacketLength
- if (configuredMaxPacketLength === 0) return Math.round(deviceMaxPacketLength)
- return Math.min(configuredMaxPacketLength, Math.round(deviceMaxPacketLength))
- }
- function resolveConfiguredMaxPacketLength(value) {
- const settings = settingsService.getState()
- const numberValue = Number(value === undefined ? settings.parameterMaxPacketLength : value)
- if (Number.isFinite(numberValue) && Math.round(numberValue) === 0) return 0
- if (Number.isFinite(numberValue) && numberValue > 0) return Math.round(numberValue)
- return 64
- }
- function normalizeTransferOptions(options = {}) {
- const maxPacketLength = options.maxPacketLength === undefined ? options.maxFrameBytes : options.maxPacketLength
- return {
- expectedByteLength: options.expectedByteLength,
- maxFrameBytes: options.useDeviceCaps === false
- ? resolveConfiguredMaxPacketLength(maxPacketLength)
- : resolveMaxPacketLength(maxPacketLength),
- onChunk: options.onChunk,
- showModal: options.showModal !== false
- }
- }
- function updateSyncedDeviceCaps(caps = {}) {
- const addressWidth = Number(caps.addressWidth)
- const maxPacketLength = Number(caps.maxPacketLength)
- const memoryEndian = String(caps.memoryEndian || '').trim().toLowerCase()
- syncedDeviceCaps = {
- addressWidth: addressWidth === 16 || addressWidth === 32 ? addressWidth : 0,
- maxPacketLength: Number.isFinite(maxPacketLength) && maxPacketLength > 0
- ? Math.round(maxPacketLength)
- : 0,
- memoryEndian: memoryEndian === 'little' ? 'little' : (memoryEndian === 'big' ? 'big' : '')
- }
- }
- async function readMemory(area, startAddress, byteLength, label, kind, options = {}) {
- const transferOptions = normalizeTransferOptions(options)
- const normalizedArea = storageAccessProtocol.normalizeMemoryArea(area)
- const bytes = []
- const chunks = storageAccessProtocol.getReadChunks(startAddress, byteLength, {
- ...transferOptions,
- area: normalizedArea
- })
- for (const chunk of chunks) {
- const response = await transport.sendManagedFrame(
- storageAccessProtocol.buildReadFrame(normalizedArea, chunk.address, chunk.quantity, {
- maxFrameBytes: transferOptions.maxFrameBytes
- }),
- storageAccessProtocol.getChunkLabel(label, chunks, chunk),
- storageAccessProtocol.createExpected(normalizedArea, chunk.address, chunk.quantity, false, kind),
- {
- maxFrameBytes: transferOptions.maxFrameBytes,
- showModal: transferOptions.showModal
- }
- )
- if (!response) return null
- const dataBytes = Array.isArray(response.dataBytes) ? response.dataBytes : []
- dataBytes.forEach((byte, index) => {
- bytes[chunk.address - startAddress + index] = Number(byte) & 0xFF
- })
- if (typeof transferOptions.onChunk === 'function') {
- transferOptions.onChunk(response, chunk)
- }
- }
- return bytes
- }
- async function writeMemory(area, startAddress, bytes, label, kind, options = {}) {
- const transferOptions = normalizeTransferOptions(options)
- const normalizedArea = storageAccessProtocol.normalizeMemoryArea(area)
- const chunks = storageAccessProtocol.getWriteChunks(startAddress, bytes, {
- ...transferOptions,
- area: normalizedArea
- })
- for (const chunk of chunks) {
- const response = await transport.sendManagedFrame(
- storageAccessProtocol.buildWriteFrame(normalizedArea, chunk.address, chunk.dataBytes, {
- maxFrameBytes: transferOptions.maxFrameBytes
- }),
- storageAccessProtocol.getChunkLabel(label, chunks, chunk),
- storageAccessProtocol.createExpected(normalizedArea, chunk.address, chunk.quantity, true, kind),
- {
- maxFrameBytes: transferOptions.maxFrameBytes,
- showModal: transferOptions.showModal
- }
- )
- if (!response) return false
- if (typeof transferOptions.onChunk === 'function') {
- transferOptions.onChunk(response, chunk)
- }
- }
- return true
- }
- async function readCodeInfoBlock(label, kind, options = {}) {
- const transferOptions = normalizeTransferOptions({
- ...options,
- useDeviceCaps: false
- })
- const descriptorResponse = await executeControl(
- storageAccessProtocol.CONTROL_OP.READ_CODE_INFO_DESCRIPTOR,
- [],
- label,
- `${kind}-descriptor`,
- {
- ...transferOptions,
- expectedByteLength: storageAccessProtocol.CODE_INFO_DESCRIPTOR_BYTE_LENGTH,
- useDeviceCaps: false,
- showModal: false
- }
- )
- if (!descriptorResponse) {
- if (transferOptions.showModal !== false) {
- transport.showCommandAlert(label, 'CodeInfo 描述符读取失败或超时')
- }
- return null
- }
- const codeInfoAddress = Number(descriptorResponse.codeInfoAddress || 0)
- const codeInfoByteLength = Number(descriptorResponse.codeInfoByteLength || 0)
- let codeInfoAddressWidth
- try {
- codeInfoAddressWidth = storageAccessProtocol.normalizeDescriptorAddressWidth(
- descriptorResponse.codeInfoAddressWidth
- )
- } catch (error) {
- if (transferOptions.showModal !== false) {
- transport.showCommandAlert(label, error.message || 'CodeInfo 描述符地址长度无效')
- }
- return null
- }
- const codeInfoMemoryEndian = String(descriptorResponse.codeInfoMemoryEndian || '').trim()
- if (!codeInfoMemoryEndian) {
- if (transferOptions.showModal !== false) {
- transport.showCommandAlert(label, 'CodeInfo 描述符内存字节序标记无效')
- }
- return null
- }
- const codeInfoMaxPacketLength = Number(descriptorResponse.codeInfoMaxPacketLength || 0) & 0xFFFF
- const codeInfoArea = codeInfoAddressWidth === 32 ? storageAccessProtocol.AREA.ADDR32 : storageAccessProtocol.AREA.CODE
- const codeInfoReadAddress = codeInfoAddressWidth === 32 ? codeInfoAddress : (codeInfoAddress & 0xFFFF)
- const codeInfoMaxFrameBytes = storageAccessProtocol.resolveDescriptorMaxFrameBytes(
- transferOptions.maxFrameBytes,
- codeInfoMaxPacketLength
- )
- if (!codeInfoByteLength || codeInfoByteLength > 0xFFFF) {
- if (transferOptions.showModal !== false) {
- transport.showCommandAlert(label, 'CodeInfo 信息块长度无效')
- }
- return null
- }
- const codeInfoBytes = await readMemory(
- codeInfoArea,
- codeInfoReadAddress,
- codeInfoByteLength,
- label,
- kind,
- {
- ...transferOptions,
- maxFrameBytes: codeInfoMaxFrameBytes,
- useDeviceCaps: false
- }
- )
- if (!codeInfoBytes) return null
- return {
- codeInfoAddress,
- codeInfoAddressWidth,
- codeInfoByteLength,
- codeInfoBytes,
- codeInfoDescriptorBytes: Array.isArray(descriptorResponse.codeInfoDescriptorBytes)
- ? descriptorResponse.codeInfoDescriptorBytes
- : [],
- codeInfoMaxPacketLength,
- codeInfoMemoryEndian,
- codeInfoMemoryEndianMark: Number(descriptorResponse.codeInfoMemoryEndianMark || 0) & 0xFFFF,
- codeInfoMemoryType: codeInfoArea
- }
- }
- async function executeControl(operation, dataBytes, label, kind, options = {}) {
- const transferOptions = normalizeTransferOptions(options)
- const response = await transport.sendManagedFrame(
- storageAccessProtocol.buildControlFrame(operation, dataBytes),
- label,
- storageAccessProtocol.createControlExpected(operation, kind, {
- expectedByteLength: transferOptions.expectedByteLength
- }),
- {
- maxFrameBytes: transferOptions.maxFrameBytes,
- showModal: transferOptions.showModal
- }
- )
- return response || null
- }
- function formatDwordHex(value) {
- const numberValue = Math.max(0, Math.floor(Number(value) || 0))
- return numberValue.toString(16).toUpperCase().padStart(8, '0')
- }
- function getAreaAddressWidth(area) {
- return Number(area && area.addressWidth) === 32 || Number(area && area.key) === storageAccessProtocol.AREA.ADDR32
- ? 32
- : 16
- }
- function getMemoryAreaOptions() {
- return MEMORY_AREAS.map((area) => ({ ...area }))
- }
- function resolveMemoryCommand(index) {
- const commandIndex = Number(index) === 2 ? MEMORY_WRITE_INDEX : Number(index)
- return {
- command: MEMORY_COMMANDS[commandIndex] || MEMORY_COMMANDS[MEMORY_READ_INDEX],
- index: commandIndex === MEMORY_WRITE_INDEX ? MEMORY_WRITE_INDEX : MEMORY_READ_INDEX
- }
- }
- function resolveMemoryArea(index, commandKey = 'read') {
- const memoryAreas = getMemoryAreaOptions()
- let areaIndex = Number(index) || 0
- if (commandKey === 'write' && memoryAreas[areaIndex] && memoryAreas[areaIndex].key === storageAccessProtocol.AREA.CODE) {
- areaIndex = 0
- }
- if (!memoryAreas[areaIndex]) areaIndex = 0
- return {
- area: memoryAreas[areaIndex] || memoryAreas[0],
- index: areaIndex,
- options: memoryAreas
- }
- }
- function normalizeDisplayHexText(value, addressWidth = 16) {
- const text = addressWidth === 32
- ? normalizeHexDwordText(value)
- : normalizeHexWordText(value)
- return text.toUpperCase()
- }
- function buildMemoryPreview(commandKey, area, address, length, dataBytes) {
- try {
- const frameOptions = {
- maxFrameBytes: 0
- }
- if (commandKey === 'write') {
- return bytesToHex(storageAccessProtocol.buildWriteFrame(area, address, dataBytes, frameOptions), ' ')
- }
- return bytesToHex(storageAccessProtocol.buildReadFrame(area, address, length, frameOptions), ' ')
- } catch (error) {
- return ''
- }
- }
- function normalizeMemoryCommandState(current = {}, changed = {}) {
- const next = {
- storageAccessAreaIndex: current.storageAccessAreaIndex || 0,
- storageAccessAddress: current.storageAccessAddress || '',
- storageAccessCommandIndex: current.storageAccessCommandIndex || 0,
- storageAccessDataText: current.storageAccessDataText || '',
- storageAccessLength: current.storageAccessLength || '',
- ...changed
- }
- const resolvedCommand = resolveMemoryCommand(next.storageAccessCommandIndex)
- const commandIndex = resolvedCommand.index
- const command = resolvedCommand.command
- const resolvedArea = resolveMemoryArea(next.storageAccessAreaIndex, command.key)
- const areaIndex = resolvedArea.index
- const area = resolvedArea.area
- const addressWidth = getAreaAddressWidth(area)
- const addressText = normalizeDisplayHexText(next.storageAccessAddress, addressWidth)
- const lengthText = normalizeDisplayHexText(next.storageAccessLength, 16)
- const dataText = normalizeHexText(next.storageAccessDataText)
- const dataBytes = dataText ? parseHexBytes(dataText) : []
- const address = parseInt(addressText || '0', 16)
- const byteLength = parseInt(lengthText || '0', 16)
- const hasAddressText = !!addressText.trim()
- const hasLengthText = !!lengthText.trim()
- let errorText = ''
- const addressError = hasAddressText
- ? (addressWidth === 32
- ? validateHexDwordText(addressText, '地址')
- : validateHexWordText(addressText, '地址'))
- : ''
- const lengthError = hasLengthText ? validateHexWordText(lengthText, '长度') : ''
- if (addressError) {
- errorText = addressError
- } else if (lengthError) {
- errorText = lengthError
- } else if (hasLengthText && byteLength <= 0) {
- errorText = '长度必须大于 0'
- } else if (command.key === 'write') {
- const hexError = validateHexText(next.storageAccessDataText)
- if (hexError) {
- errorText = hexError
- } else if (area.key === storageAccessProtocol.AREA.CODE) {
- errorText = 'code 区暂不支持写入'
- } else if (dataBytes.length !== byteLength) {
- errorText = `写入长度为 ${byteLength} 字节,当前数据为 ${dataBytes.length} 字节`
- }
- }
- const canPreview = !errorText && hasAddressText && hasLengthText && byteLength > 0
- const previewHex = canPreview
- ? buildMemoryPreview(command.key, area.key, address, byteLength, dataBytes)
- : ''
- return {
- storageAccessAddress: addressText,
- storageAccessAddressMaxLength: addressWidth === 32 ? 8 : 4,
- storageAccessAddressWidthText: `${addressWidth}bit`,
- storageAccessAreaLocked: false,
- storageAccessAreaOptions: resolvedArea.options,
- storageAccessAreaIndex: areaIndex,
- storageAccessAreaLabel: area.label,
- storageAccessCommandIndex: commandIndex,
- storageAccessCommandLabel: command.label,
- storageAccessDataText: dataText,
- storageAccessErrorText: errorText,
- storageAccessLength: lengthText,
- storageAccessPreviewHexText: previewHex,
- storageAccessPreviewText: canPreview
- ? `${area.label} 0x${addressWidth === 32 ? formatDwordHex(address) : address.toString(16).toUpperCase().padStart(4, '0')} / ${byteLength} bytes`
- : '',
- storageAccessShowWriteData: command.key === 'write',
- storageAccessTitleText: `${command.label}命令`
- }
- }
- function getSyncedDeviceCaps() {
- return {
- ...syncedDeviceCaps
- }
- }
- function parseMemoryCommandInput(data = {}) {
- const state = normalizeMemoryCommandState(data)
- const command = resolveMemoryCommand(state.storageAccessCommandIndex).command
- const area = resolveMemoryArea(state.storageAccessAreaIndex, command.key).area
- const addressWidth = getAreaAddressWidth(area)
- if (state.storageAccessErrorText) {
- throw new Error(state.storageAccessErrorText)
- }
- if (!String(state.storageAccessAddress || '').trim()) {
- throw new Error('地址请输入十六进制')
- }
- if (!String(state.storageAccessLength || '').trim()) {
- throw new Error('长度请输入十六进制')
- }
- return {
- area,
- areaValue: area.key,
- byteLength: parseHexNumber(state.storageAccessLength, '长度', 0xFFFF),
- command,
- commandKey: command.key,
- dataBytes: command.key === 'write' ? parseHexBytes(state.storageAccessDataText || '') : [],
- startAddress: addressWidth === 32
- ? parseHexDword(state.storageAccessAddress, '地址')
- : parseHexNumber(state.storageAccessAddress, '地址', 0xFFFF),
- state
- }
- }
- async function executeMemoryCommand(data = {}, options = {}) {
- const command = parseMemoryCommandInput(data)
- if (command.commandKey === 'read') {
- const bytes = await readMemory(
- command.areaValue,
- command.startAddress,
- command.byteLength,
- options.label || '存储访问协议读取',
- options.kind || 'communication-storage-read',
- options
- )
- return {
- bytes,
- command,
- ok: !!bytes,
- previewHex: bytes ? bytesToHex(bytes, ' ') : '',
- state: command.state
- }
- }
- const ok = await writeMemory(
- command.areaValue,
- command.startAddress,
- command.dataBytes,
- options.label || '存储访问协议写入',
- options.kind || 'communication-storage-write',
- options
- )
- return {
- command,
- ok,
- state: command.state
- }
- }
- function normalizeReferenceText(value, fallback = '0') {
- const source = String(value === undefined || value === null ? '' : value).trim()
- if (!source) return fallback
- const hexText = source.replace(/^0x/i, '')
- if (/^[0-9A-F]{1,4}$/i.test(hexText) && /[A-F]/i.test(hexText)) {
- const rawValue = parseInt(hexText, 16) || 0
- return String(rawValue & 0x8000 ? rawValue - 0x10000 : rawValue)
- }
- if (/^-?\d+$/.test(source)) {
- return String(Number(source))
- }
- return source
- }
- function normalizeControlReference(value) {
- const text = String(value === undefined || value === null ? '' : value).trim()
- if (!text) {
- return {
- bytes: [],
- errorText: '控制参考值请输入十进制',
- text,
- value: 0
- }
- }
- if (!/^-?\d+$/.test(text)) {
- return {
- bytes: [],
- errorText: '控制参考值只支持十进制',
- text,
- value: 0
- }
- }
- const valueNumber = Number(text)
- if (valueNumber < -0x8000 || valueNumber > 0x7FFF) {
- return {
- bytes: [],
- errorText: '控制参考值范围为 -32768 - 32767',
- text,
- value: 0
- }
- }
- const wordValue = valueNumber & 0xFFFF
- return {
- bytes: [
- (wordValue >>> 8) & 0xFF,
- wordValue & 0xFF
- ],
- errorText: '',
- text,
- value: valueNumber
- }
- }
- function getControlCommand(commandKey) {
- return CONTROL_COMMANDS.find((command) => command.key === commandKey) || null
- }
- function normalizeControlState(current = {}, changed = {}) {
- const next = {
- storageAccessControlRefText: current.storageAccessControlRefText || '0',
- ...changed
- }
- const controlRefText = normalizeReferenceText(next.storageAccessControlRefText, '0')
- const controlRef = normalizeControlReference(controlRefText)
- return {
- storageAccessControlRefErrorText: controlRef.errorText,
- storageAccessControlRefPreviewHexText: controlRef.errorText
- ? ''
- : bytesToHex(storageAccessProtocol.buildControlReferenceFrame(controlRef.value), ' '),
- storageAccessControlRefText: controlRefText
- }
- }
- function getControlCommands() {
- return CONTROL_COMMANDS.map((command) => ({
- ...command,
- previewHexText: command.key === 'controlRef'
- ? ''
- : bytesToHex(storageAccessProtocol.buildControlFrame(command.op), ' ')
- }))
- }
- async function syncCodeInfo(options = {}) {
- const result = await readCodeInfoBlock(
- options.label || '同步CodeInfo',
- options.kind || 'storage-code-info-read',
- {
- maxPacketLength: options.maxPacketLength,
- showModal: options.showModal !== false
- }
- )
- if (!result) {
- return {
- ok: false
- }
- }
- const descriptorCaps = {
- addressWidth: result.codeInfoAddressWidth,
- codeInfoByteLength: result.codeInfoByteLength,
- maxPacketLength: result.codeInfoMaxPacketLength,
- memoryEndian: result.codeInfoMemoryEndian,
- memoryEndianMark: result.codeInfoMemoryEndianMark
- }
- const codeInfo = parseCodeInfo(result.codeInfoBytes, descriptorCaps)
- const importedGroups = createGroupsFromCodeInfo(codeInfo, options)
- .map(cloneImportedGroup)
- .map(normalizeGroup)
- updateSyncedDeviceCaps(descriptorCaps)
- return {
- codeInfoAddress: result.codeInfoAddress,
- codeInfoAddressWidth: result.codeInfoAddressWidth,
- codeInfoAddressText: formatDwordHex(result.codeInfoAddress),
- codeInfoByteLength: result.codeInfoByteLength,
- codeInfoByteLengthText: formatDwordHex(result.codeInfoByteLength),
- codeInfoBytes: result.codeInfoBytes,
- codeInfo,
- codeInfoDescriptorBytes: result.codeInfoDescriptorBytes,
- codeInfoMaxPacketLength: result.codeInfoMaxPacketLength,
- codeInfoMemoryEndian: result.codeInfoMemoryEndian,
- codeInfoMemoryEndianMark: result.codeInfoMemoryEndianMark,
- groupCount: importedGroups.length,
- importedGroups,
- codeInfoMemoryType: result.codeInfoMemoryType,
- ok: true,
- structCount: codeInfo.structCount
- }
- }
- async function executeControlCommand(commandKey, data = {}, options = {}) {
- const command = getControlCommand(commandKey)
- if (!command) {
- return {
- errorText: '特殊指令无效',
- ok: false
- }
- }
- const controlState = normalizeControlState(data)
- if (command.key === 'controlRef' && controlState.storageAccessControlRefErrorText) {
- return {
- errorText: controlState.storageAccessControlRefErrorText,
- ok: false
- }
- }
- const response = await executeControl(
- command.op,
- command.key === 'controlRef'
- ? normalizeControlReference(controlState.storageAccessControlRefText).bytes
- : [],
- command.label || '特殊指令',
- `storage-control-${command.key}`,
- {
- maxPacketLength: options.maxPacketLength,
- showModal: options.showModal !== false
- }
- )
- if (!response) {
- return {
- errorText: '指令执行失败或超时',
- ok: false
- }
- }
- if (response.controlStatus !== 0) {
- return {
- errorText: response.controlStatusText || '设备拒绝执行',
- ok: false,
- response
- }
- }
- return {
- command,
- ok: true,
- response
- }
- }
- module.exports = {
- AREA: storageAccessProtocol.AREA,
- CONTROL_OP: storageAccessProtocol.CONTROL_OP,
- executeMemoryCommand,
- executeControl,
- executeControlCommand,
- formatDwordHex,
- getControlCommand,
- getControlCommands,
- getMemoryAreaOptions,
- getSyncedDeviceCaps,
- normalizeMemoryCommandState,
- normalizeControlState,
- readCodeInfoBlock,
- readMemory,
- resolveMaxPacketLength,
- syncCodeInfo,
- updateSyncedDeviceCaps,
- writeMemory
- }
|