48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
// 纯 JS 资产未类型化,关闭该文件类型检查
|
|
// @ts-ignore
|
|
import { parseEd713Radar, parseEd719Radar } from '@/ble/parsers/commonParser'
|
|
|
|
describe('parseEd713Radar', () => {
|
|
it('长度不足 60 字节时返回 valid: false', () => {
|
|
const result = parseEd713Radar(new Uint8Array(30))
|
|
expect(result.valid).toBe(false)
|
|
expect(result.reason).toBe('LENGTH_LT_60')
|
|
})
|
|
|
|
it('解析 60 字节体征帧关键字段', () => {
|
|
const buf = new Uint8Array(60)
|
|
buf[24] = 1 // peopleCount
|
|
buf[28] = 75 // heartRate
|
|
buf[29] = 18 // respRate
|
|
buf.fill(7, 38, 58) // respWave 20 字节
|
|
buf[59] = 1 // narrowFlag
|
|
const r = parseEd713Radar(buf)
|
|
expect(r.valid).toBe(true)
|
|
expect(r.heartRate).toBe(75)
|
|
expect(r.respRate).toBe(18)
|
|
expect(r.peopleCount).toBe(1)
|
|
expect(r.respWave).toHaveLength(20)
|
|
expect(r.respWave[0]).toBe(7)
|
|
expect(r.narrowFlag).toBe(1)
|
|
})
|
|
})
|
|
|
|
describe('parseEd719Radar', () => {
|
|
it('长度不足 24 字节时返回 valid: false', () => {
|
|
const result = parseEd719Radar(new Uint8Array(10))
|
|
expect(result.valid).toBe(false)
|
|
expect(result.reason).toBe('LENGTH_LT_24')
|
|
})
|
|
|
|
it('解析 24 字节跌倒检测帧', () => {
|
|
const buf = new Uint8Array(24)
|
|
buf[4] = 1 // eventState
|
|
buf[5] = 1 // peopleState
|
|
const r = parseEd719Radar(buf)
|
|
expect(r.valid).toBe(true)
|
|
expect(r.eventState).toBe(1)
|
|
expect(r.peopleState).toBe(1)
|
|
})
|
|
})
|