@zwave-js/nvmedit 15.15.3 → 15.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/convert.d.ts +6 -5
- package/build/cjs/convert.js.map +2 -2
- package/build/cjs/lib/NVM3.d.ts +6 -5
- package/build/cjs/lib/NVM3.js.map +2 -2
- package/build/cjs/lib/NVM500.js.map +2 -2
- package/build/cjs/lib/common/definitions.d.ts +5 -5
- package/build/cjs/lib/common/definitions.js.map +1 -1
- package/build/cjs/lib/common/routeCache.d.ts +2 -2
- package/build/cjs/lib/common/routeCache.js.map +2 -2
- package/build/cjs/lib/common/sucUpdateEntry.d.ts +2 -2
- package/build/cjs/lib/common/sucUpdateEntry.js.map +2 -2
- package/build/cjs/lib/common/utils.d.ts +3 -2
- package/build/cjs/lib/common/utils.js.map +2 -2
- package/build/cjs/lib/io/BufferedNVMReader.d.ts +3 -2
- package/build/cjs/lib/io/BufferedNVMReader.js.map +2 -2
- package/build/cjs/lib/io/NVMFileIO.d.ts +3 -2
- package/build/cjs/lib/io/NVMFileIO.js.map +2 -2
- package/build/cjs/lib/io/NVMMemoryIO.d.ts +4 -3
- package/build/cjs/lib/io/NVMMemoryIO.js.map +2 -2
- package/build/cjs/lib/nvm3/adapter.js.map +2 -2
- package/build/cjs/lib/nvm3/files/ControllerInfoFile.d.ts +3 -3
- package/build/cjs/lib/nvm3/files/ControllerInfoFile.js.map +2 -2
- package/build/cjs/lib/nvm3/files/NVMFile.d.ts +2 -2
- package/build/cjs/lib/nvm3/files/NVMFile.js.map +2 -2
- package/build/cjs/lib/nvm3/files/NodeInfoFiles.js.map +2 -2
- package/build/cjs/lib/nvm3/object.d.ts +3 -2
- package/build/cjs/lib/nvm3/object.js.map +2 -2
- package/build/cjs/lib/nvm3/page.d.ts +2 -1
- package/build/cjs/lib/nvm3/page.js.map +2 -2
- package/build/cjs/lib/nvm500/EntryParsers.d.ts +4 -4
- package/build/cjs/lib/nvm500/EntryParsers.js.map +2 -2
- package/build/cjs/lib/nvm500/adapter.js.map +2 -2
- package/build/cjs/lib/nvm500/shared.d.ts +2 -1
- package/build/cjs/lib/nvm500/shared.js.map +2 -2
- package/build/esm/convert.d.ts +6 -5
- package/build/esm/convert.d.ts.map +1 -1
- package/build/esm/convert.js +1 -1
- package/build/esm/convert.js.map +1 -1
- package/build/esm/lib/NVM3.d.ts +6 -5
- package/build/esm/lib/NVM3.d.ts.map +1 -1
- package/build/esm/lib/NVM3.js +1 -1
- package/build/esm/lib/NVM3.js.map +1 -1
- package/build/esm/lib/NVM500.js.map +1 -1
- package/build/esm/lib/common/definitions.d.ts +5 -5
- package/build/esm/lib/common/definitions.d.ts.map +1 -1
- package/build/esm/lib/common/routeCache.d.ts +2 -2
- package/build/esm/lib/common/routeCache.d.ts.map +1 -1
- package/build/esm/lib/common/routeCache.js.map +1 -1
- package/build/esm/lib/common/sucUpdateEntry.d.ts +2 -2
- package/build/esm/lib/common/sucUpdateEntry.d.ts.map +1 -1
- package/build/esm/lib/common/sucUpdateEntry.js.map +1 -1
- package/build/esm/lib/common/utils.d.ts +3 -2
- package/build/esm/lib/common/utils.d.ts.map +1 -1
- package/build/esm/lib/common/utils.js.map +1 -1
- package/build/esm/lib/io/BufferedNVMReader.d.ts +3 -2
- package/build/esm/lib/io/BufferedNVMReader.d.ts.map +1 -1
- package/build/esm/lib/io/BufferedNVMReader.js.map +1 -1
- package/build/esm/lib/io/NVMFileIO.d.ts +3 -2
- package/build/esm/lib/io/NVMFileIO.d.ts.map +1 -1
- package/build/esm/lib/io/NVMFileIO.js.map +1 -1
- package/build/esm/lib/io/NVMMemoryIO.d.ts +4 -3
- package/build/esm/lib/io/NVMMemoryIO.d.ts.map +1 -1
- package/build/esm/lib/io/NVMMemoryIO.js.map +1 -1
- package/build/esm/lib/nvm3/adapter.d.ts.map +1 -1
- package/build/esm/lib/nvm3/adapter.js.map +1 -1
- package/build/esm/lib/nvm3/files/ControllerInfoFile.d.ts +3 -3
- package/build/esm/lib/nvm3/files/ControllerInfoFile.d.ts.map +1 -1
- package/build/esm/lib/nvm3/files/ControllerInfoFile.js.map +1 -1
- package/build/esm/lib/nvm3/files/NVMFile.d.ts +2 -2
- package/build/esm/lib/nvm3/files/NVMFile.d.ts.map +1 -1
- package/build/esm/lib/nvm3/files/NVMFile.js.map +1 -1
- package/build/esm/lib/nvm3/files/NodeInfoFiles.d.ts.map +1 -1
- package/build/esm/lib/nvm3/files/NodeInfoFiles.js.map +1 -1
- package/build/esm/lib/nvm3/object.d.ts +3 -2
- package/build/esm/lib/nvm3/object.d.ts.map +1 -1
- package/build/esm/lib/nvm3/object.js.map +1 -1
- package/build/esm/lib/nvm3/page.d.ts +2 -1
- package/build/esm/lib/nvm3/page.d.ts.map +1 -1
- package/build/esm/lib/nvm3/page.js.map +1 -1
- package/build/esm/lib/nvm500/EntryParsers.d.ts +4 -4
- package/build/esm/lib/nvm500/EntryParsers.d.ts.map +1 -1
- package/build/esm/lib/nvm500/EntryParsers.js.map +1 -1
- package/build/esm/lib/nvm500/adapter.js.map +1 -1
- package/build/esm/lib/nvm500/shared.d.ts +2 -1
- package/build/esm/lib/nvm500/shared.d.ts.map +1 -1
- package/build/esm/lib/nvm500/shared.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/NVM3.ts"],
|
|
4
|
-
"sourcesContent": ["import { ZWaveError, ZWaveErrorCodes } from \"@zwave-js/core\";\nimport { Bytes, getEnumMemberName, num2hex } from \"@zwave-js/shared\";\nimport { type NVM, NVMAccess, type NVMIO } from \"./common/definitions.js\";\nimport {\n\tnvmReadBuffer,\n\tnvmReadUInt32LE,\n\tnvmWriteBuffer,\n} from \"./common/utils.js\";\nimport {\n\tFLASH_MAX_PAGE_SIZE_700,\n\tFLASH_MAX_PAGE_SIZE_800,\n\tFragmentType,\n\tNVM3_CODE_LARGE_SHIFT,\n\tNVM3_CODE_SMALL_SHIFT,\n\tNVM3_COUNTER_SIZE,\n\tNVM3_MAX_OBJ_SIZE_SMALL,\n\tNVM3_OBJ_FRAGTYPE_MASK,\n\tNVM3_OBJ_FRAGTYPE_SHIFT,\n\tNVM3_OBJ_HEADER_SIZE_LARGE,\n\tNVM3_OBJ_KEY_MASK,\n\tNVM3_OBJ_KEY_SHIFT,\n\tNVM3_OBJ_LARGE_LEN_MASK,\n\tNVM3_OBJ_TYPE_MASK,\n\tNVM3_PAGE_COUNTER_MASK,\n\tNVM3_PAGE_COUNTER_SIZE,\n\tNVM3_PAGE_HEADER_SIZE,\n\tNVM3_PAGE_MAGIC,\n\tObjectType,\n\tPageStatus,\n\tPageWriteSize,\n\tZWAVE_APPLICATION_NVM_SIZE,\n} from \"./nvm3/consts.js\";\nimport {\n\tApplicationVersionFile800ID,\n\ttype NVMSection,\n\tgetNVMSectionByFileID,\n} from \"./nvm3/files/index.js\";\nimport {\n\ttype NVM3Object,\n\ttype NVM3ObjectHeader,\n\tfragmentLargeObject,\n\tgetAlignedSize,\n\tgetObjectHeader,\n\tgetRequiredSpace,\n\tserializeObject,\n} from \"./nvm3/object.js\";\nimport {\n\ttype NVM3PageHeader,\n\tpageSizeFromBits,\n\tserializePageHeader,\n} from \"./nvm3/page.js\";\nimport { validateBergerCode, validateBergerCodeMulti } from \"./nvm3/utils.js\";\n\n// TODO: Possible optimizations:\n// Investigate if there is a better way to determine whether the NVM\n// uses a shared FS or not. The current implementation scans all objects\n// to find the 800 series application version file.\n// Alternatively, we could simply check if each page starts with an object header.\n// If yes, read the objects lazily when needed. If not, remember that the page is empty.\n\nexport type NVM3PageInfo = NVM3PageHeader & {\n\tobjects: NVM3ObjectHeader[];\n};\n\nexport interface NVM3SectionInfo {\n\tpages: NVM3PageInfo[];\n\t/** The index of the current page */\n\tcurrentPage: number;\n\t/** The next byte to write in the current page */\n\toffsetInPage: number;\n\t/** A map of file IDs and page indizes in which their last copy resides */\n\tobjectLocations: Map<number, number>;\n}\n\nexport type NVM3FileSystemInfo = {\n\tisSharedFileSystem: true;\n\tsections: Record<\"all\", NVM3SectionInfo>;\n} | {\n\tisSharedFileSystem: false;\n\tsections: Record<NVMSection, NVM3SectionInfo>;\n};\n\nexport interface NVM3Meta {\n\tsharedFileSystem: boolean;\n\tpageSize: number;\n\tdeviceFamily: number;\n\twriteSize: PageWriteSize;\n\tmemoryMapped: boolean;\n}\n\nexport type NVM3EraseOptions = Partial<NVM3Meta>;\n\nexport class NVM3 implements NVM<number, Uint8Array> {\n\tpublic constructor(io: NVMIO) {\n\t\tthis._io = io;\n\t}\n\n\tprivate _io: NVMIO;\n\tprivate _access: NVMAccess = NVMAccess.None;\n\n\tprivate _info: NVM3FileSystemInfo | undefined;\n\tpublic get info(): NVM3FileSystemInfo | undefined {\n\t\treturn this._info;\n\t}\n\n\tprivate async ensureReadable(): Promise<void> {\n\t\tif (\n\t\t\tthis._access === NVMAccess.Read\n\t\t\t|| this._access === NVMAccess.ReadWrite\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (this._access === NVMAccess.Write) {\n\t\t\tawait this._io.close();\n\t\t}\n\t\tthis._access = await this._io.open(NVMAccess.Read);\n\t}\n\n\tprivate async ensureWritable(): Promise<void> {\n\t\tif (\n\t\t\tthis._access === NVMAccess.Write\n\t\t\t|| this._access === NVMAccess.ReadWrite\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (this._access === NVMAccess.Read) {\n\t\t\tawait this._io.close();\n\t\t}\n\t\tthis._access = await this._io.open(NVMAccess.Write);\n\t}\n\n\tpublic async init(): Promise<NVM3FileSystemInfo> {\n\t\tawait this.ensureReadable();\n\n\t\tlet pageOffset = 0;\n\t\t// Determine NVM size, scan pages\n\t\tconst pages: NVM3PageInfo[] = [];\n\t\tlet isSharedFileSystem = false;\n\t\twhile (pageOffset < this._io.size) {\n\t\t\t// console.debug(\n\t\t\t// \t`NVM3 init() - reading page header at offset ${\n\t\t\t// \t\tnum2hex(pageOffset)\n\t\t\t// \t}`,\n\t\t\t// );\n\t\t\tconst header = await readPageHeader(this._io, pageOffset);\n\t\t\tpages.push({\n\t\t\t\t...header,\n\t\t\t\tobjects: [],\n\t\t\t});\n\t\t\tpageOffset += header.pageSize;\n\t\t}\n\n\t\t// Scan each page for objects\n\t\tfor (const page of pages) {\n\t\t\t// Scan objects in this page\n\t\t\tlet objectOffset = page.offset + NVM3_PAGE_HEADER_SIZE;\n\t\t\tconst nextPageOffset = page.offset + page.pageSize;\n\t\t\twhile (objectOffset < nextPageOffset) {\n\t\t\t\t// console.debug(\n\t\t\t\t// \t`NVM3 init() - reading object header. page offset ${\n\t\t\t\t// \t\tnum2hex(page.offset)\n\t\t\t\t// \t}, object offset ${num2hex(objectOffset)}`,\n\t\t\t\t// );\n\t\t\t\tconst objectHeader = await readObjectHeader(\n\t\t\t\t\tthis._io,\n\t\t\t\t\tobjectOffset,\n\t\t\t\t);\n\t\t\t\tif (objectHeader) {\n\t\t\t\t\tpage.objects.push(objectHeader);\n\t\t\t\t\tobjectOffset += objectHeader.alignedSize;\n\n\t\t\t\t\t// Detect the 800 series shared protocol & application NVM file system\n\t\t\t\t\t// by looking for the 800 series application version file\n\t\t\t\t\tif (objectHeader.key === ApplicationVersionFile800ID) {\n\t\t\t\t\t\tisSharedFileSystem = true;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Reached the end of the data in this page\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// By convention, we only use the applicationPages in that case\n\t\tlet applicationPages: NVM3PageInfo[];\n\t\tlet protocolPages: NVM3PageInfo[];\n\n\t\tif (isSharedFileSystem) {\n\t\t\tapplicationPages = pages;\n\t\t\tprotocolPages = [];\n\t\t} else {\n\t\t\tapplicationPages = pages.filter(\n\t\t\t\t(p) => p.offset < ZWAVE_APPLICATION_NVM_SIZE,\n\t\t\t);\n\t\t\tprotocolPages = pages.filter(\n\t\t\t\t(p) => p.offset >= ZWAVE_APPLICATION_NVM_SIZE,\n\t\t\t);\n\t\t}\n\n\t\t// NVM3 layouts pages in a ring buffer. Pages are written from front to back, then occupied pages\n\t\t// are erased and overwritten. Pages at the start of the memory section may have an erase count that's 1 higher\n\t\t// than the pages at the end.\n\t\tconst pageInfoToSectionInfo = (\n\t\t\tpages: NVM3PageInfo[],\n\t\t): NVM3SectionInfo => {\n\t\t\t// Find the current page, which is either:\n\t\t\t// - The last page with the high erase count that contains an object\n\t\t\tconst maxEraseCount = Math.max(...pages.map((p) => p.eraseCount));\n\t\t\tlet currentPageIndex = pages.findLastIndex((p) =>\n\t\t\t\tp.eraseCount === maxEraseCount && p.objects.length > 0\n\t\t\t);\n\t\t\t// - or if there is none, the last page with the lower erase count that contains an object\n\t\t\tif (currentPageIndex === -1) {\n\t\t\t\tcurrentPageIndex = pages.findLastIndex((p) =>\n\t\t\t\t\tp.objects.length > 0\n\t\t\t\t);\n\t\t\t}\n\t\t\t// - Or if no objects exist at all, the beginning of the section\n\t\t\tif (currentPageIndex === -1) currentPageIndex = 0;\n\n\t\t\t// Find the next free byte of the current page\n\t\t\tconst currentPage = pages[currentPageIndex];\n\t\t\tlet offset = NVM3_PAGE_HEADER_SIZE;\n\t\t\tfor (const object of currentPage.objects) {\n\t\t\t\toffset += object.alignedSize;\n\t\t\t}\n\n\t\t\tconst objectLocations = new Map<number, number>();\n\t\t\tfor (let i = 0; i < pages.length; i++) {\n\t\t\t\tconst page = pages[i];\n\t\t\t\tfor (const object of page.objects) {\n\t\t\t\t\tconst location = objectLocations.get(object.key);\n\t\t\t\t\tif (location == undefined) {\n\t\t\t\t\t\t// Object seen for the first time, remember the page it is in\n\t\t\t\t\t\tobjectLocations.set(object.key, i);\n\t\t\t\t\t} else if (\n\t\t\t\t\t\t(object.fragmentType === FragmentType.None\n\t\t\t\t\t\t\t|| object.fragmentType === FragmentType.First)\n\t\t\t\t\t\t&& (page.eraseCount >= pages[location].eraseCount)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Object was seen before. Only remember it if it is the only\n\t\t\t\t\t\t// or first fragment and the object appears in a later location\n\t\t\t\t\t\t// of the ring buffer\n\t\t\t\t\t\tobjectLocations.set(object.key, i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpages,\n\t\t\t\toffsetInPage: offset,\n\t\t\t\tcurrentPage: currentPageIndex,\n\t\t\t\tobjectLocations,\n\t\t\t};\n\t\t};\n\n\t\tif (isSharedFileSystem) {\n\t\t\tthis._info = {\n\t\t\t\tisSharedFileSystem: true,\n\t\t\t\tsections: {\n\t\t\t\t\tall: pageInfoToSectionInfo(applicationPages),\n\t\t\t\t},\n\t\t\t};\n\t\t} else {\n\t\t\tthis._info = {\n\t\t\t\tisSharedFileSystem: false,\n\t\t\t\tsections: {\n\t\t\t\t\tapplication: pageInfoToSectionInfo(applicationPages),\n\t\t\t\t\tprotocol: pageInfoToSectionInfo(protocolPages),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn this._info;\n\t}\n\n\tprivate getNVMSectionForFile(fileId: number): NVM3SectionInfo {\n\t\t// Determine which ring buffer to read in\n\t\treturn this._info!.isSharedFileSystem\n\t\t\t? this._info!.sections.all\n\t\t\t: this._info!.sections[getNVMSectionByFileID(fileId)];\n\t}\n\n\tpublic async has(fileId: number): Promise<boolean> {\n\t\tthis._info ??= await this.init();\n\n\t\t// Determine which ring buffer to read in\n\t\tconst section = this.getNVMSectionForFile(fileId);\n\n\t\treturn section.objectLocations.has(fileId);\n\t}\n\n\tpublic readObjectData(object: NVM3ObjectHeader): Promise<Uint8Array> {\n\t\treturn nvmReadBuffer(\n\t\t\tthis._io,\n\t\t\tobject.offset + object.headerSize,\n\t\t\tobject.fragmentSize,\n\t\t);\n\t}\n\n\tpublic async get(\n\t\tfileId: number,\n\t\tsection?: NVM3SectionInfo,\n\t): Promise<Uint8Array | undefined> {\n\t\tthis._info ??= await this.init();\n\n\t\t// Determine which ring buffer to read in, unless we were told to use a specific one\n\t\tsection ??= this.getNVMSectionForFile(fileId);\n\n\t\tconst pages = section.pages;\n\n\t\t// TODO: There should be no need for scanning, since we know the object locations after init().\n\n\t\t// Start scanning backwards through the pages ring buffer, starting with the current page\n\t\tlet parts: Uint8Array[] | undefined;\n\t\tlet complete = false;\n\t\tlet objType: ObjectType | undefined;\n\t\tconst resetFragments = () => {\n\t\t\t// if (parts?.length) {\n\t\t\t// \tconsole.debug(\"Resetting fragmented object\");\n\t\t\t// }\n\t\t\tparts = undefined;\n\t\t\tcomplete = false;\n\t\t};\n\t\tpages: for (let offset = 0; offset < pages.length; offset++) {\n\t\t\tconst index = (section.currentPage - offset + pages.length)\n\t\t\t\t% pages.length;\n\t\t\tconst page = pages[index];\n\t\t\t// console.debug(\n\t\t\t// \t`NVM3.get(${fileId}): scanning page ${index} at offset ${\n\t\t\t// \t\tnum2hex(page.offset)\n\t\t\t// \t}`,\n\t\t\t// );\n\t\t\t// Scan objects in this page, read backwards.\n\t\t\t// The last non-deleted object wins\n\t\t\tobjects: for (let j = page.objects.length - 1; j >= 0; j--) {\n\t\t\t\tconst object = page.objects[j];\n\n\t\t\t\tconst readObject = () => this.readObjectData(object);\n\n\t\t\t\tif (object.key !== fileId) {\n\t\t\t\t\t// Reset any fragmented objects when encountering a different key\n\t\t\t\t\tresetFragments();\n\t\t\t\t\tcontinue objects;\n\t\t\t\t}\n\n\t\t\t\tif (object.type === ObjectType.Deleted) {\n\t\t\t\t\t// Last action for this object was a deletion. There is no data.\n\t\t\t\t\treturn;\n\t\t\t\t} else if (object.fragmentType === FragmentType.None) {\n\t\t\t\t\t// console.debug(\n\t\t\t\t\t// \t`NVM3.get(${fileId}): found complete object - header offset ${\n\t\t\t\t\t// \t\tnum2hex(object.offset)\n\t\t\t\t\t// \t}, content offset ${\n\t\t\t\t\t// \t\tnum2hex(object.offset + object.headerSize)\n\t\t\t\t\t// \t}, length ${object.fragmentSize}`,\n\t\t\t\t\t// );\n\t\t\t\t\t// This is a complete object\n\t\t\t\t\tparts = [await readObject()];\n\t\t\t\t\tobjType = object.type;\n\t\t\t\t\tcomplete = true;\n\t\t\t\t\tbreak pages;\n\t\t\t\t} else if (object.fragmentType === FragmentType.Last) {\n\t\t\t\t\t// console.debug(\n\t\t\t\t\t// \t`NVM3.get(${fileId}): found LAST fragment - header offset ${\n\t\t\t\t\t// \t\tnum2hex(object.offset)\n\t\t\t\t\t// \t}, content offset ${\n\t\t\t\t\t// \t\tnum2hex(object.offset + object.headerSize)\n\t\t\t\t\t// \t}, length ${object.fragmentSize}`,\n\t\t\t\t\t// );\n\t\t\t\t\tparts = [await readObject()];\n\t\t\t\t\tobjType = object.type;\n\t\t\t\t\tcomplete = false;\n\t\t\t\t} else if (object.fragmentType === FragmentType.Next) {\n\t\t\t\t\tif (parts?.length && objType === object.type) {\n\t\t\t\t\t\t// console.debug(\n\t\t\t\t\t\t// \t`NVM3.get(${fileId}): found NEXT fragment - header offset ${\n\t\t\t\t\t\t// \t\tnum2hex(object.offset)\n\t\t\t\t\t\t// \t}, content offset ${\n\t\t\t\t\t\t// \t\tnum2hex(object.offset + object.headerSize)\n\t\t\t\t\t\t// \t}, length ${object.fragmentSize}`,\n\t\t\t\t\t\t// );\n\t\t\t\t\t\tparts.unshift(await readObject());\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This shouldn't be here\n\t\t\t\t\t\tresetFragments();\n\t\t\t\t\t}\n\t\t\t\t} else if (object.fragmentType === FragmentType.First) {\n\t\t\t\t\tif (parts?.length && objType === object.type) {\n\t\t\t\t\t\t// console.debug(\n\t\t\t\t\t\t// \t`NVM3.get(${fileId}): found FIRST fragment - header offset ${\n\t\t\t\t\t\t// \t\tnum2hex(object.offset)\n\t\t\t\t\t\t// \t}, content offset ${\n\t\t\t\t\t\t// \t\tnum2hex(object.offset + object.headerSize)\n\t\t\t\t\t\t// \t}, length ${object.fragmentSize}`,\n\t\t\t\t\t\t// );\n\t\t\t\t\t\tparts.unshift(await readObject());\n\t\t\t\t\t\tcomplete = true;\n\t\t\t\t\t\tbreak pages;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This shouldn't be here\n\t\t\t\t\t\tresetFragments();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!parts?.length || !complete || objType == undefined) return;\n\n\t\treturn Bytes.concat(parts);\n\t}\n\n\tprivate async writeObjects(objects: NVM3Object[]): Promise<void> {\n\t\tconst section = this.getNVMSectionForFile(objects[0].key);\n\n\t\tlet page = section.pages[section.currentPage];\n\t\tlet remainingSpace = page.pageSize\n\t\t\t- NVM3_PAGE_HEADER_SIZE\n\t\t\t- section.offsetInPage;\n\n\t\t// TODO: See if we can avoid double writes on a page change\n\n\t\t/** Moves to the next page and erases it if necessary */\n\t\tconst nextPage = async () => {\n\t\t\tsection.currentPage = (section.currentPage + 1)\n\t\t\t\t% section.pages.length;\n\t\t\tpage = section.pages[section.currentPage];\n\n\t\t\t// Find headers of objects that need to be preserved\n\t\t\tconst toPreserve = [...section.objectLocations].filter((\n\t\t\t\t[, pageIndex],\n\t\t\t) => pageIndex === section.currentPage)\n\t\t\t\t.map(([fileID]) =>\n\t\t\t\t\tpage.objects.findLast((h) => h.key === fileID)\n\t\t\t\t)\n\t\t\t\t.filter((h) => h != undefined)\n\t\t\t\t.filter((h) => h.type !== ObjectType.Deleted);\n\t\t\t// And add the objects to the TODO list\n\t\t\tfor (const header of toPreserve) {\n\t\t\t\tconst data = await this.get(header.key);\n\t\t\t\tconsole.error(`Need to preserve object ${num2hex(header.key)}\n page index: ${section.currentPage}\n object type: ${getEnumMemberName(ObjectType, header.type)}\n data: ${data != undefined ? `${data.length} bytes` : \"(no data)\"}`);\n\t\t\t\tobjects.push({\n\t\t\t\t\tkey: header.key,\n\t\t\t\t\ttype: header.type,\n\t\t\t\t\tfragmentType: FragmentType.None,\n\t\t\t\t\tdata,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (page.objects.length > 0) {\n\t\t\t\t// The page needs to be erased\n\t\t\t\tpage.eraseCount++;\n\t\t\t\tpage.objects = [];\n\n\t\t\t\tconst pageHeaderBuffer = serializePageHeader(page);\n\t\t\t\tconst pageBuffer = new Uint8Array(page.pageSize).fill(0xff);\n\t\t\t\tpageBuffer.set(pageHeaderBuffer, 0);\n\n\t\t\t\tawait nvmWriteBuffer(this._io, page.offset, pageBuffer);\n\t\t\t}\n\n\t\t\tsection.offsetInPage = NVM3_PAGE_HEADER_SIZE;\n\t\t\tremainingSpace = page.pageSize - NVM3_PAGE_HEADER_SIZE;\n\t\t};\n\n\t\t// Go through the list of objects and write all of them to the NVM\n\t\tfor (const object of objects) {\n\t\t\tconst isLargeObject = object.type === ObjectType.DataLarge\n\t\t\t\t|| object.type === ObjectType.CounterLarge;\n\n\t\t\tlet fragments: NVM3Object[] | undefined;\n\n\t\t\tif (isLargeObject) {\n\t\t\t\t// Large objects may be fragmented\n\n\t\t\t\t// We need to start a new page, if the remaining space is not enough for\n\t\t\t\t// the object header plus additional data\n\t\t\t\tif (remainingSpace <= NVM3_OBJ_HEADER_SIZE_LARGE) {\n\t\t\t\t\tawait nextPage();\n\t\t\t\t}\n\n\t\t\t\tfragments = fragmentLargeObject(\n\t\t\t\t\tobject as any,\n\t\t\t\t\tremainingSpace,\n\t\t\t\t\tpage.pageSize - NVM3_PAGE_HEADER_SIZE,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Small objects cannot be fragmented. If they don't fit,\n\t\t\t\t// they need to go on the next page.\n\t\t\t\tconst requiredSpace = getRequiredSpace(object);\n\t\t\t\tif (requiredSpace > remainingSpace) {\n\t\t\t\t\tawait nextPage();\n\t\t\t\t}\n\t\t\t\tfragments = [object];\n\t\t\t}\n\n\t\t\t// Write each fragment to the NVM. If there are multiple fragments,\n\t\t\t// each one but the first needs to be written at the beginning of a new page\n\t\t\tfor (let i = 0; i < fragments.length; i++) {\n\t\t\t\tif (i > 0) await nextPage();\n\t\t\t\tconst fragment = fragments[i];\n\n\t\t\t\tconst objBuffer = serializeObject(fragment);\n\t\t\t\tconst objOffset = page.offset + section.offsetInPage;\n\t\t\t\tawait this._io.write(objOffset, objBuffer);\n\t\t\t\tconst requiredSpace = getRequiredSpace(fragment);\n\t\t\t\tsection.offsetInPage += requiredSpace;\n\t\t\t\tremainingSpace -= requiredSpace;\n\n\t\t\t\t// Remember which objects exist in this page\n\t\t\t\tpage.objects.push(getObjectHeader(object, objOffset));\n\n\t\t\t\t// And remember where this object lives\n\t\t\t\tif (object.type === ObjectType.Deleted) {\n\t\t\t\t\tsection.objectLocations.delete(object.key);\n\t\t\t\t} else if (\n\t\t\t\t\tfragment.fragmentType === FragmentType.None\n\t\t\t\t\t|| fragment.fragmentType === FragmentType.First\n\t\t\t\t) {\n\t\t\t\t\tsection.objectLocations.set(\n\t\t\t\t\t\tfragment.key,\n\t\t\t\t\t\tsection.currentPage,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async set(property: number, value: Uint8Array): Promise<void> {\n\t\tif (!this._info) await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tawait this.writeObjects([{\n\t\t\tkey: property,\n\t\t\ttype: value.length <= NVM3_MAX_OBJ_SIZE_SMALL\n\t\t\t\t? ObjectType.DataSmall\n\t\t\t\t: ObjectType.DataLarge,\n\t\t\t// writeObject deals with fragmentation\n\t\t\tfragmentType: FragmentType.None,\n\t\t\tdata: value,\n\t\t}]);\n\t}\n\n\t/** Writes multiple values to the NVM at once. `null` / `undefined` cause the value to be deleted */\n\tpublic async setMany(\n\t\tvalues: [number, Uint8Array | null | undefined][],\n\t): Promise<void> {\n\t\tif (!this._info) await this.init();\n\t\tawait this.ensureWritable();\n\n\t\t// Group objects by their NVM section\n\t\tconst objectsBySection = new Map<\n\t\t\tnumber, /* offset */\n\t\t\t[number, Uint8Array | null | undefined][]\n\t\t>();\n\t\tfor (const [key, value] of values) {\n\t\t\tconst sectionOffset =\n\t\t\t\tthis.getNVMSectionForFile(key).pages[0].offset;\n\t\t\tif (!objectsBySection.has(sectionOffset)) {\n\t\t\t\tobjectsBySection.set(sectionOffset, []);\n\t\t\t}\n\t\t\tobjectsBySection.get(sectionOffset)!.push([key, value]);\n\t\t}\n\n\t\t// And call writeObjects for each group\n\t\tfor (const objectGroups of objectsBySection.values()) {\n\t\t\tawait this.writeObjects(\n\t\t\t\tobjectGroups.map(([key, value]) => (value\n\t\t\t\t\t? {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\ttype: value.length <= NVM3_MAX_OBJ_SIZE_SMALL\n\t\t\t\t\t\t\t? ObjectType.DataSmall\n\t\t\t\t\t\t\t: ObjectType.DataLarge,\n\t\t\t\t\t\t// writeObject deals with fragmentation\n\t\t\t\t\t\tfragmentType: FragmentType.None,\n\t\t\t\t\t\tdata: value,\n\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\ttype: ObjectType.Deleted,\n\t\t\t\t\t\tfragmentType: FragmentType.None,\n\t\t\t\t\t})\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic async delete(property: number): Promise<void> {\n\t\tif (!this._info) await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tawait this.writeObjects([{\n\t\t\tkey: property,\n\t\t\ttype: ObjectType.Deleted,\n\t\t\tfragmentType: FragmentType.None,\n\t\t}]);\n\t}\n\n\tpublic async erase(options?: NVM3EraseOptions): Promise<void> {\n\t\tconst {\n\t\t\tdeviceFamily = 2047,\n\t\t\twriteSize = PageWriteSize.WRITE_SIZE_16,\n\t\t\tmemoryMapped = true,\n\t\t\tsharedFileSystem = false,\n\t\t} = options ?? {};\n\t\tconst maxPageSize = sharedFileSystem\n\t\t\t? FLASH_MAX_PAGE_SIZE_800\n\t\t\t: FLASH_MAX_PAGE_SIZE_700;\n\t\tconst pageSize = Math.min(\n\t\t\toptions?.pageSize ?? maxPageSize,\n\t\t\tmaxPageSize,\n\t\t);\n\n\t\t// Make sure we won't be writing incomplete pages\n\t\tif (this._io.size % pageSize !== 0) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Invalid page size. NVM size ${this._io.size} must be a multiple of the page size ${pageSize}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t} else if (\n\t\t\t!sharedFileSystem && ZWAVE_APPLICATION_NVM_SIZE % pageSize !== 0\n\t\t) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Invalid page size. The application NVM size ${ZWAVE_APPLICATION_NVM_SIZE} must be a multiple of the page size ${pageSize}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t} else if (\n\t\t\t!sharedFileSystem\n\t\t\t&& (this._io.size - ZWAVE_APPLICATION_NVM_SIZE) % pageSize !== 0\n\t\t) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Invalid page size. The protocol NVM size ${\n\t\t\t\t\tthis._io.size\n\t\t\t\t\t- ZWAVE_APPLICATION_NVM_SIZE\n\t\t\t\t} must be a multiple of the page size ${pageSize}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t}\n\n\t\tawait this.ensureWritable();\n\n\t\t// Create empty pages, write them to the NVM\n\t\tconst applicationPages: NVM3PageInfo[] = [];\n\t\tconst protocolPages: NVM3PageInfo[] = [];\n\n\t\tconst numPages = this._io.size / pageSize;\n\t\tfor (let i = 0; i < numPages; i++) {\n\t\t\tconst offset = i * pageSize;\n\t\t\tconst pageBuffer = new Uint8Array(pageSize).fill(0xff);\n\t\t\tconst pageHeader: NVM3PageHeader = {\n\t\t\t\toffset,\n\t\t\t\tversion: 0x01,\n\t\t\t\teraseCount: 0,\n\t\t\t\tencrypted: false,\n\t\t\t\tdeviceFamily,\n\t\t\t\tmemoryMapped,\n\t\t\t\tpageSize,\n\t\t\t\tstatus: PageStatus.OK,\n\t\t\t\twriteSize,\n\t\t\t};\n\t\t\tpageBuffer.set(serializePageHeader(pageHeader), 0);\n\t\t\tawait nvmWriteBuffer(this._io, offset, pageBuffer);\n\n\t\t\tif (sharedFileSystem || offset < ZWAVE_APPLICATION_NVM_SIZE) {\n\t\t\t\tapplicationPages.push({ ...pageHeader, objects: [] });\n\t\t\t} else {\n\t\t\t\tprotocolPages.push({ ...pageHeader, objects: [] });\n\t\t\t}\n\t\t}\n\n\t\t// Remember the pages we just created for further use\n\t\tthis._info = sharedFileSystem\n\t\t\t? {\n\t\t\t\tisSharedFileSystem: true,\n\t\t\t\tsections: {\n\t\t\t\t\tall: {\n\t\t\t\t\t\tcurrentPage: 0,\n\t\t\t\t\t\tobjectLocations: new Map(),\n\t\t\t\t\t\toffsetInPage: NVM3_PAGE_HEADER_SIZE,\n\t\t\t\t\t\tpages: applicationPages,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}\n\t\t\t: {\n\t\t\t\tisSharedFileSystem: false,\n\t\t\t\tsections: {\n\t\t\t\t\tapplication: {\n\t\t\t\t\t\tcurrentPage: 0,\n\t\t\t\t\t\tobjectLocations: new Map(),\n\t\t\t\t\t\toffsetInPage: NVM3_PAGE_HEADER_SIZE,\n\t\t\t\t\t\tpages: applicationPages,\n\t\t\t\t\t},\n\t\t\t\t\tprotocol: {\n\t\t\t\t\t\tcurrentPage: 0,\n\t\t\t\t\t\tobjectLocations: new Map(),\n\t\t\t\t\t\toffsetInPage: NVM3_PAGE_HEADER_SIZE,\n\t\t\t\t\t\tpages: protocolPages,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\nasync function readPageHeader(\n\tio: NVMIO,\n\toffset: number,\n): Promise<NVM3PageHeader> {\n\tif (offset > io.size - NVM3_PAGE_HEADER_SIZE) {\n\t\tthrow new ZWaveError(\n\t\t\t\"Incomplete page in buffer!\",\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\tconst buffer = Bytes.view(\n\t\t(await io.read(offset, NVM3_PAGE_HEADER_SIZE)).buffer,\n\t);\n\n\tconst { version, eraseCount } = tryGetVersionAndEraseCount(buffer);\n\n\t// Page status\n\tconst status = buffer.readUInt32LE(12);\n\n\tconst devInfo = buffer.readUInt16LE(16);\n\tconst deviceFamily = devInfo & 0x7ff;\n\tconst writeSize = (devInfo >> 11) & 0b1;\n\tconst memoryMapped = !!((devInfo >> 12) & 0b1);\n\tlet pageSize = pageSizeFromBits((devInfo >> 13) & 0b111);\n\n\tif (pageSize > 0xffff) {\n\t\t// Some controllers have no valid info in the page size bits, resulting\n\t\t// in an impossibly large page size. To try and figure out the actual page\n\t\t// size without knowing the hardware, we scan the buffer for the next valid\n\t\t// page start.\n\t\tfor (let exponent = 0; exponent < 0b111; exponent++) {\n\t\t\tconst testPageSize = pageSizeFromBits(exponent);\n\t\t\tconst nextOffset = offset + testPageSize;\n\t\t\tif (\n\t\t\t\t// exactly end of NVM OR\n\t\t\t\tio.size === nextOffset\n\t\t\t\t// next page\n\t\t\t\t|| await isValidPageHeaderAtOffset(io, nextOffset)\n\t\t\t) {\n\t\t\t\tpageSize = testPageSize;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (pageSize > 0xffff) {\n\t\tthrow new ZWaveError(\n\t\t\t\"Could not determine page size!\",\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\tif (io.size < offset + pageSize) {\n\t\tthrow new ZWaveError(\n\t\t\t`NVM contains incomplete page at offset ${num2hex(offset)}!`,\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\tconst formatInfo = buffer.readUInt16LE(18);\n\tconst encrypted = !(formatInfo & 0b1);\n\n\treturn {\n\t\toffset,\n\t\tversion,\n\t\teraseCount,\n\t\tstatus,\n\t\tencrypted,\n\t\tpageSize,\n\t\twriteSize,\n\t\tmemoryMapped,\n\t\tdeviceFamily,\n\t};\n}\n\nfunction tryGetVersionAndEraseCount(\n\theader: Uint8Array,\n): { version: number; eraseCount: number } {\n\tconst buffer = Bytes.view(header);\n\tconst version = buffer.readUInt16LE(0);\n\tconst magic = buffer.readUInt16LE(2);\n\tif (magic !== NVM3_PAGE_MAGIC) {\n\t\tthrow new ZWaveError(\n\t\t\t\"Not a valid NVM3 page!\",\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\tif (version !== 0x01) {\n\t\tthrow new ZWaveError(\n\t\t\t`Unsupported NVM3 page version: ${version}`,\n\t\t\tZWaveErrorCodes.NVM_NotSupported,\n\t\t);\n\t}\n\n\t// The erase counter is saved twice, once normally, once inverted\n\tlet eraseCount = buffer.readUInt32LE(4);\n\tconst eraseCountCode = eraseCount >>> NVM3_PAGE_COUNTER_SIZE;\n\teraseCount &= NVM3_PAGE_COUNTER_MASK;\n\tvalidateBergerCode(eraseCount, eraseCountCode, NVM3_PAGE_COUNTER_SIZE);\n\n\tlet eraseCountInv = buffer.readUInt32LE(8);\n\tconst eraseCountInvCode = eraseCountInv >>> NVM3_PAGE_COUNTER_SIZE;\n\teraseCountInv &= NVM3_PAGE_COUNTER_MASK;\n\tvalidateBergerCode(\n\t\teraseCountInv,\n\t\teraseCountInvCode,\n\t\tNVM3_PAGE_COUNTER_SIZE,\n\t);\n\n\tif (eraseCount !== (~eraseCountInv & NVM3_PAGE_COUNTER_MASK)) {\n\t\tthrow new ZWaveError(\n\t\t\t\"Invalid erase count!\",\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\treturn { version, eraseCount };\n}\n\nasync function isValidPageHeaderAtOffset(\n\tio: NVMIO,\n\toffset: number,\n): Promise<boolean> {\n\tif (offset > io.size - NVM3_PAGE_HEADER_SIZE) {\n\t\treturn false;\n\t}\n\n\tconst { buffer } = await io.read(offset, NVM3_PAGE_HEADER_SIZE);\n\n\ttry {\n\t\ttryGetVersionAndEraseCount(buffer);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function readObjectHeader(\n\tio: NVMIO,\n\toffset: number,\n): Promise<NVM3ObjectHeader | undefined> {\n\tlet headerSize = 4;\n\tconst hdr1 = await nvmReadUInt32LE(io, offset);\n\n\t// Skip over blank page areas\n\tif (hdr1 === 0xffffffff) return;\n\n\tconst key = (hdr1 >> NVM3_OBJ_KEY_SHIFT) & NVM3_OBJ_KEY_MASK;\n\tlet objType: ObjectType = hdr1 & NVM3_OBJ_TYPE_MASK;\n\tlet fragmentSize = 0;\n\tlet hdr2: number | undefined;\n\tconst isLarge = objType === ObjectType.DataLarge\n\t\t|| objType === ObjectType.CounterLarge;\n\tif (isLarge) {\n\t\thdr2 = await nvmReadUInt32LE(io, offset + 4);\n\t\theaderSize += 4;\n\t\tfragmentSize = hdr2 & NVM3_OBJ_LARGE_LEN_MASK;\n\t} else if (objType > ObjectType.DataSmall) {\n\t\t// In small objects with data, the length and object type are stored in the same value\n\t\tfragmentSize = objType - ObjectType.DataSmall;\n\t\tobjType = ObjectType.DataSmall;\n\t} else if (objType === ObjectType.CounterSmall) {\n\t\tfragmentSize = NVM3_COUNTER_SIZE;\n\t}\n\n\tconst fragmentType: FragmentType = isLarge\n\t\t? (hdr1 >>> NVM3_OBJ_FRAGTYPE_SHIFT) & NVM3_OBJ_FRAGTYPE_MASK\n\t\t: FragmentType.None;\n\n\tif (isLarge) {\n\t\tvalidateBergerCodeMulti([hdr1, hdr2!], 32 + NVM3_CODE_LARGE_SHIFT);\n\t} else {\n\t\tvalidateBergerCodeMulti([hdr1], NVM3_CODE_SMALL_SHIFT);\n\t}\n\n\tif (io.size < offset + headerSize + fragmentSize) {\n\t\tthrow new ZWaveError(\n\t\t\t`NVM contains incomplete object at offset ${num2hex(offset)}!`,\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\tconst alignedFragmentSize = getAlignedSize(fragmentSize);\n\tconst alignedSize = headerSize + alignedFragmentSize;\n\n\treturn {\n\t\tkey,\n\t\toffset,\n\t\ttype: objType,\n\t\tfragmentType,\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,\n\ttype BytesView,\n\tgetEnumMemberName,\n\tnum2hex,\n} from \"@zwave-js/shared\";\nimport { type NVM, NVMAccess, type NVMIO } from \"./common/definitions.js\";\nimport {\n\tnvmReadBuffer,\n\tnvmReadUInt32LE,\n\tnvmWriteBuffer,\n} from \"./common/utils.js\";\nimport {\n\tFLASH_MAX_PAGE_SIZE_700,\n\tFLASH_MAX_PAGE_SIZE_800,\n\tFragmentType,\n\tNVM3_CODE_LARGE_SHIFT,\n\tNVM3_CODE_SMALL_SHIFT,\n\tNVM3_COUNTER_SIZE,\n\tNVM3_MAX_OBJ_SIZE_SMALL,\n\tNVM3_OBJ_FRAGTYPE_MASK,\n\tNVM3_OBJ_FRAGTYPE_SHIFT,\n\tNVM3_OBJ_HEADER_SIZE_LARGE,\n\tNVM3_OBJ_KEY_MASK,\n\tNVM3_OBJ_KEY_SHIFT,\n\tNVM3_OBJ_LARGE_LEN_MASK,\n\tNVM3_OBJ_TYPE_MASK,\n\tNVM3_PAGE_COUNTER_MASK,\n\tNVM3_PAGE_COUNTER_SIZE,\n\tNVM3_PAGE_HEADER_SIZE,\n\tNVM3_PAGE_MAGIC,\n\tObjectType,\n\tPageStatus,\n\tPageWriteSize,\n\tZWAVE_APPLICATION_NVM_SIZE,\n} from \"./nvm3/consts.js\";\nimport {\n\tApplicationVersionFile800ID,\n\ttype NVMSection,\n\tgetNVMSectionByFileID,\n} from \"./nvm3/files/index.js\";\nimport {\n\ttype NVM3Object,\n\ttype NVM3ObjectHeader,\n\tfragmentLargeObject,\n\tgetAlignedSize,\n\tgetObjectHeader,\n\tgetRequiredSpace,\n\tserializeObject,\n} from \"./nvm3/object.js\";\nimport {\n\ttype NVM3PageHeader,\n\tpageSizeFromBits,\n\tserializePageHeader,\n} from \"./nvm3/page.js\";\nimport { validateBergerCode, validateBergerCodeMulti } from \"./nvm3/utils.js\";\n\n// TODO: Possible optimizations:\n// Investigate if there is a better way to determine whether the NVM\n// uses a shared FS or not. The current implementation scans all objects\n// to find the 800 series application version file.\n// Alternatively, we could simply check if each page starts with an object header.\n// If yes, read the objects lazily when needed. If not, remember that the page is empty.\n\nexport type NVM3PageInfo = NVM3PageHeader & {\n\tobjects: NVM3ObjectHeader[];\n};\n\nexport interface NVM3SectionInfo {\n\tpages: NVM3PageInfo[];\n\t/** The index of the current page */\n\tcurrentPage: number;\n\t/** The next byte to write in the current page */\n\toffsetInPage: number;\n\t/** A map of file IDs and page indizes in which their last copy resides */\n\tobjectLocations: Map<number, number>;\n}\n\nexport type NVM3FileSystemInfo = {\n\tisSharedFileSystem: true;\n\tsections: Record<\"all\", NVM3SectionInfo>;\n} | {\n\tisSharedFileSystem: false;\n\tsections: Record<NVMSection, NVM3SectionInfo>;\n};\n\nexport interface NVM3Meta {\n\tsharedFileSystem: boolean;\n\tpageSize: number;\n\tdeviceFamily: number;\n\twriteSize: PageWriteSize;\n\tmemoryMapped: boolean;\n}\n\nexport type NVM3EraseOptions = Partial<NVM3Meta>;\n\nexport class NVM3 implements NVM<number, BytesView> {\n\tpublic constructor(io: NVMIO) {\n\t\tthis._io = io;\n\t}\n\n\tprivate _io: NVMIO;\n\tprivate _access: NVMAccess = NVMAccess.None;\n\n\tprivate _info: NVM3FileSystemInfo | undefined;\n\tpublic get info(): NVM3FileSystemInfo | undefined {\n\t\treturn this._info;\n\t}\n\n\tprivate async ensureReadable(): Promise<void> {\n\t\tif (\n\t\t\tthis._access === NVMAccess.Read\n\t\t\t|| this._access === NVMAccess.ReadWrite\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (this._access === NVMAccess.Write) {\n\t\t\tawait this._io.close();\n\t\t}\n\t\tthis._access = await this._io.open(NVMAccess.Read);\n\t}\n\n\tprivate async ensureWritable(): Promise<void> {\n\t\tif (\n\t\t\tthis._access === NVMAccess.Write\n\t\t\t|| this._access === NVMAccess.ReadWrite\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (this._access === NVMAccess.Read) {\n\t\t\tawait this._io.close();\n\t\t}\n\t\tthis._access = await this._io.open(NVMAccess.Write);\n\t}\n\n\tpublic async init(): Promise<NVM3FileSystemInfo> {\n\t\tawait this.ensureReadable();\n\n\t\tlet pageOffset = 0;\n\t\t// Determine NVM size, scan pages\n\t\tconst pages: NVM3PageInfo[] = [];\n\t\tlet isSharedFileSystem = false;\n\t\twhile (pageOffset < this._io.size) {\n\t\t\t// console.debug(\n\t\t\t// \t`NVM3 init() - reading page header at offset ${\n\t\t\t// \t\tnum2hex(pageOffset)\n\t\t\t// \t}`,\n\t\t\t// );\n\t\t\tconst header = await readPageHeader(this._io, pageOffset);\n\t\t\tpages.push({\n\t\t\t\t...header,\n\t\t\t\tobjects: [],\n\t\t\t});\n\t\t\tpageOffset += header.pageSize;\n\t\t}\n\n\t\t// Scan each page for objects\n\t\tfor (const page of pages) {\n\t\t\t// Scan objects in this page\n\t\t\tlet objectOffset = page.offset + NVM3_PAGE_HEADER_SIZE;\n\t\t\tconst nextPageOffset = page.offset + page.pageSize;\n\t\t\twhile (objectOffset < nextPageOffset) {\n\t\t\t\t// console.debug(\n\t\t\t\t// \t`NVM3 init() - reading object header. page offset ${\n\t\t\t\t// \t\tnum2hex(page.offset)\n\t\t\t\t// \t}, object offset ${num2hex(objectOffset)}`,\n\t\t\t\t// );\n\t\t\t\tconst objectHeader = await readObjectHeader(\n\t\t\t\t\tthis._io,\n\t\t\t\t\tobjectOffset,\n\t\t\t\t);\n\t\t\t\tif (objectHeader) {\n\t\t\t\t\tpage.objects.push(objectHeader);\n\t\t\t\t\tobjectOffset += objectHeader.alignedSize;\n\n\t\t\t\t\t// Detect the 800 series shared protocol & application NVM file system\n\t\t\t\t\t// by looking for the 800 series application version file\n\t\t\t\t\tif (objectHeader.key === ApplicationVersionFile800ID) {\n\t\t\t\t\t\tisSharedFileSystem = true;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Reached the end of the data in this page\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// By convention, we only use the applicationPages in that case\n\t\tlet applicationPages: NVM3PageInfo[];\n\t\tlet protocolPages: NVM3PageInfo[];\n\n\t\tif (isSharedFileSystem) {\n\t\t\tapplicationPages = pages;\n\t\t\tprotocolPages = [];\n\t\t} else {\n\t\t\tapplicationPages = pages.filter(\n\t\t\t\t(p) => p.offset < ZWAVE_APPLICATION_NVM_SIZE,\n\t\t\t);\n\t\t\tprotocolPages = pages.filter(\n\t\t\t\t(p) => p.offset >= ZWAVE_APPLICATION_NVM_SIZE,\n\t\t\t);\n\t\t}\n\n\t\t// NVM3 layouts pages in a ring buffer. Pages are written from front to back, then occupied pages\n\t\t// are erased and overwritten. Pages at the start of the memory section may have an erase count that's 1 higher\n\t\t// than the pages at the end.\n\t\tconst pageInfoToSectionInfo = (\n\t\t\tpages: NVM3PageInfo[],\n\t\t): NVM3SectionInfo => {\n\t\t\t// Find the current page, which is either:\n\t\t\t// - The last page with the high erase count that contains an object\n\t\t\tconst maxEraseCount = Math.max(...pages.map((p) => p.eraseCount));\n\t\t\tlet currentPageIndex = pages.findLastIndex((p) =>\n\t\t\t\tp.eraseCount === maxEraseCount && p.objects.length > 0\n\t\t\t);\n\t\t\t// - or if there is none, the last page with the lower erase count that contains an object\n\t\t\tif (currentPageIndex === -1) {\n\t\t\t\tcurrentPageIndex = pages.findLastIndex((p) =>\n\t\t\t\t\tp.objects.length > 0\n\t\t\t\t);\n\t\t\t}\n\t\t\t// - Or if no objects exist at all, the beginning of the section\n\t\t\tif (currentPageIndex === -1) currentPageIndex = 0;\n\n\t\t\t// Find the next free byte of the current page\n\t\t\tconst currentPage = pages[currentPageIndex];\n\t\t\tlet offset = NVM3_PAGE_HEADER_SIZE;\n\t\t\tfor (const object of currentPage.objects) {\n\t\t\t\toffset += object.alignedSize;\n\t\t\t}\n\n\t\t\tconst objectLocations = new Map<number, number>();\n\t\t\tfor (let i = 0; i < pages.length; i++) {\n\t\t\t\tconst page = pages[i];\n\t\t\t\tfor (const object of page.objects) {\n\t\t\t\t\tconst location = objectLocations.get(object.key);\n\t\t\t\t\tif (location == undefined) {\n\t\t\t\t\t\t// Object seen for the first time, remember the page it is in\n\t\t\t\t\t\tobjectLocations.set(object.key, i);\n\t\t\t\t\t} else if (\n\t\t\t\t\t\t(object.fragmentType === FragmentType.None\n\t\t\t\t\t\t\t|| object.fragmentType === FragmentType.First)\n\t\t\t\t\t\t&& (page.eraseCount >= pages[location].eraseCount)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Object was seen before. Only remember it if it is the only\n\t\t\t\t\t\t// or first fragment and the object appears in a later location\n\t\t\t\t\t\t// of the ring buffer\n\t\t\t\t\t\tobjectLocations.set(object.key, i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpages,\n\t\t\t\toffsetInPage: offset,\n\t\t\t\tcurrentPage: currentPageIndex,\n\t\t\t\tobjectLocations,\n\t\t\t};\n\t\t};\n\n\t\tif (isSharedFileSystem) {\n\t\t\tthis._info = {\n\t\t\t\tisSharedFileSystem: true,\n\t\t\t\tsections: {\n\t\t\t\t\tall: pageInfoToSectionInfo(applicationPages),\n\t\t\t\t},\n\t\t\t};\n\t\t} else {\n\t\t\tthis._info = {\n\t\t\t\tisSharedFileSystem: false,\n\t\t\t\tsections: {\n\t\t\t\t\tapplication: pageInfoToSectionInfo(applicationPages),\n\t\t\t\t\tprotocol: pageInfoToSectionInfo(protocolPages),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn this._info;\n\t}\n\n\tprivate getNVMSectionForFile(fileId: number): NVM3SectionInfo {\n\t\t// Determine which ring buffer to read in\n\t\treturn this._info!.isSharedFileSystem\n\t\t\t? this._info!.sections.all\n\t\t\t: this._info!.sections[getNVMSectionByFileID(fileId)];\n\t}\n\n\tpublic async has(fileId: number): Promise<boolean> {\n\t\tthis._info ??= await this.init();\n\n\t\t// Determine which ring buffer to read in\n\t\tconst section = this.getNVMSectionForFile(fileId);\n\n\t\treturn section.objectLocations.has(fileId);\n\t}\n\n\tpublic readObjectData(object: NVM3ObjectHeader): Promise<BytesView> {\n\t\treturn nvmReadBuffer(\n\t\t\tthis._io,\n\t\t\tobject.offset + object.headerSize,\n\t\t\tobject.fragmentSize,\n\t\t);\n\t}\n\n\tpublic async get(\n\t\tfileId: number,\n\t\tsection?: NVM3SectionInfo,\n\t): Promise<BytesView | undefined> {\n\t\tthis._info ??= await this.init();\n\n\t\t// Determine which ring buffer to read in, unless we were told to use a specific one\n\t\tsection ??= this.getNVMSectionForFile(fileId);\n\n\t\tconst pages = section.pages;\n\n\t\t// TODO: There should be no need for scanning, since we know the object locations after init().\n\n\t\t// Start scanning backwards through the pages ring buffer, starting with the current page\n\t\tlet parts: BytesView[] | undefined;\n\t\tlet complete = false;\n\t\tlet objType: ObjectType | undefined;\n\t\tconst resetFragments = () => {\n\t\t\t// if (parts?.length) {\n\t\t\t// \tconsole.debug(\"Resetting fragmented object\");\n\t\t\t// }\n\t\t\tparts = undefined;\n\t\t\tcomplete = false;\n\t\t};\n\t\tpages: for (let offset = 0; offset < pages.length; offset++) {\n\t\t\tconst index = (section.currentPage - offset + pages.length)\n\t\t\t\t% pages.length;\n\t\t\tconst page = pages[index];\n\t\t\t// console.debug(\n\t\t\t// \t`NVM3.get(${fileId}): scanning page ${index} at offset ${\n\t\t\t// \t\tnum2hex(page.offset)\n\t\t\t// \t}`,\n\t\t\t// );\n\t\t\t// Scan objects in this page, read backwards.\n\t\t\t// The last non-deleted object wins\n\t\t\tobjects: for (let j = page.objects.length - 1; j >= 0; j--) {\n\t\t\t\tconst object = page.objects[j];\n\n\t\t\t\tconst readObject = () => this.readObjectData(object);\n\n\t\t\t\tif (object.key !== fileId) {\n\t\t\t\t\t// Reset any fragmented objects when encountering a different key\n\t\t\t\t\tresetFragments();\n\t\t\t\t\tcontinue objects;\n\t\t\t\t}\n\n\t\t\t\tif (object.type === ObjectType.Deleted) {\n\t\t\t\t\t// Last action for this object was a deletion. There is no data.\n\t\t\t\t\treturn;\n\t\t\t\t} else if (object.fragmentType === FragmentType.None) {\n\t\t\t\t\t// console.debug(\n\t\t\t\t\t// \t`NVM3.get(${fileId}): found complete object - header offset ${\n\t\t\t\t\t// \t\tnum2hex(object.offset)\n\t\t\t\t\t// \t}, content offset ${\n\t\t\t\t\t// \t\tnum2hex(object.offset + object.headerSize)\n\t\t\t\t\t// \t}, length ${object.fragmentSize}`,\n\t\t\t\t\t// );\n\t\t\t\t\t// This is a complete object\n\t\t\t\t\tparts = [await readObject()];\n\t\t\t\t\tobjType = object.type;\n\t\t\t\t\tcomplete = true;\n\t\t\t\t\tbreak pages;\n\t\t\t\t} else if (object.fragmentType === FragmentType.Last) {\n\t\t\t\t\t// console.debug(\n\t\t\t\t\t// \t`NVM3.get(${fileId}): found LAST fragment - header offset ${\n\t\t\t\t\t// \t\tnum2hex(object.offset)\n\t\t\t\t\t// \t}, content offset ${\n\t\t\t\t\t// \t\tnum2hex(object.offset + object.headerSize)\n\t\t\t\t\t// \t}, length ${object.fragmentSize}`,\n\t\t\t\t\t// );\n\t\t\t\t\tparts = [await readObject()];\n\t\t\t\t\tobjType = object.type;\n\t\t\t\t\tcomplete = false;\n\t\t\t\t} else if (object.fragmentType === FragmentType.Next) {\n\t\t\t\t\tif (parts?.length && objType === object.type) {\n\t\t\t\t\t\t// console.debug(\n\t\t\t\t\t\t// \t`NVM3.get(${fileId}): found NEXT fragment - header offset ${\n\t\t\t\t\t\t// \t\tnum2hex(object.offset)\n\t\t\t\t\t\t// \t}, content offset ${\n\t\t\t\t\t\t// \t\tnum2hex(object.offset + object.headerSize)\n\t\t\t\t\t\t// \t}, length ${object.fragmentSize}`,\n\t\t\t\t\t\t// );\n\t\t\t\t\t\tparts.unshift(await readObject());\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This shouldn't be here\n\t\t\t\t\t\tresetFragments();\n\t\t\t\t\t}\n\t\t\t\t} else if (object.fragmentType === FragmentType.First) {\n\t\t\t\t\tif (parts?.length && objType === object.type) {\n\t\t\t\t\t\t// console.debug(\n\t\t\t\t\t\t// \t`NVM3.get(${fileId}): found FIRST fragment - header offset ${\n\t\t\t\t\t\t// \t\tnum2hex(object.offset)\n\t\t\t\t\t\t// \t}, content offset ${\n\t\t\t\t\t\t// \t\tnum2hex(object.offset + object.headerSize)\n\t\t\t\t\t\t// \t}, length ${object.fragmentSize}`,\n\t\t\t\t\t\t// );\n\t\t\t\t\t\tparts.unshift(await readObject());\n\t\t\t\t\t\tcomplete = true;\n\t\t\t\t\t\tbreak pages;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This shouldn't be here\n\t\t\t\t\t\tresetFragments();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!parts?.length || !complete || objType == undefined) return;\n\n\t\treturn Bytes.concat(parts);\n\t}\n\n\tprivate async writeObjects(objects: NVM3Object[]): Promise<void> {\n\t\tconst section = this.getNVMSectionForFile(objects[0].key);\n\n\t\tlet page = section.pages[section.currentPage];\n\t\tlet remainingSpace = page.pageSize\n\t\t\t- NVM3_PAGE_HEADER_SIZE\n\t\t\t- section.offsetInPage;\n\n\t\t// TODO: See if we can avoid double writes on a page change\n\n\t\t/** Moves to the next page and erases it if necessary */\n\t\tconst nextPage = async () => {\n\t\t\tsection.currentPage = (section.currentPage + 1)\n\t\t\t\t% section.pages.length;\n\t\t\tpage = section.pages[section.currentPage];\n\n\t\t\t// Find headers of objects that need to be preserved\n\t\t\tconst toPreserve = [...section.objectLocations].filter((\n\t\t\t\t[, pageIndex],\n\t\t\t) => pageIndex === section.currentPage)\n\t\t\t\t.map(([fileID]) =>\n\t\t\t\t\tpage.objects.findLast((h) => h.key === fileID)\n\t\t\t\t)\n\t\t\t\t.filter((h) => h != undefined)\n\t\t\t\t.filter((h) => h.type !== ObjectType.Deleted);\n\t\t\t// And add the objects to the TODO list\n\t\t\tfor (const header of toPreserve) {\n\t\t\t\tconst data = await this.get(header.key);\n\t\t\t\tconsole.error(`Need to preserve object ${num2hex(header.key)}\n page index: ${section.currentPage}\n object type: ${getEnumMemberName(ObjectType, header.type)}\n data: ${data != undefined ? `${data.length} bytes` : \"(no data)\"}`);\n\t\t\t\tobjects.push({\n\t\t\t\t\tkey: header.key,\n\t\t\t\t\ttype: header.type,\n\t\t\t\t\tfragmentType: FragmentType.None,\n\t\t\t\t\tdata,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (page.objects.length > 0) {\n\t\t\t\t// The page needs to be erased\n\t\t\t\tpage.eraseCount++;\n\t\t\t\tpage.objects = [];\n\n\t\t\t\tconst pageHeaderBuffer = serializePageHeader(page);\n\t\t\t\tconst pageBuffer = new Uint8Array(page.pageSize).fill(0xff);\n\t\t\t\tpageBuffer.set(pageHeaderBuffer, 0);\n\n\t\t\t\tawait nvmWriteBuffer(this._io, page.offset, pageBuffer);\n\t\t\t}\n\n\t\t\tsection.offsetInPage = NVM3_PAGE_HEADER_SIZE;\n\t\t\tremainingSpace = page.pageSize - NVM3_PAGE_HEADER_SIZE;\n\t\t};\n\n\t\t// Go through the list of objects and write all of them to the NVM\n\t\tfor (const object of objects) {\n\t\t\tconst isLargeObject = object.type === ObjectType.DataLarge\n\t\t\t\t|| object.type === ObjectType.CounterLarge;\n\n\t\t\tlet fragments: NVM3Object[] | undefined;\n\n\t\t\tif (isLargeObject) {\n\t\t\t\t// Large objects may be fragmented\n\n\t\t\t\t// We need to start a new page, if the remaining space is not enough for\n\t\t\t\t// the object header plus additional data\n\t\t\t\tif (remainingSpace <= NVM3_OBJ_HEADER_SIZE_LARGE) {\n\t\t\t\t\tawait nextPage();\n\t\t\t\t}\n\n\t\t\t\tfragments = fragmentLargeObject(\n\t\t\t\t\tobject as any,\n\t\t\t\t\tremainingSpace,\n\t\t\t\t\tpage.pageSize - NVM3_PAGE_HEADER_SIZE,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Small objects cannot be fragmented. If they don't fit,\n\t\t\t\t// they need to go on the next page.\n\t\t\t\tconst requiredSpace = getRequiredSpace(object);\n\t\t\t\tif (requiredSpace > remainingSpace) {\n\t\t\t\t\tawait nextPage();\n\t\t\t\t}\n\t\t\t\tfragments = [object];\n\t\t\t}\n\n\t\t\t// Write each fragment to the NVM. If there are multiple fragments,\n\t\t\t// each one but the first needs to be written at the beginning of a new page\n\t\t\tfor (let i = 0; i < fragments.length; i++) {\n\t\t\t\tif (i > 0) await nextPage();\n\t\t\t\tconst fragment = fragments[i];\n\n\t\t\t\tconst objBuffer = serializeObject(fragment);\n\t\t\t\tconst objOffset = page.offset + section.offsetInPage;\n\t\t\t\tawait this._io.write(objOffset, objBuffer);\n\t\t\t\tconst requiredSpace = getRequiredSpace(fragment);\n\t\t\t\tsection.offsetInPage += requiredSpace;\n\t\t\t\tremainingSpace -= requiredSpace;\n\n\t\t\t\t// Remember which objects exist in this page\n\t\t\t\tpage.objects.push(getObjectHeader(object, objOffset));\n\n\t\t\t\t// And remember where this object lives\n\t\t\t\tif (object.type === ObjectType.Deleted) {\n\t\t\t\t\tsection.objectLocations.delete(object.key);\n\t\t\t\t} else if (\n\t\t\t\t\tfragment.fragmentType === FragmentType.None\n\t\t\t\t\t|| fragment.fragmentType === FragmentType.First\n\t\t\t\t) {\n\t\t\t\t\tsection.objectLocations.set(\n\t\t\t\t\t\tfragment.key,\n\t\t\t\t\t\tsection.currentPage,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async set(property: number, value: BytesView): Promise<void> {\n\t\tif (!this._info) await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tawait this.writeObjects([{\n\t\t\tkey: property,\n\t\t\ttype: value.length <= NVM3_MAX_OBJ_SIZE_SMALL\n\t\t\t\t? ObjectType.DataSmall\n\t\t\t\t: ObjectType.DataLarge,\n\t\t\t// writeObject deals with fragmentation\n\t\t\tfragmentType: FragmentType.None,\n\t\t\tdata: value,\n\t\t}]);\n\t}\n\n\t/** Writes multiple values to the NVM at once. `null` / `undefined` cause the value to be deleted */\n\tpublic async setMany(\n\t\tvalues: [number, BytesView | null | undefined][],\n\t): Promise<void> {\n\t\tif (!this._info) await this.init();\n\t\tawait this.ensureWritable();\n\n\t\t// Group objects by their NVM section\n\t\tconst objectsBySection = new Map<\n\t\t\tnumber, /* offset */\n\t\t\t[number, BytesView | null | undefined][]\n\t\t>();\n\t\tfor (const [key, value] of values) {\n\t\t\tconst sectionOffset =\n\t\t\t\tthis.getNVMSectionForFile(key).pages[0].offset;\n\t\t\tif (!objectsBySection.has(sectionOffset)) {\n\t\t\t\tobjectsBySection.set(sectionOffset, []);\n\t\t\t}\n\t\t\tobjectsBySection.get(sectionOffset)!.push([key, value]);\n\t\t}\n\n\t\t// And call writeObjects for each group\n\t\tfor (const objectGroups of objectsBySection.values()) {\n\t\t\tawait this.writeObjects(\n\t\t\t\tobjectGroups.map(([key, value]) => (value\n\t\t\t\t\t? {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\ttype: value.length <= NVM3_MAX_OBJ_SIZE_SMALL\n\t\t\t\t\t\t\t? ObjectType.DataSmall\n\t\t\t\t\t\t\t: ObjectType.DataLarge,\n\t\t\t\t\t\t// writeObject deals with fragmentation\n\t\t\t\t\t\tfragmentType: FragmentType.None,\n\t\t\t\t\t\tdata: value,\n\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\ttype: ObjectType.Deleted,\n\t\t\t\t\t\tfragmentType: FragmentType.None,\n\t\t\t\t\t})\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic async delete(property: number): Promise<void> {\n\t\tif (!this._info) await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tawait this.writeObjects([{\n\t\t\tkey: property,\n\t\t\ttype: ObjectType.Deleted,\n\t\t\tfragmentType: FragmentType.None,\n\t\t}]);\n\t}\n\n\tpublic async erase(options?: NVM3EraseOptions): Promise<void> {\n\t\tconst {\n\t\t\tdeviceFamily = 2047,\n\t\t\twriteSize = PageWriteSize.WRITE_SIZE_16,\n\t\t\tmemoryMapped = true,\n\t\t\tsharedFileSystem = false,\n\t\t} = options ?? {};\n\t\tconst maxPageSize = sharedFileSystem\n\t\t\t? FLASH_MAX_PAGE_SIZE_800\n\t\t\t: FLASH_MAX_PAGE_SIZE_700;\n\t\tconst pageSize = Math.min(\n\t\t\toptions?.pageSize ?? maxPageSize,\n\t\t\tmaxPageSize,\n\t\t);\n\n\t\t// Make sure we won't be writing incomplete pages\n\t\tif (this._io.size % pageSize !== 0) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Invalid page size. NVM size ${this._io.size} must be a multiple of the page size ${pageSize}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t} else if (\n\t\t\t!sharedFileSystem && ZWAVE_APPLICATION_NVM_SIZE % pageSize !== 0\n\t\t) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Invalid page size. The application NVM size ${ZWAVE_APPLICATION_NVM_SIZE} must be a multiple of the page size ${pageSize}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t} else if (\n\t\t\t!sharedFileSystem\n\t\t\t&& (this._io.size - ZWAVE_APPLICATION_NVM_SIZE) % pageSize !== 0\n\t\t) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Invalid page size. The protocol NVM size ${\n\t\t\t\t\tthis._io.size\n\t\t\t\t\t- ZWAVE_APPLICATION_NVM_SIZE\n\t\t\t\t} must be a multiple of the page size ${pageSize}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t}\n\n\t\tawait this.ensureWritable();\n\n\t\t// Create empty pages, write them to the NVM\n\t\tconst applicationPages: NVM3PageInfo[] = [];\n\t\tconst protocolPages: NVM3PageInfo[] = [];\n\n\t\tconst numPages = this._io.size / pageSize;\n\t\tfor (let i = 0; i < numPages; i++) {\n\t\t\tconst offset = i * pageSize;\n\t\t\tconst pageBuffer = new Uint8Array(pageSize).fill(0xff);\n\t\t\tconst pageHeader: NVM3PageHeader = {\n\t\t\t\toffset,\n\t\t\t\tversion: 0x01,\n\t\t\t\teraseCount: 0,\n\t\t\t\tencrypted: false,\n\t\t\t\tdeviceFamily,\n\t\t\t\tmemoryMapped,\n\t\t\t\tpageSize,\n\t\t\t\tstatus: PageStatus.OK,\n\t\t\t\twriteSize,\n\t\t\t};\n\t\t\tpageBuffer.set(serializePageHeader(pageHeader), 0);\n\t\t\tawait nvmWriteBuffer(this._io, offset, pageBuffer);\n\n\t\t\tif (sharedFileSystem || offset < ZWAVE_APPLICATION_NVM_SIZE) {\n\t\t\t\tapplicationPages.push({ ...pageHeader, objects: [] });\n\t\t\t} else {\n\t\t\t\tprotocolPages.push({ ...pageHeader, objects: [] });\n\t\t\t}\n\t\t}\n\n\t\t// Remember the pages we just created for further use\n\t\tthis._info = sharedFileSystem\n\t\t\t? {\n\t\t\t\tisSharedFileSystem: true,\n\t\t\t\tsections: {\n\t\t\t\t\tall: {\n\t\t\t\t\t\tcurrentPage: 0,\n\t\t\t\t\t\tobjectLocations: new Map(),\n\t\t\t\t\t\toffsetInPage: NVM3_PAGE_HEADER_SIZE,\n\t\t\t\t\t\tpages: applicationPages,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}\n\t\t\t: {\n\t\t\t\tisSharedFileSystem: false,\n\t\t\t\tsections: {\n\t\t\t\t\tapplication: {\n\t\t\t\t\t\tcurrentPage: 0,\n\t\t\t\t\t\tobjectLocations: new Map(),\n\t\t\t\t\t\toffsetInPage: NVM3_PAGE_HEADER_SIZE,\n\t\t\t\t\t\tpages: applicationPages,\n\t\t\t\t\t},\n\t\t\t\t\tprotocol: {\n\t\t\t\t\t\tcurrentPage: 0,\n\t\t\t\t\t\tobjectLocations: new Map(),\n\t\t\t\t\t\toffsetInPage: NVM3_PAGE_HEADER_SIZE,\n\t\t\t\t\t\tpages: protocolPages,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\nasync function readPageHeader(\n\tio: NVMIO,\n\toffset: number,\n): Promise<NVM3PageHeader> {\n\tif (offset > io.size - NVM3_PAGE_HEADER_SIZE) {\n\t\tthrow new ZWaveError(\n\t\t\t\"Incomplete page in buffer!\",\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\tconst buffer = Bytes.view(\n\t\t(await io.read(offset, NVM3_PAGE_HEADER_SIZE)).buffer,\n\t);\n\n\tconst { version, eraseCount } = tryGetVersionAndEraseCount(buffer);\n\n\t// Page status\n\tconst status = buffer.readUInt32LE(12);\n\n\tconst devInfo = buffer.readUInt16LE(16);\n\tconst deviceFamily = devInfo & 0x7ff;\n\tconst writeSize = (devInfo >> 11) & 0b1;\n\tconst memoryMapped = !!((devInfo >> 12) & 0b1);\n\tlet pageSize = pageSizeFromBits((devInfo >> 13) & 0b111);\n\n\tif (pageSize > 0xffff) {\n\t\t// Some controllers have no valid info in the page size bits, resulting\n\t\t// in an impossibly large page size. To try and figure out the actual page\n\t\t// size without knowing the hardware, we scan the buffer for the next valid\n\t\t// page start.\n\t\tfor (let exponent = 0; exponent < 0b111; exponent++) {\n\t\t\tconst testPageSize = pageSizeFromBits(exponent);\n\t\t\tconst nextOffset = offset + testPageSize;\n\t\t\tif (\n\t\t\t\t// exactly end of NVM OR\n\t\t\t\tio.size === nextOffset\n\t\t\t\t// next page\n\t\t\t\t|| await isValidPageHeaderAtOffset(io, nextOffset)\n\t\t\t) {\n\t\t\t\tpageSize = testPageSize;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (pageSize > 0xffff) {\n\t\tthrow new ZWaveError(\n\t\t\t\"Could not determine page size!\",\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\tif (io.size < offset + pageSize) {\n\t\tthrow new ZWaveError(\n\t\t\t`NVM contains incomplete page at offset ${num2hex(offset)}!`,\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\tconst formatInfo = buffer.readUInt16LE(18);\n\tconst encrypted = !(formatInfo & 0b1);\n\n\treturn {\n\t\toffset,\n\t\tversion,\n\t\teraseCount,\n\t\tstatus,\n\t\tencrypted,\n\t\tpageSize,\n\t\twriteSize,\n\t\tmemoryMapped,\n\t\tdeviceFamily,\n\t};\n}\n\nfunction tryGetVersionAndEraseCount(\n\theader: BytesView,\n): { version: number; eraseCount: number } {\n\tconst buffer = Bytes.view(header);\n\tconst version = buffer.readUInt16LE(0);\n\tconst magic = buffer.readUInt16LE(2);\n\tif (magic !== NVM3_PAGE_MAGIC) {\n\t\tthrow new ZWaveError(\n\t\t\t\"Not a valid NVM3 page!\",\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\tif (version !== 0x01) {\n\t\tthrow new ZWaveError(\n\t\t\t`Unsupported NVM3 page version: ${version}`,\n\t\t\tZWaveErrorCodes.NVM_NotSupported,\n\t\t);\n\t}\n\n\t// The erase counter is saved twice, once normally, once inverted\n\tlet eraseCount = buffer.readUInt32LE(4);\n\tconst eraseCountCode = eraseCount >>> NVM3_PAGE_COUNTER_SIZE;\n\teraseCount &= NVM3_PAGE_COUNTER_MASK;\n\tvalidateBergerCode(eraseCount, eraseCountCode, NVM3_PAGE_COUNTER_SIZE);\n\n\tlet eraseCountInv = buffer.readUInt32LE(8);\n\tconst eraseCountInvCode = eraseCountInv >>> NVM3_PAGE_COUNTER_SIZE;\n\teraseCountInv &= NVM3_PAGE_COUNTER_MASK;\n\tvalidateBergerCode(\n\t\teraseCountInv,\n\t\teraseCountInvCode,\n\t\tNVM3_PAGE_COUNTER_SIZE,\n\t);\n\n\tif (eraseCount !== (~eraseCountInv & NVM3_PAGE_COUNTER_MASK)) {\n\t\tthrow new ZWaveError(\n\t\t\t\"Invalid erase count!\",\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\treturn { version, eraseCount };\n}\n\nasync function isValidPageHeaderAtOffset(\n\tio: NVMIO,\n\toffset: number,\n): Promise<boolean> {\n\tif (offset > io.size - NVM3_PAGE_HEADER_SIZE) {\n\t\treturn false;\n\t}\n\n\tconst { buffer } = await io.read(offset, NVM3_PAGE_HEADER_SIZE);\n\n\ttry {\n\t\ttryGetVersionAndEraseCount(buffer);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function readObjectHeader(\n\tio: NVMIO,\n\toffset: number,\n): Promise<NVM3ObjectHeader | undefined> {\n\tlet headerSize = 4;\n\tconst hdr1 = await nvmReadUInt32LE(io, offset);\n\n\t// Skip over blank page areas\n\tif (hdr1 === 0xffffffff) return;\n\n\tconst key = (hdr1 >> NVM3_OBJ_KEY_SHIFT) & NVM3_OBJ_KEY_MASK;\n\tlet objType: ObjectType = hdr1 & NVM3_OBJ_TYPE_MASK;\n\tlet fragmentSize = 0;\n\tlet hdr2: number | undefined;\n\tconst isLarge = objType === ObjectType.DataLarge\n\t\t|| objType === ObjectType.CounterLarge;\n\tif (isLarge) {\n\t\thdr2 = await nvmReadUInt32LE(io, offset + 4);\n\t\theaderSize += 4;\n\t\tfragmentSize = hdr2 & NVM3_OBJ_LARGE_LEN_MASK;\n\t} else if (objType > ObjectType.DataSmall) {\n\t\t// In small objects with data, the length and object type are stored in the same value\n\t\tfragmentSize = objType - ObjectType.DataSmall;\n\t\tobjType = ObjectType.DataSmall;\n\t} else if (objType === ObjectType.CounterSmall) {\n\t\tfragmentSize = NVM3_COUNTER_SIZE;\n\t}\n\n\tconst fragmentType: FragmentType = isLarge\n\t\t? (hdr1 >>> NVM3_OBJ_FRAGTYPE_SHIFT) & NVM3_OBJ_FRAGTYPE_MASK\n\t\t: FragmentType.None;\n\n\tif (isLarge) {\n\t\tvalidateBergerCodeMulti([hdr1, hdr2!], 32 + NVM3_CODE_LARGE_SHIFT);\n\t} else {\n\t\tvalidateBergerCodeMulti([hdr1], NVM3_CODE_SMALL_SHIFT);\n\t}\n\n\tif (io.size < offset + headerSize + fragmentSize) {\n\t\tthrow new ZWaveError(\n\t\t\t`NVM contains incomplete object at offset ${num2hex(offset)}!`,\n\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t);\n\t}\n\n\tconst alignedFragmentSize = getAlignedSize(fragmentSize);\n\tconst alignedSize = headerSize + alignedFragmentSize;\n\n\treturn {\n\t\tkey,\n\t\toffset,\n\t\ttype: objType,\n\t\tfragmentType,\n\t\theaderSize,\n\t\tfragmentSize,\n\t\talignedSize,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kBAA4C;AAC5C,oBAKO;AACP,yBAAgD;AAChD,mBAIO;AACP,oBAuBO;AACP,mBAIO;AACP,oBAQO;AACP,kBAIO;AACP,IAAAA,gBAA4D;AAyCtD,MAAO,KAAI;EAjGjB,OAiGiB;;;EAChB,YAAmB,IAAS;AAC3B,SAAK,MAAM;EACZ;EAEQ;EACA,UAAqB,6BAAU;EAE/B;EACR,IAAW,OAAI;AACd,WAAO,KAAK;EACb;EAEQ,MAAM,iBAAc;AAC3B,QACC,KAAK,YAAY,6BAAU,QACxB,KAAK,YAAY,6BAAU,WAC7B;AACD;IACD;AACA,QAAI,KAAK,YAAY,6BAAU,OAAO;AACrC,YAAM,KAAK,IAAI,MAAK;IACrB;AACA,SAAK,UAAU,MAAM,KAAK,IAAI,KAAK,6BAAU,IAAI;EAClD;EAEQ,MAAM,iBAAc;AAC3B,QACC,KAAK,YAAY,6BAAU,SACxB,KAAK,YAAY,6BAAU,WAC7B;AACD;IACD;AACA,QAAI,KAAK,YAAY,6BAAU,MAAM;AACpC,YAAM,KAAK,IAAI,MAAK;IACrB;AACA,SAAK,UAAU,MAAM,KAAK,IAAI,KAAK,6BAAU,KAAK;EACnD;EAEO,MAAM,OAAI;AAChB,UAAM,KAAK,eAAc;AAEzB,QAAI,aAAa;AAEjB,UAAM,QAAwB,CAAA;AAC9B,QAAI,qBAAqB;AACzB,WA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T,gDAA4C,uBAAQ,MAAM,CAAC,KAC3D,4BAAgB,iBAAiB;EAEnC;AAEA,QAAM,0BAAsB,8BAAe,YAAY;AACvD,QAAM,cAAc,aAAa;AAEjC,SAAO;IACN;IACA;IACA,MAAM;IACN;IACA;IACA;IACA;;AAEF;AAzDe;",
|
|
6
6
|
"names": ["import_utils", "pages"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/NVM500.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tMAX_NODES,\n\tZWaveError,\n\tZWaveErrorCodes,\n\tencodeBitMask,\n\tparseBitMask,\n} from \"@zwave-js/core\";\nimport { Bytes } from \"@zwave-js/shared\";\nimport { type NVM, NVMAccess, type NVMIO } from \"./common/definitions.js\";\nimport { type Route, encodeRoute, parseRoute } from \"./common/routeCache.js\";\nimport {\n\ttype SUCUpdateEntry,\n\tencodeSUCUpdateEntry,\n\tparseSUCUpdateEntry,\n} from \"./common/sucUpdateEntry.js\";\nimport {\n\tnvmReadBuffer,\n\tnvmReadUInt16BE,\n\tnvmWriteBuffer,\n} from \"./common/utils.js\";\nimport {\n\ttype NVM500NodeInfo,\n\ttype NVMDescriptor,\n\ttype NVMModuleDescriptor,\n\tencodeNVM500NodeInfo,\n\tencodeNVMDescriptor,\n\tencodeNVMModuleDescriptor,\n\tparseNVM500NodeInfo,\n\tparseNVMDescriptor,\n\tparseNVMModuleDescriptor,\n} from \"./nvm500/EntryParsers.js\";\nimport { nvm500Impls } from \"./nvm500/impls/index.js\";\nimport {\n\tCONFIGURATION_VALID_0,\n\tCONFIGURATION_VALID_1,\n\tMAGIC_VALUE,\n\ttype NVM500Impl,\n\ttype NVMData,\n\ttype NVMEntryName,\n\tNVMEntrySizes,\n\tNVMEntryType,\n\tNVMModuleType,\n\tROUTECACHE_VALID,\n\ttype ResolvedNVMEntry,\n\ttype ResolvedNVMLayout,\n} from \"./nvm500/shared.js\";\n\nexport interface NVM500Info {\n\tlayout: ResolvedNVMLayout;\n\tlibrary: NVM500Impl[\"library\"];\n\tmoduleDescriptors: Map<NVMEntryName, NVMModuleDescriptor>;\n\tnvmDescriptor: NVMDescriptor;\n}\n\nexport type NVM500EraseOptions = {\n\tlayout: ResolvedNVMLayout;\n\tnvmSize: number;\n\tlibrary: NVM500Impl[\"library\"];\n\tnvmDescriptor: NVMDescriptor;\n};\n\nexport class NVM500 implements NVM<NVMEntryName, NVMData[]> {\n\tpublic constructor(io: NVMIO) {\n\t\tthis._io = io;\n\t}\n\n\tprivate _io: NVMIO;\n\tprivate _access: NVMAccess = NVMAccess.None;\n\n\tprivate _info: NVM500Info | undefined;\n\tpublic get info(): NVM500Info | undefined {\n\t\treturn this._info;\n\t}\n\n\tprivate async ensureReadable(): Promise<void> {\n\t\tif (\n\t\t\tthis._access === NVMAccess.Read\n\t\t\t|| this._access === NVMAccess.ReadWrite\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (this._access === NVMAccess.Write) {\n\t\t\tawait this._io.close();\n\t\t}\n\t\tthis._access = await this._io.open(NVMAccess.Read);\n\t}\n\n\tprivate async ensureWritable(): Promise<void> {\n\t\tif (\n\t\t\tthis._access === NVMAccess.Write\n\t\t\t|| this._access === NVMAccess.ReadWrite\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (this._access === NVMAccess.Read) {\n\t\t\tawait this._io.close();\n\t\t}\n\t\tthis._access = await this._io.open(NVMAccess.Write);\n\t}\n\n\tpublic async init(): Promise<NVM500Info> {\n\t\tawait this.ensureReadable();\n\n\t\t// Try the different known layouts to find one that works\n\t\tfor (const impl of nvm500Impls) {\n\t\t\ttry {\n\t\t\t\tconst info = await this.resolveLayout(impl);\n\t\t\t\tif (await this.isLayoutValid(info, impl.protocolVersions)) {\n\t\t\t\t\tthis._info = info;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (!this._info) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"Did not find a matching NVM 500 parser implementation! Make sure that the NVM data belongs to a controller with Z-Wave SDK 6.61 or higher.\",\n\t\t\t\tZWaveErrorCodes.NVM_NotSupported,\n\t\t\t);\n\t\t}\n\n\t\treturn this._info;\n\t}\n\n\tprivate async resolveLayout(impl: NVM500Impl): Promise<NVM500Info> {\n\t\tconst resolvedLayout = new Map<NVMEntryName, ResolvedNVMEntry>();\n\t\tlet nvmDescriptor: NVMDescriptor | undefined;\n\t\tconst moduleDescriptors = new Map<NVMEntryName, NVMModuleDescriptor>();\n\n\t\tlet offset = 0;\n\t\tlet moduleStart = -1;\n\t\tlet moduleSize = -1;\n\t\tconst nvmEnd = await nvmReadUInt16BE(this._io, 0);\n\n\t\tfor (const entry of impl.layout) {\n\t\t\tconst size = entry.size ?? NVMEntrySizes[entry.type];\n\n\t\t\tif (entry.type === NVMEntryType.NVMModuleSize) {\n\t\t\t\tif (moduleStart !== -1) {\n\t\t\t\t\t// All following NVM modules must start at the last module's end\n\t\t\t\t\toffset = moduleStart + moduleSize;\n\t\t\t\t}\n\n\t\t\t\tmoduleStart = offset;\n\t\t\t\tmoduleSize = await nvmReadUInt16BE(this._io, offset);\n\t\t\t} else if (entry.type === NVMEntryType.NVMModuleDescriptor) {\n\t\t\t\t// The module descriptor is always at the end of the module\n\t\t\t\toffset = moduleStart + moduleSize - size;\n\t\t\t}\n\n\t\t\tif (entry.offset != undefined && entry.offset !== offset) {\n\t\t\t\t// The entry has a defined offset but is at the wrong location\n\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t`${entry.name} is at wrong location in NVM buffer!`,\n\t\t\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst resolvedEntry: ResolvedNVMEntry = {\n\t\t\t\t...entry,\n\t\t\t\toffset,\n\t\t\t\tsize,\n\t\t\t};\n\n\t\t\tif (entry.type === NVMEntryType.NVMDescriptor) {\n\t\t\t\tconst entryData = await this.readRawEntry(resolvedEntry);\n\t\t\t\t// NVMDescriptor is always a single entry\n\t\t\t\tnvmDescriptor = parseNVMDescriptor(entryData[0]);\n\t\t\t} else if (entry.type === NVMEntryType.NVMModuleDescriptor) {\n\t\t\t\tconst entryData = await this.readRawEntry(resolvedEntry);\n\t\t\t\t// NVMModuleDescriptor is always a single entry\n\t\t\t\tconst descriptor = parseNVMModuleDescriptor(\n\t\t\t\t\tentryData[0],\n\t\t\t\t);\n\t\t\t\tif (descriptor.size !== moduleSize) {\n\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\"NVM module descriptor size does not match module size!\",\n\t\t\t\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tmoduleDescriptors.set(entry.name, descriptor);\n\t\t\t}\n\n\t\t\tresolvedLayout.set(entry.name, resolvedEntry);\n\n\t\t\t// Skip forward\n\t\t\toffset += size * entry.count;\n\t\t\tif (offset >= nvmEnd) break;\n\t\t}\n\n\t\tif (!nvmDescriptor) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"NVM descriptor not found in NVM!\",\n\t\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tlayout: resolvedLayout,\n\t\t\tlibrary: impl.library,\n\t\t\tmoduleDescriptors,\n\t\t\tnvmDescriptor,\n\t\t};\n\t}\n\n\tprivate async isLayoutValid(\n\t\tinfo: NVM500Info,\n\t\tprotocolVersions: string[],\n\t): Promise<boolean> {\n\t\t// Checking if an NVM is valid requires checking multiple bytes at different locations\n\t\tconst eeoffset_magic_entry = info.layout.get(\"EEOFFSET_MAGIC_far\");\n\t\tif (!eeoffset_magic_entry) return false;\n\t\tconst eeoffset_magic =\n\t\t\t(await this.readEntry(eeoffset_magic_entry))[0] as number;\n\n\t\tconst configuration_valid_0_entry = info.layout.get(\n\t\t\t\"NVM_CONFIGURATION_VALID_far\",\n\t\t);\n\t\tif (!configuration_valid_0_entry) return false;\n\t\tconst configuration_valid_0 =\n\t\t\t(await this.readEntry(configuration_valid_0_entry))[0] as number;\n\n\t\tconst configuration_valid_1_entry = info.layout.get(\n\t\t\t\"NVM_CONFIGURATION_REALLYVALID_far\",\n\t\t);\n\t\tif (!configuration_valid_1_entry) return false;\n\t\tconst configuration_valid_1 =\n\t\t\t(await this.readEntry(configuration_valid_1_entry))[0] as number;\n\n\t\tconst routecache_valid_entry = info.layout.get(\n\t\t\t\"EX_NVM_ROUTECACHE_MAGIC_far\",\n\t\t);\n\t\tif (!routecache_valid_entry) return false;\n\t\tconst routecache_valid =\n\t\t\t(await this.readEntry(routecache_valid_entry))[0] as number;\n\n\t\tconst endMarker_entry = info.layout.get(\"nvmModuleSizeEndMarker\");\n\t\tif (!endMarker_entry) return false;\n\t\tconst endMarker = (await this.readEntry(endMarker_entry))[0] as number;\n\n\t\treturn (\n\t\t\teeoffset_magic === MAGIC_VALUE\n\t\t\t&& configuration_valid_0 === CONFIGURATION_VALID_0\n\t\t\t&& configuration_valid_1 === CONFIGURATION_VALID_1\n\t\t\t&& routecache_valid === ROUTECACHE_VALID\n\t\t\t&& protocolVersions.includes(info.nvmDescriptor.protocolVersion)\n\t\t\t&& endMarker === 0\n\t\t);\n\t}\n\n\tasync has(property: NVMEntryName): Promise<boolean> {\n\t\tthis._info ??= await this.init();\n\t\treturn this._info.layout.has(property);\n\t}\n\n\tprivate async readSingleRawEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tindex: number,\n\t): Promise<Uint8Array> {\n\t\tif (index >= entry.count) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Index out of range. Tried to read entry ${index} of ${entry.count}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t}\n\t\treturn nvmReadBuffer(\n\t\t\tthis._io,\n\t\t\tentry.offset + index * entry.size,\n\t\t\tentry.size,\n\t\t);\n\t}\n\n\tprivate async readRawEntry(\n\t\tentry: ResolvedNVMEntry,\n\t): Promise<Uint8Array[]> {\n\t\tconst ret: Uint8Array[] = [];\n\t\tconst nvmData = await nvmReadBuffer(\n\t\t\tthis._io,\n\t\t\tentry.offset,\n\t\t\tentry.count * entry.size,\n\t\t);\n\t\tfor (let i = 0; i < entry.count; i++) {\n\t\t\tret.push(\n\t\t\t\tnvmData.subarray(i * entry.size, (i + 1) * entry.size),\n\t\t\t);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tprivate parseEntry(type: NVMEntryType, data: Bytes): NVMData {\n\t\tswitch (type) {\n\t\t\tcase NVMEntryType.Byte:\n\t\t\t\treturn data.readUInt8(0);\n\t\t\tcase NVMEntryType.Word:\n\t\t\tcase NVMEntryType.NVMModuleSize:\n\t\t\t\treturn data.readUInt16BE(0);\n\t\t\tcase NVMEntryType.DWord:\n\t\t\t\treturn data.readUInt32BE(0);\n\t\t\tcase NVMEntryType.NodeInfo:\n\t\t\t\tif (data.every((byte) => byte === 0)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\treturn parseNVM500NodeInfo(data, 0);\n\t\t\tcase NVMEntryType.NodeMask:\n\t\t\t\treturn parseBitMask(data);\n\t\t\tcase NVMEntryType.SUCUpdateEntry:\n\t\t\t\tif (data.every((byte) => byte === 0)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\treturn parseSUCUpdateEntry(data, 0);\n\t\t\tcase NVMEntryType.Route:\n\t\t\t\tif (data.every((byte) => byte === 0)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\treturn parseRoute(data, 0);\n\t\t\tcase NVMEntryType.NVMModuleDescriptor: {\n\t\t\t\treturn parseNVMModuleDescriptor(data);\n\t\t\t}\n\t\t\tcase NVMEntryType.NVMDescriptor:\n\t\t\t\treturn parseNVMDescriptor(data);\n\t\t\tdefault:\n\t\t\t\t// This includes NVMEntryType.BUFFER\n\t\t\t\treturn data;\n\t\t}\n\t}\n\n\tprivate async readEntry(\n\t\tentry: ResolvedNVMEntry,\n\t): Promise<NVMData[]> {\n\t\tconst data: Uint8Array[] = await this.readRawEntry(entry);\n\t\treturn data.map((buffer) =>\n\t\t\tthis.parseEntry(entry.type, Bytes.view(buffer))\n\t\t);\n\t}\n\n\tprivate async readSingleEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tindex: number,\n\t): Promise<NVMData> {\n\t\tconst data = await this.readSingleRawEntry(entry, index);\n\t\treturn this.parseEntry(entry.type, Bytes.view(data));\n\t}\n\n\tpublic async get(property: NVMEntryName): Promise<NVMData[] | undefined> {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureReadable();\n\n\t\tconst entry = this._info.layout.get(property);\n\t\tif (!entry) return undefined;\n\n\t\treturn this.readEntry(entry);\n\t}\n\n\tpublic async getSingle(\n\t\tproperty: NVMEntryName,\n\t\tindex: number,\n\t): Promise<NVMData | undefined> {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureReadable();\n\n\t\tconst entry = this._info.layout.get(property);\n\t\tif (!entry) return undefined;\n\n\t\treturn this.readSingleEntry(entry, index);\n\t}\n\n\tprivate encodeEntry(\n\t\ttype: NVMEntryType,\n\t\tdata: NVMData,\n\t\tentrySize?: number,\n\t): Bytes {\n\t\tconst size = entrySize ?? NVMEntrySizes[type];\n\n\t\tswitch (type) {\n\t\t\tcase NVMEntryType.Byte:\n\t\t\t\treturn Bytes.from([data as number]);\n\t\t\tcase NVMEntryType.Word:\n\t\t\tcase NVMEntryType.NVMModuleSize: {\n\t\t\t\tconst ret = new Bytes(2);\n\t\t\t\tret.writeUInt16BE(data as number, 0);\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t\tcase NVMEntryType.DWord: {\n\t\t\t\tconst ret = new Bytes(4);\n\t\t\t\tret.writeUInt32BE(data as number, 0);\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t\tcase NVMEntryType.NodeInfo:\n\t\t\t\treturn data\n\t\t\t\t\t? encodeNVM500NodeInfo(data as NVM500NodeInfo)\n\t\t\t\t\t: new Bytes(size).fill(0);\n\t\t\tcase NVMEntryType.NodeMask: {\n\t\t\t\tconst ret = new Bytes(size).fill(0);\n\t\t\t\tif (data) {\n\t\t\t\t\tret.set(encodeBitMask(data as number[], MAX_NODES, 1), 0);\n\t\t\t\t}\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t\tcase NVMEntryType.SUCUpdateEntry:\n\t\t\t\treturn encodeSUCUpdateEntry(data as SUCUpdateEntry);\n\t\t\tcase NVMEntryType.Route:\n\t\t\t\treturn encodeRoute(data as Route);\n\t\t\tcase NVMEntryType.NVMModuleDescriptor:\n\t\t\t\treturn encodeNVMModuleDescriptor(\n\t\t\t\t\tdata as NVMModuleDescriptor,\n\t\t\t\t);\n\t\t\tcase NVMEntryType.NVMDescriptor:\n\t\t\t\treturn encodeNVMDescriptor(data as NVMDescriptor);\n\t\t\tcase NVMEntryType.Buffer:\n\t\t\t\treturn data as Bytes;\n\t\t}\n\t}\n\n\tprivate async writeSingleRawEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tindex: number,\n\t\tdata: Uint8Array,\n\t): Promise<void> {\n\t\tif (index >= entry.count) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Index out of range. Tried to write entry ${index} of ${entry.count}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t}\n\t\treturn nvmWriteBuffer(\n\t\t\tthis._io,\n\t\t\tentry.offset + index * entry.size,\n\t\t\tdata,\n\t\t);\n\t}\n\n\tprivate async writeRawEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tdata: Uint8Array[],\n\t): Promise<void> {\n\t\tawait nvmWriteBuffer(\n\t\t\tthis._io,\n\t\t\tentry.offset,\n\t\t\tBytes.concat(data),\n\t\t);\n\t}\n\n\tprivate async writeEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tdata: NVMData[],\n\t): Promise<void> {\n\t\tconst buffers = data.map((d) =>\n\t\t\tthis.encodeEntry(entry.type, d, entry.size)\n\t\t);\n\t\tawait this.writeRawEntry(entry, buffers);\n\t}\n\n\tprivate async writeSingleEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tindex: number,\n\t\tdata: NVMData,\n\t): Promise<void> {\n\t\tconst buffer = this.encodeEntry(entry.type, data, entry.size);\n\t\tawait this.writeSingleRawEntry(entry, index, buffer);\n\t}\n\n\tpublic async set(property: NVMEntryName, value: NVMData[]): Promise<void> {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tconst entry = this._info.layout.get(property);\n\t\tif (!entry) return;\n\n\t\tawait this.writeEntry(entry, value);\n\t}\n\n\tpublic async setSingle(\n\t\tproperty: NVMEntryName,\n\t\tindex: number,\n\t\tvalue: NVMData,\n\t): Promise<void> {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tconst entry = this._info.layout.get(property);\n\t\tif (!entry) return undefined;\n\n\t\tawait this.writeSingleEntry(entry, index, value);\n\t}\n\n\tprivate async fill(key: NVMEntryName, value: number) {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tconst entry = this._info.layout.get(key);\n\t\t// Skip entries not present in this layout\n\t\tif (!entry) return;\n\n\t\tconst size = entry.size ?? NVMEntrySizes[entry.type];\n\n\t\tconst data: NVMData[] = [];\n\t\tfor (let i = 1; i <= entry.count; i++) {\n\t\t\tswitch (entry.type) {\n\t\t\t\tcase NVMEntryType.Byte:\n\t\t\t\tcase NVMEntryType.Word:\n\t\t\t\tcase NVMEntryType.DWord:\n\t\t\t\t\tdata.push(value);\n\t\t\t\t\tbreak;\n\t\t\t\tcase NVMEntryType.Buffer:\n\t\t\t\t\tdata.push(new Uint8Array(size).fill(value));\n\t\t\t\t\tbreak;\n\t\t\t\tcase NVMEntryType.NodeMask:\n\t\t\t\t\tdata.push(new Array(size).fill(value));\n\t\t\t\t\tbreak;\n\t\t\t\tcase NVMEntryType.NodeInfo:\n\t\t\t\tcase NVMEntryType.Route:\n\t\t\t\t\tdata.push(undefined);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot fill entry of type ${NVMEntryType[entry.type]}`,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tawait this.writeEntry(entry, data);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/require-await\n\tpublic async delete(_property: NVMEntryName): Promise<void> {\n\t\tthrow new Error(\n\t\t\t\"Deleting entries is not supported for 500 series NVMs\",\n\t\t);\n\t}\n\n\tpublic async erase(\n\t\toptions: NVM500EraseOptions,\n\t): Promise<void> {\n\t\t// Blank NVM with 0xff\n\t\tawait nvmWriteBuffer(\n\t\t\tthis._io,\n\t\t\t0,\n\t\t\tnew Uint8Array(options.nvmSize).fill(0xff),\n\t\t);\n\n\t\t// Compute module sizes\n\t\tconst layoutEntries = Array.from(options.layout.values());\n\t\tconst moduleSizeEntries = layoutEntries\n\t\t\t.filter((entry) => entry.type === NVMEntryType.NVMModuleSize);\n\t\tconst moduleDescriptorEntries = layoutEntries\n\t\t\t.filter((entry) => entry.type === NVMEntryType.NVMModuleDescriptor);\n\t\tconst moduleDescriptors = new Map<NVMEntryName, NVMModuleDescriptor>();\n\t\t// Each module starts with a size marker and ends with a descriptor\n\t\tfor (let i = 0; i < moduleSizeEntries.length; i++) {\n\t\t\tconst sizeEntry = moduleSizeEntries[i];\n\t\t\tconst descriptorEntry = moduleDescriptorEntries[i];\n\t\t\tconst size = descriptorEntry.offset\n\t\t\t\t+ descriptorEntry.size\n\t\t\t\t- sizeEntry.offset;\n\n\t\t\t// Write each module size to their NVMModuleSize marker\n\t\t\tawait this.writeEntry(sizeEntry, [size]);\n\n\t\t\t// Write each module size, type and version to the NVMModuleDescriptor at the end\n\t\t\tconst moduleType = descriptorEntry.name === \"nvmZWlibraryDescriptor\"\n\t\t\t\t? NVMModuleType.ZW_LIBRARY\n\t\t\t\t: descriptorEntry.name === \"nvmApplicationDescriptor\"\n\t\t\t\t? NVMModuleType.APPLICATION\n\t\t\t\t: descriptorEntry.name === \"nvmHostApplicationDescriptor\"\n\t\t\t\t? NVMModuleType.HOST_APPLICATION\n\t\t\t\t: descriptorEntry.name === \"nvmDescriptorDescriptor\"\n\t\t\t\t? NVMModuleType.NVM_DESCRIPTOR\n\t\t\t\t: 0;\n\n\t\t\tconst moduleDescriptor: NVMModuleDescriptor = {\n\t\t\t\tsize,\n\t\t\t\ttype: moduleType,\n\t\t\t\tversion: descriptorEntry.name === \"nvmZWlibraryDescriptor\"\n\t\t\t\t\t? options.nvmDescriptor.protocolVersion\n\t\t\t\t\t: options.nvmDescriptor.firmwareVersion,\n\t\t\t};\n\t\t\tmoduleDescriptors.set(descriptorEntry.name, moduleDescriptor);\n\t\t\tawait this.writeEntry(descriptorEntry, [moduleDescriptor]);\n\t\t}\n\n\t\t// Initialize this._info, so the following works\n\t\tthis._info = {\n\t\t\t...options,\n\t\t\tmoduleDescriptors,\n\t\t};\n\n\t\t// Write NVM size to nvmTotalEnd\n\t\t// the value points to the last byte, therefore subtract 1\n\t\tawait this.set(\"nvmTotalEnd\", [options.nvmSize - 1]);\n\n\t\t// Set some entries that are always identical\n\t\tawait this.set(\"NVM_CONFIGURATION_VALID_far\", [CONFIGURATION_VALID_0]);\n\t\tawait this.set(\"NVM_CONFIGURATION_REALLYVALID_far\", [\n\t\t\tCONFIGURATION_VALID_1,\n\t\t]);\n\t\tawait this.set(\"EEOFFSET_MAGIC_far\", [MAGIC_VALUE]);\n\t\tawait this.set(\"EX_NVM_ROUTECACHE_MAGIC_far\", [ROUTECACHE_VALID]);\n\t\tawait this.set(\"nvmModuleSizeEndMarker\", [0]);\n\n\t\t// Set NVM descriptor\n\t\tawait this.set(\"nvmDescriptor\", [options.nvmDescriptor]);\n\n\t\t// Set dummy entries we're never going to fill\n\t\tawait this.fill(\"NVM_INTERNAL_RESERVED_1_far\", 0);\n\t\tawait this.fill(\"NVM_INTERNAL_RESERVED_2_far\", 0xff);\n\t\tawait this.fill(\"NVM_INTERNAL_RESERVED_3_far\", 0);\n\t\tawait this.fill(\"NVM_RTC_TIMERS_far\", 0);\n\t\tawait this.fill(\"EX_NVM_SUC_ACTIVE_START_far\", 0);\n\t\tawait this.fill(\"EX_NVM_ZENSOR_TABLE_START_far\", 0);\n\t\tawait this.fill(\"NVM_SECURITY0_KEY_far\", 0);\n\n\t\t// And blank fields that are not supposed to be filled with 0xff\n\t\tawait this.fill(\"EX_NVM_SUC_CONTROLLER_LIST_START_far\", 0xfe);\n\t\tawait this.fill(\"EX_NVM_NODE_TABLE_START_far\", 0);\n\t\tawait this.fill(\"EX_NVM_ROUTING_TABLE_START_far\", 0);\n\t\t// For routes the value does not matter\n\t\tawait this.fill(\"EX_NVM_ROUTECACHE_START_far\", 0);\n\t\tawait this.fill(\"EX_NVM_ROUTECACHE_NLWR_SR_START_far\", 0);\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kBAMO;AACP,
|
|
4
|
+
"sourcesContent": ["import {\n\tMAX_NODES,\n\tZWaveError,\n\tZWaveErrorCodes,\n\tencodeBitMask,\n\tparseBitMask,\n} from \"@zwave-js/core\";\nimport { Bytes, type BytesView } from \"@zwave-js/shared\";\nimport { type NVM, NVMAccess, type NVMIO } from \"./common/definitions.js\";\nimport { type Route, encodeRoute, parseRoute } from \"./common/routeCache.js\";\nimport {\n\ttype SUCUpdateEntry,\n\tencodeSUCUpdateEntry,\n\tparseSUCUpdateEntry,\n} from \"./common/sucUpdateEntry.js\";\nimport {\n\tnvmReadBuffer,\n\tnvmReadUInt16BE,\n\tnvmWriteBuffer,\n} from \"./common/utils.js\";\nimport {\n\ttype NVM500NodeInfo,\n\ttype NVMDescriptor,\n\ttype NVMModuleDescriptor,\n\tencodeNVM500NodeInfo,\n\tencodeNVMDescriptor,\n\tencodeNVMModuleDescriptor,\n\tparseNVM500NodeInfo,\n\tparseNVMDescriptor,\n\tparseNVMModuleDescriptor,\n} from \"./nvm500/EntryParsers.js\";\nimport { nvm500Impls } from \"./nvm500/impls/index.js\";\nimport {\n\tCONFIGURATION_VALID_0,\n\tCONFIGURATION_VALID_1,\n\tMAGIC_VALUE,\n\ttype NVM500Impl,\n\ttype NVMData,\n\ttype NVMEntryName,\n\tNVMEntrySizes,\n\tNVMEntryType,\n\tNVMModuleType,\n\tROUTECACHE_VALID,\n\ttype ResolvedNVMEntry,\n\ttype ResolvedNVMLayout,\n} from \"./nvm500/shared.js\";\n\nexport interface NVM500Info {\n\tlayout: ResolvedNVMLayout;\n\tlibrary: NVM500Impl[\"library\"];\n\tmoduleDescriptors: Map<NVMEntryName, NVMModuleDescriptor>;\n\tnvmDescriptor: NVMDescriptor;\n}\n\nexport type NVM500EraseOptions = {\n\tlayout: ResolvedNVMLayout;\n\tnvmSize: number;\n\tlibrary: NVM500Impl[\"library\"];\n\tnvmDescriptor: NVMDescriptor;\n};\n\nexport class NVM500 implements NVM<NVMEntryName, NVMData[]> {\n\tpublic constructor(io: NVMIO) {\n\t\tthis._io = io;\n\t}\n\n\tprivate _io: NVMIO;\n\tprivate _access: NVMAccess = NVMAccess.None;\n\n\tprivate _info: NVM500Info | undefined;\n\tpublic get info(): NVM500Info | undefined {\n\t\treturn this._info;\n\t}\n\n\tprivate async ensureReadable(): Promise<void> {\n\t\tif (\n\t\t\tthis._access === NVMAccess.Read\n\t\t\t|| this._access === NVMAccess.ReadWrite\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (this._access === NVMAccess.Write) {\n\t\t\tawait this._io.close();\n\t\t}\n\t\tthis._access = await this._io.open(NVMAccess.Read);\n\t}\n\n\tprivate async ensureWritable(): Promise<void> {\n\t\tif (\n\t\t\tthis._access === NVMAccess.Write\n\t\t\t|| this._access === NVMAccess.ReadWrite\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tif (this._access === NVMAccess.Read) {\n\t\t\tawait this._io.close();\n\t\t}\n\t\tthis._access = await this._io.open(NVMAccess.Write);\n\t}\n\n\tpublic async init(): Promise<NVM500Info> {\n\t\tawait this.ensureReadable();\n\n\t\t// Try the different known layouts to find one that works\n\t\tfor (const impl of nvm500Impls) {\n\t\t\ttry {\n\t\t\t\tconst info = await this.resolveLayout(impl);\n\t\t\t\tif (await this.isLayoutValid(info, impl.protocolVersions)) {\n\t\t\t\t\tthis._info = info;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (!this._info) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"Did not find a matching NVM 500 parser implementation! Make sure that the NVM data belongs to a controller with Z-Wave SDK 6.61 or higher.\",\n\t\t\t\tZWaveErrorCodes.NVM_NotSupported,\n\t\t\t);\n\t\t}\n\n\t\treturn this._info;\n\t}\n\n\tprivate async resolveLayout(impl: NVM500Impl): Promise<NVM500Info> {\n\t\tconst resolvedLayout = new Map<NVMEntryName, ResolvedNVMEntry>();\n\t\tlet nvmDescriptor: NVMDescriptor | undefined;\n\t\tconst moduleDescriptors = new Map<NVMEntryName, NVMModuleDescriptor>();\n\n\t\tlet offset = 0;\n\t\tlet moduleStart = -1;\n\t\tlet moduleSize = -1;\n\t\tconst nvmEnd = await nvmReadUInt16BE(this._io, 0);\n\n\t\tfor (const entry of impl.layout) {\n\t\t\tconst size = entry.size ?? NVMEntrySizes[entry.type];\n\n\t\t\tif (entry.type === NVMEntryType.NVMModuleSize) {\n\t\t\t\tif (moduleStart !== -1) {\n\t\t\t\t\t// All following NVM modules must start at the last module's end\n\t\t\t\t\toffset = moduleStart + moduleSize;\n\t\t\t\t}\n\n\t\t\t\tmoduleStart = offset;\n\t\t\t\tmoduleSize = await nvmReadUInt16BE(this._io, offset);\n\t\t\t} else if (entry.type === NVMEntryType.NVMModuleDescriptor) {\n\t\t\t\t// The module descriptor is always at the end of the module\n\t\t\t\toffset = moduleStart + moduleSize - size;\n\t\t\t}\n\n\t\t\tif (entry.offset != undefined && entry.offset !== offset) {\n\t\t\t\t// The entry has a defined offset but is at the wrong location\n\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t`${entry.name} is at wrong location in NVM buffer!`,\n\t\t\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst resolvedEntry: ResolvedNVMEntry = {\n\t\t\t\t...entry,\n\t\t\t\toffset,\n\t\t\t\tsize,\n\t\t\t};\n\n\t\t\tif (entry.type === NVMEntryType.NVMDescriptor) {\n\t\t\t\tconst entryData = await this.readRawEntry(resolvedEntry);\n\t\t\t\t// NVMDescriptor is always a single entry\n\t\t\t\tnvmDescriptor = parseNVMDescriptor(entryData[0]);\n\t\t\t} else if (entry.type === NVMEntryType.NVMModuleDescriptor) {\n\t\t\t\tconst entryData = await this.readRawEntry(resolvedEntry);\n\t\t\t\t// NVMModuleDescriptor is always a single entry\n\t\t\t\tconst descriptor = parseNVMModuleDescriptor(\n\t\t\t\t\tentryData[0],\n\t\t\t\t);\n\t\t\t\tif (descriptor.size !== moduleSize) {\n\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\"NVM module descriptor size does not match module size!\",\n\t\t\t\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tmoduleDescriptors.set(entry.name, descriptor);\n\t\t\t}\n\n\t\t\tresolvedLayout.set(entry.name, resolvedEntry);\n\n\t\t\t// Skip forward\n\t\t\toffset += size * entry.count;\n\t\t\tif (offset >= nvmEnd) break;\n\t\t}\n\n\t\tif (!nvmDescriptor) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"NVM descriptor not found in NVM!\",\n\t\t\t\tZWaveErrorCodes.NVM_InvalidFormat,\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tlayout: resolvedLayout,\n\t\t\tlibrary: impl.library,\n\t\t\tmoduleDescriptors,\n\t\t\tnvmDescriptor,\n\t\t};\n\t}\n\n\tprivate async isLayoutValid(\n\t\tinfo: NVM500Info,\n\t\tprotocolVersions: string[],\n\t): Promise<boolean> {\n\t\t// Checking if an NVM is valid requires checking multiple bytes at different locations\n\t\tconst eeoffset_magic_entry = info.layout.get(\"EEOFFSET_MAGIC_far\");\n\t\tif (!eeoffset_magic_entry) return false;\n\t\tconst eeoffset_magic =\n\t\t\t(await this.readEntry(eeoffset_magic_entry))[0] as number;\n\n\t\tconst configuration_valid_0_entry = info.layout.get(\n\t\t\t\"NVM_CONFIGURATION_VALID_far\",\n\t\t);\n\t\tif (!configuration_valid_0_entry) return false;\n\t\tconst configuration_valid_0 =\n\t\t\t(await this.readEntry(configuration_valid_0_entry))[0] as number;\n\n\t\tconst configuration_valid_1_entry = info.layout.get(\n\t\t\t\"NVM_CONFIGURATION_REALLYVALID_far\",\n\t\t);\n\t\tif (!configuration_valid_1_entry) return false;\n\t\tconst configuration_valid_1 =\n\t\t\t(await this.readEntry(configuration_valid_1_entry))[0] as number;\n\n\t\tconst routecache_valid_entry = info.layout.get(\n\t\t\t\"EX_NVM_ROUTECACHE_MAGIC_far\",\n\t\t);\n\t\tif (!routecache_valid_entry) return false;\n\t\tconst routecache_valid =\n\t\t\t(await this.readEntry(routecache_valid_entry))[0] as number;\n\n\t\tconst endMarker_entry = info.layout.get(\"nvmModuleSizeEndMarker\");\n\t\tif (!endMarker_entry) return false;\n\t\tconst endMarker = (await this.readEntry(endMarker_entry))[0] as number;\n\n\t\treturn (\n\t\t\teeoffset_magic === MAGIC_VALUE\n\t\t\t&& configuration_valid_0 === CONFIGURATION_VALID_0\n\t\t\t&& configuration_valid_1 === CONFIGURATION_VALID_1\n\t\t\t&& routecache_valid === ROUTECACHE_VALID\n\t\t\t&& protocolVersions.includes(info.nvmDescriptor.protocolVersion)\n\t\t\t&& endMarker === 0\n\t\t);\n\t}\n\n\tasync has(property: NVMEntryName): Promise<boolean> {\n\t\tthis._info ??= await this.init();\n\t\treturn this._info.layout.has(property);\n\t}\n\n\tprivate async readSingleRawEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tindex: number,\n\t): Promise<BytesView> {\n\t\tif (index >= entry.count) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Index out of range. Tried to read entry ${index} of ${entry.count}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t}\n\t\treturn nvmReadBuffer(\n\t\t\tthis._io,\n\t\t\tentry.offset + index * entry.size,\n\t\t\tentry.size,\n\t\t);\n\t}\n\n\tprivate async readRawEntry(\n\t\tentry: ResolvedNVMEntry,\n\t): Promise<BytesView[]> {\n\t\tconst ret: BytesView[] = [];\n\t\tconst nvmData = await nvmReadBuffer(\n\t\t\tthis._io,\n\t\t\tentry.offset,\n\t\t\tentry.count * entry.size,\n\t\t);\n\t\tfor (let i = 0; i < entry.count; i++) {\n\t\t\tret.push(\n\t\t\t\tnvmData.subarray(i * entry.size, (i + 1) * entry.size),\n\t\t\t);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tprivate parseEntry(type: NVMEntryType, data: Bytes): NVMData {\n\t\tswitch (type) {\n\t\t\tcase NVMEntryType.Byte:\n\t\t\t\treturn data.readUInt8(0);\n\t\t\tcase NVMEntryType.Word:\n\t\t\tcase NVMEntryType.NVMModuleSize:\n\t\t\t\treturn data.readUInt16BE(0);\n\t\t\tcase NVMEntryType.DWord:\n\t\t\t\treturn data.readUInt32BE(0);\n\t\t\tcase NVMEntryType.NodeInfo:\n\t\t\t\tif (data.every((byte) => byte === 0)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\treturn parseNVM500NodeInfo(data, 0);\n\t\t\tcase NVMEntryType.NodeMask:\n\t\t\t\treturn parseBitMask(data);\n\t\t\tcase NVMEntryType.SUCUpdateEntry:\n\t\t\t\tif (data.every((byte) => byte === 0)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\treturn parseSUCUpdateEntry(data, 0);\n\t\t\tcase NVMEntryType.Route:\n\t\t\t\tif (data.every((byte) => byte === 0)) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\treturn parseRoute(data, 0);\n\t\t\tcase NVMEntryType.NVMModuleDescriptor: {\n\t\t\t\treturn parseNVMModuleDescriptor(data);\n\t\t\t}\n\t\t\tcase NVMEntryType.NVMDescriptor:\n\t\t\t\treturn parseNVMDescriptor(data);\n\t\t\tdefault:\n\t\t\t\t// This includes NVMEntryType.BUFFER\n\t\t\t\treturn data;\n\t\t}\n\t}\n\n\tprivate async readEntry(\n\t\tentry: ResolvedNVMEntry,\n\t): Promise<NVMData[]> {\n\t\tconst data: BytesView[] = await this.readRawEntry(entry);\n\t\treturn data.map((buffer) =>\n\t\t\tthis.parseEntry(entry.type, Bytes.view(buffer))\n\t\t);\n\t}\n\n\tprivate async readSingleEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tindex: number,\n\t): Promise<NVMData> {\n\t\tconst data = await this.readSingleRawEntry(entry, index);\n\t\treturn this.parseEntry(entry.type, Bytes.view(data));\n\t}\n\n\tpublic async get(property: NVMEntryName): Promise<NVMData[] | undefined> {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureReadable();\n\n\t\tconst entry = this._info.layout.get(property);\n\t\tif (!entry) return undefined;\n\n\t\treturn this.readEntry(entry);\n\t}\n\n\tpublic async getSingle(\n\t\tproperty: NVMEntryName,\n\t\tindex: number,\n\t): Promise<NVMData | undefined> {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureReadable();\n\n\t\tconst entry = this._info.layout.get(property);\n\t\tif (!entry) return undefined;\n\n\t\treturn this.readSingleEntry(entry, index);\n\t}\n\n\tprivate encodeEntry(\n\t\ttype: NVMEntryType,\n\t\tdata: NVMData,\n\t\tentrySize?: number,\n\t): Bytes {\n\t\tconst size = entrySize ?? NVMEntrySizes[type];\n\n\t\tswitch (type) {\n\t\t\tcase NVMEntryType.Byte:\n\t\t\t\treturn Bytes.from([data as number]);\n\t\t\tcase NVMEntryType.Word:\n\t\t\tcase NVMEntryType.NVMModuleSize: {\n\t\t\t\tconst ret = new Bytes(2);\n\t\t\t\tret.writeUInt16BE(data as number, 0);\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t\tcase NVMEntryType.DWord: {\n\t\t\t\tconst ret = new Bytes(4);\n\t\t\t\tret.writeUInt32BE(data as number, 0);\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t\tcase NVMEntryType.NodeInfo:\n\t\t\t\treturn data\n\t\t\t\t\t? encodeNVM500NodeInfo(data as NVM500NodeInfo)\n\t\t\t\t\t: new Bytes(size).fill(0);\n\t\t\tcase NVMEntryType.NodeMask: {\n\t\t\t\tconst ret = new Bytes(size).fill(0);\n\t\t\t\tif (data) {\n\t\t\t\t\tret.set(encodeBitMask(data as number[], MAX_NODES, 1), 0);\n\t\t\t\t}\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t\tcase NVMEntryType.SUCUpdateEntry:\n\t\t\t\treturn encodeSUCUpdateEntry(data as SUCUpdateEntry);\n\t\t\tcase NVMEntryType.Route:\n\t\t\t\treturn encodeRoute(data as Route);\n\t\t\tcase NVMEntryType.NVMModuleDescriptor:\n\t\t\t\treturn encodeNVMModuleDescriptor(\n\t\t\t\t\tdata as NVMModuleDescriptor,\n\t\t\t\t);\n\t\t\tcase NVMEntryType.NVMDescriptor:\n\t\t\t\treturn encodeNVMDescriptor(data as NVMDescriptor);\n\t\t\tcase NVMEntryType.Buffer:\n\t\t\t\treturn data as Bytes;\n\t\t}\n\t}\n\n\tprivate async writeSingleRawEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tindex: number,\n\t\tdata: BytesView,\n\t): Promise<void> {\n\t\tif (index >= entry.count) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Index out of range. Tried to write entry ${index} of ${entry.count}.`,\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t}\n\t\treturn nvmWriteBuffer(\n\t\t\tthis._io,\n\t\t\tentry.offset + index * entry.size,\n\t\t\tdata,\n\t\t);\n\t}\n\n\tprivate async writeRawEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tdata: BytesView[],\n\t): Promise<void> {\n\t\tawait nvmWriteBuffer(\n\t\t\tthis._io,\n\t\t\tentry.offset,\n\t\t\tBytes.concat(data),\n\t\t);\n\t}\n\n\tprivate async writeEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tdata: NVMData[],\n\t): Promise<void> {\n\t\tconst buffers = data.map((d) =>\n\t\t\tthis.encodeEntry(entry.type, d, entry.size)\n\t\t);\n\t\tawait this.writeRawEntry(entry, buffers);\n\t}\n\n\tprivate async writeSingleEntry(\n\t\tentry: ResolvedNVMEntry,\n\t\tindex: number,\n\t\tdata: NVMData,\n\t): Promise<void> {\n\t\tconst buffer = this.encodeEntry(entry.type, data, entry.size);\n\t\tawait this.writeSingleRawEntry(entry, index, buffer);\n\t}\n\n\tpublic async set(property: NVMEntryName, value: NVMData[]): Promise<void> {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tconst entry = this._info.layout.get(property);\n\t\tif (!entry) return;\n\n\t\tawait this.writeEntry(entry, value);\n\t}\n\n\tpublic async setSingle(\n\t\tproperty: NVMEntryName,\n\t\tindex: number,\n\t\tvalue: NVMData,\n\t): Promise<void> {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tconst entry = this._info.layout.get(property);\n\t\tif (!entry) return undefined;\n\n\t\tawait this.writeSingleEntry(entry, index, value);\n\t}\n\n\tprivate async fill(key: NVMEntryName, value: number) {\n\t\tthis._info ??= await this.init();\n\t\tawait this.ensureWritable();\n\n\t\tconst entry = this._info.layout.get(key);\n\t\t// Skip entries not present in this layout\n\t\tif (!entry) return;\n\n\t\tconst size = entry.size ?? NVMEntrySizes[entry.type];\n\n\t\tconst data: NVMData[] = [];\n\t\tfor (let i = 1; i <= entry.count; i++) {\n\t\t\tswitch (entry.type) {\n\t\t\t\tcase NVMEntryType.Byte:\n\t\t\t\tcase NVMEntryType.Word:\n\t\t\t\tcase NVMEntryType.DWord:\n\t\t\t\t\tdata.push(value);\n\t\t\t\t\tbreak;\n\t\t\t\tcase NVMEntryType.Buffer:\n\t\t\t\t\tdata.push(new Uint8Array(size).fill(value));\n\t\t\t\t\tbreak;\n\t\t\t\tcase NVMEntryType.NodeMask:\n\t\t\t\t\tdata.push(new Array(size).fill(value));\n\t\t\t\t\tbreak;\n\t\t\t\tcase NVMEntryType.NodeInfo:\n\t\t\t\tcase NVMEntryType.Route:\n\t\t\t\t\tdata.push(undefined);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot fill entry of type ${NVMEntryType[entry.type]}`,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tawait this.writeEntry(entry, data);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/require-await\n\tpublic async delete(_property: NVMEntryName): Promise<void> {\n\t\tthrow new Error(\n\t\t\t\"Deleting entries is not supported for 500 series NVMs\",\n\t\t);\n\t}\n\n\tpublic async erase(\n\t\toptions: NVM500EraseOptions,\n\t): Promise<void> {\n\t\t// Blank NVM with 0xff\n\t\tawait nvmWriteBuffer(\n\t\t\tthis._io,\n\t\t\t0,\n\t\t\tnew Uint8Array(options.nvmSize).fill(0xff),\n\t\t);\n\n\t\t// Compute module sizes\n\t\tconst layoutEntries = Array.from(options.layout.values());\n\t\tconst moduleSizeEntries = layoutEntries\n\t\t\t.filter((entry) => entry.type === NVMEntryType.NVMModuleSize);\n\t\tconst moduleDescriptorEntries = layoutEntries\n\t\t\t.filter((entry) => entry.type === NVMEntryType.NVMModuleDescriptor);\n\t\tconst moduleDescriptors = new Map<NVMEntryName, NVMModuleDescriptor>();\n\t\t// Each module starts with a size marker and ends with a descriptor\n\t\tfor (let i = 0; i < moduleSizeEntries.length; i++) {\n\t\t\tconst sizeEntry = moduleSizeEntries[i];\n\t\t\tconst descriptorEntry = moduleDescriptorEntries[i];\n\t\t\tconst size = descriptorEntry.offset\n\t\t\t\t+ descriptorEntry.size\n\t\t\t\t- sizeEntry.offset;\n\n\t\t\t// Write each module size to their NVMModuleSize marker\n\t\t\tawait this.writeEntry(sizeEntry, [size]);\n\n\t\t\t// Write each module size, type and version to the NVMModuleDescriptor at the end\n\t\t\tconst moduleType = descriptorEntry.name === \"nvmZWlibraryDescriptor\"\n\t\t\t\t? NVMModuleType.ZW_LIBRARY\n\t\t\t\t: descriptorEntry.name === \"nvmApplicationDescriptor\"\n\t\t\t\t? NVMModuleType.APPLICATION\n\t\t\t\t: descriptorEntry.name === \"nvmHostApplicationDescriptor\"\n\t\t\t\t? NVMModuleType.HOST_APPLICATION\n\t\t\t\t: descriptorEntry.name === \"nvmDescriptorDescriptor\"\n\t\t\t\t? NVMModuleType.NVM_DESCRIPTOR\n\t\t\t\t: 0;\n\n\t\t\tconst moduleDescriptor: NVMModuleDescriptor = {\n\t\t\t\tsize,\n\t\t\t\ttype: moduleType,\n\t\t\t\tversion: descriptorEntry.name === \"nvmZWlibraryDescriptor\"\n\t\t\t\t\t? options.nvmDescriptor.protocolVersion\n\t\t\t\t\t: options.nvmDescriptor.firmwareVersion,\n\t\t\t};\n\t\t\tmoduleDescriptors.set(descriptorEntry.name, moduleDescriptor);\n\t\t\tawait this.writeEntry(descriptorEntry, [moduleDescriptor]);\n\t\t}\n\n\t\t// Initialize this._info, so the following works\n\t\tthis._info = {\n\t\t\t...options,\n\t\t\tmoduleDescriptors,\n\t\t};\n\n\t\t// Write NVM size to nvmTotalEnd\n\t\t// the value points to the last byte, therefore subtract 1\n\t\tawait this.set(\"nvmTotalEnd\", [options.nvmSize - 1]);\n\n\t\t// Set some entries that are always identical\n\t\tawait this.set(\"NVM_CONFIGURATION_VALID_far\", [CONFIGURATION_VALID_0]);\n\t\tawait this.set(\"NVM_CONFIGURATION_REALLYVALID_far\", [\n\t\t\tCONFIGURATION_VALID_1,\n\t\t]);\n\t\tawait this.set(\"EEOFFSET_MAGIC_far\", [MAGIC_VALUE]);\n\t\tawait this.set(\"EX_NVM_ROUTECACHE_MAGIC_far\", [ROUTECACHE_VALID]);\n\t\tawait this.set(\"nvmModuleSizeEndMarker\", [0]);\n\n\t\t// Set NVM descriptor\n\t\tawait this.set(\"nvmDescriptor\", [options.nvmDescriptor]);\n\n\t\t// Set dummy entries we're never going to fill\n\t\tawait this.fill(\"NVM_INTERNAL_RESERVED_1_far\", 0);\n\t\tawait this.fill(\"NVM_INTERNAL_RESERVED_2_far\", 0xff);\n\t\tawait this.fill(\"NVM_INTERNAL_RESERVED_3_far\", 0);\n\t\tawait this.fill(\"NVM_RTC_TIMERS_far\", 0);\n\t\tawait this.fill(\"EX_NVM_SUC_ACTIVE_START_far\", 0);\n\t\tawait this.fill(\"EX_NVM_ZENSOR_TABLE_START_far\", 0);\n\t\tawait this.fill(\"NVM_SECURITY0_KEY_far\", 0);\n\n\t\t// And blank fields that are not supposed to be filled with 0xff\n\t\tawait this.fill(\"EX_NVM_SUC_CONTROLLER_LIST_START_far\", 0xfe);\n\t\tawait this.fill(\"EX_NVM_NODE_TABLE_START_far\", 0);\n\t\tawait this.fill(\"EX_NVM_ROUTING_TABLE_START_far\", 0);\n\t\t// For routes the value does not matter\n\t\tawait this.fill(\"EX_NVM_ROUTECACHE_START_far\", 0);\n\t\tawait this.fill(\"EX_NVM_ROUTECACHE_NLWR_SR_START_far\", 0);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kBAMO;AACP,oBAAsC;AACtC,yBAAgD;AAChD,wBAAoD;AACpD,4BAIO;AACP,mBAIO;AACP,0BAUO;AACP,mBAA4B;AAC5B,IAAAA,iBAaO;AAgBD,MAAO,OAAM;EA7DnB,OA6DmB;;;EAClB,YAAmB,IAAS;AAC3B,SAAK,MAAM;EACZ;EAEQ;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} from "@zwave-js/core";
|
|
2
|
-
import type { Expand } from "@zwave-js/shared";
|
|
2
|
+
import type { BytesView, Expand } from "@zwave-js/shared";
|
|
3
3
|
import type { ApplicationCCsFile, ApplicationRFConfigFile, ApplicationTypeFile, ControllerInfoFile, LRNodeInfo, NodeInfo } from "../nvm3/files/index.js";
|
|
4
4
|
import type { Route } from "./routeCache.js";
|
|
5
5
|
import type { SUCUpdateEntry } from "./sucUpdateEntry.js";
|
|
@@ -32,14 +32,14 @@ export interface NVMIO {
|
|
|
32
32
|
* the returned buffer will be shorter than the requested length.
|
|
33
33
|
*/
|
|
34
34
|
read(offset: number, length: number): Promise<{
|
|
35
|
-
buffer:
|
|
35
|
+
buffer: BytesView;
|
|
36
36
|
endOfFile: boolean;
|
|
37
37
|
}>;
|
|
38
38
|
/**
|
|
39
39
|
* Writes a chunk of data with the given length from the NVM.
|
|
40
40
|
* The returned value indicates how many bytes were actually written.
|
|
41
41
|
*/
|
|
42
|
-
write(offset: number, data:
|
|
42
|
+
write(offset: number, data: BytesView): Promise<{
|
|
43
43
|
bytesWritten: number;
|
|
44
44
|
endOfFile: boolean;
|
|
45
45
|
}>;
|
|
@@ -81,7 +81,7 @@ export type ControllerNVMPropertyTypes = Expand<{
|
|
|
81
81
|
protocolVersion: string;
|
|
82
82
|
protocolFileFormat: number;
|
|
83
83
|
applicationVersion: string;
|
|
84
|
-
applicationData:
|
|
84
|
+
applicationData: BytesView;
|
|
85
85
|
preferredRepeaters?: number[];
|
|
86
86
|
sucUpdateEntries: SUCUpdateEntry[];
|
|
87
87
|
appRouteLock: number[];
|
|
@@ -95,7 +95,7 @@ export type ControllerNVMPropertyTypes = Expand<{
|
|
|
95
95
|
applicationName: string;
|
|
96
96
|
lrNodeIds: number[];
|
|
97
97
|
}> & Partial<{
|
|
98
|
-
learnedHomeId:
|
|
98
|
+
learnedHomeId: BytesView;
|
|
99
99
|
commandClasses: CommandClasses[];
|
|
100
100
|
systemState: number;
|
|
101
101
|
watchdogStarted: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/common/definitions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CommandClasses } from \"@zwave-js/core\";\nimport type { Expand } from \"@zwave-js/shared\";\nimport type {\n\tApplicationCCsFile,\n\tApplicationRFConfigFile,\n\tApplicationTypeFile,\n\tControllerInfoFile,\n\tLRNodeInfo,\n\tNodeInfo,\n} from \"../nvm3/files/index.js\";\nimport type { Route } from \"./routeCache.js\";\nimport type { SUCUpdateEntry } from \"./sucUpdateEntry.js\";\n\nexport enum NVMAccess {\n\tNone,\n\tRead,\n\tWrite,\n\tReadWrite,\n}\n\n/** Provides an abstraction to access the contents of an NVM at the binary level */\nexport interface NVMIO {\n\t/**\n\t * Opens the NVM for reading and/or writing.\n\t * Since different NVM implementations may or may not allow reading and writing at the same time,\n\t * the returned value indicates which access patterns are actually allowed.\n\t */\n\topen(access: NVMAccess.Read | NVMAccess.Write): Promise<NVMAccess>;\n\n\t/** Returns the size of the NVM, after it has been opened */\n\tget size(): number;\n\t/** Returns which access is currently allowed for this NVM implementation */\n\tget accessMode(): NVMAccess;\n\n\t/**\n\t * Determines the size of the data chunks that can be used for writing.\n\t * Requires the NVM to be readable.\n\t */\n\tdetermineChunkSize(): Promise<number>;\n\n\t/**\n\t * Reads a chunk of data with the given length from the NVM.\n\t * If the length is longer than the chunk size, or the end of the NVM is reached,\n\t * the returned buffer will be shorter than the requested length.\n\t */\n\tread(\n\t\toffset: number,\n\t\tlength: number,\n\t): Promise<{ buffer:
|
|
4
|
+
"sourcesContent": ["import type { CommandClasses } from \"@zwave-js/core\";\nimport type { BytesView, Expand } from \"@zwave-js/shared\";\nimport type {\n\tApplicationCCsFile,\n\tApplicationRFConfigFile,\n\tApplicationTypeFile,\n\tControllerInfoFile,\n\tLRNodeInfo,\n\tNodeInfo,\n} from \"../nvm3/files/index.js\";\nimport type { Route } from \"./routeCache.js\";\nimport type { SUCUpdateEntry } from \"./sucUpdateEntry.js\";\n\nexport enum NVMAccess {\n\tNone,\n\tRead,\n\tWrite,\n\tReadWrite,\n}\n\n/** Provides an abstraction to access the contents of an NVM at the binary level */\nexport interface NVMIO {\n\t/**\n\t * Opens the NVM for reading and/or writing.\n\t * Since different NVM implementations may or may not allow reading and writing at the same time,\n\t * the returned value indicates which access patterns are actually allowed.\n\t */\n\topen(access: NVMAccess.Read | NVMAccess.Write): Promise<NVMAccess>;\n\n\t/** Returns the size of the NVM, after it has been opened */\n\tget size(): number;\n\t/** Returns which access is currently allowed for this NVM implementation */\n\tget accessMode(): NVMAccess;\n\n\t/**\n\t * Determines the size of the data chunks that can be used for writing.\n\t * Requires the NVM to be readable.\n\t */\n\tdetermineChunkSize(): Promise<number>;\n\n\t/**\n\t * Reads a chunk of data with the given length from the NVM.\n\t * If the length is longer than the chunk size, or the end of the NVM is reached,\n\t * the returned buffer will be shorter than the requested length.\n\t */\n\tread(\n\t\toffset: number,\n\t\tlength: number,\n\t): Promise<{ buffer: BytesView; endOfFile: boolean }>;\n\n\t/**\n\t * Writes a chunk of data with the given length from the NVM.\n\t * The returned value indicates how many bytes were actually written.\n\t */\n\twrite(\n\t\toffset: number,\n\t\tdata: BytesView,\n\t): Promise<{ bytesWritten: number; endOfFile: boolean }>;\n\n\t/** Closes the NVM */\n\tclose(): Promise<void>;\n}\n\n/** A specific NVM implementation */\nexport interface NVM<ID, Data> {\n\t/** Checks if a property exists in the NVM */\n\thas(property: ID): Promise<boolean>;\n\n\t/** Reads a property from the NVM */\n\tget(property: ID): Promise<Data | undefined>;\n\n\t/** Writes a property to the NVM */\n\tset(property: ID, value: Data): Promise<void>;\n\n\t/** Deletes the property from the NVM */\n\tdelete(property: ID): Promise<void>;\n}\n\n/**\n * Provides an application-level abstraction over an NVM implementation\n */\nexport interface NVMAdapter {\n\t/** Reads a property from the NVM */\n\tget<T extends NVMProperty, R extends boolean = boolean>(\n\t\tproperty: T,\n\t\trequired?: R,\n\t): Promise<\n\t\tR extends true ? NVMPropertyToDataType<T>\n\t\t\t: (NVMPropertyToDataType<T> | undefined)\n\t>;\n\n\t/**\n\t * Changes a property to be written to the NVM later\n\t */\n\tset<T extends NVMProperty>(\n\t\tproperty: T,\n\t\tvalue: NVMPropertyToDataType<T>,\n\t): Promise<void>;\n\n\t/**\n\t * Marks a property for deletion from the NVM. In some implementations,\n\t * deleting one property may delete multiple properties that are stored together.\n\t */\n\tdelete(property: NVMProperty): Promise<void>;\n\n\t/** Returns whether there are pending changes that weren't written to the NVM yet */\n\thasPendingChanges(): boolean;\n\n\t/** Writes all pending changes to the NVM */\n\tcommit(): Promise<void>;\n}\n\nexport type ControllerNVMPropertyTypes = Expand<\n\t& {\n\t\tprotocolVersion: string;\n\t\tprotocolFileFormat: number;\n\t\tapplicationVersion: string;\n\t\tapplicationData: BytesView;\n\t\tpreferredRepeaters?: number[];\n\t\tsucUpdateEntries: SUCUpdateEntry[];\n\t\tappRouteLock: number[];\n\t\trouteSlaveSUC: number[];\n\t\tsucPendingUpdate: number[];\n\t\tpendingDiscovery: number[];\n\t\tvirtualNodeIds: number[];\n\t\tnodeIds: number[];\n\t}\n\t// 700+ series only\n\t& Partial<{\n\t\tapplicationFileFormat: number;\n\t\tapplicationName: string;\n\t\tlrNodeIds: number[];\n\t}>\n\t// 500 series only\n\t& Partial<{\n\t\tlearnedHomeId: BytesView;\n\t\tcommandClasses: CommandClasses[];\n\t\tsystemState: number;\n\t\twatchdogStarted: number;\n\t\tpowerLevelNormal: number[];\n\t\tpowerLevelLow: number[];\n\t\tpowerMode: number;\n\t\tpowerModeExtintEnable: number;\n\t\tpowerModeWutTimeout: number;\n\t}>\n\t& Pick<\n\t\tControllerInfoFile,\n\t\t| \"homeId\"\n\t\t| \"nodeId\"\n\t\t| \"lastNodeId\"\n\t\t| \"staticControllerNodeId\"\n\t\t| \"sucLastIndex\"\n\t\t| \"controllerConfiguration\"\n\t\t| \"sucAwarenessPushNeeded\"\n\t\t| \"maxNodeId\"\n\t\t| \"reservedId\"\n\t\t| \"systemState\"\n\t\t| \"lastNodeIdLR\"\n\t\t| \"maxNodeIdLR\"\n\t\t| \"reservedIdLR\"\n\t\t| \"primaryLongRangeChannelId\"\n\t\t| \"dcdcConfig\"\n\t>\n\t// 700+ series only\n\t& Partial<\n\t\tPick<\n\t\t\tApplicationCCsFile,\n\t\t\t| \"includedInsecurely\"\n\t\t\t| \"includedSecurelyInsecureCCs\"\n\t\t\t| \"includedSecurelySecureCCs\"\n\t\t>\n\t>\n\t// 700+ series only\n\t& Partial<\n\t\tPick<\n\t\t\tApplicationRFConfigFile,\n\t\t\t| \"rfRegion\"\n\t\t\t| \"txPower\"\n\t\t\t| \"measured0dBm\"\n\t\t\t| \"enablePTI\"\n\t\t\t| \"maxTXPower\"\n\t\t\t| \"nodeIdType\"\n\t\t>\n\t>\n\t// 700+ series only\n\t& Partial<\n\t\tPick<\n\t\t\tApplicationTypeFile,\n\t\t\t| \"isListening\"\n\t\t\t| \"optionalFunctionality\"\n\t\t\t| \"genericDeviceClass\"\n\t\t\t| \"specificDeviceClass\"\n\t\t>\n\t>\n>;\n\nexport interface NodeNVMPropertyTypes {\n\tinfo: NodeInfo;\n\troutes: { lwr?: Route; nlwr?: Route };\n}\n\nexport interface LRNodeNVMPropertyTypes {\n\tinfo: LRNodeInfo;\n}\n\nexport type ControllerNVMProperty = {\n\tdomain: \"controller\";\n\ttype: keyof ControllerNVMPropertyTypes;\n\tnodeId?: undefined;\n};\n\nexport type ControllerNVMPropertyToDataType<P extends ControllerNVMProperty> =\n\tControllerNVMPropertyTypes[P[\"type\"]];\n\nexport type NodeNVMProperty = {\n\tdomain: \"node\";\n\ttype: keyof NodeNVMPropertyTypes;\n\tnodeId: number;\n};\n\nexport type NodeNVMPropertyToDataType<P extends NodeNVMProperty> =\n\tP[\"type\"] extends keyof NodeNVMPropertyTypes\n\t\t? NodeNVMPropertyTypes[P[\"type\"]]\n\t\t: never;\n\nexport type LRNodeNVMProperty = {\n\tdomain: \"lrnode\";\n\ttype: keyof LRNodeNVMPropertyTypes;\n\tnodeId: number;\n};\n\nexport type LRNodeNVMPropertyToDataType<P extends LRNodeNVMProperty> =\n\tP[\"type\"] extends keyof LRNodeNVMPropertyTypes\n\t\t? LRNodeNVMPropertyTypes[P[\"type\"]]\n\t\t: never;\n\nexport type NVMProperty =\n\t| ControllerNVMProperty\n\t| NodeNVMProperty\n\t| LRNodeNVMProperty;\n\nexport type NVMPropertyToDataType<P extends NVMProperty> = P extends\n\tControllerNVMProperty ? ControllerNVMPropertyToDataType<P>\n\t: P extends NodeNVMProperty ? NodeNVMPropertyToDataType<P>\n\t: P extends LRNodeNVMProperty ? LRNodeNVMPropertyToDataType<P>\n\t: never;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAaA;;;;;AAAA,IAAY;CAAZ,SAAYA,YAAS;AACpB,EAAAA,WAAAA,WAAA,MAAA,IAAA,CAAA,IAAA;AACA,EAAAA,WAAAA,WAAA,MAAA,IAAA,CAAA,IAAA;AACA,EAAAA,WAAAA,WAAA,OAAA,IAAA,CAAA,IAAA;AACA,EAAAA,WAAAA,WAAA,WAAA,IAAA,CAAA,IAAA;AACD,GALY,cAAA,YAAS,CAAA,EAAA;",
|
|
6
6
|
"names": ["NVMAccess"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FLiRS, RouteProtocolDataRate } from "@zwave-js/core";
|
|
2
|
-
import { Bytes } from "@zwave-js/shared";
|
|
2
|
+
import { Bytes, type BytesView } from "@zwave-js/shared";
|
|
3
3
|
export declare const ROUTECACHE_SIZE: number;
|
|
4
4
|
export declare const EMPTY_ROUTECACHE_FILL = 255;
|
|
5
5
|
export declare const emptyRouteCache: Uint8Array<ArrayBuffer>;
|
|
@@ -13,7 +13,7 @@ export interface RouteCache {
|
|
|
13
13
|
lwr: Route;
|
|
14
14
|
nlwr: Route;
|
|
15
15
|
}
|
|
16
|
-
export declare function parseRoute(buffer:
|
|
16
|
+
export declare function parseRoute(buffer: BytesView, offset: number): Route;
|
|
17
17
|
export declare function encodeRoute(route: Route | undefined): Bytes;
|
|
18
18
|
export declare function getEmptyRoute(): Route;
|
|
19
19
|
//# sourceMappingURL=routeCache.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/common/routeCache.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\ttype FLiRS,\n\tMAX_REPEATERS,\n\tRouteProtocolDataRate,\n\tprotocolDataRateMask,\n} from \"@zwave-js/core\";\nimport { Bytes } from \"@zwave-js/shared\";\n\nconst ROUTE_SIZE = MAX_REPEATERS + 1;\nexport const ROUTECACHE_SIZE = 2 * ROUTE_SIZE;\nexport const EMPTY_ROUTECACHE_FILL = 0xff;\nexport const emptyRouteCache = new Uint8Array(ROUTECACHE_SIZE)\n\t.fill(EMPTY_ROUTECACHE_FILL);\n\nenum Beaming {\n\t\"1000ms\" = 0x40,\n\t\"250ms\" = 0x20,\n}\n\nexport interface Route {\n\tbeaming: FLiRS;\n\tprotocolRate: RouteProtocolDataRate;\n\trepeaterNodeIDs?: number[];\n}\n\nexport interface RouteCache {\n\tnodeId: number;\n\tlwr: Route;\n\tnlwr: Route;\n}\n\nexport function parseRoute(buffer:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;AAAA,kBAKO;AACP,
|
|
4
|
+
"sourcesContent": ["import {\n\ttype FLiRS,\n\tMAX_REPEATERS,\n\tRouteProtocolDataRate,\n\tprotocolDataRateMask,\n} from \"@zwave-js/core\";\nimport { Bytes, type BytesView } from \"@zwave-js/shared\";\n\nconst ROUTE_SIZE = MAX_REPEATERS + 1;\nexport const ROUTECACHE_SIZE = 2 * ROUTE_SIZE;\nexport const EMPTY_ROUTECACHE_FILL = 0xff;\nexport const emptyRouteCache = new Uint8Array(ROUTECACHE_SIZE)\n\t.fill(EMPTY_ROUTECACHE_FILL);\n\nenum Beaming {\n\t\"1000ms\" = 0x40,\n\t\"250ms\" = 0x20,\n}\n\nexport interface Route {\n\tbeaming: FLiRS;\n\tprotocolRate: RouteProtocolDataRate;\n\trepeaterNodeIDs?: number[];\n}\n\nexport interface RouteCache {\n\tnodeId: number;\n\tlwr: Route;\n\tnlwr: Route;\n}\n\nexport function parseRoute(buffer: BytesView, offset: number): Route {\n\tconst routeConf = buffer[offset + MAX_REPEATERS];\n\tconst ret: Route = {\n\t\tbeaming: (Beaming[routeConf & 0x60] ?? false) as FLiRS,\n\t\tprotocolRate: routeConf & protocolDataRateMask,\n\t\trepeaterNodeIDs: [\n\t\t\t...buffer.subarray(offset, offset + MAX_REPEATERS),\n\t\t].filter((id) => id !== 0),\n\t};\n\tif (ret.repeaterNodeIDs![0] === 0xfe) delete ret.repeaterNodeIDs;\n\treturn ret;\n}\n\nexport function encodeRoute(route: Route | undefined): Bytes {\n\tconst ret = new Bytes(ROUTE_SIZE).fill(0);\n\tif (route) {\n\t\tif (route.repeaterNodeIDs) {\n\t\t\tfor (\n\t\t\t\tlet i = 0;\n\t\t\t\ti < MAX_REPEATERS && i < route.repeaterNodeIDs.length;\n\t\t\t\ti++\n\t\t\t) {\n\t\t\t\tret[i] = route.repeaterNodeIDs[i];\n\t\t\t}\n\t\t} else {\n\t\t\tret[0] = 0xfe;\n\t\t}\n\t\tlet routeConf = 0;\n\t\tif (route.beaming) routeConf |= Beaming[route.beaming] ?? 0;\n\t\trouteConf |= route.protocolRate & protocolDataRateMask;\n\t\tret[ROUTE_SIZE - 1] = routeConf;\n\t}\n\n\treturn ret;\n}\n\nexport function getEmptyRoute(): Route {\n\treturn {\n\t\tbeaming: false,\n\t\tprotocolRate: RouteProtocolDataRate.ZWave_40k,\n\t\trepeaterNodeIDs: undefined,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;AAAA,kBAKO;A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 +1,11 @@
|
|
|
1
1
|
import { type CommandClasses } from "@zwave-js/core";
|
|
2
|
-
import { Bytes } from "@zwave-js/shared";
|
|
2
|
+
import { Bytes, type BytesView } from "@zwave-js/shared";
|
|
3
3
|
export interface SUCUpdateEntry {
|
|
4
4
|
nodeId: number;
|
|
5
5
|
changeType: number;
|
|
6
6
|
supportedCCs: CommandClasses[];
|
|
7
7
|
controlledCCs: CommandClasses[];
|
|
8
8
|
}
|
|
9
|
-
export declare function parseSUCUpdateEntry(buffer:
|
|
9
|
+
export declare function parseSUCUpdateEntry(buffer: BytesView, offset: number): SUCUpdateEntry | undefined;
|
|
10
10
|
export declare function encodeSUCUpdateEntry(entry: SUCUpdateEntry | undefined): Bytes;
|
|
11
11
|
//# sourceMappingURL=sucUpdateEntry.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/common/sucUpdateEntry.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\ttype CommandClasses,\n\tZWaveError,\n\tZWaveErrorCodes,\n\tencodeCCList,\n\tparseCCList,\n} from \"@zwave-js/core\";\nimport { Bytes } from \"@zwave-js/shared\";\nimport {\n\tSUC_UPDATE_ENTRY_SIZE,\n\tSUC_UPDATE_NODEPARM_MAX,\n} from \"../../consts.js\";\n\nexport interface SUCUpdateEntry {\n\tnodeId: number;\n\tchangeType: number; // TODO: This is some kind of enum\n\tsupportedCCs: CommandClasses[];\n\tcontrolledCCs: CommandClasses[];\n}\n\nexport function parseSUCUpdateEntry(\n\tbuffer:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAA,kBAMO;AACP,
|
|
4
|
+
"sourcesContent": ["import {\n\ttype CommandClasses,\n\tZWaveError,\n\tZWaveErrorCodes,\n\tencodeCCList,\n\tparseCCList,\n} from \"@zwave-js/core\";\nimport { Bytes, type BytesView } from \"@zwave-js/shared\";\nimport {\n\tSUC_UPDATE_ENTRY_SIZE,\n\tSUC_UPDATE_NODEPARM_MAX,\n} from \"../../consts.js\";\n\nexport interface SUCUpdateEntry {\n\tnodeId: number;\n\tchangeType: number; // TODO: This is some kind of enum\n\tsupportedCCs: CommandClasses[];\n\tcontrolledCCs: CommandClasses[];\n}\n\nexport function parseSUCUpdateEntry(\n\tbuffer: BytesView,\n\toffset: number,\n): SUCUpdateEntry | undefined {\n\tconst slice = buffer.subarray(offset, offset + SUC_UPDATE_ENTRY_SIZE);\n\tif (slice.every((b) => b === 0x00 || b === 0xff)) {\n\t\treturn;\n\t}\n\tconst nodeId = slice[0];\n\tconst changeType = slice[1];\n\tconst { supportedCCs, controlledCCs } = parseCCList(\n\t\tslice.subarray(2, SUC_UPDATE_ENTRY_SIZE),\n\t);\n\treturn {\n\t\tnodeId,\n\t\tchangeType,\n\t\tsupportedCCs: supportedCCs.filter((cc) => cc > 0),\n\t\tcontrolledCCs: controlledCCs.filter((cc) => cc > 0),\n\t};\n}\n\nexport function encodeSUCUpdateEntry(\n\tentry: SUCUpdateEntry | undefined,\n): Bytes {\n\tconst ret = new Bytes(SUC_UPDATE_ENTRY_SIZE).fill(0);\n\tif (entry) {\n\t\tret[0] = entry.nodeId;\n\t\tret[1] = entry.changeType;\n\t\tconst ccList = encodeCCList(entry.supportedCCs, entry.controlledCCs);\n\t\tif (ccList.length > SUC_UPDATE_NODEPARM_MAX) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"Cannot encode SUC update entry, too many CCs\",\n\t\t\t\tZWaveErrorCodes.Argument_Invalid,\n\t\t\t);\n\t\t}\n\t\tret.set(ccList, 2);\n\t}\n\treturn ret;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAA,kBAMO;AACP,oBAAsC;AACtC,oBAGO;AASD,SAAU,oBACf,QACA,QAAc;AAEd,QAAM,QAAQ,OAAO,SAAS,QAAQ,SAAS,mCAAqB;AACpE,MAAI,MAAM,MAAM,CAAC,MAAM,MAAM,KAAQ,MAAM,GAAI,GAAG;AACjD;EACD;AACA,QAAM,SAAS,MAAM,CAAC;AACtB,QAAM,aAAa,MAAM,CAAC;AAC1B,QAAM,EAAE,cAAc,cAAa,QAAK,yBACvC,MAAM,SAAS,GAAG,mCAAqB,CAAC;AAEzC,SAAO;IACN;IACA;IACA,cAAc,aAAa,OAAO,CAAC,OAAO,KAAK,CAAC;IAChD,eAAe,cAAc,OAAO,CAAC,OAAO,KAAK,CAAC;;AAEpD;AAnBgB;AAqBV,SAAU,qBACf,OAAiC;AAEjC,QAAM,MAAM,IAAI,oBAAM,mCAAqB,EAAE,KAAK,CAAC;AACnD,MAAI,OAAO;AACV,QAAI,CAAC,IAAI,MAAM;AACf,QAAI,CAAC,IAAI,MAAM;AACf,UAAM,aAAS,0BAAa,MAAM,cAAc,MAAM,aAAa;AACnE,QAAI,OAAO,SAAS,uCAAyB;AAC5C,YAAM,IAAI,uBACT,gDACA,4BAAgB,gBAAgB;IAElC;AACA,QAAI,IAAI,QAAQ,CAAC;EAClB;AACA,SAAO;AACR;AAjBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { type BytesView } from "@zwave-js/shared";
|
|
1
2
|
import type { NVMIO } from "./definitions.js";
|
|
2
3
|
export declare function nvmReadUInt32LE(io: NVMIO, position: number): Promise<number>;
|
|
3
4
|
export declare function nvmReadUInt16LE(io: NVMIO, position: number): Promise<number>;
|
|
4
5
|
export declare function nvmReadUInt32BE(io: NVMIO, position: number): Promise<number>;
|
|
5
6
|
export declare function nvmReadUInt16BE(io: NVMIO, position: number): Promise<number>;
|
|
6
7
|
export declare function nvmReadUInt8(io: NVMIO, position: number): Promise<number>;
|
|
7
|
-
export declare function nvmWriteBuffer(io: NVMIO, position: number, buffer:
|
|
8
|
-
export declare function nvmReadBuffer(io: NVMIO, position: number, length: number): Promise<
|
|
8
|
+
export declare function nvmWriteBuffer(io: NVMIO, position: number, buffer: BytesView): Promise<void>;
|
|
9
|
+
export declare function nvmReadBuffer(io: NVMIO, position: number, length: number): Promise<BytesView>;
|
|
9
10
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/common/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { Bytes } from \"@zwave-js/shared\";\nimport type { NVMIO } from \"./definitions.js\";\n\nexport async function nvmReadUInt32LE(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 4);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt32LE(0);\n}\n\nexport async function nvmReadUInt16LE(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 2);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt16LE(0);\n}\n\nexport async function nvmReadUInt32BE(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 4);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt32BE(0);\n}\n\nexport async function nvmReadUInt16BE(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 2);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt16BE(0);\n}\n\nexport async function nvmReadUInt8(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 1);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt8(0);\n}\n\nexport async function nvmWriteBuffer(\n\tio: NVMIO,\n\tposition: number,\n\tbuffer:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Bytes, type BytesView } from \"@zwave-js/shared\";\nimport type { NVMIO } from \"./definitions.js\";\n\nexport async function nvmReadUInt32LE(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 4);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt32LE(0);\n}\n\nexport async function nvmReadUInt16LE(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 2);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt16LE(0);\n}\n\nexport async function nvmReadUInt32BE(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 4);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt32BE(0);\n}\n\nexport async function nvmReadUInt16BE(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 2);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt16BE(0);\n}\n\nexport async function nvmReadUInt8(\n\tio: NVMIO,\n\tposition: number,\n): Promise<number> {\n\tconst { buffer } = await io.read(position, 1);\n\tconst bytes = Bytes.view(buffer);\n\treturn bytes.readUInt8(0);\n}\n\nexport async function nvmWriteBuffer(\n\tio: NVMIO,\n\tposition: number,\n\tbuffer: BytesView,\n): Promise<void> {\n\tconst chunkSize = await io.determineChunkSize();\n\tlet offset = 0;\n\twhile (offset < buffer.length) {\n\t\tconst chunk = buffer.subarray(offset, offset + chunkSize);\n\t\tconst { bytesWritten } = await io.write(position + offset, chunk);\n\t\toffset += bytesWritten;\n\t}\n}\n\nexport async function nvmReadBuffer(\n\tio: NVMIO,\n\tposition: number,\n\tlength: number,\n): Promise<BytesView> {\n\tconst ret = new Uint8Array(length);\n\tconst chunkSize = await io.determineChunkSize();\n\tlet offset = 0;\n\twhile (offset < length) {\n\t\tconst { buffer, endOfFile } = await io.read(\n\t\t\tposition + offset,\n\t\t\tMath.min(chunkSize, length - offset),\n\t\t);\n\t\tret.set(buffer, offset);\n\t\toffset += buffer.length;\n\t\tif (endOfFile) break;\n\t}\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AAQ,KAAK;AAChE,cAAU;EACX;AACD;AAZsB;AActB,eAAsB,cACrB,IACA,UACA,QAAc;AAEd,QAAM,MAAM,IAAI,WAAW,MAAM;AACjC,QAAM,YAAY,MAAM,GAAG,mBAAkB;AAC7C,MAAI,SAAS;AACb,SAAO,SAAS,QAAQ;AACvB,UAAM,EAAE,QAAQ,UAAS,IAAK,MAAM,GAAG,KACtC,WAAW,QACX,KAAK,IAAI,WAAW,SAAS,MAAM,CAAC;AAErC,QAAI,IAAI,QAAQ,MAAM;AACtB,cAAU,OAAO;AACjB,QAAI;AAAW;EAChB;AACA,SAAO,IAAI,SAAS,GAAG,MAAM;AAC9B;AAlBsB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type BytesView } from "@zwave-js/shared";
|
|
1
2
|
import type { NVMAccess, NVMIO } from "../common/definitions.js";
|
|
2
3
|
export declare class BufferedNVMReader implements NVMIO {
|
|
3
4
|
constructor(inner: NVMIO);
|
|
@@ -9,10 +10,10 @@ export declare class BufferedNVMReader implements NVMIO {
|
|
|
9
10
|
determineChunkSize(): Promise<number>;
|
|
10
11
|
private readBuffered;
|
|
11
12
|
read(offset: number, length: number): Promise<{
|
|
12
|
-
buffer:
|
|
13
|
+
buffer: BytesView;
|
|
13
14
|
endOfFile: boolean;
|
|
14
15
|
}>;
|
|
15
|
-
write(offset: number, data:
|
|
16
|
+
write(offset: number, data: BytesView): Promise<{
|
|
16
17
|
bytesWritten: number;
|
|
17
18
|
endOfFile: boolean;
|
|
18
19
|
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/io/BufferedNVMReader.ts"],
|
|
4
|
-
"sourcesContent": ["import { Bytes } from \"@zwave-js/shared\";\nimport type { NVMAccess, NVMIO } from \"../common/definitions.js\";\n\ninterface BufferedChunk {\n\toffset: number;\n\tdata:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Bytes, type BytesView } from \"@zwave-js/shared\";\nimport type { NVMAccess, NVMIO } from \"../common/definitions.js\";\n\ninterface BufferedChunk {\n\toffset: number;\n\tdata: BytesView;\n}\n\nexport class BufferedNVMReader implements NVMIO {\n\tpublic constructor(inner: NVMIO) {\n\t\tthis._inner = inner;\n\t}\n\n\tprivate _inner: NVMIO;\n\t// Already-read chunks. There are a few rules to follow:\n\t// - Offsets MUST be multiples of the chunk size\n\t// - The size of each chunk must be exactly the chunk size\n\tprivate _buffer: BufferedChunk[] = [];\n\n\topen(access: NVMAccess.Read | NVMAccess.Write): Promise<NVMAccess> {\n\t\treturn this._inner.open(access);\n\t}\n\tget size(): number {\n\t\treturn this._inner.size;\n\t}\n\tget accessMode(): NVMAccess {\n\t\treturn this._inner.accessMode;\n\t}\n\tdetermineChunkSize(): Promise<number> {\n\t\treturn this._inner.determineChunkSize();\n\t}\n\n\tprivate async readBuffered(\n\t\talignedOffset: number,\n\t\tchunkSize: number,\n\t): Promise<BytesView> {\n\t\tlet buffered = this._buffer.find((chunk) =>\n\t\t\tchunk.offset === alignedOffset\n\t\t);\n\t\tif (!buffered) {\n\t\t\tconst { buffer: data } = await this._inner.read(\n\t\t\t\talignedOffset,\n\t\t\t\tchunkSize,\n\t\t\t);\n\t\t\tbuffered = { data, offset: alignedOffset };\n\t\t\tthis._buffer.push(buffered);\n\t\t}\n\t\treturn buffered.data;\n\t}\n\n\tasync read(\n\t\toffset: number,\n\t\tlength: number,\n\t): Promise<{ buffer: BytesView; endOfFile: boolean }> {\n\t\t// Limit the read size to the chunk size. This ensures we have to deal with maximum 2 chunks or read requests\n\t\tconst chunkSize = await this.determineChunkSize();\n\t\tlength = Math.min(length, chunkSize);\n\n\t\t// Figure out at which offsets to read\n\t\tconst firstChunkStart = offset - offset % chunkSize;\n\t\tconst secondChunkStart = (offset + length)\n\t\t\t- (offset + length) % chunkSize;\n\n\t\t// Read one or two chunks, depending on how many are needed\n\t\tconst chunks: BytesView[] = [];\n\t\tchunks.push(await this.readBuffered(firstChunkStart, chunkSize));\n\t\tif (secondChunkStart > firstChunkStart) {\n\t\t\tchunks.push(await this.readBuffered(secondChunkStart, chunkSize));\n\t\t}\n\t\tconst alignedBuffer = Bytes.concat(chunks);\n\n\t\t// Then slice out the section we need\n\t\tconst endOfFile = offset + length >= this.size;\n\t\tconst buffer = alignedBuffer.subarray(\n\t\t\toffset - firstChunkStart,\n\t\t\toffset - firstChunkStart + length,\n\t\t);\n\n\t\treturn {\n\t\t\tbuffer,\n\t\t\tendOfFile,\n\t\t};\n\t}\n\n\tasync write(\n\t\toffset: number,\n\t\tdata: BytesView,\n\t): Promise<{ bytesWritten: number; endOfFile: boolean }> {\n\t\tconst ret = await this._inner.write(offset, data);\n\n\t\t// Invalidate cached chunks\n\t\tconst chunkSize = await this.determineChunkSize();\n\t\t// Figure out at which offsets to read\n\t\tconst firstChunkStart = offset - offset % chunkSize;\n\t\tconst lastChunkStart = (offset + ret.bytesWritten)\n\t\t\t- (offset + ret.bytesWritten) % chunkSize;\n\n\t\t// TODO: We should update existing chunks where possible\n\t\tfor (let i = firstChunkStart; i <= lastChunkStart; i += chunkSize) {\n\t\t\tconst index = this._buffer.findIndex((chunk) => chunk.offset === i);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis._buffer.splice(index, 1);\n\t\t\t}\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tclose(): Promise<void> {\n\t\treturn this._inner.close();\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,oBAAsC;AAQhC,MAAO,kBAAiB;EAR9B,OAQ8B;;;EAC7B,YAAmB,OAAY;AAC9B,SAAK,SAAS;EACf;EAEQ;;;;EAIA,UAA2B,CAAA;EAEnC,KAAK,QAAwC;AAC5C,WAAO,KAAK,OAAO,KAAK,MAAM;EAC/B;EACA,IAAI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