joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MeshThread.cpp Source File

MeshThread.cpp

00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * Thread network interface.
00019  * Class provides methods for 6LoWPAN (Thread mode) network handling.
00020  */
00021 
00022 #include <stdio.h>
00023 #include "mbed.h"
00024 #include "mbed-mesh-api/MeshThread.h"
00025 #include "include/thread_tasklet.h"
00026 #include "include/callback_handler.h"
00027 
00028 #define HAVE_DEBUG 1
00029 #include "ns_trace.h"
00030 
00031 #define TRACE_GROUP  "m6LTh"
00032 
00033 MeshThread::MeshThread() : AbstractMesh(MESH_TYPE_THREAD)
00034 {
00035 }
00036 
00037 MeshThread::~MeshThread()
00038 {
00039     tr_debug("~MeshThread()");
00040     thread_tasklet_disconnect(false);
00041 }
00042 
00043 mesh_error_t MeshThread::init(int8_t registered_device_id, mesh_network_handler_t callbackHandler, uint8_t *eui64, char *pskd)
00044 {
00045 
00046     if (eui64 == NULL) {
00047         return MESH_ERROR_PARAM;
00048     }
00049 
00050     mesh_error_t status = AbstractMesh::init(registered_device_id, callbackHandler);
00051 
00052     if (status == MESH_ERROR_NONE) {
00053         thread_tasklet_device_config_set(eui64, pskd);
00054     }
00055 
00056     return status;
00057 }
00058 
00059 mesh_error_t MeshThread::init(int8_t registered_device_id, mesh_network_handler_t  callbackHandler)
00060 {
00061     // TODO: Use test values for device configuration
00062     return MeshThread::init(registered_device_id, callbackHandler, NULL, NULL);
00063 }
00064 
00065 bool MeshThread::getOwnIpAddress(char *address, int8_t len)
00066 {
00067     tr_debug("getOwnIpAddress()");
00068     if (thread_tasklet_get_ip_address(address, len) == 0) {
00069         return true;
00070     }
00071     return false;
00072 }
00073 
00074 mesh_error_t MeshThread::data_poll_rate_set(uint32_t pollrate)
00075 {
00076     mesh_error_t status = MESH_ERROR_NONE;
00077     int8_t retval = thread_tasklet_data_poll_rate_set(pollrate);
00078     switch (retval) {
00079         case 0:
00080             status = MESH_ERROR_NONE;
00081             break;
00082         case -2:
00083             status = MESH_ERROR_PARAM;
00084             break;
00085         default:
00086         //case -1:
00087             status = MESH_ERROR_UNKNOWN;
00088             break;
00089     }
00090 
00091     return status;
00092 }
00093