steamclock / bluejay

A simple Swift framework for building reliable Bluetooth LE apps.
MIT License
1.09k stars 97 forks source link

Add a simple json schema for adding services to dittojay through json #228

Closed brendanlensink closed 2 years ago

brendanlensink commented 4 years ago

Fixes: #225

Summary of Problem:

We'd like to be able to add and manage services created with Dittojay through JSON instead of having to add them in code.

Proposed Solution:

Created a simple JSON schema that can be parsed to create services from.

A couple questions:

brendanlensink commented 4 years ago

I don't think we should merge this to master.

That's totally reasonable, would this end up being version 0.7.2 then?

I think we can allow specifying name and even description

Description is a great idea, added that as well.

Instead of just value ...

Changed value to hold another JSON object, with the intent being that Dittojay will parse the JSON and concat all the values to create the Data to be read.

I think it would be neat to create some sort of framework to separate the value data and the schema, but it might be a more 2.0/next iteration feature if that makes sense?

sakuraehikaru commented 4 years ago

Yes, let's defer any high complexity features that might not be necessary to have right away :)

nbrooke commented 4 years ago

value being an object might not work (or at least, not work by itself).

The fields are going to be order dependant (except in the trivial case of only one field), but I don't think that ordering is well defined for JSON (like once we have loaded that in, there is no way to say "give me the fields in order", which is pretty essential for creating the binary data to send).

What I think we want is an array that defines things like ordering and byte width:

"value" : [
   { "byteWidth": 2, "value": 700 },
   { "byteWidth": 4, "value": -100 }
]

This is (I believe) the simplest thing that could work. We can get more complicated by adding possible options to the fields ({"byteWidth": 2, "bigEndian": true, "value": 700 }) or by naming the fields so we can do the more seperate-schema-and-data approach later:

"schema" : [
   { "name" : "foo", "byteWidth": 2, "bigEndian": true}.
   { "name" : "bar", "byteWidth": 4, "bigEndian": false}
],
data: {
  "foo": 700,
  "bar": -100
}
brendanlensink commented 2 years ago

@sakuraehikaru Is it worth keeping this PR open, or can we close this and re-open if we want to address this in the future?

sakuraehikaru commented 2 years ago

@brendanlensink I have no preference, other than if we do close this, then let's not delete this branch so we don't lose any work that's already done.