-
Notifications
You must be signed in to change notification settings - Fork 329
Expose LPP data type size lookup via a static method #1196
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
Open
ssozonoff
wants to merge
1
commit into
meshcore-dev:dev
Choose a base branch
from
ssozonoff:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,45 @@ | |
| #define LPP_ERROR_OVERFLOW 1 | ||
| #define LPP_ERROR_UNKOWN_TYPE 2 | ||
|
|
||
| /** | ||
| * Get the data size in bytes for a CayenneLPP type | ||
| * @param type The LPP type code | ||
| * @return Number of bytes of data for this type | ||
| */ | ||
| static inline uint8_t getLPPDataSize(uint8_t type) { | ||
| switch (type) { | ||
| case LPP_GPS: | ||
| return 9; | ||
| case LPP_POLYLINE: | ||
| return 8; // Minimum size | ||
| case LPP_GYROMETER: | ||
| case LPP_ACCELEROMETER: | ||
| return 6; | ||
| case LPP_GENERIC_SENSOR: | ||
| case LPP_FREQUENCY: | ||
| case LPP_DISTANCE: | ||
| case LPP_ENERGY: | ||
| case LPP_UNIXTIME: | ||
| return 4; | ||
| case LPP_COLOUR: | ||
| return 3; | ||
| case LPP_ANALOG_INPUT: | ||
| case LPP_ANALOG_OUTPUT: | ||
| case LPP_LUMINOSITY: | ||
| case LPP_TEMPERATURE: | ||
| case LPP_CONCENTRATION: | ||
| case LPP_BAROMETRIC_PRESSURE: | ||
| case LPP_ALTITUDE: | ||
| case LPP_VOLTAGE: | ||
| case LPP_CURRENT: | ||
| case LPP_DIRECTION: | ||
| case LPP_POWER: | ||
| return 2; | ||
| default: | ||
| return 1; // Digital input/output, presence, humidity, percentage, switch | ||
| } | ||
| } | ||
|
|
||
| class LPPReader { | ||
| const uint8_t* _buf; | ||
| uint8_t _len; | ||
|
|
@@ -113,7 +152,7 @@ class LPPReader { | |
| return _pos <= _len; | ||
| } | ||
| bool readCurrent(float& amps) { | ||
| amps = getFloat(&_buf[_pos], 2, 1000, true); _pos += 2; | ||
| amps = getFloat(&_buf[_pos], 2, 1000, false); _pos += 2; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was changed to signed in last commit. Please update your branch |
||
| return _pos <= _len; | ||
| } | ||
| bool readPower(float& watts) { | ||
|
|
@@ -138,37 +177,7 @@ class LPPReader { | |
| } | ||
|
|
||
| void skipData(uint8_t type) { | ||
| switch (type) { | ||
| case LPP_GPS: | ||
| _pos += 9; break; | ||
| case LPP_POLYLINE: | ||
| _pos += 8; break; // TODO: this is MINIMIUM | ||
| case LPP_GYROMETER: | ||
| case LPP_ACCELEROMETER: | ||
| _pos += 6; break; | ||
| case LPP_GENERIC_SENSOR: | ||
| case LPP_FREQUENCY: | ||
| case LPP_DISTANCE: | ||
| case LPP_ENERGY: | ||
| case LPP_UNIXTIME: | ||
| _pos += 4; break; | ||
| case LPP_COLOUR: | ||
| _pos += 3; break; | ||
| case LPP_ANALOG_INPUT: | ||
| case LPP_ANALOG_OUTPUT: | ||
| case LPP_LUMINOSITY: | ||
| case LPP_TEMPERATURE: | ||
| case LPP_CONCENTRATION: | ||
| case LPP_BAROMETRIC_PRESSURE: | ||
| case LPP_ALTITUDE: | ||
| case LPP_VOLTAGE: | ||
| case LPP_CURRENT: | ||
| case LPP_DIRECTION: | ||
| case LPP_POWER: | ||
| _pos += 2; break; | ||
| default: | ||
| _pos++; | ||
| } | ||
| _pos += getLPPDataSize(type); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would be neater if this was a public static method in the helper class