Cellular: Refactor cellular variable visibilities

- Earlier some variables were public even though used only internally
- Also refactored variables to the end of class definitions
- Removed duplicate _property_array from CellularDevice
- Changed _impl methods as protected
pull/12123/head
Kimmo Vaisanen 2019-12-17 13:36:43 +02:00
parent 5f495db06b
commit f7cc3db70b
12 changed files with 58 additions and 71 deletions

View File

@ -42,7 +42,7 @@ CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0),
_sms_ref_count(0), _sms_ref_count(0),
#endif //MBED_CONF_CELLULAR_USE_SMS #endif //MBED_CONF_CELLULAR_USE_SMS
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0), _info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0),
_nw(0), _status_cb(0), _property_array(0) _nw(0), _status_cb(0)
{ {
} }

View File

@ -161,7 +161,6 @@ public: // from NetworkInterface
*/ */
static CellularContext *get_default_instance(); static CellularContext *get_default_instance();
/** Instantiates a default Non-IP cellular interface /** Instantiates a default Non-IP cellular interface
* *
* This function creates a new Non-IP PDP context. * This function creates a new Non-IP PDP context.

View File

@ -485,9 +485,7 @@ protected: //Common functions
private: //Common functions private: //Common functions
nsapi_error_t start_state_machine(CellularStateMachine::CellularState target_state); nsapi_error_t start_state_machine(CellularStateMachine::CellularState target_state);
nsapi_error_t create_state_machine(); nsapi_error_t create_state_machine();
void stm_callback(nsapi_event_t ev, intptr_t ptr); void stm_callback(nsapi_event_t ev, intptr_t ptr);
protected: //Member variables protected: //Member variables
@ -499,15 +497,13 @@ protected: //Member variables
FileHandle *_fh; FileHandle *_fh;
events::EventQueue _queue; events::EventQueue _queue;
CellularStateMachine *_state_machine; CellularStateMachine *_state_machine;
Callback<void(nsapi_event_t, intptr_t)> _status_cb;
private: //Member variables private: //Member variables
CellularNetwork *_nw; CellularNetwork *_nw;
char _sim_pin[MAX_PIN_SIZE + 1]; char _sim_pin[MAX_PIN_SIZE + 1];
char _plmn[MAX_PLMN_SIZE + 1]; char _plmn[MAX_PLMN_SIZE + 1];
PlatformMutex _mutex; PlatformMutex _mutex;
Callback<void(nsapi_event_t, intptr_t)> _status_cb;
const intptr_t *_property_array;
}; };
/** /**

View File

@ -56,8 +56,8 @@ protected:
* virtual Destructor * virtual Destructor
*/ */
virtual ~CellularSMS() {}; virtual ~CellularSMS() {};
public:
public:
/* Enumeration for possible SMS modes, PDU and Text */ /* Enumeration for possible SMS modes, PDU and Text */
enum CellularSMSMmode { enum CellularSMSMmode {
CellularSMSMmodePDU = 0, CellularSMSMmodePDU = 0,

View File

@ -73,6 +73,7 @@ public:
AT_CellularDevice *get_device() const; AT_CellularDevice *get_device() const;
ATHandler &get_at_handler(); ATHandler &get_at_handler();
protected: protected:
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr); virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr);
@ -107,6 +108,7 @@ protected:
virtual bool get_context(); virtual bool get_context();
AT_CellularDevice::CellularProperty pdp_type_t_to_cellular_property(pdp_type_t pdp_type); AT_CellularDevice::CellularProperty pdp_type_t_to_cellular_property(pdp_type_t pdp_type);
bool set_new_context(int cid); bool set_new_context(int cid);
private: private:
#if NSAPI_PPP_AVAILABLE #if NSAPI_PPP_AVAILABLE
nsapi_error_t open_data_channel(); nsapi_error_t open_data_channel();
@ -124,6 +126,7 @@ private:
virtual void do_connect_with_retry(); virtual void do_connect_with_retry();
void do_disconnect(); void do_disconnect();
void set_cid(int cid); void set_cid(int cid);
private: private:
ContextOperation _current_op; ContextOperation _current_op;
FileHandle *_fh; FileHandle *_fh;
@ -135,8 +138,6 @@ protected:
// flag indicating if CP was requested to be setup // flag indicating if CP was requested to be setup
bool _cp_req; bool _cp_req;
bool _is_connected; bool _is_connected;
protected:
ATHandler &_at; ATHandler &_at;
}; };

View File

@ -123,6 +123,30 @@ public:
*/ */
virtual nsapi_error_t release_at_handler(ATHandler *at_handler); virtual nsapi_error_t release_at_handler(ATHandler *at_handler);
virtual CellularContext *get_context_list() const;
virtual nsapi_error_t set_baud_rate(int baud_rate);
#if MBED_CONF_CELLULAR_USE_SMS
virtual CellularSMS *open_sms(FileHandle *fh = NULL);
virtual void close_sms();
#endif
/** Get value for the given key.
*
* @param key key for value to be fetched
* @return property value for the given key. Value type is defined in enum CellularProperty
*/
intptr_t get_property(CellularProperty key);
/** Cellular module need to define an array of cellular properties which defines module supported property values.
*
* @param property_array array of module properties
*/
void set_cellular_properties(const intptr_t *property_array);
protected:
/** Creates new instance of AT_CellularContext or if overridden, modem specific implementation. /** Creates new instance of AT_CellularContext or if overridden, modem specific implementation.
* *
* @param at ATHandler reference for communication with the modem. * @param at ATHandler reference for communication with the modem.
@ -148,50 +172,15 @@ public:
*/ */
virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual AT_CellularInformation *open_information_impl(ATHandler &at);
virtual CellularContext *get_context_list() const;
virtual nsapi_error_t set_baud_rate(int baud_rate);
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS
virtual CellularSMS *open_sms(FileHandle *fh = NULL);
virtual void close_sms();
/** Create new instance of AT_CellularSMS or if overridden, modem specific implementation. /** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
* *
* @param at ATHandler reference for communication with the modem. * @param at ATHandler reference for communication with the modem.
* @return new instance of class AT_CellularSMS * @return new instance of class AT_CellularSMS
*/ */
virtual AT_CellularSMS *open_sms_impl(ATHandler &at); virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
AT_CellularSMS *_sms;
#endif // MBED_CONF_CELLULAR_USE_SMS #endif // MBED_CONF_CELLULAR_USE_SMS
public:
/** Get value for the given key.
*
* @param key key for value to be fetched
* @return property value for the given key. Value type is defined in enum CellularProperty
*/
intptr_t get_property(CellularProperty key);
/** Cellular module need to define an array of cellular properties which defines module supported property values.
*
* @param property_array array of module properties
*/
void set_cellular_properties(const intptr_t *property_array);
public: //Member variables
AT_CellularNetwork *_network;
AT_CellularInformation *_information;
AT_CellularContext *_context_list;
int _default_timeout;
bool _modem_debug_on;
ATHandler *_at;
protected:
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL); virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
void send_disconnect_to_context(int cid); void send_disconnect_to_context(int cid);
// Sets commonly used URCs // Sets commonly used URCs
@ -207,7 +196,20 @@ private:
void urc_nw_deact(); void urc_nw_deact();
void urc_pdn_deact(); void urc_pdn_deact();
protected:
ATHandler *_at;
private: private:
#if MBED_CONF_CELLULAR_USE_SMS
AT_CellularSMS *_sms;
#endif // MBED_CONF_CELLULAR_USE_SMS
AT_CellularNetwork *_network;
AT_CellularInformation *_information;
AT_CellularContext *_context_list;
int _default_timeout;
bool _modem_debug_on;
const intptr_t *_property_array; const intptr_t *_property_array;
}; };

View File

@ -49,6 +49,7 @@ public:
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
ATHandler &get_at_handler(); ATHandler &get_at_handler();
protected: protected:
/** Request information text from cellular device /** Request information text from cellular device
* *
@ -61,7 +62,6 @@ protected:
protected: protected:
ATHandler &_at; ATHandler &_at;
AT_CellularDevice &_device; AT_CellularDevice &_device;
}; };

View File

@ -36,7 +36,6 @@ namespace mbed {
* Class for attaching to a network and getting information from it. * Class for attaching to a network and getting information from it.
*/ */
class AT_CellularNetwork : public CellularNetwork { class AT_CellularNetwork : public CellularNetwork {
public: public:
AT_CellularNetwork(ATHandler &atHandler, AT_CellularDevice &device); AT_CellularNetwork(ATHandler &atHandler, AT_CellularDevice &device);
@ -101,7 +100,6 @@ public:
ATHandler &get_at_handler(); ATHandler &get_at_handler();
protected: protected:
/** Sets access technology to be scanned. Modem specific implementation. /** Sets access technology to be scanned. Modem specific implementation.
* *
* @param op_rat Access technology * @param op_rat Access technology
@ -140,7 +138,6 @@ private:
void call_network_cb(nsapi_connection_status_t status); void call_network_cb(nsapi_connection_status_t status);
protected: protected:
Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
Callback<void(CIoT_Supported_Opt)> _ciotopt_network_support_cb; Callback<void(CIoT_Supported_Opt)> _ciotopt_network_support_cb;
RadioAccessTechnology _op_act; RadioAccessTechnology _op_act;
@ -150,9 +147,7 @@ protected:
registration_params_t _reg_params; registration_params_t _reg_params;
mbed::Callback<void()> _urc_funcs[C_MAX]; mbed::Callback<void()> _urc_funcs[C_MAX];
protected:
ATHandler &_at; ATHandler &_at;
AT_CellularDevice &_device; AT_CellularDevice &_device;
}; };

View File

@ -66,7 +66,6 @@ public:
ATHandler &get_at_handler(); ATHandler &get_at_handler();
private: private:
struct sms_info_t { struct sms_info_t {
char date[SMS_MAX_TIME_STAMP_SIZE]; char date[SMS_MAX_TIME_STAMP_SIZE];
uint16_t msg_index[50]; // can hold up to 50 concatenated msg parts, indexes are in correct order. So max sms size is 50*140 = 7kb uint16_t msg_index[50]; // can hold up to 50 concatenated msg parts, indexes are in correct order. So max sms size is 50*140 = 7kb
@ -78,14 +77,6 @@ private:
sms_info_t() : msg_size(0), parts(1), parts_added(1), msg_ref_number(0), next_info(0) {}; sms_info_t() : msg_size(0), parts(1), parts_added(1), msg_ref_number(0), next_info(0) {};
}; };
// application callback function for received sms
Callback<void()> _cb;
CellularSMSMmode _mode;
bool _use_8bit_encoding;
uint32_t _sim_wait_time;
uint16_t _sms_message_ref_number;
sms_info_t *_sms_info;
// SMS urc's // SMS urc's
void cmt_urc(); void cmt_urc();
void cmti_urc(); void cmti_urc();
@ -171,8 +162,15 @@ private:
int msg_len); int msg_len);
private: private:
ATHandler &_at; // application callback function for received sms
Callback<void()> _cb;
CellularSMSMmode _mode;
bool _use_8bit_encoding;
uint32_t _sim_wait_time;
uint16_t _sms_message_ref_number;
sms_info_t *_sms_info;
ATHandler &_at;
AT_CellularDevice &_device; AT_CellularDevice &_device;
}; };

View File

@ -99,7 +99,6 @@ protected: // NetworkStack
virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data); virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data);
protected: protected:
class CellularSocket { class CellularSocket {
public: public:
CellularSocket() : CellularSocket() :
@ -188,6 +187,7 @@ protected:
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
void *buffer, nsapi_size_t size) = 0; void *buffer, nsapi_size_t size) = 0;
protected:
/** /**
* Find the socket handle based on the index of the socket construct * Find the socket handle based on the index of the socket construct
* in the socket container. Please note that this index may or may not be * in the socket container. Please note that this index may or may not be
@ -211,6 +211,10 @@ protected:
*/ */
bool is_addr_stack_compatible(const SocketAddress &addr); bool is_addr_stack_compatible(const SocketAddress &addr);
private:
int get_socket_index_by_port(uint16_t port);
protected:
// socket container // socket container
CellularSocket **_socket; CellularSocket **_socket;
@ -229,16 +233,10 @@ protected:
// IP version of send to address // IP version of send to address
nsapi_version_t _ip_ver_sendto; nsapi_version_t _ip_ver_sendto;
private:
int get_socket_index_by_port(uint16_t port);
protected:
// mutex for write/read to a _socket array, needed when multiple threads may use sockets simultaneously // mutex for write/read to a _socket array, needed when multiple threads may use sockets simultaneously
PlatformMutex _socket_mutex; PlatformMutex _socket_mutex;
ATHandler &_at; ATHandler &_at;
AT_CellularDevice &_device; AT_CellularDevice &_device;
}; };

View File

@ -9,7 +9,6 @@ public:
virtual ~AT_ControlPlane_netif(); virtual ~AT_ControlPlane_netif();
protected: protected:
// ControlPlane_netif // ControlPlane_netif
/* Sends data using +CSODCP specified in /* Sends data using +CSODCP specified in
@ -17,7 +16,6 @@ protected:
*/ */
virtual nsapi_size_or_error_t send(const void *cpdata, nsapi_size_t cpdata_length); virtual nsapi_size_or_error_t send(const void *cpdata, nsapi_size_t cpdata_length);
/* Receives data using +CRTDCP specified in /* Receives data using +CRTDCP specified in
* 3GPP 27007 10.1.44: Reporting of terminating data via the control plane * 3GPP 27007 10.1.44: Reporting of terminating data via the control plane
*/ */

View File

@ -38,7 +38,7 @@ CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0),
_sms_ref_count(0), _sms_ref_count(0),
#endif //MBED_CONF_CELLULAR_USE_SMS #endif //MBED_CONF_CELLULAR_USE_SMS
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0), _info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0),
_nw(0), _status_cb(0), _property_array(0) _status_cb(0), _nw(0)
{ {
MBED_ASSERT(fh); MBED_ASSERT(fh);
set_sim_pin(NULL); set_sim_pin(NULL);