Skip to content

Commit 1eab072

Browse files
authored
Merge pull request #7745 from OPpuolitaival/icetea
Icetea support
2 parents 90ede7a + 6609faa commit 1eab072

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5689
-66
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,9 @@ tags
8888
.vscode/
8989

9090
features/FEATURE_BLE/targets/TARGET_CORDIO/stack_backup/
91+
92+
.pytest_cache
93+
log
94+
95+
# Icetea related file
96+
test_suite.json

TEST_APPS/__init__.py

Whitespace-only changes.

TEST_APPS/device/exampleapp/main.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2018 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* 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, WITHOUT
12+
* 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+
#include <stdio.h>
17+
#include <stdarg.h>
18+
#include "mbed.h"
19+
#include "mbed-client-cli/ns_cmdline.h"
20+
21+
#ifndef ICETEA_EXAMPLE_ENABLED
22+
#error [NOT_SUPPORTED] Skipping example application.
23+
#endif
24+
/**
25+
* Macros for setting console flow control.
26+
*/
27+
#define CONSOLE_FLOWCONTROL_RTS 1
28+
#define CONSOLE_FLOWCONTROL_CTS 2
29+
#define CONSOLE_FLOWCONTROL_RTSCTS 3
30+
#define mbed_console_concat_(x) CONSOLE_FLOWCONTROL_##x
31+
#define mbed_console_concat(x) mbed_console_concat_(x)
32+
#define CONSOLE_FLOWCONTROL mbed_console_concat(MBED_CONF_TARGET_CONSOLE_UART_FLOW_CONTROL)
33+
34+
#define SERIAL_CONSOLE_BAUD_RATE 115200
35+
36+
void cmd_ready_cb(int retcode)
37+
{
38+
cmd_next(retcode);
39+
}
40+
41+
void wrap_printf(const char *f, va_list a)
42+
{
43+
vprintf(f, a);
44+
}
45+
46+
int main()
47+
{
48+
cmd_init(&wrap_printf);
49+
50+
int c;
51+
while ((c = getchar()) != EOF) {
52+
cmd_char_input(c);
53+
}
54+
return 0;
55+
}
56+
57+
FileHandle *mbed::mbed_override_console(int)
58+
{
59+
static UARTSerial console(STDIO_UART_TX, STDIO_UART_RX, SERIAL_CONSOLE_BAUD_RATE);
60+
#if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS
61+
console.set_flow_control(SerialBase::RTS, STDIO_UART_RTS, NC);
62+
#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS
63+
console.set_flow_control(SerialBase::CTS, NC, STDIO_UART_CTS);
64+
#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS
65+
console.set_flow_control(SerialBase::RTSCTS, STDIO_UART_RTS, STDIO_UART_CTS);
66+
#endif
67+
return &console;
68+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright (c) 2018 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* 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, WITHOUT
12+
* 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+
#include "NetworkStack.h"
17+
#include "NetworkInterface.h"
18+
19+
#include "mbed-client-cli/ns_cmdline.h"
20+
#include "mbed-trace/mbed_trace.h"
21+
22+
#include "ip4string.h"
23+
24+
#define WIFI 2
25+
#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \
26+
(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID))
27+
#error [NOT_SUPPORTED] No network configuration found for this target.
28+
#endif
29+
30+
#include <string.h>
31+
32+
#define TRACE_GROUP "Aifc"
33+
34+
NetworkInterface *net;
35+
36+
NetworkInterface *get_interface(void)
37+
{
38+
return net;
39+
}
40+
41+
int cmd_ifup(int argc, char *argv[]);
42+
int cmd_ifdown(int argc, char *argv[]);
43+
int cmd_ifconfig(int argc, char *argv[]);
44+
45+
const char *MAN_IFCONFIG = " ifup interface up\r\n"\
46+
" ifdown interface down\r\n";
47+
48+
static void ifconfig_print()
49+
{
50+
if (!net) {
51+
cmd_printf("No interface configured\r\n");
52+
return;
53+
}
54+
const char *str = net->get_ip_address();
55+
if (str) {
56+
uint8_t buf[4];
57+
if (stoip4(str, strlen(str), buf)) {
58+
cmd_printf("IPv4 if addr: %s\r\n", str);
59+
} else {
60+
cmd_printf("IPv6 if addr:\r\n [0]: %s\r\n", str);
61+
}
62+
} else {
63+
cmd_printf("No IP address\r\n");
64+
}
65+
str = net->get_mac_address();
66+
if (str) {
67+
cmd_printf("MAC-48: %s\r\n", str);
68+
} else {
69+
cmd_printf("MAC-48: unknown\r\n");
70+
}
71+
}
72+
73+
74+
void cmd_ifconfig_init(void)
75+
{
76+
cmd_add("ifup", cmd_ifup, "ifconfig up", MAN_IFCONFIG);
77+
cmd_add("ifdown", cmd_ifdown, "ifconfig down", MAN_IFCONFIG);
78+
cmd_add("ifconfig", cmd_ifconfig, "ifconfig", MAN_IFCONFIG);
79+
}
80+
81+
int cmd_ifconfig(int argc, char *argv[])
82+
{
83+
ifconfig_print();
84+
return CMDLINE_RETCODE_SUCCESS;
85+
}
86+
87+
int cmd_ifup(int argc, char *argv[])
88+
{
89+
if (!net) {
90+
net = NetworkInterface::get_default_instance();
91+
}
92+
int err = net->connect();
93+
if (err != NSAPI_ERROR_OK) {
94+
return CMDLINE_RETCODE_FAIL;
95+
}
96+
97+
ifconfig_print();
98+
return CMDLINE_RETCODE_SUCCESS;
99+
}
100+
101+
int cmd_ifdown(int argc, char *argv[])
102+
{
103+
if (!net) {
104+
return CMDLINE_RETCODE_FAIL;
105+
}
106+
int err = net->disconnect();
107+
if (err != NSAPI_ERROR_OK) {
108+
return CMDLINE_RETCODE_FAIL;
109+
}
110+
111+
return CMDLINE_RETCODE_SUCCESS;
112+
}
113+
114+
115+
116+
const char *networkstack_error_to_str(int errorcode)
117+
{
118+
switch (errorcode) {
119+
case NSAPI_ERROR_OK:
120+
return "NSAPI_ERROR_OK";
121+
case NSAPI_ERROR_WOULD_BLOCK:
122+
return "NSAPI_ERROR_WOULD_BLOCK";
123+
case NSAPI_ERROR_UNSUPPORTED:
124+
return "NSAPI_ERROR_UNSUPPORTED";
125+
case NSAPI_ERROR_PARAMETER:
126+
return "NSAPI_ERROR_PARAMETER";
127+
case NSAPI_ERROR_NO_CONNECTION:
128+
return "NSAPI_ERROR_NO_CONNECTION";
129+
case NSAPI_ERROR_NO_SOCKET:
130+
return "NSAPI_ERROR_NO_SOCKET";
131+
case NSAPI_ERROR_NO_ADDRESS:
132+
return "NSAPI_ERROR_NO_ADDRESS";
133+
case NSAPI_ERROR_NO_MEMORY:
134+
return "NSAPI_ERROR_NO_MEMORY";
135+
case NSAPI_ERROR_NO_SSID:
136+
return "NSAPI_ERROR_NO_SSID";
137+
case NSAPI_ERROR_DNS_FAILURE:
138+
return "NSAPI_ERROR_DNS_FAILURE";
139+
case NSAPI_ERROR_DHCP_FAILURE:
140+
return "NSAPI_ERROR_DHCP_FAILURE";
141+
case NSAPI_ERROR_AUTH_FAILURE:
142+
return "NSAPI_ERROR_AUTH_FAILURE";
143+
case NSAPI_ERROR_DEVICE_ERROR:
144+
return "NSAPI_ERROR_DEVICE_ERROR";
145+
case NSAPI_ERROR_IN_PROGRESS:
146+
return "NSAPI_ERROR_IN_PROGRESS";
147+
case NSAPI_ERROR_ALREADY:
148+
return "NSAPI_ERROR_ALREADY";
149+
case NSAPI_ERROR_IS_CONNECTED:
150+
return "NSAPI_ERROR_IS_CONNECTED";
151+
case NSAPI_ERROR_CONNECTION_LOST:
152+
return "NSAPI_ERROR_CONNECTION_LOST";
153+
case NSAPI_ERROR_CONNECTION_TIMEOUT:
154+
return "NSAPI_ERROR_CONNECTION_TIMEOUT";
155+
default:
156+
return "unknown error code";
157+
}
158+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2018 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* 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, WITHOUT
12+
* 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+
#ifndef CMD_IFCONFIG_H
17+
#define CMD_IFCONFIG_H
18+
19+
#include "NetworkInterface.h"
20+
#include "NetworkStack.h"
21+
22+
/** Get a pointer to a network interface instance
23+
*
24+
* Allowed interface types (depend on application configurations):
25+
* cell0, wlan0, eth0, mesh0
26+
*
27+
* @return pointer to the network interface, or NULL if unrecognized or ambiguous
28+
*/
29+
NetworkInterface *get_interface(void);
30+
31+
void cmd_ifconfig_init(void);
32+
const char *networkstack_error_to_str(int errorcode);
33+
34+
#endif

0 commit comments

Comments
 (0)