npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cross-def

v1.1.9

Published

JSON manifest to C definitions for embedded systems

Downloads

13

Readme

cross-def

A utility to generate cross-language definitions from a JSON manifest. Built for CANtastic, but useful elsewhere too.

This was built to solve the problem of maintaining values for symbols between embedded web apps and firmware. Define symbols once, and cross-def will maintain your language definitions for you.

Simply pass in a JSON 'manifest', to define your symbols and how you'd like them represented for each language. Then specify output formats, and cross-def will generate your definition sources.

Currently, two output formats are supported:

  • c (typedef enum, static const char* label map)
  • json (object:value map, object map with labels)

Install and get started

With NPM:

npm i -g cross-def

Then on your command line: cross-def build manifest.json -o c:my_header.h json:my_json.json

What is this, and why?

Sometimes, when we build an embedded system, we design an application to go alongside it. Whether that be a mobile app, CLI, or web app. More often than not, these complimentary apps are written in a different language to the firmware, and so symbols that are shared between them need to be defined in multiple places.

An example of this could be a smart switch. Suppose the the firmware for the switch has three outputs, identified by 0xA, 0xB, 0xC. We want our mobile application to understand these switch IDs too, so when making a HTTP request to toggle a switch, the mobile app knows that Switch 1 is 0xA, and can pass that value to the device firmware.

With cross-def, we can define a manifest listing all the switches, and their IDs, and generate both a C header file (containing a typedef enum for each switch), and a JSON file (containing integers for each switch). The app and firmware now reference the same symbol values.

Adding / readdressing / removing switches (or symbols) can be done easily, and when both apps are built, they remain in sync.

This is particularly useful when writing embedded web-apps that run on tiny devices, like the ESP32.

In addition to symbols, cross-def can define labels - human readable strings - corresponding to symbols.

Manifest format

An example manifest is available in ./examples/manifest.json. Run cross-def build manifest.json -o c:my_header.h json:my_json.json and have a look at the resulting C (my_header.h) and JSON output.