From b3f0f5264846a7d63a79fe58cff56431af94492d Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 8 Nov 2022 20:32:35 +0100 Subject: [PATCH] Refreshed docs --- docs/classes/DatabaseService.html | 51 +-- docs/classes/Message.html | 81 +++-- docs/classes/Signal.html | 199 ++++++----- docs/classes/exports.html | 543 ++++++++++++++++++++++++++++- docs/data.json | 302 ++++++++++++---- docs/files/socketcan.js.html | 456 ------------------------ docs/files/src_can.d.ts.html | 191 ++++++++++ docs/files/src_socketcan.ts.html | 556 ++++++++++++++++++++++++++++++ docs/modules/Signals.html | 2 +- package.json | 2 +- src/socketcan.ts | 2 +- 11 files changed, 1697 insertions(+), 688 deletions(-) delete mode 100644 docs/files/socketcan.js.html create mode 100644 docs/files/src_can.d.ts.html create mode 100644 docs/files/src_socketcan.ts.html diff --git a/docs/classes/DatabaseService.html b/docs/classes/DatabaseService.html index a529856..9d6c7f9 100644 --- a/docs/classes/DatabaseService.html +++ b/docs/classes/DatabaseService.html @@ -85,7 +85,7 @@

DatabaseService Class

- Defined in: socketcan.js:203 + Defined in: src/socketcan.ts:284
Module: Signals @@ -128,7 +128,7 @@

DatabaseService

Defined in - socketcan.js:203 + src/socketcan.ts:284

@@ -186,7 +186,6 @@

Returns:

  • Index
  • Methods
  • -
  • Attributes
  • @@ -205,15 +204,6 @@

    Methods

    -
    -

    Attributes

    - - -
    @@ -241,7 +231,7 @@

    send

    Defined in - socketcan.js:279 + src/socketcan.ts:364

    @@ -264,7 +254,7 @@

    Parameters:

    -

    Name of the message to generate

    +

    Name of the message to generate (indicate mux by append .MUX_VALUE in hex)

    @@ -278,39 +268,6 @@

    Parameters:

    -
    -

    Attributes

    - -
    - -

    messages

    - Message - - - - - - - - -
    -

    - Defined in - socketcan.js:216 -

    - - -
    - -
    -

    Named array of known messages. Accessible via index and name.

    - -
    - - - -
    -
    diff --git a/docs/classes/Message.html b/docs/classes/Message.html index 18aaf35..e040782 100644 --- a/docs/classes/Message.html +++ b/docs/classes/Message.html @@ -85,7 +85,7 @@

    Message Class

    - Defined in: socketcan.js:134 + Defined in: src/socketcan.ts:198
    Module: Signals @@ -116,6 +116,9 @@

    Item Index

    Attributes

    @@ -147,6 +150,36 @@

    Attributes

    Attributes

    +
    + +

    Boolean

    + + + + + final + + + + + +
    +

    + Defined in + src/socketcan.ts:266 +

    + + +
    + +
    +

    Named information to inform that the frame is CAN_FD format .

    + +
    + + + +

    ext

    @@ -163,7 +196,7 @@

    ext

    Defined in - socketcan.js:147 + src/socketcan.ts:220

    @@ -193,7 +226,7 @@

    id

    Defined in - socketcan.js:140 + src/socketcan.ts:213

    @@ -223,7 +256,7 @@

    interval

    Defined in - socketcan.js:169 + src/socketcan.ts:242

    @@ -253,7 +286,7 @@

    len

    Defined in - socketcan.js:161 + src/socketcan.ts:234

    @@ -267,9 +300,9 @@

    len

    -
    - -

    muxed

    +
    + +

    mux

    @@ -283,23 +316,23 @@

    muxed

    -

    This is tells us the message is mutliplexed.

    +

    Multiplexor parameter (just one supported right now).

    -
    - -

    name

    +
    + +

    muxed

    @@ -313,24 +346,24 @@

    name

    -

    Symbolic name

    +

    This tells us the message is mutliplexed.

    -
    - -

    signals

    - Signal +
    + +

    name

    + @@ -343,14 +376,14 @@

    signals

    -

    Named array of signals within this message. Accessible via index and name.

    +

    Symbolic name

    diff --git a/docs/classes/Signal.html b/docs/classes/Signal.html index f8cbb75..1427b97 100644 --- a/docs/classes/Signal.html +++ b/docs/classes/Signal.html @@ -85,7 +85,7 @@

    Signal Class

    - Defined in: socketcan.js:47 + Defined in: src/socketcan.ts:86
    Module: Signals @@ -104,7 +104,6 @@

    Signal Class

  • Index
  • Methods
  • -
  • Attributes
  • @@ -120,26 +119,22 @@

    Methods

  • - update + onUpdate
  • - -
    - - -
    -

    Attributes

    +
  • + removeListener -
  • + +
    @@ -166,7 +161,7 @@

    onChange

    Defined in - socketcan.js:95 + src/socketcan.ts:122

    @@ -198,6 +193,114 @@

    Parameters:

    +
    +
    +

    onUpdate

    + +
    + (
      +
    • + listener +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/socketcan.ts:133 +

    + + + +
    + +
    +

    Keep track of listeners who want to be notified if this signal updates

    + +
    + +
    +

    Parameters:

    + +
      +
    • + listener + Object + + +
      +

      JS callback to get notification

      + +
      + +
    • +
    +
    + + + +
    +
    +

    removeListener

    + +
    + (
      +
    • + listener +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/socketcan.ts:144 +

    + + + +
    + +
    +

    Remove listener from signal onChange and/or onUpdate

    + +
    + +
    +

    Parameters:

    + +
      +
    • + listener + Object + + +
      +

      to be removed

      + +
      + +
    • +
    +
    + + +

    update

    @@ -220,7 +323,7 @@

    update

    Defined in - socketcan.js:105 + src/socketcan.ts:157

    @@ -258,70 +361,6 @@

    Parameters:

    -
    -

    Attributes

    - -
    - -

    name

    - - - - - final - - - - - -
    -

    - Defined in - socketcan.js:53 -

    - - -
    - -
    -

    Symbolic name

    - -
    - - - -
    -
    - -

    value

    - - - - - final - - - - - -
    -

    - Defined in - socketcan.js:84 -

    - - -
    - -
    -

    Current value

    - -
    - - - -
    -
    diff --git a/docs/classes/exports.html b/docs/classes/exports.html index 9f72fc5..7805518 100644 --- a/docs/classes/exports.html +++ b/docs/classes/exports.html @@ -110,14 +110,50 @@

    Item Index

    Methods

    @@ -128,6 +164,88 @@

    Methods

    Methods

    +
    +

    addListener

    + +
    + (
      +
    • + event +
    • +
    • + callback +
    • +
    • + instance +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/can.d.ts:17 +

    + + + +
    + +
    +

    Add listener to receive certain notifications

    + +
    + +
    +

    Parameters:

    + +
      +
    • + event + String + + +
      +

      onMessage to register for incoming messages

      + +
      + +
    • +
    • + callback + Any + + +
      +

      JS callback object

      + +
      + +
    • +
    • + instance + Any + + +
      +

      Optional instance pointer to call callback

      + +
      + +
    • +
    +
    + + + +

    createRawChannel

    @@ -136,6 +254,102 @@

    createRawChannel

  • channel
  • +
  • + timestamps +
  • +
  • + protocol +
  • + ) +
    + + + RawChannel + + + + + + + + +
    +

    + Defined in + src/socketcan.ts:39 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + channel + String + + +
      +

      Channel name (e.g. vcan0)

      + +
      + +
    • +
    • + timestamps + Bool + + +
      +

      Whether or not timestamps shall be generated when reading a message

      + +
      + +
    • +
    • + protocol + Integer + + +
      +

      optionally provide another default protocol value (default is CAN_RAW)

      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + RawChannel: +

    a new channel object or exception

    + +
    +
    + + +
    +
    +

    createRawChannelWithOptions

    + +
    + (
      +
    • + channel +
    • +
    • + options +
    )
    @@ -152,7 +366,7 @@

    createRawChannel

    Defined in - socketcan.js:28 + src/socketcan.ts:61

    @@ -178,6 +392,17 @@

    Parameters:

    +
  • + options + Dict + + +
    +

    list of options (timestamps, protocol, non_block_send)

    + +
    + +
  • @@ -192,6 +417,37 @@

    Returns:

    +
    +
    +

    disableLoopback

    + + () + + + + + + + + +
    +

    + Defined in + src/can.d.ts:80 +

    + + + +
    + +
    +

    Disable loopback of channel. By default it is activated

    + +
    + + + +

    parseNetworkDescription

    @@ -217,7 +473,7 @@

    parseNetworkDescription

    Defined in - socketcan.js:343 + src/socketcan.ts:444

    @@ -256,6 +512,289 @@

    Returns:

    +
    +
    +

    send

    + +
    + (
      +
    • + message +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/can.d.ts:42 +

    + + + +
    + +
    +

    Send a CAN message immediately.

    +

    PLEASE NOTE: By default, this function may block if the Tx buffer is not available. Please use +createRawChannelWithOptions({non_block_send: false}) to get non-blocking sending activated.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + message + Object + + +
      +

      JSON object describing the CAN message, keys are id, length, data {Buffer}, ext or rtr

      + +
      + +
    • +
    +
    + + + +
    +
    +

    sendFD

    + +
    + (
      +
    • + message +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/can.d.ts:53 +

    + + + +
    + +
    +

    Send a CAN FD message immediately.

    +

    PLEASE NOTE: By default, this function may block if the Tx buffer is not available. Please use +createRawChannelWithOptions({non_block_send: false}) to get non-blocking sending activated.

    +

    PLEASE NOTE: Might fail if underlying device doesnt support CAN FD. Structure is not yet validated.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + message + Object + + +
      +

      JSON object describing the CAN message, keys are id, length, data {Buffer}, ext

      + +
      + +
    • +
    +
    + + + +
    +
    +

    setErrorFilters

    + +
    + (
      +
    • + errorMask +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/can.d.ts:73 +

    + + + +
    + +
    +

    Set a list of active filters to be applied for errors

    + +
    + +
    +

    Parameters:

    + +
      +
    • + errorMask + Uint32 + + +
      +

      CAN error mask

      + +
      + +
    • +
    +
    + + + +
    +
    +

    setRxFilters

    + +
    + (
      +
    • + filters +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/can.d.ts:66 +

    + + + +
    + +
    +

    Set a list of active filters to be applied for incoming messages

    + +
    + +
    +

    Parameters:

    + +
      +
    • + filters + Object + + +
      +

      single filter or array of filter e.g. { id: 0x1ff, mask: 0x1ff, invert: false}, result of (id & mask)

      + +
      + +
    • +
    +
    + + + +
    +
    +

    start

    + + () + + + + + + + + +
    +

    + Defined in + src/can.d.ts:30 +

    + + + +
    + +
    +

    Start operation on this CAN channel

    + +
    + + + + +
    +
    +

    stop

    + + () + + + + + + + + +
    +

    + Defined in + src/can.d.ts:36 +

    + + + +
    + +
    +

    Stop any operations on this CAN channel

    + +
    + + + +
    diff --git a/docs/data.json b/docs/data.json index b0eb10b..4c3e9fb 100644 --- a/docs/data.json +++ b/docs/data.json @@ -1,8 +1,15 @@ { "project": {}, "files": { - "socketcan.js": { - "name": "socketcan.js", + "src/can.d.ts": { + "name": "src/can.d.ts", + "modules": {}, + "classes": {}, + "fors": {}, + "namespaces": {} + }, + "src/socketcan.ts": { + "name": "src/socketcan.ts", "modules": { "Signals": 1 }, @@ -31,14 +38,14 @@ "DatabaseService": 1 }, "fors": { + "exports": 1, "Signal": 1, - "DatabaseService": 1, - "exports": 1 + "DatabaseService": 1 }, "namespaces": {}, "tag": "module", - "file": "socketcan.js", - "line": 203, + "file": "src/socketcan.ts", + "line": 284, "description": "The Signals modules provides an interface to access the values/signals\nencoded in CAN messages." } }, @@ -51,7 +58,8 @@ "extensions": [], "plugin_for": [], "extension_for": [], - "module": "Signals" + "module": "Signals", + "namespace": "" }, "Signal": { "name": "Signal", @@ -63,8 +71,8 @@ "extension_for": [], "module": "Signals", "namespace": "", - "file": "socketcan.js", - "line": 47, + "file": "src/socketcan.ts", + "line": 86, "description": "The actual signal." }, "Message": { @@ -77,8 +85,8 @@ "extension_for": [], "module": "Signals", "namespace": "", - "file": "socketcan.js", - "line": 134, + "file": "src/socketcan.ts", + "line": 198, "description": "Just a container to keep the Signals." }, "DatabaseService": { @@ -91,8 +99,8 @@ "extension_for": [], "module": "Signals", "namespace": "", - "file": "socketcan.js", - "line": 203, + "file": "src/socketcan.ts", + "line": 284, "description": "A DatabaseService is usually generated once per bus to collect signals\ncoded in the CAN messages according a DB description.", "is_constructor": 1, "params": [ @@ -113,8 +121,117 @@ "elements": {}, "classitems": [ { - "file": "socketcan.js", - "line": 28, + "file": "src/can.d.ts", + "line": 17, + "description": "Add listener to receive certain notifications", + "itemtype": "method", + "name": "addListener", + "params": [ + { + "name": "event", + "description": "onMessage to register for incoming messages", + "type": "String" + }, + { + "name": "callback", + "description": "JS callback object", + "type": "Any" + }, + { + "name": "instance", + "description": "Optional instance pointer to call callback", + "type": "Any" + } + ], + "class": "exports" + }, + { + "file": "src/can.d.ts", + "line": 30, + "description": "Start operation on this CAN channel", + "itemtype": "method", + "name": "start", + "class": "exports" + }, + { + "file": "src/can.d.ts", + "line": 36, + "description": "Stop any operations on this CAN channel", + "itemtype": "method", + "name": "stop", + "class": "exports" + }, + { + "file": "src/can.d.ts", + "line": 42, + "description": "Send a CAN message immediately.\n\nPLEASE NOTE: By default, this function may block if the Tx buffer is not available. Please use\ncreateRawChannelWithOptions({non_block_send: false}) to get non-blocking sending activated.", + "itemtype": "method", + "name": "send", + "params": [ + { + "name": "message", + "description": "JSON object describing the CAN message, keys are id, length, data {Buffer}, ext or rtr", + "type": "Object" + } + ], + "class": "exports" + }, + { + "file": "src/can.d.ts", + "line": 53, + "description": "Send a CAN FD message immediately.\n\nPLEASE NOTE: By default, this function may block if the Tx buffer is not available. Please use\ncreateRawChannelWithOptions({non_block_send: false}) to get non-blocking sending activated.\n\nPLEASE NOTE: Might fail if underlying device doesnt support CAN FD. Structure is not yet validated.", + "itemtype": "method", + "name": "sendFD", + "params": [ + { + "name": "message", + "description": "JSON object describing the CAN message, keys are id, length, data {Buffer}, ext", + "type": "Object" + } + ], + "class": "exports" + }, + { + "file": "src/can.d.ts", + "line": 66, + "description": "Set a list of active filters to be applied for incoming messages", + "itemtype": "method", + "name": "setRxFilters", + "params": [ + { + "name": "filters", + "description": "single filter or array of filter e.g. { id: 0x1ff, mask: 0x1ff, invert: false}, result of (id & mask)", + "type": "Object" + } + ], + "class": "exports" + }, + { + "file": "src/can.d.ts", + "line": 73, + "description": "Set a list of active filters to be applied for errors", + "itemtype": "method", + "name": "setErrorFilters", + "params": [ + { + "name": "errorMask", + "description": "CAN error mask", + "type": "Uint32" + } + ], + "class": "exports" + }, + { + "file": "src/can.d.ts", + "line": 80, + "description": "Disable loopback of channel. By default it is activated", + "itemtype": "method", + "name": "disableLoopback", + "class": "exports" + }, + { + "file": "src/socketcan.ts", + "line": 39, "itemtype": "method", "name": "createRawChannel", "params": [ @@ -122,66 +239,104 @@ "name": "channel", "description": "Channel name (e.g. vcan0)", "type": "String" + }, + { + "name": "timestamps", + "description": "Whether or not timestamps shall be generated when reading a message", + "type": "Bool" + }, + { + "name": "protocol", + "description": "optionally provide another default protocol value (default is CAN_RAW)", + "type": "Integer" } ], "return": { "description": "a new channel object or exception", "type": "RawChannel" }, - "class": "exports" + "class": "exports", + "module": "Signals" }, { - "file": "socketcan.js", - "line": 53, - "description": "Symbolic name", - "itemtype": "attribute", - "name": "name", - "final": 1, - "class": "Signal", + "file": "src/socketcan.ts", + "line": 61, + "itemtype": "method", + "name": "createRawChannelWithOptions", + "params": [ + { + "name": "channel", + "description": "Channel name (e.g. vcan0)", + "type": "String" + }, + { + "name": "options", + "description": "list of options (timestamps, protocol, non_block_send)", + "type": "Dict" + } + ], + "return": { + "description": "a new channel object or exception", + "type": "RawChannel" + }, + "class": "exports", "module": "Signals" }, { - "file": "socketcan.js", - "line": 74, - "description": "Label set for defined states of the signal.", + "file": "src/socketcan.ts", + "line": 116, + "description": "this will allow triggering on mux'ed message ids.", "class": "Signal", "module": "Signals" }, { - "file": "socketcan.js", - "line": 79, - "description": "this will allow triggering on mux'ed message ids.", + "file": "src/socketcan.ts", + "line": 122, + "description": "Keep track of listeners who want to be notified if this signal changes", + "itemtype": "method", + "name": "onChange", + "params": [ + { + "name": "listener", + "description": "JS callback to get notification" + } + ], "class": "Signal", "module": "Signals" }, { - "file": "socketcan.js", - "line": 84, - "description": "Current value", - "itemtype": "attribute", - "name": "value", - "final": 1, + "file": "src/socketcan.ts", + "line": 133, + "description": "Keep track of listeners who want to be notified if this signal updates", + "itemtype": "method", + "name": "onUpdate", + "params": [ + { + "name": "listener", + "description": "JS callback to get notification" + } + ], "class": "Signal", "module": "Signals" }, { - "file": "socketcan.js", - "line": 95, - "description": "Keep track of listeners who want to be notified if this signal changes", + "file": "src/socketcan.ts", + "line": 144, + "description": "Remove listener from signal onChange and/or onUpdate", "itemtype": "method", - "name": "onChange", + "name": "removeListener", "params": [ { "name": "listener", - "description": "JS callback to get notification" + "description": "to be removed" } ], "class": "Signal", "module": "Signals" }, { - "file": "socketcan.js", - "line": 105, + "file": "src/socketcan.ts", + "line": 157, "description": "Set new value of this signal. Any local registered clients will\nreceive a notification. Please note, no CAN message is actually\nsend to the bus (@see DatabaseServer::send)", "itemtype": "method", "name": "update", @@ -196,8 +351,8 @@ "module": "Signals" }, { - "file": "socketcan.js", - "line": 140, + "file": "src/socketcan.ts", + "line": 213, "description": "CAN identifier", "itemtype": "attribute", "name": "id", @@ -206,8 +361,8 @@ "module": "Signals" }, { - "file": "socketcan.js", - "line": 147, + "file": "src/socketcan.ts", + "line": 220, "description": "Extended Frame Format used", "itemtype": "attribute", "name": "ext", @@ -216,8 +371,8 @@ "module": "Signals" }, { - "file": "socketcan.js", - "line": 154, + "file": "src/socketcan.ts", + "line": 227, "description": "Symbolic name", "itemtype": "attribute", "name": "name", @@ -226,8 +381,8 @@ "module": "Signals" }, { - "file": "socketcan.js", - "line": 161, + "file": "src/socketcan.ts", + "line": 234, "description": "Length in bytes of resulting CAN message", "itemtype": "attribute", "name": "len", @@ -236,8 +391,8 @@ "module": "Signals" }, { - "file": "socketcan.js", - "line": 169, + "file": "src/socketcan.ts", + "line": 242, "description": "This is the time frame that the message gets generated", "itemtype": "attribute", "name": "interval", @@ -246,9 +401,9 @@ "module": "Signals" }, { - "file": "socketcan.js", - "line": 177, - "description": "This is tells us the message is mutliplexed.", + "file": "src/socketcan.ts", + "line": 250, + "description": "This tells us the message is mutliplexed.", "itemtype": "attribute", "name": "muxed", "final": 1, @@ -256,44 +411,43 @@ "module": "Signals" }, { - "file": "socketcan.js", - "line": 185, - "description": "Named array of signals within this message. Accessible via index and name.", + "file": "src/socketcan.ts", + "line": 258, + "description": "Multiplexor parameter (just one supported right now).", "itemtype": "attribute", - "name": "signals", - "type": "Signal", + "name": "mux", "final": 1, "class": "Message", "module": "Signals" }, { - "file": "socketcan.js", - "line": 216, - "description": "Named array of known messages. Accessible via index and name.", + "file": "src/socketcan.ts", + "line": 266, + "description": "Named information to inform that the frame is CAN_FD format .", "itemtype": "attribute", - "name": "messages", - "type": "Message", - "class": "DatabaseService", + "name": "Boolean", + "final": 1, + "class": "Message", "module": "Signals" }, { - "file": "socketcan.js", - "line": 279, + "file": "src/socketcan.ts", + "line": 364, "description": "Construct a CAN message and encode all related signals according\nthe rules. Finally send the message to the bus.", "itemtype": "method", "name": "send", "params": [ { "name": "msg_name", - "description": "Name of the message to generate" + "description": "Name of the message to generate (indicate mux by append .MUX_VALUE in hex)" } ], "class": "DatabaseService", "module": "Signals" }, { - "file": "socketcan.js", - "line": 343, + "file": "src/socketcan.ts", + "line": 444, "itemtype": "method", "name": "parseNetworkDescription", "params": [ @@ -311,13 +465,9 @@ } ], "warnings": [ - { - "message": "Missing item type\nLabel set for defined states of the signal.", - "line": " socketcan.js:74" - }, { "message": "Missing item type\nthis will allow triggering on mux'ed message ids.", - "line": " socketcan.js:79" + "line": " src/socketcan.ts:116" } ] } \ No newline at end of file diff --git a/docs/files/socketcan.js.html b/docs/files/socketcan.js.html deleted file mode 100644 index 8359feb..0000000 --- a/docs/files/socketcan.js.html +++ /dev/null @@ -1,456 +0,0 @@ - - - - - socketcan.js - - - - - - - - -
    -
    -
    -

    -
    -
    - API Docs for: -
    -
    -
    - -
    - -
    -
    -
    - Show: - - - - - - - -
    - -
    -
    -
    -

    File: socketcan.js

    - -
    -
    -/* Copyright Sebastian Haas <sebastian@sebastianhaas.info>. All rights reserved.
    - *
    - * Permission is hereby granted, free of charge, to any person obtaining a copy
    - * of this software and associated documentation files (the "Software"), to
    - * deal in the Software without restriction, including without limitation the
    - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    - * sell copies of the Software, and to permit persons to whom the Software is
    - * furnished to do so, subject to the following conditions:
    - *
    - * The above copyright notice and this permission notice shall be included in
    - * all copies or substantial portions of the Software.
    - *
    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    - * IN THE SOFTWARE.
    - */
    -
    -//-----------------------------------------------------------------------------
    -// CAN-Object
    -
    -var can = require('./build/Release/can');
    -var buffer = require('buffer');
    -
    -/**
    - * @method createRawChannel
    - * @param channel {string} Channel name (e.g. vcan0)
    - * @return {RawChannel} a new channel object or exception
    - * @for exports
    - */
    -exports.createRawChannel = function(channel, timestamps) { return new can.RawChannel(channel, timestamps); }
    -
    -//-----------------------------------------------------------------------------
    -/**
    - * The Signals modules provides an interface to access the values/signals
    - * encoded in CAN messages.
    - * @module Signals
    - */
    -
    -var _signals = require('./build/Release/can_signals');
    -
    -var kcd = require('./parse_kcd');
    -
    -/**
    - * The actual signal.
    - * @class Signal
    - */
    -function Signal(desc)
    -{
    -        /**
    -         * Symbolic name
    -         * @attribute name
    -         * @final
    -         */
    -	this.name = desc['name'];
    -	this.spn = desc['spn'];
    -
    -	this.bitOffset = desc['bitOffset'];
    -	this.bitLength = desc['bitLength'];
    -	this.endianess = desc['endianess'];
    -	this.type = desc['type'];
    -
    -	this.intercept = desc['intercept'];
    -	this.slope = desc['slope'];
    -
    -	this.minValue = desc['minValue'];
    -	this.maxValue = desc['maxValue'];
    -
    -	this.unit = desc['unit'];
    -
    -	/**
    -	 * Label set for defined states of the signal.
    -	 */
    -	this.labels = desc['labels'];
    -
    -	/**
    -	 * this will allow triggering on mux'ed message ids.
    -	 */
    -	this.muxGroup = [ desc['mux'] ];
    -
    -	/**
    -	 * Current value
    -	 *
    -	 * @attribute value
    -	 * @final
    -	 */
    -	this.value = null;
    -
    -	this.listeners = [];
    -}
    -
    -/**
    - * Keep track of listeners who want to be notified if this signal changes
    - * @method onChange
    - * @param listener JS callback to get notification
    - * @for Signal
    - */
    -Signal.prototype.onChange = function(listener) {
    -	this.listeners.push(listener);
    -}
    -
    -/**
    - * Set new value of this signal. Any local registered clients will
    - * receive a notification. Please note, no CAN message is actually
    - * send to the bus (@see DatabaseServer::send)
    - * @method update
    - * @param newValue {bool|double|integer} New value to set
    - * @for Signal
    - */
    -Signal.prototype.update = function(newValue) {
    -	// Nothing changed
    -	if (this.value == newValue) {
    -		return;
    -	} else if (newValue > this.maxValue) {
    -		console.error("ERROR : " + this.name + " value= " + newValue
    -				+ " is outof bounds  > " + this.maxValue);
    -	} else if (newValue < this.minValue) {
    -		console.error("ERROR : " + this.name + " value= " + newValue
    -				+ " is outof bounds  < " + this.minValue);
    -	}
    -
    -	this.value = newValue;
    -
    -	// Update all listeners, that the signal changed
    -	for (f in this.listeners) {
    -		this.listeners[f](this);
    -	}
    -}
    -
    -//-----------------------------------------------------------------------------
    -/**
    - * Just a container to keep the Signals.
    - * @class Message
    - */
    -function Message(desc)
    -{
    -        /**
    -         * CAN identifier
    -         * @attribute id
    -         * @final
    -         */
    -	this.id = desc.id;
    -
    -	/**
    -         * Extended Frame Format used
    -         * @attribute ext
    -         * @final
    -         */
    -	this.ext = desc.ext;
    -
    -        /**
    -         * Symbolic name
    -         * @attribute name
    -         * @final
    -         */
    -	this.name = desc.name;
    -
    -        /**
    -         * Length in bytes of resulting CAN message
    -	 *
    -	 * @attribute len
    -	 * @final
    -	 */
    -	this.len = desc.length;
    -
    -	/**
    -	 * This is the time frame that the message gets generated
    -	 *
    -	 * @attribute interval
    -	 * @final
    -	 */
    -	this.interval = desc.interval;
    -
    -	/**
    -	 * This is tells us the message is mutliplexed.
    -	 *
    -	 * @attribute muxed
    -	 * @final
    -	 */
    -	this.muxed = desc.muxed;
    -
    -	/**
    -         * Named array of signals within this message. Accessible via index and name.
    -         * @attribute {Signal} signals
    -         * @final
    -         */
    -	this.signals = [];
    -
    -	for (i in desc['signals']) {
    -		var s = desc['signals'][i];
    -		if (this.signals[s.name] && this.signals[s.name].muxGroup) {
    -			this.signals[s.name].muxGroup.push(s.mux);
    -		} else {
    -			this.signals[s.name] = new Signal(s);
    -		}
    -	}
    -}
    -
    -//-----------------------------------------------------------------------------
    -/**
    - * A DatabaseService is usually generated once per bus to collect signals
    - * coded in the CAN messages according a DB description.
    - * @class DatabaseService
    - * @constructor DatabaseService
    - * @param channel RAW channel
    - * @param db_desc Set of rules to decode/encode signals (@parse_kcd.js)
    - * @return a new DatabaseService
    - * @for DatabaseService
    - */
    -function DatabaseService(channel, db_desc) {
    -	this.channel = channel;
    -
    -        /**
    -         * Named array of known messages. Accessible via index and name.
    -         * @attribute {Message} messages
    -         */
    -	this.messages = [];
    -
    -	for (i in db_desc['messages']) {
    -		var m = db_desc['messages'][i];
    -		var id = m.id | (m.ext ? 1 : 0) << 31;
    -
    -		var nm = new Message(m);
    -		this.messages[id] = nm;
    -		this.messages[m.name] = nm;
    -	}
    -
    -	// Subscribe to any incoming messages
    -	channel.addListener("onMessage", this.onMessage, this);
    -}
    -
    -// Callback for incoming messages
    -DatabaseService.prototype.onMessage = function (msg) {
    -	if (msg == undefined)
    -		return;
    -	if (msg.rtr)
    -		return;
    -
    -	id = msg.id | (msg.ext ? 1 : 0) << 31;
    -
    -	var m = this.messages[id];
    -
    -	if (!m)
    -	{
    -		return;
    -	}
    -
    -	// this is the possible multiplexor for the signals coming in.
    -	var b1mux = _signals.decode_signal(msg.data, 0, 8, true, false);
    -
    -	// Let the C-Portition extract and convert the signal
    -	for (i in m.signals) {
    -		var s = m.signals[i];
    -
    -		if (s.value === undefined)
    -			continue;
    -
    -		// if this is a mux signal and the muxor isnt in my list...
    -		if (m.muxed && s.muxGroup && s.muxGroup.indexOf(b1mux) == -1) {
    -			continue;
    -		}
    -
    -		var val = _signals.decode_signal(msg.data, s.bitOffset, s.bitLength,
    -				s.endianess == 'little', s.type == 'signed');
    -
    -		if (s.slope)
    -			val *= s.slope;
    -
    -		if (s.intercept)
    -			val += s.intercept;
    -
    -		s.update(val);
    -	}
    -}
    -
    -/**
    - * Construct a CAN message and encode all related signals according
    - * the rules. Finally send the message to the bus.
    - * @method send
    - * @param msg_name Name of the message to generate
    - * @for DatabaseService
    - */
    -DatabaseService.prototype.send = function (msg_name) {
    -	var args = msg_name.split("."); // allow for mux'ed messages sent.
    -
    -	var m = this.messages[args[0]];
    -	var mux = (args.length > 1) ? args[1] : undefined;
    -
    -	if (!m)
    -		throw msg_name + " not defined";
    -
    -	var canmsg = {
    -		id: m.id,
    -		ext: m.ext,
    -		rtr: false,
    -		data : (m.len > 0 && m.len < 8) ? Buffer.alloc(m.len) : Buffer.alloc(8)
    -	};
    -
    -	canmsg.data.fill(0); // should be 0xFF for j1939 message def.
    -
    -
    -	if (mux) {
    -		_signals.encode_signal(canmsg.data, 0, 8, true, false,
    -				parseInt(mux, 16));
    -	}
    -	for (i in m.signals) {
    -		var s = m.signals[i];
    -		if (s.value == undefined)
    -			continue;
    -
    -		if (mux) {
    -			if (s.muxGroup.indexOf(parseInt(mux, 16)) === -1) {
    -				continue;
    -			}
    -		}
    -
    -		var val = s.value;
    -
    -		// Apply factor/intercept and convert to Integer
    -		if (s.intercept)
    -			val -= s.intercept;
    -
    -		if (s.slope)
    -			val /= s.slope;
    -
    -		if (typeof(val) == 'double')
    -			val = parseInt(Math.round(val));
    -
    -		if (m.len == 0) {
    -			return;
    -		}
    -
    -		_signals.encode_signal(canmsg.data, s.bitOffset, s.bitLength,
    -				s.endianess == 'little', s.type == 'signed', val);
    -	}
    -
    -	this.channel.send(canmsg);
    -}
    -
    -/**
    - * @method parseNetworkDescription
    - * @param file {string} Path to KCD file to parse
    - * @return DB description to be used in DatabaseService
    - * @for exports
    - */
    -exports.parseNetworkDescription = kcd.parseKcdFile;
    -exports.DatabaseService = DatabaseService;
    -
    -
    -    
    -
    -
    -
    -
    -
    -
    -
    - - - - - - - - - - diff --git a/docs/files/src_can.d.ts.html b/docs/files/src_can.d.ts.html new file mode 100644 index 0000000..be3b0e3 --- /dev/null +++ b/docs/files/src_can.d.ts.html @@ -0,0 +1,191 @@ + + + + + src/can.d.ts + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: +
    +
    +
    + +
    + +
    +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    File: src/can.d.ts

    + +
    +
    +declare module "*can.node" {
    +	export interface Message {
    +		id: number;
    +		ext: boolean;
    +		rtr: boolean;
    +		data: Buffer;
    +	}
    +
    +	export class RawChannel {
    +		constructor(
    +			name: string,
    +			timestamps?: boolean,
    +			protocol?: number,
    +			non_block_send?: boolean
    +		);
    +
    +		/**
    +		 * Add listener to receive certain notifications
    +		 * @method addListener
    +		 * @param event {string} onMessage to register for incoming messages
    +		 * @param callback {any} JS callback object
    +		 * @param instance {any} Optional instance pointer to call callback
    +		 */
    +		addListener(
    +			event: string,
    +			callback: CallableFunction,
    +			instance?: object
    +		): void;
    +
    +		/**
    +		 * Start operation on this CAN channel
    +		 * @method start
    +		 */
    +		start(): void;
    +
    +		/**
    +		 * Stop any operations on this CAN channel
    +		 * @method stop
    +		 */
    +		stop(): void;
    +
    +		/**
    +		 * Send a CAN message immediately.
    +		 *
    +		 * PLEASE NOTE: By default, this function may block if the Tx buffer is not available. Please use
    +		 * createRawChannelWithOptions({non_block_send: false}) to get non-blocking sending activated.
    +		 *
    +		 * @method send
    +		 * @param message {Object} JSON object describing the CAN message, keys are id, length, data {Buffer}, ext or rtr
    +		 */
    +		send(message: Message): void;
    +
    +		/**
    +		 * Send a CAN FD message immediately.
    +		 *
    +		 * PLEASE NOTE: By default, this function may block if the Tx buffer is not available. Please use
    +		 * createRawChannelWithOptions({non_block_send: false}) to get non-blocking sending activated.
    +		 *
    +		 * PLEASE NOTE: Might fail if underlying device doesnt support CAN FD. Structure is not yet validated.
    +		 *
    +		 * @method sendFD
    +		 * @param message {Object} JSON object describing the CAN message, keys are id, length, data {Buffer}, ext
    +		 */
    +		sendFD(message: Message): void;
    +
    +		/**
    +		 * Set a list of active filters to be applied for incoming messages
    +		 * @method setRxFilters
    +		 * @param filters {Object} single filter or array of filter e.g. { id: 0x1ff, mask: 0x1ff, invert: false}, result of (id & mask)
    +		 */
    +		setRxFilters(filters: Record<string, unknown>[]): void;
    +
    +		/**
    +		 * Set a list of active filters to be applied for errors
    +		 * @method setErrorFilters
    +		 * @param errorMask {Uint32} CAN error mask
    +		 */
    +		setErrorFilters(errorMask: number): void;
    +
    +		/**
    +		 * Disable loopback of channel. By default it is activated
    +		 * @method disableLoopback
    +		 */
    +		disableLoopback(): void;
    +	}
    +}
    +
    +    
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_socketcan.ts.html b/docs/files/src_socketcan.ts.html new file mode 100644 index 0000000..02643d1 --- /dev/null +++ b/docs/files/src_socketcan.ts.html @@ -0,0 +1,556 @@ + + + + + src/socketcan.ts + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: +
    +
    +
    + +
    + +
    +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    File: src/socketcan.ts

    + +
    +
    +/* Copyright Sebastian Haas <sebastian@sebastianhaas.info>. All rights reserved.
    + *
    + * Permission is hereby granted, free of charge, to any person obtaining a copy
    + * of this software and associated documentation files (the "Software"), to
    + * deal in the Software without restriction, including without limitation the
    + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    + * sell copies of the Software, and to permit persons to whom the Software is
    + * furnished to do so, subject to the following conditions:
    + *
    + * The above copyright notice and this permission notice shall be included in
    + * all copies or substantial portions of the Software.
    + *
    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    + * IN THE SOFTWARE.
    + */
    +
    +// -----------------------------------------------------------------------------
    +// CAN-Object
    +
    +import * as can from "../build/Release/can.node";
    +
    +// -----------------------------------------------------------------------------
    +/**
    + * The Signals modules provides an interface to access the values/signals
    + * encoded in CAN messages.
    + * @module Signals
    + */
    +import * as _signals from "../build/Release/can_signals.node";
    +
    +// import * as _signals from "can_signals";
    +
    +import * as kcd from "./parse_kcd";
    +
    +/**
    + * @method createRawChannel
    + * @param channel {string} Channel name (e.g. vcan0)
    + * @param timestamps {bool} Whether or not timestamps shall be generated when reading a message
    + * @param protocol {integer} optionally provide another default protocol value (default is CAN_RAW)
    + * @return {RawChannel} a new channel object or exception
    + * @for exports
    + */
    +export function createRawChannel(
    +	channel: string,
    +	timestamps?: boolean,
    +	protocol?: number
    +): can.RawChannel {
    +	return new can.RawChannel(channel, timestamps, protocol, false);
    +}
    +
    +interface ChannelOptions {
    +	timestamps?: boolean;
    +	protocol?: number;
    +	non_block_send?: boolean;
    +}
    +
    +/**
    + * @method createRawChannelWithOptions
    + * @param channel {string} Channel name (e.g. vcan0)
    + * @param options {dict} list of options (timestamps, protocol, non_block_send)
    + * @return {RawChannel} a new channel object or exception
    + * @for exports
    + */
    +export function createRawChannelWithOptions(
    +	channel: string,
    +	options: ChannelOptions
    +): can.RawChannel {
    +	if (options === undefined) options = {};
    +
    +	if (options.timestamps === undefined) options.timestamps = false;
    +	if (options.protocol === undefined) options.protocol = 1; /* CAN RAW */
    +	if (options.non_block_send === undefined) options.non_block_send = false;
    +
    +	return new can.RawChannel(
    +		channel,
    +		options.timestamps,
    +		options.protocol,
    +		options.non_block_send
    +	);
    +}
    +
    +/**
    + * The actual signal.
    + * @class Signal
    + */
    +export class Signal extends kcd.Signal {
    +	readonly muxGroup: number[];
    +
    +	public value?: number = undefined;
    +
    +	public changeListeners: CallableFunction[] = [];
    +	public updateListeners: CallableFunction[] = [];
    +
    +	constructor(desc: kcd.Signal) {
    +		super(
    +			desc.name,
    +			desc.spn,
    +			desc.bitOffset,
    +			desc.bitLength,
    +			desc.endianess,
    +			desc.labels,
    +			desc.mux,
    +			desc.slope,
    +			desc.intercept,
    +			desc.unit,
    +			desc.type,
    +			desc.defaultValue,
    +			desc.minValue,
    +			desc.maxValue
    +		);
    +
    +		/**
    +		 * this will allow triggering on mux'ed message ids.
    +		 */
    +		this.muxGroup = [desc.mux];
    +	}
    +
    +	/**
    +	 * Keep track of listeners who want to be notified if this signal changes
    +	 * @method onChange
    +	 * @param listener JS callback to get notification
    +	 * @for Signal
    +	 */
    +	onChange(listener: CallableFunction) {
    +		this.changeListeners.push(listener);
    +		return listener;
    +	}
    +
    +	/**
    +	 * Keep track of listeners who want to be notified if this signal updates
    +	 * @method onUpdate
    +	 * @param listener JS callback to get notification
    +	 * @for Signal
    +	 */
    +	onUpdate(listener: CallableFunction) {
    +		this.updateListeners.push(listener);
    +		return listener;
    +	}
    +
    +	/**
    +	 * Remove listener from signal onChange and/or onUpdate
    +	 * @method removeListener
    +	 * @param listener to be removed
    +	 * @for Signal
    +	 */
    +	removeListener(listener: CallableFunction) {
    +		let idx = this.changeListeners.indexOf(listener);
    +		if (idx >= 0) this.changeListeners.splice(idx, 1);
    +		idx = this.updateListeners.indexOf(listener);
    +		if (idx >= 0) this.updateListeners.splice(idx, 1);
    +	}
    +
    +	/**
    +	 * Set new value of this signal. Any local registered clients will
    +	 * receive a notification. Please note, no CAN message is actually
    +	 * send to the bus (@see DatabaseServer::send)
    +	 * @method update
    +	 * @param newValue {bool|double|integer} New value to set
    +	 * @for Signal
    +	 */
    +	update(newValue: number) {
    +		// TODO: Move this block to a `Value.isValid(v)` function?
    +		if (this.maxValue && newValue > this.maxValue) {
    +			console.error(
    +				`ERROR : ${this.name} value = ${newValue} is out of bounds > ${this.maxValue}`
    +			);
    +		}
    +
    +		if (this.minValue && newValue < this.minValue) {
    +			console.error(
    +				`ERROR : ${this.name} value = ${newValue} is out of bounds < ${this.minValue}`
    +			);
    +		}
    +
    +		const changed = this.value !== newValue;
    +		this.value = newValue;
    +
    +		// Update all updateListeners, that the signal updated
    +		this.updateListeners.forEach((listener) => {
    +			listener(this);
    +		});
    +
    +		// Nothing changed
    +		if (!changed) return;
    +
    +		// Update all changelisteners, that the signal changed
    +		this.changeListeners.forEach((listener) => {
    +			listener(this);
    +		});
    +	}
    +}
    +
    +// -----------------------------------------------------------------------------
    +/**
    + * Just a container to keep the Signals.
    + * @class Message
    + */
    +export class Message {
    +	readonly id: number;
    +	readonly name: string;
    +	readonly ext: boolean;
    +	readonly len: number;
    +	readonly interval: number;
    +	readonly muxed: boolean;
    +	readonly mux: kcd.Mux | undefined;
    +	readonly signals: Record<string, Signal> = {};
    +
    +	constructor(msgDef: kcd.Message) {
    +		/**
    +		 * CAN identifier
    +		 * @attribute id
    +		 * @final
    +		 */
    +		this.id = msgDef.id;
    +
    +		/**
    +		 * Extended Frame Format used
    +		 * @attribute ext
    +		 * @final
    +		 */
    +		this.ext = msgDef.ext;
    +
    +		/**
    +		 * Symbolic name
    +		 * @attribute name
    +		 * @final
    +		 */
    +		this.name = msgDef.name;
    +
    +		/**
    +		 * Length in bytes of resulting CAN message
    +		 *
    +		 * @attribute len
    +		 * @final
    +		 */
    +		this.len = msgDef.length;
    +
    +		/**
    +		 * This is the time frame that the message gets generated
    +		 *
    +		 * @attribute interval
    +		 * @final
    +		 */
    +		this.interval = msgDef.interval;
    +
    +		/**
    +		 * This tells us the message is mutliplexed.
    +		 *
    +		 * @attribute muxed
    +		 * @final
    +		 */
    +		this.muxed = msgDef.muxed;
    +
    +		/**
    +		 * Multiplexor parameter (just one supported right now).
    +		 *
    +		 * @attribute mux
    +		 * @final
    +		 */
    +		this.mux = msgDef.mux;
    +
    +		/**
    +		 * Named information to inform that the frame is CAN_FD format .
    +		 * @attribute Boolean
    +		 * @final
    +		 */
    +		// this.canfd = msgDef.canfd;
    +
    +		msgDef.signals.forEach((s) => {
    +			if (this.signals[s.name] && this.signals[s.name].muxGroup) {
    +				this.signals[s.name].muxGroup.push(s.mux);
    +			} else {
    +				this.signals[s.name] = new Signal(s);
    +			}
    +		});
    +	}
    +}
    +
    +// -----------------------------------------------------------------------------
    +/**
    + * A DatabaseService is usually generated once per bus to collect signals
    + * coded in the CAN messages according a DB description.
    + * @class DatabaseService
    + * @constructor DatabaseService
    + * @param channel RAW channel
    + * @param db_desc Set of rules to decode/encode signals (@parse_kcd.js)
    + * @return a new DatabaseService
    + * @for DatabaseService
    + */
    +export class DatabaseService {
    +	readonly messages: Record<string, Message> = {};
    +	constructor(private channel: can.RawChannel, busDef: kcd.Bus) {
    +		busDef.messages.forEach((m) => {
    +			const id = m.id | ((m.ext ? 1 : 0) << 31);
    +
    +			const nm = new Message(m);
    +			this.messages[id] = nm;
    +			this.messages[m.name] = nm;
    +		});
    +
    +		// Subscribe to any incoming messages
    +		channel.addListener("onMessage", this.onMessage, this);
    +	}
    +
    +	// Callback for incoming messages
    +	onMessage(msg: can.Message) {
    +		if (msg == undefined) return;
    +
    +		// RTR (Remote-Transmit-Request) dont have payload
    +		if (msg.rtr) return;
    +
    +		const id = msg.id | ((msg.ext ? 1 : 0) << 31);
    +
    +		const m = this.messages[id];
    +
    +		if (!m) {
    +			return;
    +		}
    +
    +		let mux_count = -1;
    +
    +		if (m.muxed && m.mux) {
    +			const b_mux = _signals.decodeSignal(
    +				msg.data,
    +				m.mux.offset,
    +				m.mux.length,
    +				true,
    +				false
    +			);
    +			mux_count = b_mux[0] + (b_mux[1] << 32);
    +		}
    +
    +		// Let the C-Portition extract and convert the signal
    +		for (const i in m.signals) {
    +			const s = m.signals[i];
    +
    +			// if this is a mux signal and the muxor isnt in my list...
    +			if (m.muxed && s.muxGroup.indexOf(mux_count) == -1) {
    +				continue;
    +			}
    +
    +			const ret = _signals.decodeSignal(
    +				msg.data,
    +				s.bitOffset,
    +				s.bitLength,
    +				s.endianess == "little",
    +				s.type == "signed"
    +			);
    +
    +			let val = ret[0] + (ret[1] << 32);
    +
    +			if (s.slope) val *= s.slope;
    +
    +			if (s.intercept) val += s.intercept;
    +
    +			s.update(val);
    +		}
    +	}
    +
    +	/**
    +	 * Construct a CAN message and encode all related signals according
    +	 * the rules. Finally send the message to the bus.
    +	 * @method send
    +	 * @param msg_name Name of the message to generate (indicate mux by append .MUX_VALUE in hex)
    +	 * @for DatabaseService
    +	 */
    +	send(msg_name: string) {
    +		const args = msg_name.split("."); // allow for mux'ed messages sent.
    +
    +		const m = this.messages[args[0]];
    +		const mux = args.length > 1 ? args[1] : undefined;
    +
    +		if (!m) throw msg_name + " not defined";
    +
    +		const canmsg = {
    +			id: m.id,
    +			ext: m.ext,
    +			rtr: false,
    +			// for CANFD data buffer 64 bytes
    +			data: m.len > 0 && m.len < 64 ? Buffer.alloc(m.len) : Buffer.alloc(64),
    +		};
    +
    +		canmsg.data.fill(0); // should be 0xFF for j1939 message def.
    +
    +		if (mux && m.mux)
    +			_signals.encodeSignal(
    +				canmsg.data,
    +				m.mux.offset,
    +				m.mux.length,
    +				true,
    +				false,
    +				parseInt(mux, 16)
    +			);
    +
    +		Object.values(m.signals).forEach((s) => {
    +			if (s.value == undefined) return;
    +
    +			if (mux) {
    +				if (s.muxGroup.indexOf(parseInt(mux, 16)) === -1) {
    +					return;
    +				}
    +			}
    +
    +			let val = s.value!;
    +
    +			// Apply factor/intercept and convert to Integer
    +			val -= s.intercept;
    +			val /= s.slope;
    +
    +			// Make sure we are sending an integer because the division above could change it to a float.
    +			val = Math.round(val);
    +
    +			if (m.len == 0) {
    +				return;
    +			}
    +
    +			const word1 = val & 0xffffffff;
    +			let word2 = 0;
    +
    +			// shift doesn't work above 32 bit, only do this if required to save cycles
    +			if (val > 0xffffffff) {
    +				word2 = val / Math.pow(2, 32);
    +			}
    +
    +			_signals.encodeSignal(
    +				canmsg.data,
    +				s.bitOffset,
    +				s.bitLength,
    +				s.endianess == "little",
    +				s.type == "signed",
    +				word1,
    +				word2
    +			);
    +		});
    +
    +		this.channel.send(canmsg);
    +	}
    +}
    +
    +/**
    + * @method parseNetworkDescription
    + * @param file {string} Path to KCD file to parse
    + * @return DB description to be used in DatabaseService
    + * @for exports
    + */
    +export const parseNetworkDescription = kcd.parseKcdFile;
    +export { kcd };
    +
    +    
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/modules/Signals.html b/docs/modules/Signals.html index d2c5588..3526494 100644 --- a/docs/modules/Signals.html +++ b/docs/modules/Signals.html @@ -85,7 +85,7 @@

    Signals Module

    - Defined in: socketcan.js:203 + Defined in: src/socketcan.ts:284
    diff --git a/package.json b/package.json index 2af6637..45e5141 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "email": "sebastian@sebastianhaas.info" }, "description": "A SocketCAN abstraction layer for NodeJS.", - "version": "3.0.0", + "version": "4.0.0", "license": "MIT", "repository": { "type": "git", diff --git a/src/socketcan.ts b/src/socketcan.ts index 7fcba43..df135c4 100644 --- a/src/socketcan.ts +++ b/src/socketcan.ts @@ -59,7 +59,7 @@ interface ChannelOptions { } /** - * @method createRawChannel + * @method createRawChannelWithOptions * @param channel {string} Channel name (e.g. vcan0) * @param options {dict} list of options (timestamps, protocol, non_block_send) * @return {RawChannel} a new channel object or exception