-
Notifications
You must be signed in to change notification settings - Fork 6
Updates for ThingSet Protocol draft v0.5 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
45b91eb
5699351
7ce2093
a2910b5
727cb4d
c69d111
7546f94
cd5c514
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -341,15 +341,15 @@ static inline void *ts_array_to_void(struct ts_array_info *ptr) { return (void * | |
| #define TS_ROLE_EXP (1U << 1) // expert user | ||
| #define TS_ROLE_MKR (1U << 2) // maker | ||
|
|
||
| #define TS_READ_MASK 0x00FF // read flags stored in 4 least-significant bits | ||
| #define TS_WRITE_MASK 0xFF00 // write flags stored in 4 most-significant bits | ||
| #define TS_READ_MASK 0x0F // read flags stored in 4 least-significant bits | ||
| #define TS_WRITE_MASK 0xF0 // write flags stored in 4 most-significant bits | ||
|
|
||
| #define TS_USR_MASK (TS_ROLE_USR << 8 | TS_ROLE_USR) | ||
| #define TS_EXP_MASK (TS_ROLE_EXP << 8 | TS_ROLE_EXP) | ||
| #define TS_MKR_MASK (TS_ROLE_MKR << 8 | TS_ROLE_MKR) | ||
| #define TS_USR_MASK (TS_ROLE_USR << 4 | TS_ROLE_USR) | ||
| #define TS_EXP_MASK (TS_ROLE_EXP << 4 | TS_ROLE_EXP) | ||
| #define TS_MKR_MASK (TS_ROLE_MKR << 4 | TS_ROLE_MKR) | ||
|
|
||
| #define TS_READ(roles) ((roles) & TS_READ_MASK) | ||
| #define TS_WRITE(roles) (((roles) << 8) & TS_WRITE_MASK) | ||
| #define TS_WRITE(roles) (((roles) << 4) & TS_WRITE_MASK) | ||
| #define TS_READ_WRITE(roles) (TS_READ(roles) | TS_WRITE(roles)) | ||
|
|
||
| #define TS_USR_R TS_READ(TS_ROLE_USR) | ||
|
|
@@ -401,25 +401,29 @@ struct ts_data_object { | |
| /** | ||
| * One of TS_TYPE_INT32, _FLOAT, ... | ||
| */ | ||
| const uint8_t type; | ||
| const uint32_t type : 4; | ||
|
|
||
| /** | ||
| * Exponent (10^exponent = factor to convert to SI unit) for decimal fraction type, | ||
| * decimal digits to use for printing of floats in JSON strings or | ||
| * length of string buffer for string type | ||
| */ | ||
| const int16_t detail; | ||
| const int32_t detail : 12; | ||
|
|
||
| /** | ||
| * Flags to define read/write access | ||
| */ | ||
| const uint16_t access; | ||
| const uint32_t access : 8; | ||
|
|
||
| /** | ||
| * Flags to assign data item to different data item subsets (e.g. for publication messages) | ||
| */ | ||
| uint16_t subsets; | ||
| uint32_t subsets : 7; | ||
|
|
||
| /** | ||
| * Bit to store if value has been updated via ThingSet (e.g. for NVM stoarage) | ||
| */ | ||
| uint32_t updated : 1; | ||
| }; | ||
|
|
||
| /* support for legacy code with old nomenclature */ | ||
|
|
@@ -479,7 +483,7 @@ struct ts_context { | |
| /** | ||
| * Stores current authentication status (authentication as "normal" user as default) | ||
| */ | ||
| uint16_t _auth_flags; | ||
| uint8_t _auth_flags; | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -529,7 +533,16 @@ void ts_dump_json(struct ts_context *ts, ts_object_id_t obj_id, int level); | |
| * @param ts Pointer to ThingSet context. | ||
| * @param flags Flags to define authentication level (1 = access allowed) | ||
| */ | ||
| void ts_set_authentication(struct ts_context *ts, uint16_t flags); | ||
| void ts_set_authentication(struct ts_context *ts, uint8_t flags); | ||
|
|
||
| /** | ||
| * Checks if any of the data objects belonging to the subsets was updated. | ||
| * | ||
| * @param ts Pointer to ThingSet context. | ||
| * @param subsets Flags to select which subset(s) of data items should be considered | ||
| * @param clear If set to true, the updated status is cleared after checking. | ||
| */ | ||
| bool ts_check_updated(struct ts_context *ts, const uint16_t subsets, bool clear); | ||
|
||
|
|
||
| /** | ||
| * Retrieve data in JSON format for given subset(s). | ||
|
|
@@ -676,7 +689,7 @@ int ts_bin_pub_can(struct ts_context *ts, int *start_pos, uint16_t subset, uint8 | |
| * | ||
| * @returns ThingSet status code | ||
| */ | ||
| int ts_bin_import(struct ts_context *ts, uint8_t *data, size_t len, uint16_t auth_flags, | ||
| int ts_bin_import(struct ts_context *ts, uint8_t *data, size_t len, uint8_t auth_flags, | ||
| uint16_t subsets); | ||
|
|
||
| /** | ||
|
|
@@ -760,11 +773,16 @@ class ThingSet | |
| ts_dump_json(&ts, obj_id, level); | ||
| }; | ||
|
|
||
| inline void set_authentication(uint16_t flags) | ||
| inline void set_authentication(uint8_t flags) | ||
| { | ||
| ts_set_authentication(&ts, flags); | ||
| }; | ||
|
|
||
| inline bool check_updated(const uint16_t subsets, bool clear) | ||
| { | ||
| return ts_check_updated(&ts, subsets, clear); | ||
| }; | ||
|
|
||
| inline int txt_export(char *buf, size_t size, const uint16_t subsets) | ||
| { | ||
| return ts_txt_export(&ts, buf, size, subsets); | ||
|
|
@@ -790,7 +808,7 @@ class ThingSet | |
| return ts_bin_export(&ts, buf, size, subsets); | ||
| }; | ||
|
|
||
| inline int bin_import(uint8_t *buf, size_t size, uint16_t auth_flags, const uint16_t subsets) | ||
| inline int bin_import(uint8_t *buf, size_t size, uint8_t auth_flags, const uint16_t subsets) | ||
| { | ||
| return ts_bin_import(&ts, buf, size, auth_flags, subsets); | ||
| }; | ||
|
|
@@ -880,7 +898,7 @@ class ThingSet | |
| * | ||
| * @returns ThingSet status code | ||
| */ | ||
| inline int bin_sub(uint8_t *cbor_data, size_t len, uint16_t auth_flags, uint16_t subsets) | ||
| inline int bin_sub(uint8_t *cbor_data, size_t len, uint8_t auth_flags, uint16_t subsets) | ||
| __attribute__((deprecated)) | ||
| { | ||
| return ts_bin_import(&ts, cbor_data + 1, len - 1, auth_flags, subsets); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you improve the documentation a little bit in the course of the change. It took me quite a time to understand that this are three different usages of the detail information depending on the type of data object. And I'm stiill not shure how to handle the exponent of the decimal fraction type. It seems you expect this to be a fixed value and not something that can be adapted acc. to the value.
For doxygen it would be nice to have a brief description and a detailed description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Will improve the docs here.
The idea was to have it fixed so that e.g. the firmware could store values in mV as integers, but send out the data in V without any numeric conversion to float. In that case the exponent would be -3. But so far I've never actually used the decimal fraction type (I can't even remember if it's implemented...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the documentation, please have a look.