Skip to content

Cellular: added setting of data carrier support for UART. #8971

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

Merged

Conversation

jarvte
Copy link
Contributor

@jarvte jarvte commented Dec 5, 2018

Description

In case when UART is used to communicate to modem we should use data carrier detect to detect disconnect faster when in PPP mode. This PR fixes that missing feature,

@AriParkkila @mirelachirica please review

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[X] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

@0xc0170 0xc0170 requested review from kjbracey and a team December 5, 2018 08:54
Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

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

Feels a bit weird putting Serial-specific knowledge into this generic class, but okay with it as long as it's done right and still works for other FileHandle types. So some notes on that.

@@ -614,6 +644,22 @@ void AT_CellularContext::ppp_status_cb(nsapi_event_t ev, intptr_t ptr)
_device->cellular_callback(ev, ptr);
}

void AT_CellularContext::ppp_disconnected()
{
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is conditional on that - there are other possible implementations of enable_hup. Could certainly work over USB serial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed #ifdef

void AT_CellularContext::enable_hup(bool enable)
{
if (_dcd_pin != NC) {
(static_cast<UARTSerial *>(_fh))->set_data_carrier_detect(enable ? _dcd_pin : NC, _active_high);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need the extra () - the static_cast has its own built-in which seem clear enough to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@@ -230,6 +239,17 @@ class CellularContext : public CellularBase {
*/
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr) = 0;

#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN && NSAPI_PPP_AVAILABLE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure whether enable_hup really needs to be conditional on PPP, but it certainly isn't conditional on UARTSerial, as an abstract API. I'd simplify by making this unconditional.

If it is conditional in any way, you should at least provide a dummy method in the #else so callers don't all need ifdef.

(Callers definitely shouldn't have ifdef, because maybe someone has inherited from AT_CellularDevice and provided an alternate enable_hup for a totally alien FileHandle).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed #ifdef

@@ -70,6 +70,22 @@ class CellularDevice {
*
*/
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) = 0;
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN && NSAPI_PPP_AVAILABLE)
Copy link
Contributor

Choose a reason for hiding this comment

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

This does need to be conditional on serial+interrupt_in, because it takes UARTSerial, but again doesn't necessarily need to be conditional on PPP. Wouldn't do any harm for an app to call this one, if it knew it was using UARTSerial, but wasn't committed about PPP or not.

Why are the apn and serial parameters reversed? Overload issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed #ifdef. _Yes overload when calling internally to avoid copy-paste.

@@ -592,18 +613,27 @@ nsapi_error_t AT_CellularContext::open_data_channel()
}

_at.set_is_filehandle_usable(false);

#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN)
Copy link
Contributor

Choose a reason for hiding this comment

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

Mustn't be conditional - see other comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed #ifdef

@jarvte jarvte force-pushed the add_datacarrier_detect branch 2 times, most recently from 9a946aa to 55246e3 Compare December 10, 2018 08:15
CellularContext *AT_CellularDevice::create_context(const char *const apn, UARTSerial *serial, PinName dcd_pin,
bool active_high)
{
AT_CellularContext *ctx = (AT_CellularContext *)create_context(serial, apn);
Copy link
Contributor

Choose a reason for hiding this comment

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

If there was an overload problem on this call, then rather than reverse the parameters, you could do

// Call FileHandle base version - explict upcast to avoid recursing into ourselves
create_context(static_cast<FileHandle *>(serial), apn);

Bit ugly, but I'd rather have an ugly internal than a weird inconsistent public API.

I note that create_context should really return AT_CellularContext -when overriding, a derived class is allowed to return a more-specific derived pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, that's a better way, did not think of that.

_active_high = active_high;
_fh = serial;
_at.set_file_handle(_fh);
enable_hup(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be inclined to call set_file_handle(static_cast<FileHandle *>(serial)) here too for consistency of logic with the create_context, even though it doesn't really save anything.

And hey, if you do that explicit upcast in two places it becomes a recognisable pattern!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I meant call AT_CellularContext::set_file_handle(FileHandle *)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do'h, I need to sleep more :) Fixed.

// after ppp disconnect if we wan't to use same at handler we need to set filehandle again to athandler so it
// will set the correct sigio and nonblocking
_at.lock();
_at.set_file_handle(_at.get_file_handle());
Copy link
Contributor

Choose a reason for hiding this comment

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

This line seems like daft magic. Surely set_is_filehandle_usable(true) should know it needs to reset settings itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, fixed.

@jarvte jarvte force-pushed the add_datacarrier_detect branch from 55246e3 to 587cc23 Compare December 10, 2018 12:17
* @return new instance of class CellularContext or NULL in case of failure
*
*/
virtual CellularContext *create_context(UARTSerial *serial, const char *apn, PinName dcd_pin = NC,
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the other declaration should also still have the = NULL default on apn I assume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, added.

@cmonr
Copy link
Contributor

cmonr commented Dec 12, 2018

@kjbracey-arm Mind doing a quick re-review?

@ARMmbed/mbed-os-wan Thoughts?

@cmonr
Copy link
Contributor

cmonr commented Dec 17, 2018

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 17, 2018

Test run: FAILED

Summary: 3 of 7 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-IAR

@jarvte jarvte force-pushed the add_datacarrier_detect branch from 7606d8a to fa18876 Compare December 18, 2018 05:58
@jarvte
Copy link
Contributor Author

jarvte commented Dec 18, 2018

Fixed ci build

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 18, 2018

CI restarted (might take a while as the queue is filling up)

@mbed-ci
Copy link

mbed-ci commented Dec 18, 2018

Test run: FAILED

Summary: 1 of 1 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_unittests

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 18, 2018

Unittest failed, related to the changes, please review

@jarvte jarvte force-pushed the add_datacarrier_detect branch from fa18876 to e4956ce Compare December 18, 2018 12:51
@jarvte
Copy link
Contributor Author

jarvte commented Dec 18, 2018

Unittest failed, related to the changes, please review

Fixed.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 18, 2018

CI restarted

@mbed-ci
Copy link

mbed-ci commented Dec 18, 2018

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 3
Build artifacts

@0xc0170 0xc0170 merged commit a7f4388 into ARMmbed:feature-cellular-refactor Dec 19, 2018
@jarvte jarvte deleted the add_datacarrier_detect branch December 19, 2018 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants