Skip to content

gribbet/dronecan.ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dronecan.ts

TypeScript implementation of the DroneCAN protocol.

Example

Usage overview

Define protocol schema

export const schema = {
  messages: [
    message({
      id: 341,
      type: "uavcan.protocol.NodeStatus",
      definition: {
        uptimeSec: uint(32),
        health: enumeration(2, ["ok", "warning", "error", "critical"] as const),
        mode: enumeration(3, [
          "operational",
          "initialization",
          "maintenance",
          "software update",
          4,
          5,
          6,
          "offline",
        ] as const),
        subMode: uint(3),
        vendorSpecificStatusCode: uint(16),
      },
    }),
  ],
  services: [],
} as const;

Broadcast

 dronecan.broadcast("uavcan.protocol.NodeStatus", {
    uptimeSec: 0,
    health: "ok",
    mode: "operational",
    subMode: 0,
    vendorSpecificStatusCode: 0,
  })

Request

const info = await dronecan.request("uavcan.protocol.GetNodeInfo", destinationId, {});

Respond

dronecan.onRequest("uavcan.protocol.GetNodeInfo", () => ({
  status: {
    uptimeSec: 0,
    health: "ok",
    mode: "operational",
    subMode: 0,
    vendorSpecificStatusCode: 0,
  },
  softwareVersion: {
    major: 1,
    minor: 0,
    optionalFieldFlags: 0,
    vcsCommit: 0,
    imageCrc: 0n,
  },
  hardwareVersion: {
    major: 1,
    minor: 0,
    uniqueId: new Uint8Array(new Array(16)),
    certificateOfAuthenticity: new Uint8Array(),
  },
  name: "",
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published