mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /*
elessair 0:f269e3021894 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
elessair 0:f269e3021894 3 * SPDX-License-Identifier: Apache-2.0
elessair 0:f269e3021894 4 * Licensed under the Apache License, Version 2.0 (the License); you may
elessair 0:f269e3021894 5 * not use this file except in compliance with the License.
elessair 0:f269e3021894 6 * You may obtain a copy of the License at
elessair 0:f269e3021894 7 *
elessair 0:f269e3021894 8 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 9 *
elessair 0:f269e3021894 10 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
elessair 0:f269e3021894 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 13 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 14 * limitations under the License.
elessair 0:f269e3021894 15 */
elessair 0:f269e3021894 16
elessair 0:f269e3021894 17 /*
elessair 0:f269e3021894 18 * Thread network interface.
elessair 0:f269e3021894 19 * Class provides methods for 6LoWPAN (Thread mode) network handling.
elessair 0:f269e3021894 20 */
elessair 0:f269e3021894 21
elessair 0:f269e3021894 22 #include <stdio.h>
elessair 0:f269e3021894 23 #include "mbed.h"
elessair 0:f269e3021894 24 #include "mbed-mesh-api/MeshThread.h"
elessair 0:f269e3021894 25 #include "include/thread_tasklet.h"
elessair 0:f269e3021894 26 #include "include/callback_handler.h"
elessair 0:f269e3021894 27
elessair 0:f269e3021894 28 #define HAVE_DEBUG 1
elessair 0:f269e3021894 29 #include "ns_trace.h"
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31 #define TRACE_GROUP "m6LTh"
elessair 0:f269e3021894 32
elessair 0:f269e3021894 33 MeshThread::MeshThread() : AbstractMesh(MESH_TYPE_THREAD)
elessair 0:f269e3021894 34 {
elessair 0:f269e3021894 35 }
elessair 0:f269e3021894 36
elessair 0:f269e3021894 37 MeshThread::~MeshThread()
elessair 0:f269e3021894 38 {
elessair 0:f269e3021894 39 tr_debug("~MeshThread()");
elessair 0:f269e3021894 40 thread_tasklet_disconnect(false);
elessair 0:f269e3021894 41 }
elessair 0:f269e3021894 42
elessair 0:f269e3021894 43 mesh_error_t MeshThread::init(int8_t registered_device_id, mesh_network_handler_t callbackHandler, uint8_t *eui64, char *pskd)
elessair 0:f269e3021894 44 {
elessair 0:f269e3021894 45
elessair 0:f269e3021894 46 if (eui64 == NULL) {
elessair 0:f269e3021894 47 return MESH_ERROR_PARAM;
elessair 0:f269e3021894 48 }
elessair 0:f269e3021894 49
elessair 0:f269e3021894 50 mesh_error_t status = AbstractMesh::init(registered_device_id, callbackHandler);
elessair 0:f269e3021894 51
elessair 0:f269e3021894 52 if (status == MESH_ERROR_NONE) {
elessair 0:f269e3021894 53 thread_tasklet_device_config_set(eui64, pskd);
elessair 0:f269e3021894 54 }
elessair 0:f269e3021894 55
elessair 0:f269e3021894 56 return status;
elessair 0:f269e3021894 57 }
elessair 0:f269e3021894 58
elessair 0:f269e3021894 59 mesh_error_t MeshThread::init(int8_t registered_device_id, mesh_network_handler_t callbackHandler)
elessair 0:f269e3021894 60 {
elessair 0:f269e3021894 61 // TODO: Use test values for device configuration
elessair 0:f269e3021894 62 return MeshThread::init(registered_device_id, callbackHandler, NULL, NULL);
elessair 0:f269e3021894 63 }
elessair 0:f269e3021894 64
elessair 0:f269e3021894 65 bool MeshThread::getOwnIpAddress(char *address, int8_t len)
elessair 0:f269e3021894 66 {
elessair 0:f269e3021894 67 tr_debug("getOwnIpAddress()");
elessair 0:f269e3021894 68 if (thread_tasklet_get_ip_address(address, len) == 0) {
elessair 0:f269e3021894 69 return true;
elessair 0:f269e3021894 70 }
elessair 0:f269e3021894 71 return false;
elessair 0:f269e3021894 72 }
elessair 0:f269e3021894 73
elessair 0:f269e3021894 74 mesh_error_t MeshThread::data_poll_rate_set(uint32_t pollrate)
elessair 0:f269e3021894 75 {
elessair 0:f269e3021894 76 mesh_error_t status = MESH_ERROR_NONE;
elessair 0:f269e3021894 77 int8_t retval = thread_tasklet_data_poll_rate_set(pollrate);
elessair 0:f269e3021894 78 switch (retval) {
elessair 0:f269e3021894 79 case 0:
elessair 0:f269e3021894 80 status = MESH_ERROR_NONE;
elessair 0:f269e3021894 81 break;
elessair 0:f269e3021894 82 case -2:
elessair 0:f269e3021894 83 status = MESH_ERROR_PARAM;
elessair 0:f269e3021894 84 break;
elessair 0:f269e3021894 85 default:
elessair 0:f269e3021894 86 //case -1:
elessair 0:f269e3021894 87 status = MESH_ERROR_UNKNOWN;
elessair 0:f269e3021894 88 break;
elessair 0:f269e3021894 89 }
elessair 0:f269e3021894 90
elessair 0:f269e3021894 91 return status;
elessair 0:f269e3021894 92 }
elessair 0:f269e3021894 93