-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,11 +59,13 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co | |
_cid = -1; | ||
_new_context_set = false; | ||
_next = NULL; | ||
_dcd_pin = NC; | ||
_active_high = false; | ||
} | ||
|
||
AT_CellularContext::~AT_CellularContext() | ||
{ | ||
tr_info("Delete CellularContext %s (%p)", _apn ? _apn : "", this); | ||
tr_info("Delete CellularContext with apn: [%s] (%p)", _apn ? _apn : "", this); | ||
|
||
(void)disconnect(); | ||
|
||
|
@@ -79,6 +81,23 @@ void AT_CellularContext::set_file_handle(FileHandle *fh) | |
_at.set_file_handle(_fh); | ||
} | ||
|
||
void AT_CellularContext::set_file_handle(UARTSerial *serial, PinName dcd_pin, bool active_high) | ||
{ | ||
tr_info("CellularContext serial %p", serial); | ||
_dcd_pin = dcd_pin; | ||
_active_high = active_high; | ||
_fh = serial; | ||
_at.set_file_handle(static_cast<FileHandle *>(serial)); | ||
enable_hup(false); | ||
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. I'd be inclined to call 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. No, I meant call 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. Do'h, I need to sleep more :) Fixed. |
||
} | ||
|
||
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); | ||
} | ||
} | ||
|
||
nsapi_error_t AT_CellularContext::connect() | ||
{ | ||
tr_info("CellularContext connect"); | ||
|
@@ -592,18 +611,25 @@ nsapi_error_t AT_CellularContext::open_data_channel() | |
} | ||
|
||
_at.set_is_filehandle_usable(false); | ||
|
||
enable_hup(true); | ||
/* Initialize PPP | ||
* If blocking: mbed_ppp_init() is a blocking call, it will block until | ||
connected, or timeout after 30 seconds*/ | ||
return nsapi_ppp_connect(_at.get_file_handle(), callback(this, &AT_CellularContext::ppp_status_cb), _uname, _pwd, _ip_stack_type); | ||
nsapi_error_t err = nsapi_ppp_connect(_at.get_file_handle(), callback(this, &AT_CellularContext::ppp_status_cb), _uname, _pwd, _ip_stack_type); | ||
if (err) { | ||
ppp_disconnected(); | ||
} | ||
|
||
return err; | ||
} | ||
|
||
void AT_CellularContext::ppp_status_cb(nsapi_event_t ev, intptr_t ptr) | ||
{ | ||
tr_debug("ppp_status_cb: event %d, ptr %d", ev, ptr); | ||
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) { | ||
_is_connected = true; | ||
} else if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) { | ||
ppp_disconnected(); | ||
} else { | ||
_is_connected = false; | ||
} | ||
|
@@ -614,6 +640,20 @@ void AT_CellularContext::ppp_status_cb(nsapi_event_t ev, intptr_t ptr) | |
_device->cellular_callback(ev, ptr); | ||
} | ||
|
||
void AT_CellularContext::ppp_disconnected() | ||
{ | ||
enable_hup(false); | ||
|
||
// 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_is_filehandle_usable(true); | ||
if (!_at.sync(AT_SYNC_TIMEOUT)) { // consume extra characters after ppp disconnect, also it may take a while until modem listens AT commands | ||
tr_error("AT sync failed after PPP Disconnect"); | ||
} | ||
_at.unlock(); | ||
} | ||
|
||
#endif //#if NSAPI_PPP_AVAILABLE | ||
|
||
nsapi_error_t AT_CellularContext::disconnect() | ||
|
@@ -628,15 +668,7 @@ nsapi_error_t AT_CellularContext::disconnect() | |
tr_error("CellularContext disconnect failed!"); | ||
// continue even in failure due to ppp disconnect in any case releases filehandle | ||
} | ||
// 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()); | ||
_at.set_is_filehandle_usable(true); | ||
if (!_at.sync(AT_SYNC_TIMEOUT)) { // consume extra characters after ppp disconnect, also it may take a while until modem listens AT commands | ||
tr_error("AT sync failed after PPP Disconnect"); | ||
} | ||
_at.unlock(); | ||
ppp_disconnected(); | ||
#endif // NSAPI_PPP_AVAILABLE | ||
_at.lock(); | ||
|
||
|
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 onapn
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.