Constructors

Methods

  • Register a function, this function will be invoked when UDSClass is terminated.

    Parameters

    • fc: () => void | Promise<void>

      Non-async or async function

    Returns void

    
    
  • Get the tester name, valid in Tester script

    Returns undefined | string

  • Register a function, this function will be invoked when UDSClass is initialized.

    Parameters

    • fc: () => void | Promise<void>

      Non-async or async function

    Returns void

    • Perform actions following UDS initialization using a normal function.

      Util.Init(()=>{
      console.log('Hello UDS!')
      })
    • Perform actions following UDS initialization using an async function.

      Util.Init(async ()=>{
      const file=await fs.readFile(path.join(process.env.PROJECT_ROOT,'file.bin'))
      let length=file.length
      console.log('Hello UDS file! file length is', length)
      })
    • The last registered function will override the previous ones.

      // The following code will be ignored
      Util.Init(async ()=>{
      console.log('1')
      })

      // The following code will take effect
      Util.Init(async ()=>{
      console.log('2')
      })
  • Unsubscribe from an event.

    Only non-anonymous functions can be unsubscribed.

    Type Parameters

    • Name extends "{{{serviceName}}}.send" | "{{{serviceName}}}.recv"

    Parameters

    • eventName: Name

      Service name, formatted as <tester name>.<service name>.<send|recv>

    • listener: (eventData: EventMap[Name]) => void | Promise<void>

      Function to be unsubscribed

    Returns void

    Util.On('Can.testService.send', ()=>{
    console.log('this function will not be Off')
    })

    Util.Off('Can.testService.send', ()=>{
    console.log('this function will not be Off')
    })
  • Unsubscribes from CAN messages.

    Parameters

    • id: number | true

      The identifier of the CAN message to unsubscribe from. If true, unsubscribes from all CAN messages.

    • fc: (msg: CanMessage) => void | Promise<void>

      The callback function to remove from the event listeners.

    Returns void

  • Unsubscribes from an event listener for a specific key.

    Parameters

    • key: string

      The key to unsubscribe from. Only the first character of the key is used, * is a wildcard.

    • fc: (key: string) => void | Promise<void>

      The callback function to remove from the event listeners.

    Returns void

  • Unsubscribes from LIN messages.

    Parameters

    • id: string | number | true

      The identifier of the LIN message to unsubscribe from. If true, unsubscribes from all LIN messages.

    • fc: (msg: LinMsg) => void | Promise<void>

      The callback function to remove from the event listeners.

    Returns void

  • Unsubscribes from an event listener for a variable update.

    Type Parameters

    • Name extends "stub"

    Parameters

    • name: Name

      The name of the variable to unsubscribe from, * is a wildcard.

    • fc: (
          __namedParameters: { name: Name; value: VariableMap[Name] },
      ) => void | Promise<void>

      The callback function to remove from the event listeners.

    Returns void

  • Subscribe to an event, invoking the registered function when the event is emitted.

    Type Parameters

    • Name extends "{{{serviceName}}}.send" | "{{{serviceName}}}.recv"

    Parameters

    • eventName: Name

      Service name, formatted as <tester name>.<service name>.<send|recv>

    • listener: (eventData: EventMap[Name]) => void | Promise<void>

      Function to be called when the event is emitted

    Returns void

    The UDS is a UDSClass type and has already been created by Service.

    1. send functions

      Util.On('Can.testService.send', async (req) => {
      // The req is a `DiagRequest`
      console.log(req.getServiceName(), ': send');
      });
    2. recv function

      Util.On('Can.testService.recv', async (req) => {
      // The req is a `DiagResponse`
      console.log(req.getServiceName(), ':recv');
      });
  • Registers an event listener for CAN messages.

    Parameters

    • id: number | true

      The CAN message ID to listen for. If true, listens for all CAN messages.

    • fc: (msg: CanMessage) => void | Promise<void>

      The callback function to be invoked when a CAN message is received.

    Returns void

  • Registers an event listener for CAN messages that will be invoked once.

    Parameters

    • id: number | true

      The CAN message ID to listen for. If true, listens for all CAN messages.

    • fc: (msg: CanMessage) => void | Promise<void>

      The callback function to be invoked when a CAN message is received.

    Returns void

  • Registers an event listener for a specific key.

    Parameters

    • key: string

      The key to listen for. Only the first character of the key is used, * is a wildcard.

    • fc: (key: string) => void | Promise<void>

      The callback function to be executed when the event is triggered. This can be a synchronous function or a function returning a Promise.

    Returns void

  • Registers an event listener for a specific key that will be invoked once.

    Parameters

    • key: string

      The key to listen for. Only the first character of the key is used, * is a wildcard.

    • fc: (key: string) => void | Promise<void>

      The callback function to be executed when the event is triggered. This can be a synchronous function or a function returning a Promise.

    Returns void

  • Registers an event listener for LIN messages.

    Parameters

    • id: string | number | true

      The LIN message ID or ${databaseName}.${frameName} to listen for. If true, listens for all LIN messages.

    • fc: (msg: LinMsg) => void | Promise<void>

      The callback function to be invoked when a LIN message is received.

    Returns void

  • Registers an event listener for LIN messages that will be invoked once.

    Parameters

    • id: string | number | true

      The LIN message ID or ${databaseName}.${frameName} to listen for. If true, listens for all LIN messages.

    • fc: (msg: LinMsg) => void | Promise<void>

      The callback function to be invoked when a LIN message is received.

    Returns void

  • Subscribe to an event once, invoking the registered function when the event is emitted.

    Type Parameters

    • Name extends "{{{serviceName}}}.send" | "{{{serviceName}}}.recv"

    Parameters

    • eventName: Name

      Service name, formatted as <tester name>.<service name>.<send|recv>

    • listener: (eventData: EventMap[Name]) => void | Promise<void>

      Function to be called when the event is emitted

    Returns void

    Util.OnOnce('Can.testService.send', async (req) => {
    // The req is a `DiagRequest`
    console.log(req.getServiceName(), ': send once');
    });
  • Registers an event listener for a variable update.

    Type Parameters

    • Name extends "stub"

    Parameters

    • name: Name

      The name of the variable to listen for, * is a wildcard.

    • fc: (
          __namedParameters: { name: Name; value: VariableMap[Name] },
      ) => void | Promise<void>

      The callback function to be executed when the variable is updated. This can be a synchronous function or a function returning a Promise. The callback receives an object with name and value properties.

    Returns void

  • Registers an event listener for a variable update that will be invoked once.

    Type Parameters

    • Name extends "stub"

    Parameters

    • name: Name

      The name of the variable to listen for, * is a wildcard.

    • fc: (
          __namedParameters: { name: Name; value: VariableMap[Name] },
      ) => void | Promise<void>

      The callback function to be executed when the variable is updated. This can be a synchronous function or a function returning a Promise. The callback receives an object with name and value properties.

    Returns void

  • Register a handler function for a job.

    Parameters

    • jobs: "string"

      Job name, valid format is <tester name>.<job name>

    • func: (data: Buffer) => string

      Handler function for the job

    Returns void

    Util.Register('Can.testJob', async (v) => {

    const testService = new DiagRequest();
    const newData = Buffer.from([0x10, 0x01, 0x00, 0x01, 0x02]);
    await testService.diagSetRaw(newData);
    return [testService];
    });