-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
110 lines (91 loc) · 3.15 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "rtos.h"
#include "NanostackInterface.h"
#include "mbed-trace/mbed_trace.h"
#include "mesh_nvm.h"
#if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
#include "mesh_led_blink_pattern_example.h"
#endif
void trace_printer(const char* str) {
printf("%s\n", str);
}
#define ATMEL 1
#define MCR20 2
#define NCS36510 3
#define KW24D 4
#define MESH_LOWPAN 3
#define MESH_THREAD 4
#if MBED_CONF_APP_RADIO_TYPE == ATMEL
#include "NanostackRfPhyAtmel.h"
NanostackRfPhyAtmel rf_phy(ATMEL_SPI_MOSI, ATMEL_SPI_MISO, ATMEL_SPI_SCLK, ATMEL_SPI_CS,
ATMEL_SPI_RST, ATMEL_SPI_SLP, ATMEL_SPI_IRQ, ATMEL_I2C_SDA, ATMEL_I2C_SCL);
#elif MBED_CONF_APP_RADIO_TYPE == MCR20 || MBED_CONF_APP_RADIO_TYPE == KW24D
#include "NanostackRfPhyMcr20a.h"
NanostackRfPhyMcr20a rf_phy(MCR20A_SPI_MOSI, MCR20A_SPI_MISO, MCR20A_SPI_SCLK, MCR20A_SPI_CS, MCR20A_SPI_RST, MCR20A_SPI_IRQ);
#elif MBED_CONF_APP_RADIO_TYPE == NCS36510
#include "NanostackRfPhyNcs36510.h"
NanostackRfPhyNcs36510 rf_phy;
#endif //MBED_CONF_APP_RADIO_TYPE
#if MBED_CONF_APP_MESH_TYPE == MESH_LOWPAN
LoWPANNDInterface mesh;
#elif MBED_CONF_APP_MESH_TYPE == MESH_THREAD
ThreadInterface mesh;
#endif //MBED_CONF_APP_MESH_TYPE
static Mutex SerialOutMutex;
void serial_out_mutex_wait()
{
SerialOutMutex.lock();
}
void serial_out_mutex_release()
{
SerialOutMutex.unlock();
}
int main()
{
mbed_trace_init();
mbed_trace_print_function_set(trace_printer);
mbed_trace_mutex_wait_function_set( serial_out_mutex_wait );
mbed_trace_mutex_release_function_set( serial_out_mutex_release );
printf("Start mesh-minimal application\n");
printf("Build: %s %s\nMesh type: %d\n", __DATE__, __TIME__, MBED_CONF_APP_MESH_TYPE);
//SET LED COLOR BLUE
set_led_color(LED_COLOR_BLUE);
set_led_on();
printf("\n\nConnecting...\n");
mesh.initialize(&rf_phy);
mesh_nvm_initialize();
int error = mesh.connect();
if (error) {
printf("Connection failed! %d\n", error);
//SET LED COLOR RED - OH NO!
set_led_color(LED_COLOR_RED);
set_led_on();
return error;
}else {
//SET LED COLOR GREEN - SUCCESS!
set_led_color(LED_COLOR_GREEN);
set_led_on();
}
while (NULL == mesh.get_ip_address())
Thread::wait(500);
printf("connected. IP = %s\n", mesh.get_ip_address());
#if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
// Network found, start socket example
start_mesh_led_blink_pattern_example((NetworkInterface *)&mesh);
#endif
}