19
19
#include " QUECTEL/BG96/QUECTEL_BG96_CellularNetwork.h"
20
20
#include " QUECTEL/BG96/QUECTEL_BG96_CellularStack.h"
21
21
22
+ #include " CellularUtil.h"
23
+ #include " UARTSerial.h"
24
+ #include " CellularLog.h"
25
+
22
26
using namespace mbed ;
23
27
using namespace events ;
24
28
@@ -56,3 +60,50 @@ CellularNetwork *QUECTEL_BG96::open_network(FileHandle *fh)
56
60
}
57
61
return _network;
58
62
}
63
+
64
+ nsapi_error_t QUECTEL_BG96::init_module (FileHandle *fh) {
65
+ ATHandler *atHandler = get_at_handler (fh);
66
+ if (atHandler) {
67
+ bool didAccessAt = false ;
68
+ // enable flow control if required
69
+ #if defined (MDMRTS) && defined (MDMCTS)
70
+ if (!didAccessAt) atHandler->lock ();
71
+ didAccessAt = true ;
72
+
73
+ atHandler->cmd_start (" AT+IFC=2,2" );
74
+ atHandler->cmd_stop ();
75
+ atHandler->resp_start ();
76
+ atHandler->resp_stop ();
77
+ if (atHandler->get_last_error () == NSAPI_ERROR_OK) {
78
+ tr_info (" Cellular device - enabled flow control." );
79
+ } else {
80
+ tr_warn (" Cellular device - failed to enable flow control." );
81
+ }
82
+ #endif
83
+
84
+ // set target baud rate
85
+ #if defined(MDM_TARGET_BAUD_RATE)
86
+ if (!didAccessAt) atHandler->lock ();
87
+ didAccessAt = true ;
88
+
89
+ atHandler->cmd_start (" AT+IPR=" CELLULAR_STRINGIFY (MDM_TARGET_BAUD_RATE));
90
+ atHandler->cmd_stop ();
91
+ atHandler->resp_start ();
92
+ atHandler->resp_stop ();
93
+ if (atHandler->get_last_error () == NSAPI_ERROR_OK) {
94
+ // update uart baud rate
95
+ ((UARTSerial*)atHandler->get_file_handle ())->set_baud (MDM_TARGET_BAUD_RATE);
96
+
97
+ tr_info (" Cellular device - set baud rate (" CELLULAR_STRINGIFY (MDM_TARGET_BAUD_RATE) " )." );
98
+ } else {
99
+ tr_warn (" Cellular device - failed to set baud rate (" CELLULAR_STRINGIFY (MDM_TARGET_BAUD_RATE) " )." );
100
+ }
101
+ #endif
102
+
103
+ if (didAccessAt) {
104
+ return atHandler->unlock_return_error ();
105
+ }
106
+ }
107
+
108
+ return NSAPI_ERROR_OK;
109
+ }
0 commit comments