Skip to content

Commit

Permalink
start add config
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie-zeng committed Nov 29, 2024
1 parent 3c34e40 commit f2ce0a2
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 28 deletions.
34 changes: 18 additions & 16 deletions src/main/doip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ export class DOIP {
this.tcpClientMap.delete(key)
}
async createClient(testerAddr: EthAddr, entityAddr: EntityAddr): Promise<clientTcp> {
const allowRequest = testerAddr.entityNotFoundBehavior || 'no'
const allowRequest = entityAddr.entityNotFoundBehavior || 'no'
let ip: string | undefined
if (testerAddr.virReqType == 'omit') {
if (entityAddr.virReqType == 'omit') {
this.udsLog.systemMsg('omit vin find, connect special ip', getTsUs() - this.startTs, 'info')
ip = testerAddr.virReqAddr
ip = entityAddr.virReqAddr

} else {
//find in entityMap,
Expand Down Expand Up @@ -425,7 +425,7 @@ export class DOIP {
pendingBuffer: Buffer.alloc(0),
payloadLen: 0,
}
item.testerAddr.virReqAddr = ip
item.entityAddr.virReqAddr = ip
const timeout = setTimeout(() => {
reject(new DoipError(DOIP_ERROR_ID.DOIP_TCP_ERROR, undefined, 'tcp connect timeout'))
socket.destroy()
Expand Down Expand Up @@ -455,7 +455,7 @@ export class DOIP {
socket.on('data', (val) => {

if (this.eth.handle != socket.remoteAddress) {
this.log.ipBase('tcp', 'IN', testerAddr.virReqAddr, socket.localPort, 13400, val)
this.log.ipBase('tcp', 'IN', entityAddr.virReqAddr, socket.localPort, 13400, val)
}
this.parseDataClient(socket, item, val)
})
Expand All @@ -476,7 +476,7 @@ export class DOIP {
if (err) {
reject(new DoipError(DOIP_ERROR_ID.DOIP_TCP_ERROR, undefined, err.toString()))
} else {
this.log.ipBase('tcp', 'OUT', client.testerAddr.virReqAddr, client.socket.localPort, 13400, allData)
this.log.ipBase('tcp', 'OUT', client.entityAddr.virReqAddr, client.socket.localPort, 13400, allData)
}
})
client.timeout = setTimeout(() => {
Expand Down Expand Up @@ -504,7 +504,7 @@ export class DOIP {
}
data.copy(buffer, 4)
const val = this.buildMessage(PayloadType.DoIP_DiagnosticMessage, buffer)
this.log.ipBase('tcp', 'OUT', item.testerAddr.virReqAddr, item.socket.localPort, 13400, val)
this.log.ipBase('tcp', 'OUT', item.entityAddr.virReqAddr, item.socket.localPort, 13400, val)
item.socket.write(val, (err) => {
if (err) {
reject(new DoipError(DOIP_ERROR_ID.DOIP_TCP_ERROR, undefined, err.toString()))
Expand Down Expand Up @@ -541,7 +541,7 @@ export class DOIP {
if (err) {
reject(new DoipError(DOIP_ERROR_ID.DOIP_TCP_ERROR, undefined, err.toString()))
} else {
this.log.ipBase('tcp', 'OUT', testerAddr.virReqAddr, sitem.socket.localPort, sitem.socket.remotePort, val)
this.log.ipBase('tcp', 'OUT', sitem.socket.localAddress, sitem.socket.localPort, sitem.socket.remotePort, val)
resolve({ ts: getTsUs() - this.startTs, data: val })
}
})
Expand Down Expand Up @@ -603,7 +603,7 @@ export class DOIP {
recvState: 'header',
pendingBuffer: Buffer.alloc(0),
payloadLen: 0,
remoteIp: testerAddr.virReqAddr,
remoteIp: entityAddr.virReqAddr,
remotePort: 13400
}
socket.on('message', (msg, rinfo) => {
Expand Down Expand Up @@ -642,7 +642,7 @@ export class DOIP {
if (this.ethAddr) {
this.ethAddr.udpLocalPort = udpData.localPort
}
if (testerAddr.virReqType == 'broadcast') {
if (entityAddr.virReqType == 'broadcast') {
socket.setBroadcast(true)
socket.send(data, 13400, '255.255.255.255', (err) => {
if (err) {
Expand All @@ -653,25 +653,25 @@ export class DOIP {
}

})
} else if (testerAddr.virReqType == 'unicast') {
socket.send(data, 13400, testerAddr.virReqAddr, (err) => {
} else if (entityAddr.virReqType == 'unicast') {
socket.send(data, 13400, entityAddr.virReqAddr, (err) => {
if (err) {
reject(new DoipError(DOIP_ERROR_ID.DOIP_UDP_SEND_ERR, data, err.toString()))
} else {
this.log.ipBase('udp', 'OUT', testerAddr.virReqAddr, socket.address().port, 13400, data)
this.log.ipBase('udp', 'OUT', entityAddr.virReqAddr, socket.address().port, 13400, data)

}

})
} else if (testerAddr.virReqType == 'omit') {
} else if (entityAddr.virReqType == 'omit') {
reject(new DoipError(DOIP_ERROR_ID.DOIP_PARAM_ERR, undefined, 'omit ignore'))
clearTimeout(timeout)
socket.close()

}
else {
clearTimeout(timeout)
reject(new DoipError(DOIP_ERROR_ID.DOIP_PARAM_ERR, undefined, `unknown virReqType:${testerAddr.virReqType}`))
reject(new DoipError(DOIP_ERROR_ID.DOIP_PARAM_ERR, undefined, `unknown virReqType:${entityAddr.virReqType}`))
socket.close()
}

Expand Down Expand Up @@ -1060,7 +1060,9 @@ is in the state “Registered [Routing Active]”.*/
...vin,
ip: item.remoteIp,
localPort: item.localPort,

taType: 'physical',
virReqType: 'broadcast',
virReqAddr: ''
}
this.entityMap.set(`${item.remoteIp}-${item.remotePort}`, entityAddr)
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/share/doip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ export interface EthAddr {
name: string
desc?: string
routeActiveTime: number
taType: 'physical' | 'functional'
testerLogicalAddr: number
virReqType:'unicast'|'omit'|'broadcast'|'multicast'
virReqAddr: string
entityNotFoundBehavior?: 'no' | 'normal' | 'withVin' | 'withEid' | 'forceNormal' | 'forceWithVin' | 'forceWithEid'

}

export interface VinInfo {
Expand All @@ -37,6 +34,7 @@ export interface VinInfo {

export interface EntityAddr extends VinInfo {
name?:string,
taType: 'physical' | 'functional'
nodeType?:'node'|'gateway'
ta?: string
ip?: string
Expand All @@ -47,4 +45,8 @@ export interface EntityAddr extends VinInfo {
localPort?: number
sendSync?: boolean
udpLocalPort?: number

virReqType:'unicast'|'omit'|'broadcast'|'multicast'
virReqAddr: string
entityNotFoundBehavior?: 'no' | 'normal' | 'withVin' | 'withEid' | 'forceNormal' | 'forceWithVin' | 'forceWithEid'
}
193 changes: 193 additions & 0 deletions src/renderer/src/views/uds/components/config/tester/ethAddr.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<template>
<el-form :model="data" label-width="150px" size="small" :disabled="globalStart" :rules="rules" ref="ruleFormRef"
class="hardware" hide-required-asterisk>
<el-form-item label="Address name" required prop="name">
<el-input v-model="data.name" />
</el-form-item>
<el-form-item label="Address Type" required prop="taType">
<el-select v-model="data.taType">
<el-option value="physical" label="Physical"></el-option>
<el-option value="functional" label="Functional"></el-option>
</el-select>
</el-form-item>
<el-divider content-position="left">
ECU
</el-divider>
<el-form-item label-width="0">

<el-col :span="12">
<el-form-item label="logical address" required prop="logicalAddr">
<el-input v-model="data.logicalAddr" />
</el-form-item>

</el-col>
<el-col :span="12">
<el-form-item label="EID" required prop="eid">
<el-input v-model="data.eid" />
</el-form-item>

</el-col>
</el-form-item>
<el-form-item label-width="0">

<el-col :span="12">

<el-form-item label="VIN" required prop="vin">
<el-input v-model="data.vin" :max="17" />
</el-form-item>
</el-col>
<el-col :span="12">

<el-form-item label="GID" required prop="gid">
<el-input v-model="data.gid" :max="17" />
</el-form-item>
</el-col>
</el-form-item>
<el-divider content-position="left">
Vehicle Identify Request Behavior
</el-divider>
<el-form-item label="VIN Request method" required prop="virReqType">
<el-select v-model="data.virReqType">
<el-option value="unicast" label="Unicast VIN Request"></el-option>
<el-option value="omit" label="Omit VIN, tcp connect directly"></el-option>
<el-option value="broadcast" label="Broadcast UDP4"></el-option>
<el-option value="multicast" label="Multicast UDP6" disabled></el-option>
</el-select>
</el-form-item>
<el-form-item label-width="0">

<el-col :span="12">
<el-form-item label="Request Address" prop="virReqAddr">
<el-input v-model="data.virReqAddr" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="Entity Miss Behavior" prop="entityNotFoundBehavior">
<el-select v-model="data.entityNotFoundBehavior">
<el-option value="no" label="Report Error"></el-option>
<el-option value="normal" label="Send Normal Request"></el-option>
<el-option value="withVin" label="Send VIN Request"></el-option>
<el-option value="withEid" label="Send EID Request" disabled></el-option>
</el-select>
</el-form-item>

</el-col>
</el-form-item>
</el-form>
</template>

<script lang="ts" setup>
import {
Ref,
computed,
inject,
onBeforeMount,
onMounted,
onUnmounted,
ref,
toRef,
watch,
} from "vue";
import {
CanAddr,
calcCanIdMixed,
calcCanIdNormalFixed,
CAN_ADDR_FORMAT,
CAN_ID_TYPE,
CAN_ADDR_TYPE,
} from "nodeCan/can";
import { v4 } from "uuid";
import { type FormRules, type FormInstance, ElMessageBox } from "element-plus";
import { assign, cloneDeep } from "lodash";
import { UdsAddress } from "nodeCan/uds";
import { EntityAddr } from "nodeCan/doip";
const ruleFormRef = ref<FormInstance>();
const globalStart = toRef(window, 'globalStart')
const data = defineModel<EntityAddr>({
required: true
});
const nameCheck = (rule: any, value: any, callback: any) => {
if (value) {
for (let i = 0; i < addrs.value.length; i++) {
const hasName = addrs.value[i].canAddr?.name;
if (hasName == value && i != editIndex.value) {
callback(new Error("The name already exists"));
}
}
callback();
} else {
callback(new Error("Please input node name"));
}
};
const addrCheck = (rule: any, value: any, callback: any) => {
if (value) {
for (let i = 0; i < addrs.value.length; i++) {
const hasName = addrs.value[i].ethAddr?.logicalAddr;
if (hasName == value && i != editIndex.value) {
callback(new Error("The address already exists"));
}
}
callback();
} else {
callback(new Error("Please input node name"));
}
};
const rules: FormRules<EntityAddr> = {
"name": [
{
required: true,
message: "Please input addr name",
trigger: "blur",
validator: nameCheck,
},
],
"logicalAddr": [
{
required: true,
message: "Please input correct logical name",
trigger: "blur",
validator: addrCheck,
},
],
};
const props = defineProps<{
index: number;
addrs: UdsAddress[];
}>();
const editIndex = toRef(props, "index");
const addrs = toRef(props, "addrs")
onMounted(() => {
ruleFormRef.value?.validate().catch(null)
})
async function dataValid() {
await ruleFormRef.value?.validate()
}
defineExpose({
dataValid
})
</script>
<style scoped>
.hardware {
margin: 20px;
}
.vm {
display: flex;
align-items: center;
/* 垂直居中对齐 */
gap: 4px;
}
</style>
Loading

0 comments on commit f2ce0a2

Please sign in to comment.