-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Cellular: added setting of data carrier support for UART. #8971
Conversation
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.
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) |
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 don't think this is conditional on that - there are other possible implementations of enable_hup
. Could certainly work over USB serial.
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.
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); |
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.
Don't need the extra ()
- the static_cast
has its own built-in which seem clear enough to me.
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.
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) |
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.
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).
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.
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) |
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.
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?
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.
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) |
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.
Mustn't be conditional - see other comments.
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.
removed #ifdef
9a946aa
to
55246e3
Compare
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); |
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.
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.
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.
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); |
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'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!
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.
fixed
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.
No, I meant call AT_CellularContext::set_file_handle(FileHandle *)
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.
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()); |
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.
This line seems like daft magic. Surely set_is_filehandle_usable(true)
should know it needs to reset settings itself?
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.
true, fixed.
55246e3
to
587cc23
Compare
* @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, |
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.
This and the other declaration should also still have the = NULL
default on apn
I assume?
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.
Yep, added.
587cc23
to
7606d8a
Compare
@kjbracey-arm Mind doing a quick re-review? @ARMmbed/mbed-os-wan Thoughts? |
CI started |
Test run: FAILEDSummary: 3 of 7 test jobs failed Failed test jobs:
|
7606d8a
to
fa18876
Compare
Fixed ci build |
CI restarted (might take a while as the queue is filling up) |
Test run: FAILEDSummary: 1 of 1 test jobs failed Failed test jobs:
|
Unittest failed, related to the changes, please review |
fa18876
to
e4956ce
Compare
Fixed. |
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
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