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

Conversation

@zfields
Copy link
Contributor

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 Jun 3, 2019

@zfields zfields force-pushed the mnc2d branch 2 times, most recently from 35b4030 to f739317 Jun 3, 2019

@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 Jun 3, 2019

@zfields zfields requested a review from avtolstoy Jun 3, 2019

@zfields zfields force-pushed the mnc2d branch from 83b509e to 716a7b9 Jun 3, 2019

@@ -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);

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Jun 4, 2019

Member

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

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

@@ -302,7 +302,14 @@ class NetworkCellularCellGlobalIdentityMobileNetworkCodeDiagnosticData
{
CellularGlobalIdentity cgi;

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Jun 4, 2019

Member

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

This comment has been minimized.

Copy link
@zfields

zfields Jun 4, 2019

Author Contributor

Great catch! Thank you!

@zfields zfields requested review from avtolstoy and m-mcgowan Jun 4, 2019

@@ -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};

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Jun 4, 2019

Member

Nitpicking: = {}; in C++.

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

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

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Jun 4, 2019

Member

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};

This comment has been minimized.

Copy link
@zfields

zfields Jun 4, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Jun 4, 2019

Member

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

This comment has been minimized.

Copy link
@zfields

zfields Jun 4, 2019

Author Contributor

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?

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Jun 4, 2019

Member

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

This comment has been minimized.

Copy link
@zfields

zfields Jun 4, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Jun 5, 2019

Member

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;

This comment has been minimized.

Copy link
@zfields

zfields Jun 5, 2019

Author Contributor

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

This comment has been minimized.

Copy link
Member

commented Jun 4, 2019

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

@zfields zfields added this to the 1.2.1 milestone Jun 4, 2019

@zfields zfields force-pushed the mnc2d branch from 44748c6 to 8c80389 Jun 4, 2019

@zfields zfields force-pushed the mnc2d branch from 8c80389 to fccbff6 Jun 4, 2019

@zfields zfields changed the base branch from develop to release/v1.2.1 Jun 4, 2019

@zfields zfields force-pushed the mnc2d branch from fccbff6 to 5c34025 Jun 4, 2019

@zfields zfields force-pushed the mnc2d branch from 5c34025 to e565d22 Jun 4, 2019

@@ -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);

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Jun 5, 2019

Member

Prefer typedef enum XXX {} XXX

This comment has been minimized.

Copy link
@zfields

zfields Jun 5, 2019

Author Contributor

done

@technobly technobly added the bug label Jun 5, 2019

zfields added 2 commits Jun 5, 2019

@zfields zfields merged commit 12d45eb into release/v1.2.1 Jun 6, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@zfields zfields deleted the mnc2d branch Jun 6, 2019

@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
Projects
None yet
3 participants
You can’t perform that action at this time.