Skip to content

Commit 3519b6b

Browse files
committed
[feat]:add uds tester simulate by
1 parent b94f488 commit 3519b6b

File tree

8 files changed

+70
-48
lines changed

8 files changed

+70
-48
lines changed

resources/examples/uds_bin_file/uds_bin_file.ecb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@
392392
"autoSubfunc": true
393393
}
394394
]
395-
}
395+
},
396+
"simulateBy": "5c043bd6-ddca-449a-b535-1ae865085123"
396397
}
397398
},
398399
"subFunction": {},
@@ -414,7 +415,10 @@
414415
"can": {}
415416
},
416417
"graphs": {},
417-
"tests": {}
418+
"tests": {},
419+
"guages": {},
420+
"vars": {},
421+
"datas": {}
418422
},
419423
"project": {
420424
"wins": {
@@ -452,8 +456,8 @@
452456
},
453457
"f304259b-dc7d-460b-9729-4eee2d1156de_sequence": {
454458
"pos": {
455-
"x": 219,
456-
"y": 63,
459+
"x": 462,
460+
"y": 39,
457461
"w": 984,
458462
"h": 400
459463
},
@@ -481,8 +485,8 @@
481485
},
482486
"tester": {
483487
"pos": {
484-
"x": 425,
485-
"y": 14,
488+
"x": 46,
489+
"y": 284,
486490
"w": 1067,
487491
"h": 444
488492
},

resources/examples/uds_hex_file/uds_hex_file.ecb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@
457457
"autoSubfunc": true
458458
}
459459
]
460-
}
460+
},
461+
"simulateBy": "5c043bd6-ddca-449a-b535-1ae865085123"
461462
}
462463
},
463464
"subFunction": {},
@@ -565,8 +566,8 @@
565566
},
566567
"tester": {
567568
"pos": {
568-
"x": 952,
569-
"y": 65,
569+
"x": 327,
570+
"y": 26,
570571
"w": 906,
571572
"h": 400
572573
},
@@ -662,8 +663,8 @@
662663
},
663664
"datas": {
664665
"pos": {
665-
"x": 275.5,
666-
"y": 246,
666+
"x": 346.5,
667+
"y": 215,
667668
"w": 1116,
668669
"h": 400
669670
},

src/main/docan/cantp.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,7 @@ export class CAN_TP implements CanTp {
172172
}
173173
> = {}
174174
lastWriteError?: TpError
175-
constructor(
176-
base: CanBase,
177-
private listenOnly = false
178-
) {
175+
constructor(base: CanBase) {
179176
this.base = base
180177
//close peak tp default handle
181178

@@ -283,7 +280,7 @@ export class CAN_TP implements CanTp {
283280
}
284281
})
285282
}
286-
async sendFC(addr: CanAddr, fs: number) {
283+
async sendFC(addr: CanAddr, fs: number, listenOnly: boolean) {
287284
return new Promise<{ ts: number; bs: number; stMin: number }>((resolve, reject) => {
288285
const extAddr = []
289286
if (addr.addrFormat == CAN_ADDR_FORMAT.EXTENDED || addr.addrFormat == CAN_ADDR_FORMAT.MIXED) {
@@ -298,7 +295,7 @@ export class CAN_TP implements CanTp {
298295
stMin = 127
299296
}
300297
const bs = addr.bs
301-
if (this.listenOnly) {
298+
if (listenOnly) {
302299
resolve({
303300
ts: 0,
304301
bs,
@@ -575,11 +572,11 @@ export class CAN_TP implements CanTp {
575572
}
576573
}
577574

578-
getReadId(addr: CanAddr): string {
575+
getReadId(addr: CanAddr, listenOnly = false): string {
579576
const id = addrToId(addr)
580577
const tpIdStr = `tp-${id}-${addrToStr(addr)}`
581578
if (!this.rxBaseHandleExist.has(tpIdStr)) {
582-
const cb = baseHandle.bind({ addr, id, inst: this })
579+
const cb = baseHandle.bind({ addr, id, inst: this, listenOnly })
583580
const baseId = this.base.getReadBaseId(id, addr)
584581
this.rxBaseHandleExist.set(tpIdStr, {
585582
baseId,
@@ -625,7 +622,7 @@ export class CAN_TP implements CanTp {
625622
function baseHandle(val: CanMessage) {
626623
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
627624
//@ts-ignore
628-
const _this = this as { addr: CanAddr; id: number; inst: CAN_TP }
625+
const _this = this as { addr: CanAddr; id: number; inst: CAN_TP; listenOnly: boolean }
629626
const tpCmdId = _this.inst.getReadId(_this.addr)
630627
const status = _this.inst.tpStatus[tpCmdId] || 0
631628
let index = 0
@@ -728,11 +725,10 @@ shall ignore the received FF N_PDU and not transmit a FC N_PDU.*/
728725
// this.inst.event.emit(tpCmdId,{data,ts:val.ts})
729726
_this.inst.tpDataBuffer[tpCmdId] = data
730727
_this.inst.tpStatus[tpCmdId] = 2
731-
732728
const nbrTImer = setTimeout(() => {
733729
//write flow control
734730
_this.inst
735-
.sendFC(swapAddr(_this.addr), 0)
731+
.sendFC(swapAddr(_this.addr), 0, _this.listenOnly)
736732
.then((val) => {
737733
_this.inst.tpStatus[tpCmdId] = 1
738734
_this.inst.tpDataFc[tpCmdId] = {
@@ -826,7 +822,7 @@ shall ignore the received FF N_PDU and not transmit a FC N_PDU.*/
826822
_this.inst.tpStatus[tpCmdId] = 2
827823
//TODO:add delay here?
828824
_this.inst
829-
.sendFC(swapAddr(_this.addr), 0)
825+
.sendFC(swapAddr(_this.addr), 0, _this.listenOnly)
830826
.then((val) => {
831827
_this.inst.tpStatus[tpCmdId] = 1
832828
fcInfo.stMin = val.stMin

src/main/ipc/uds.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ async function globalStart(
328328
const tester = testers[key]
329329
if (tester.type == 'can') {
330330
for (const val of canBaseMap.values()) {
331-
const cantp = new CAN_TP(val, true)
331+
const cantp = new CAN_TP(val)
332332
for (const addr of tester.address) {
333333
if (addr.type == 'can' && addr.canAddr) {
334-
const id = cantp.getReadId(addr.canAddr)
334+
const id = cantp.getReadId(addr.canAddr, true)
335335
cantp.event.on(id, (data) => {
336336
if (!(data instanceof TpError)) {
337337
const log = new UdsLOG(tester.name)
@@ -343,7 +343,7 @@ async function globalStart(
343343
log.close()
344344
}
345345
})
346-
const idR = cantp.getReadId(swapAddr(addr.canAddr))
346+
const idR = cantp.getReadId(swapAddr(addr.canAddr), true)
347347
cantp.event.on(idR, (data) => {
348348
if (!(data instanceof TpError)) {
349349
const log = new UdsLOG(tester.name)

src/main/nodeItem.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ export class NodeClass {
177177

178178
//cantp
179179
for (const tester of Object.values(this.testers)) {
180-
if (tester && tester.address.length > 0) {
180+
console.log(tester.simulateBy, nodeItem.id)
181+
if (tester.simulateBy == nodeItem.id && tester.address.length > 0) {
181182
for (const c of nodeItem.channel) {
182183
const canBaseItem = this.canBaseMap.get(c)
183184
if (canBaseItem && tester.type == 'can') {
@@ -204,7 +205,7 @@ export class NodeClass {
204205
}
205206
}
206207
})
207-
const idR = tp.getReadId(swapAddr(addr.canAddr))
208+
const idR = tp.getReadId(swapAddr(addr.canAddr), true)
208209
tp.event.on(idR, (data) => {
209210
if (data instanceof CanTpError) {
210211
//TODO:

src/main/share/tester.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export interface TesterInfo {
1010
targetDeviceId?: string
1111
seqList: Sequence[]
1212
address: UdsAddress[]
13+
simulateBy?: string
1314
allServiceList: Partial<Record<ServiceId, ServiceItem[]>>
1415
}

src/renderer/src/views/uds/components/config/tester/subsequence.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,16 @@ function logDisplay(method: string, vals: LogItem[]) {
435435
if (val.message.id != props.id) {
436436
continue
437437
}
438-
excuseResults.value[val.message.data.index].status = val.message.data.action
439-
if (val.message.data.action == 'start') {
440-
excuseResults.value[val.message.data.index].msg = 'Running'
441-
} else if (val.message.data.action == 'finished') {
442-
excuseResults.value[val.message.data.index].msg = 'Success'
443-
}
444-
if (val.message.data.percent) {
445-
excuseResults.value[val.message.data.index].msg = val.message.data.percent.toFixed(2) + '%'
438+
if (excuseResults.value[val.message.data.index]) {
439+
excuseResults.value[val.message.data.index].status = val.message.data.action
440+
if (val.message.data.action == 'start') {
441+
excuseResults.value[val.message.data.index].msg = 'Running'
442+
} else if (val.message.data.action == 'finished') {
443+
excuseResults.value[val.message.data.index].msg = 'Success'
444+
}
445+
if (val.message.data.percent) {
446+
excuseResults.value[val.message.data.index].msg = val.message.data.percent.toFixed(2) + '%'
447+
}
446448
}
447449
}
448450
}

src/renderer/src/views/uds/components/config/tester/testercan.vue

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
label-width="150px"
77
:rules="rules"
88
size="small"
9-
:disabled="globalStart"
109
hide-required-asterisk
1110
>
1211
<el-form-item label="Tester Name" prop="name">
13-
<el-input v-model="data.name" placeholder="Name" />
12+
<el-input v-model="data.name" :disabled="globalStart" placeholder="Name" />
13+
</el-form-item>
14+
<el-form-item label="Simulate By" prop="simulateBy">
15+
<el-select v-model="data.simulateBy" :disabled="globalStart" clearable>
16+
<el-option v-for="item in nodesName" :key="item.id" :label="item.name" :value="item.id">
17+
</el-option>
18+
</el-select>
1419
</el-form-item>
1520
<!-- <el-form-item label="Target Device" prop="targetDeviceId">
1621
<el-select v-model="data.targetDeviceId" placeholder="Device" clearable>
@@ -27,10 +32,10 @@
2732
</el-select>
2833
</el-form-item> -->
2934
<el-form-item label="Tester Script File" prop="script">
30-
<el-input v-model="data.script" clearable> </el-input>
35+
<el-input v-model="data.script" :disabled="globalStart" clearable> </el-input>
3136
<div class="lr">
3237
<el-button-group v-loading="buildLoading" style="margin-top: 5px">
33-
<el-button size="small" plain @click="editScript('open')">
38+
<el-button size="small" plain :disabled="globalStart" @click="editScript('open')">
3439
<Icon :icon="newIcon" class="icon" style="margin-right: 5px" /> Choose
3540
</el-button>
3641

@@ -96,34 +101,34 @@
96101
<el-form-item label-width="0">
97102
<el-col :span="12">
98103
<el-form-item label="P2 timeout" prop="udsTime.pTime">
99-
<el-input v-model.number="data.udsTime.pTime" />
104+
<el-input v-model.number="data.udsTime.pTime" :disabled="globalStart" />
100105
</el-form-item>
101106
</el-col>
102107
<el-col :span="12">
103108
<el-form-item label="P2 max (0x78)" prop="udsTime.pExtTime">
104-
<el-input v-model.number="data.udsTime.pExtTime" />
109+
<el-input v-model.number="data.udsTime.pExtTime" :disabled="globalStart" />
105110
</el-form-item>
106111
</el-col>
107112
</el-form-item>
108113
<el-form-item label-width="0">
109114
<el-col :span="12">
110115
<el-form-item label="S3 Time" prop="data.udsTime.s3Time">
111-
<el-input v-model.number="data.udsTime.s3Time" disabled />
116+
<el-input v-model.number="data.udsTime.s3Time" :disabled="globalStart" />
112117
</el-form-item>
113118
</el-col>
114119
<el-col :span="12">
115120
<el-form-item label="Tester Present Enable" prop="udsTime.testerPresentEnable">
116121
<el-checkbox
117122
v-model="data.udsTime.testerPresentEnable"
118-
:disabled="props.type != 'can'"
123+
:disabled="props.type != 'can' || globalStart"
119124
/>
120125
</el-form-item>
121126
</el-col>
122127
</el-form-item>
123128
<el-form-item v-if="data.udsTime.testerPresentEnable" label-width="0">
124129
<el-col :span="12">
125130
<el-form-item label="Tester Present Address" prop="udsTime.testerPresentAddrIndex">
126-
<el-select v-model.number="data.udsTime.testerPresentAddrIndex">
131+
<el-select v-model.number="data.udsTime.testerPresentAddrIndex" :disabled="globalStart">
127132
<el-option
128133
v-for="(item, index) in data.address"
129134
:key="index"
@@ -135,7 +140,7 @@
135140
</el-col>
136141
<el-col :span="12">
137142
<el-form-item label="From Special Service" prop="udsTime.testerPresentSpecialService">
138-
<el-select v-model="data.udsTime.testerPresentSpecialService">
143+
<el-select v-model="data.udsTime.testerPresentSpecialService" :disabled="globalStart">
139144
<el-option
140145
v-for="(item, index) in all3EServices"
141146
:key="index"
@@ -147,11 +152,11 @@
147152
</el-col>
148153
</el-form-item>
149154
<el-divider content-position="left">
150-
<el-button icon="Plus" link type="primary" @click="addCanAddress">
155+
<el-button icon="Plus" link type="primary" :disabled="globalStart" @click="addCanAddress">
151156
Add
152157
{{ props.type.toLocaleUpperCase() }} Address
153158
</el-button>
154-
<el-button icon="Switch" link type="success" @click="addAddrFromDb">
159+
<el-button icon="Switch" link type="success" :disabled="globalStart" @click="addAddrFromDb">
155160
Load From Database
156161
</el-button>
157162
</el-divider>
@@ -287,6 +292,9 @@ import dbchoose from './dbchoose.vue'
287292
const globalStart = toRef(window, 'globalStart')
288293
const ruleFormRef = ref<FormInstance>()
289294
const dataBase = useDataStore()
295+
const nodesName = computed(() => {
296+
return Object.values(dataBase.nodes)
297+
})
290298
const props = defineProps<{
291299
index: string
292300
height: number
@@ -628,6 +636,7 @@ const onSubmit = async () => {
628636
dataBase.tester[editIndex.value].name = data.value.name
629637
dataBase.tester[editIndex.value].script = data.value.script
630638
dataBase.tester[editIndex.value].udsTime = cloneDeep(data.value.udsTime)
639+
dataBase.tester[editIndex.value].simulateBy = data.value.simulateBy
631640
632641
emits('change', editIndex.value, data.value.name)
633642
return true
@@ -646,6 +655,14 @@ onBeforeMount(() => {
646655
if (editData) {
647656
data.value = cloneDeep(editData)
648657
if (data.value.address.length > 0) activeTabName.value = `index${0}`
658+
659+
//check simulateBy exist
660+
if (data.value.simulateBy) {
661+
const node = dataBase.nodes[data.value.simulateBy]
662+
if (!node) {
663+
data.value.simulateBy = undefined
664+
}
665+
}
649666
} else {
650667
editIndex.value = ''
651668
data.value.name = `Tester ${props.type}_${Object.keys(dataBase.tester).length}`

0 commit comments

Comments
 (0)