@rdbi/tools
v1.0.0-beta.20220825.2
Published
为 rdbi-admin 微服务集成环境提供的工具包,提供了 `socket.sendMsg`, `sendEvent` 之类的工具函数。
Downloads
24
Readme
@rdbi/tools
为 rdbi-admin 微服务集成环境提供的工具包,提供了 socket.sendMsg
, sendEvent
之类的工具函数。
这些工具函数只有在以微服务方式集成到主应用时才会被注入具体实现,请在集成环境里进行调试。
Install
yarn add @rdbi/tools
APIs
拼装消息
请调用此方法进行消息拼装,内部会生成唯一的 seq。
import { RDBITools } from '@rdbi/tools'
const message = await RDBITools.configureMessage({
cmd_type: 'call_function',
cmd_cont: 'go',
handler: 'patternTracerConsumerHandler',
board_id: RDBITools.getGlobalSelectedSite?.()?.boardId,
})
获取全局选中的 Site 及相关属性
import { RDBITools } from '@rdbi/tools'
// 可能是空,空就给予默认值(空对象)
const site = RDBITools.getGlobalSelectedSite?.() ?? ({} as Site)
// board_id
const board_id: string = site.boardId
// board_slot
const board_slot: string | number = site.boardSlot
// board_sn
const board_sn: string = site.boardSn
// board_block,值为 1 和 2,1 是 left / ALPG1, 2 是 right / ALPG2
const board_block: string | number = site.boardBlock
// dut_list,为 当前 site 的 system_dut list
const board_dut_list: number[] = site.dut_list ?? []
// dut_pin list,resource 可能为空,切勿去掉问号
const dut_pin: number[] = site.resource?.dut_pin ?? []
// TS 定义
export type Site = {
boardSlot: string | number
boardBlock: string | number
boardId: string
boardSn: string
protoVersion?: string
dut_list?: number[]
resource?: Resource
}
export type Resource = {
bib_dut_count: number
system_dut: Systemdut[]
dut_pin: number[]
}
export type Systemdut = {
block: number
dut_list: number[]
}
获取所有 sites
import { RDBITools } from '@rdbi/tools'
const sites: Site[] = RDBITools.getSites()
// TS 定义
export type Site = {
boardSlot: string | number
boardBlock: string | number
boardId: string
boardSn: string
protoVersion?: string
dut_list?: number[]
resource?: Resource
}
export type Resource = {
bib_dut_count: number
system_dut: Systemdut[]
dut_pin: number[]
}
export type Systemdut = {
block: number
dut_list: number[]
}
获取所有 start test 以及 pattern 信息
import { RDBITools } from '@rdbi/tools'
const startTests: TestInfor[] = RDBITools.getStartTests()
// TS 定义
type TestInfor = {
test_name: string
test_num: number
pattern: string
}
获取所有的 system_dut
import { RDBITools } from '@rdbi/tools'
const system_duts: number[] = RDBITools.getSystemDUTs()
获取所有的 dut_pin
import { RDBITools } from '@rdbi/tools'
const dut_pins: number[] = RDBITools.getDUTPins()
获取全局选中的 system_dut
import { RDBITools } from '@rdbi/tools'
const system_dut: number = RDBITools.getGlobalSelectedSystemDUT()
获取 Control Panel -> Setting DUT 选中的 dut 列表
import { RDBITools } from '@rdbi/tools'
const system_duts: number[] = RDBITools.getCheckedSettingDUT()
获取全局的 msg_session
import { RDBITools } from '@rdbi/tools'
const msg_session: string = RDBITools.getMsgSession()
发送 websocket 请求
import { RDBITools } from '@rdbi/tools'
const message = await RDBITools.configureMessage({
cmd_type: 'call_function',
cmd_cont: 'go',
board_id: RDBITools.getGlobalSelectedSite?.()?.boardId,
})
RDBITools.getSokcet().sendMsg({
seq: message.msg_seq,
data: message,
success: (data) => {
console.log(data, 'data')
},
error: (error) => {
console.log(error, 'error')
},
})
发送 sse 请求
import { RDBITools } from '@rdbi/tools'
const message = await RDBITools.configureMessage({
cmd_type: 'call_function',
cmd_cont: 'go',
handler: 'patternTracerConsumerHandler', // 必传
board_id: RDBITools.getGlobalSelectedSite?.()?.boardId,
})
// T 为范型,自由指定
const evtSource = RDBITools.sendEvent<T>('http://ip:port', message, {
onSuccess: (data) => {
console.log(data, 'data')
// 如果知道符合条件可以关闭
// evtSource?.close()
},
})