const VIEW_ID = 'storageProtocolImplementation' const TITLE = '协议实现' const SOURCES = { STORAGE_ACCESS_C: '', STORAGE_ACCESS_H: '', STRUCT_H: '' } const GUIDE = { kicker: '存储访问协议', title: '协议说明与实现规划', text: '存储访问协议普通读写使用 CMD + ADDR + LEN + DATA + CRC16-CCITT-FALSE 帧格式,不带从机地址。当前先固定上位机协议模型,从机源码参考暂不提供,后续再单独规划实现细节。', points: [ { id: 'frame', text: 'CMD bit7 为故障位,bit3 为读写位,bit4/bit5 暂时保留,bit0~bit2 表示地址模式或区域。' }, { id: 'addr', text: 'bit0~bit2 为 0x7 时下发 32 位地址;0x1~0x4 对应 DATA、IDATA、XDATA、CODE 的 16 位地址;0x0、0x5、0x6 保留。' }, { id: 'info', text: 'bit0、bit1、bit2、bit3、bit6 全为 1 时为特殊指令,即 CMD=0x4F;OP=0x05 返回 CodeInfo 地址、长度、CodeInfo 读取地址宽度、目标内存字节序与最大包长。' }, { id: 'struct', text: 'CodeInfo 使用 TYPE + LEN8 + VALUE 的纯 TLV 信息块;0x20/0x21 表示 16 位地址入口,0x28/0x29 表示 32 位地址入口。' }, { id: 'source', text: '协议实现源码已暂时移除,设置页仅保留文件占位与说明,避免给出过期从机实现。' } ] } const FILES = [ { badge: '从机', details: [ '源码暂未提供。', '后续需要按新 CMD 位定义重新规划从机头文件。', '当前页面仅保留文件占位。' ], location: 'User/function/storage_access.h', name: 'storage_access.h', role: '从机协议头文件', sourceKey: 'STORAGE_ACCESS_H', summary: '源码暂时移除,等待协议实现方案确认。' }, { badge: '从机', details: [ '源码暂未提供。', '后续需要重新设计普通读写、特殊指令、异常响应和 CodeInfo 描述符读取。', '当前页面仅保留文件占位。' ], location: 'User/function/storage_access.c', name: 'storage_access.c', role: '从机协议实现', sourceKey: 'STORAGE_ACCESS_C', summary: '源码暂时移除,等待协议实现方案确认。' }, { badge: '定义', details: [ '源码暂未提供。', '后续再决定是否在此提供 struct.h 示例。', '当前页面仅保留文件占位。' ], location: 'struct.h', name: 'struct.h', role: '结构体定义参考', sourceKey: 'STRUCT_H', summary: '结构体定义参考暂时移除,等待后续实现规划。' } ] function getSourceText(file) { return String(SOURCES[file && file.sourceKey] || '') } function getLineCount(text) { if (!text) return 0 return text.split(/\r?\n/).length } function formatSourceMeta(text) { const chars = text.length const lines = getLineCount(text) return `${lines} 行 / ${chars} 字符` } function getSourceMetaText(text) { return text ? formatSourceMeta(text) : '暂未提供' } function normalizeIndex(index) { const numberValue = Number(index) if (!Number.isFinite(numberValue)) return 0 return Math.max(0, Math.min(FILES.length - 1, Math.round(numberValue))) } function getFiles(activeIndex = 0) { const normalizedIndex = normalizeIndex(activeIndex) return FILES.map((file, index) => ({ ...file, active: index === normalizedIndex, id: file.name, sourceAvailable: !!getSourceText(file), sourceMeta: getSourceMetaText(getSourceText(file)) })) } function getState(activeIndex = 0) { const normalizedIndex = normalizeIndex(activeIndex) const activeFile = FILES[normalizedIndex] const sourceText = getSourceText(activeFile) return { storageProtocolImplementationActiveFile: { ...activeFile, sourceAvailable: !!sourceText, sourceMeta: getSourceMetaText(sourceText) }, storageProtocolImplementationActiveIndex: normalizedIndex, storageProtocolImplementationFiles: getFiles(normalizedIndex), storageProtocolImplementationGuide: { ...GUIDE, points: GUIDE.points.map((point) => ({ ...point })) } } } module.exports = { TITLE, VIEW_ID, getSourceText(index = 0) { return getSourceText(FILES[normalizeIndex(index)]) }, getState }