Skip to content

Commit 7bcc63b

Browse files
authored
Merge pull request #2977 from andreaslarssonublox/ublox_drivers
Ublox drivers
2 parents a42457d + e2c6b8d commit 7bcc63b

36 files changed

+7452
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Unless specifically indicated otherwise in a file, files are licensed under the
2+
Permissive Binary License1.0 (PBL-1.0) as can be found in: LICENSE-permissive-binary-license-1.0.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Permissive Binary License
2+
3+
Version 1.0, September 2015
4+
5+
Redistribution. Redistribution and use in binary form, without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1) Redistributions must reproduce the above copyright notice and the
10+
following disclaimer in the documentation and/or other materials
11+
provided with the distribution.
12+
13+
2) Unless to the extent explicitly permitted by law, no reverse
14+
engineering, decompilation, or disassembly of this software is
15+
permitted.
16+
17+
3) Redistribution as part of a software development kit must include the
18+
accompanying file named “DEPENDENCIES” and any dependencies listed in
19+
that file.
20+
21+
4) Neither the name of the copyright holder nor the names of its
22+
contributors may be used to endorse or promote products derived from
23+
this software without specific prior written permission.
24+
25+
Limited patent license. The copyright holders (and contributors) grant a
26+
worldwide, non-exclusive, no-charge, royalty-free patent license to
27+
make, have made, use, offer to sell, sell, import, and otherwise
28+
transfer this software, where such license applies only to those patent
29+
claims licensable by the copyright holders (and contributors) that are
30+
necessarily infringed by this software. This patent license shall not
31+
apply to any combinations that include this software. No hardware is
32+
licensed hereunder.
33+
34+
If you institute patent litigation against any entity (including a
35+
cross-claim or counterclaim in a lawsuit) alleging that the software
36+
itself infringes your patent(s), then your rights granted under this
37+
license shall terminate as of the date such litigation is filed.
38+
39+
DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
40+
CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
41+
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
42+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
43+
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
45+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
46+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
47+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
48+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _ODIN_W2_MBEDTLS_CONFIG_H_
2+
#define _ODIN_W2_MBEDTLS_CONFIG_H_
3+
4+
#define MBEDTLS_ARC4_C
5+
#define MBEDTLS_DES_C
6+
#define MBEDTLS_MD4_C
7+
#define MBEDTLS_MD5_C
8+
#define MBEDTLS_SHA1_C
9+
10+
#endif /* _ODIN_W2_MBEDTLS_CONFIG_H_ */
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/* ODIN-W2 implementation of WiFiInterface
2+
* Copyright (c) 2016 u-blox Malmö AB
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef ODIN_WIFI_INTERFACE_H
18+
#define ODIN_WIFI_INTERFACE_H
19+
20+
#include "WiFiInterface.h"
21+
#include "Callback.h"
22+
#include "mbed_events.h"
23+
24+
#include "rtos.h"
25+
#include "emac_api.h"
26+
#include "nsapi_types.h"
27+
#include "lwip/netif.h"
28+
29+
typedef Queue<void*, 1> MsgQueue;
30+
31+
class OdinWiFiInterface;
32+
33+
struct PrivContext;
34+
35+
/** OdinWiFiInterface class
36+
* Implementation of the WiFiInterface for the ODIN-W2 module
37+
*/
38+
class OdinWiFiInterface : public WiFiInterface
39+
{
40+
public:
41+
/** OdinWiFiInterface lifetime
42+
*/
43+
OdinWiFiInterface();
44+
45+
OdinWiFiInterface(bool debug);
46+
47+
~OdinWiFiInterface();
48+
49+
/** Set the WiFi network credentials
50+
*
51+
* @param ssid Name of the network to connect to
52+
* @param pass Security passphrase to connect to the network
53+
* @param security Type of encryption for connection
54+
* (defaults to NSAPI_SECURITY_NONE)
55+
* @return 0 on success, or error code on failure
56+
*/
57+
virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
58+
59+
/** Set the WiFi network channel
60+
*
61+
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
62+
* @return 0 on success, or error code on failure
63+
*/
64+
virtual int set_channel(uint8_t channel);
65+
66+
/** Start the interface
67+
*
68+
* Attempts to connect to a WiFi network.
69+
*
70+
* @param ssid Name of the network to connect to
71+
* @param pass Security passphrase to connect to the network
72+
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
73+
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
74+
* @return 0 on success, or error code on failure
75+
*/
76+
virtual int connect(const char *ssid,
77+
const char *pass,
78+
nsapi_security_t security = NSAPI_SECURITY_NONE,
79+
uint8_t channel = 0);
80+
81+
/** Start the interface
82+
*
83+
* Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
84+
* If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
85+
*
86+
* @return 0 on success, negative error code on failure
87+
*/
88+
virtual int connect();
89+
90+
/** Stop the interface
91+
*
92+
* @return 0 on success, or error code on failure
93+
*/
94+
virtual int disconnect();
95+
96+
/** Get the local MAC address
97+
*
98+
* Provided MAC address is intended for info or debug purposes and
99+
* may not be provided if the underlying network interface does not
100+
* provide a MAC address
101+
*
102+
* @return Null-terminated representation of the local MAC address
103+
* or null if no MAC address is available
104+
*/
105+
virtual const char *get_mac_address();
106+
107+
/** Get the local IP address
108+
*
109+
* @return Null-terminated representation of the local IP address
110+
* or null if no IP address has been recieved
111+
*/
112+
virtual const char *get_ip_address();
113+
114+
/** Get the local network mask
115+
*
116+
* @return Null-terminated representation of the local network mask
117+
* or null if no network mask has been recieved
118+
*/
119+
virtual const char *get_netmask();
120+
121+
/** Get the local gateway
122+
*
123+
* @return Null-terminated representation of the local gateway
124+
* or null if no network mask has been recieved
125+
*/
126+
virtual const char *get_gateway();
127+
128+
/** Set a static IP address
129+
*
130+
* Configures this network interface to use a static IP address.
131+
* Implicitly disables DHCP, which can be enabled in set_dhcp.
132+
* Requires that the network is disconnected.
133+
*
134+
* @param address Null-terminated representation of the local IP address
135+
* @param netmask Null-terminated representation of the local network mask
136+
* @param gateway Null-terminated representation of the local gateway
137+
* @return 0 on success, negative error code on failure
138+
*/
139+
virtual int set_network(const char *ip_address, const char *netmask, const char *gateway);
140+
141+
/** Enable or disable DHCP on the network
142+
*
143+
* Enables DHCP on connecting the network. Defaults to enabled unless
144+
* a static IP address has been assigned. Requires that the network is
145+
* disconnected.
146+
*
147+
* @param dhcp True to enable DHCP
148+
* @return 0 on success, negative error code on failure
149+
*/
150+
virtual int set_dhcp(bool dhcp);
151+
152+
/** Gets the current radio signal strength for active connection
153+
*
154+
* @return Connection strength in dBm (negative value),
155+
* or 0 if measurement impossible
156+
*/
157+
virtual int8_t get_rssi();
158+
159+
/** Scan for available networks
160+
*
161+
* If the network interface is set to non-blocking mode, scan will attempt to scan
162+
* for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback
163+
* is attached, the callback will be called when the operation has completed.
164+
*
165+
* @param ap Pointer to allocated array to store discovered AP
166+
* @param count Size of allocated @a res array, or 0 to only count available AP
167+
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
168+
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
169+
* see @a nsapi_error
170+
*/
171+
virtual int scan(WiFiAccessPoint *res, unsigned count);
172+
173+
/** Sets timeout for connection setup. Note that the time for DHCP retrieval is not included.
174+
*
175+
* @param timeout Timeout in ms. Use 0 for waiting forever. The timeout might take up to X sec longer than
176+
* specified since the Wi-Fi driver might need some time to finish and cleanup.
177+
* @return 0 on success, negative error code on failure
178+
*/
179+
virtual void set_timeout(int timeout);
180+
181+
virtual NetworkStack *get_stack();
182+
183+
protected:
184+
185+
private:
186+
187+
int connect_async(const char *ssid,
188+
const char *pass,
189+
nsapi_security_t security = NSAPI_SECURITY_NONE,
190+
uint8_t channel = 0,
191+
void *data = NULL,
192+
unsigned timeout = 0);
193+
194+
bool start(bool debug);
195+
bool stop();
196+
197+
char _mac_addr_str[18];
198+
// Private context to share between C and C++ calls
199+
PrivContext* _priv_context;
200+
const char *_ssid;
201+
const char *_pass;
202+
char _ip_address[IPADDR_STRLEN_MAX];
203+
char _netmask[IPADDR_STRLEN_MAX];
204+
char _gateway[IPADDR_STRLEN_MAX];
205+
nsapi_security_t _security;
206+
uint8_t _channel;
207+
bool _use_dhcp;
208+
int _timeout;
209+
// Event queue when the driver context need to be used
210+
EventQueue* _odin_event_queue;
211+
int32_t target_id;
212+
// Event queue for sending start up and connection events from driver to this class
213+
MsgQueue _event_queue;
214+
// Event queue for sending scan events from driver to this class
215+
MsgQueue _scan_event_queue;
216+
};
217+
218+
#endif

0 commit comments

Comments
 (0)