Skip to content
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

Add two-digit mnc diagnostic flag #1804

Merged
merged 6 commits into from Jun 6, 2019
Merged

Add two-digit mnc diagnostic flag #1804

merged 6 commits into from Jun 6, 2019

Conversation

zfields
Copy link
Contributor

@zfields zfields commented Jun 3, 2019

The two-digit `mnc` diagnostic allows the original `mnc` to be reconstructed accurately.

Problem

Currently, the mnc is translated to and stored as a decimal value. According to the specification, 40 and 040 are not equal values. Currently when using the mcc and mnc tuple, there does not appear to be a clash. However, maintaining this distinction is important is important to ensure future bugs do not appear in the system.

Solution

By sending an indicator as to the original form of the information, we are able to reconstruct the original value in a lossless manner.

Steps to Test

user/tests/accept/hal-api-test-plan.md

Example App

user/tests/app/cellular_global_identity/cellular_global_identity.cpp

Tickets

  • ch33501

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

  • [bugfix] Add two-digit mnc diagnostic flag #1804

@zfields zfields requested review from avtolstoy and sergeuz June 3, 2019 00:33
@zfields zfields force-pushed the mnc2d branch 2 times, most recently from 35b4030 to f739317 Compare June 3, 2019 02:29
@zfields zfields changed the title Add two-digit mnc diagnostic Add two-digit mnc diagnostic flag Jun 3, 2019
@zfields zfields force-pushed the mnc2d branch 4 times, most recently from bf0dda4 to 83b509e Compare June 3, 2019 19:44
@zfields zfields requested a review from avtolstoy June 3, 2019 19:48
@@ -412,6 +412,15 @@ int SaraNcpClient::queryAndParseAtCops(CellularSignalQuality* qual) {
r = CHECK_PARSER(resp.readResult());
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_AT_NOT_OK);

// Preserve digit format data
const int mnc_digits = ::strnlen(mobileNetworkCode, 4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number, let's use sizeof(mobileNetworkCode) here.

Same here https://github.com/particle-iot/device-os/pull/1804/files#diff-13c08dca4df073df121b6a68266e0105R1520

hal/src/boron/network/sara_ncp_client.cpp Show resolved Hide resolved
@@ -302,7 +302,14 @@ class NetworkCellularCellGlobalIdentityMobileNetworkCodeDiagnosticData
{
CellularGlobalIdentity cgi;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just noticed this. Why aren't we zeroing out this struct and not setting neither size nor version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Thank you!

@@ -77,7 +77,7 @@ class SaraNcpClient: public CellularNcpClient {
gsm0710::Muxer<particle::Stream, StaticRecursiveMutex> muxer_;
std::unique_ptr<particle::MuxerChannelStream<decltype(muxer_)> > muxerAtStream_;
CellularNetworkConfig netConf_;
CellularGlobalIdentity cgi_;
CellularGlobalIdentity cgi_ = {0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: = {}; in C++.

@@ -321,7 +328,7 @@ class NetworkCellularCellGlobalIdentityLocationAreaCodeDiagnosticData

virtual int get(IntType& val)
{
CellularGlobalIdentity cgi;
CellularGlobalIdentity cgi{sizeof(CellularGlobalIdentity),CGI_VERSION_LATEST};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: spaces.
Same here https://github.com/particle-iot/device-os/pull/1804/files#diff-027356106780d045bc6ae658497e6c92R350

Also perhaps prefer designated initializers:

Suggested change
CellularGlobalIdentity cgi{sizeof(CellularGlobalIdentity),CGI_VERSION_LATEST};
CellularGlobalIdentity cgi {.size = sizeof(CellularGlobalIdentity), .version = CGI_VERSION_LATEST};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually prefer those, but I thought that was only a C thing. I will switch over.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK it's in C++20 officially, but GCC supported trivial cases since long ago.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did a cursory check and I cannot find where designated initialization has made it into the c++ standard.
@avtolstoy Can you please confirm when it was added to the standard and if our compile flags -std=c++14 support it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See message above. Yes, it'll work as long as the designators are specified in the same order as the fields during the declaration.

Copy link
Contributor Author

@zfields zfields Jun 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I truly like the clarity of the syntax, I would prefer to maintain standard compliance and not become compiler dependent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case you should consider removing __attribute__ or any other GNU Extensions as well.

I simply want to improve readability, so you could also consider:

Suggested change
CellularGlobalIdentity cgi{sizeof(CellularGlobalIdentity),CGI_VERSION_LATEST};
CellularGlobalIdentity cgi = {};
cgi.size = sizeof(cgi);
cgi.version = CGI_VERSION_LATEST;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You make a good point about __attribute__, seems like we are well committed to GNU at this point. I will follow your first suggestion, and use the designated initializers so we can keep it on one line.

@avtolstoy avtolstoy added the ready to merge PR has been reviewed and tested label Jun 4, 2019
@avtolstoy
Copy link
Member

@zfields Please also set the appropriate milestone for this PR.

@@ -33,6 +35,8 @@ enum __attribute__((__packed__)) CgiFlags
CGI_FLAG_TWO_DIGIT_MNC = 0b00000001, /*!< Indicates two-digit format of Mobile Network Code */
};

PARTICLE_STATIC_ASSERT(CgiFlags_size, sizeof(enum CgiFlags) == 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer typedef enum XXX {} XXX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@technobly technobly added the bug label Jun 5, 2019
@zfields zfields merged commit 12d45eb into release/v1.2.1 Jun 6, 2019
@zfields zfields deleted the mnc2d branch June 6, 2019 00:26
@technobly technobly modified the milestones: 1.2.1, 1.2.1-rc.3 Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ready to merge PR has been reviewed and tested
Projects
None yet
3 participants