Device handling in Applications

This document describes the way for applications to know about devices mounted on their containers and formats used in the communication.

Background and Purpose #

When the Actcast Agent starts an application, agent mounts devices based on the manifesto of the application. In this case, it is usefull if you have access to the detail of the mounted devices in a few reasons:

  • No need to write the same device file name twice in the manifesto and the code
  • Code reusability; the code don’t depends on manifesto
  • Need to get device details because manifesto v2 allows you to omit device file in some cases.

The Actcast Agent and the Actsim provides these mechanisms.

How to get the detail of supplied devices #

The environment variable DEVICE_SUPPLY_PATH is available at application runtime. The JSON file at that path describes the details of mounted devices.

When you are using actfw-core, you can get these information with get_device_supply() function.

File Format #

It’s in JSON format like below:

{
  "devices": [
    {
      "type": "<DEVICE TYPE>",
      "nodes": [
        {"path": "<DEVICE PATH>", "label": "<LABEL>"},
        ...
      ]
    },
    ...
  ]
}

where, each placeholders means:

  • DEVICE TYPE: the device type specified in the manifesto. See manifesto for more detail.
  • DEVICE PATH: Actual device path, including those specified in the manifesto.
  • LABEL: Optional . It holds the device’s role in the device type, etc.

Examples #

Default manifesto #

Give you have a manifesto like below:

{
  "boards": [
    "RSPi1A",
    "RSPi1B",
    "RSPi1APlus",
    "RSPi1BPlus",
    "RSPi2B",
    "RSPiAlpha",
    "RSPiCM1",
    "RSPi3B",
    "RSPiZero",
    "RSPiCM3",
    "RSPiZeroW",
    "RSPi3BPlus",
    "RSPi3APlus",
    "RSPiCM3Plus",
    "RSPiZero2W"
  ],
  "devices": [
    {
      "type": "camera",
      "device": [
        "/dev/video0"
      ]
    },
    {
      "type": "videocore",
      "device": [
        "/dev/vcsm",
        "/dev/vcio",
        "/dev/vc-mem",
        "/dev/vchiq",
        "/dev/gpiomem"
      ]
    },
    {
      "type": "framebuffer",
      "device": [
        "/dev/fb0"
      ]
    }
  ]
}

Then you can get these device suppliment informaton from the applicationg

{
  "devices": [
    {
      "type": "camera",
      "nodes": [{"path": "/dev/video0"}]
    },
    {
      "type": "videocore",
      "nodes": [
        {"path": "/dev/vcsm"},
        {"path": "/dev/vcio"},
        {"path": "/dev/vc-mem"},
        {"path": "/dev/vchiq"},
        {"path": "/dev/gpiomem"}
      ]
    },
    {
      "type": "framebuffer",
      "nodes": [{"path":"/dev/fb0"}]
    }
  ]
}

Elision in manifesto V2 #

Give you have a manifesto like below:

{
  "version": 2,
  "boards": [
      "RSPi4B"
  ],
  "target_type": "raspberrypi-buster",
  "devices": [
    {"type": "camera"},
    {"type": "display"}
  ]
}

Then you can get these device suppliment informaton from the applicationg

{
  "devices": [
    {
      "type": "camera",
      "nodes": [{"path": "/dev/video0", "label": "image_source"}]
    },
    {
      "type": "display",
      "nodes": [{"path":"/dev/vchiq"}]
    }
  ]
}

Back to Actcast SDK Reference Manual