Initial release of Web Tools 0.0.5
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { calculateCrc, calculateCrcChunks, formatCrc, type CrcParameters } from '@/lib/crc'
|
||||
|
||||
export interface CrcWorkerBlock {
|
||||
startAddress: number
|
||||
data: Uint8Array
|
||||
}
|
||||
|
||||
export interface CrcWorkerParseRequest {
|
||||
type: 'parse'
|
||||
id: number
|
||||
file: File
|
||||
}
|
||||
|
||||
export interface CrcWorkerCalculateRequest {
|
||||
type: 'calculate'
|
||||
id: number
|
||||
parameters: CrcParameters
|
||||
}
|
||||
|
||||
export type CrcWorkerRequest = CrcWorkerParseRequest | CrcWorkerCalculateRequest
|
||||
|
||||
export interface CrcBlockResult {
|
||||
startAddress: number
|
||||
endAddress: number
|
||||
length: number
|
||||
crc: string
|
||||
}
|
||||
|
||||
export type CrcWorkerResponse = {
|
||||
type: 'parsed'
|
||||
id: number
|
||||
format: 'Intel HEX' | 'BIN'
|
||||
totalBytes: number
|
||||
blockCount: number
|
||||
warnings: string[]
|
||||
} | {
|
||||
type: 'calculated'
|
||||
id: number
|
||||
combinedResult: string
|
||||
blockResults: CrcBlockResult[]
|
||||
} | {
|
||||
type: 'error'
|
||||
id: number
|
||||
operation: CrcWorkerRequest['type']
|
||||
error: string
|
||||
}
|
||||
|
||||
export function calculateCrcReport(blocks: CrcWorkerBlock[], parameters: CrcParameters) {
|
||||
const combinedValue = calculateCrcChunks(blocks.map((block) => block.data), parameters)
|
||||
const combinedResult = formatCrc(combinedValue, parameters.width)
|
||||
const blockResults = blocks.map((block) => ({
|
||||
startAddress: block.startAddress,
|
||||
endAddress: block.startAddress + block.data.length - 1,
|
||||
length: block.data.length,
|
||||
crc: blocks.length === 1
|
||||
? combinedResult
|
||||
: formatCrc(calculateCrc(block.data, parameters), parameters.width),
|
||||
}))
|
||||
return { combinedResult, blockResults }
|
||||
}
|
||||
Reference in New Issue
Block a user