Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
cmd_commands.cpp
00001 /* 00002 * Copyright (c) 2014-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 #include <string.h> 00017 #include <stdarg.h> 00018 #include <stdio.h> 00019 00020 #include "ns_types.h" 00021 #include "eventOS_event.h" 00022 #include "eventOS_event_timer.h" 00023 #include "net_interface.h" 00024 #include "socket_api.h" 00025 #include "mbed-trace/mbed_trace.h" 00026 #include "common_functions.h" 00027 00028 #include "ns_cmdline.h" 00029 #include "cmd_commands.h" 00030 #include "cmd_lwm2m.h" 00031 00032 #define TRACE_GROUP "cApp" 00033 00034 #define ESC 0x03 00035 #define EVENT_DATA_COMMAND_EXECUTED 6 00036 00037 // Prototypes 00038 void cmd_ready_cb(int retcode); 00039 00040 static void cmdline_event(arm_event_s *event); 00041 00042 /** 00043 * Callback function for thread handling. 00044 */ 00045 void* __thread_poll_function(void*); 00046 00047 typedef struct { 00048 uint8_t tasklet_id; 00049 } cmd_commands_t; 00050 00051 cmd_commands_t cmd_commands; 00052 pthread_t input_thread; /* Thread for input_terminal-function */ 00053 00054 void initialize_app_commands(int8_t /*rf_driver_id*/) 00055 { 00056 //initialize ready cb 00057 cmd_set_ready_cb( cmd_ready_cb ); 00058 lwm2m_command_init(); 00059 00060 cmd_commands.tasklet_id = eventOS_event_handler_create(&cmdline_event, EVENT_TYPE_CMDLINE); 00061 pthread_create(&input_thread, NULL,__thread_poll_function, NULL); 00062 } 00063 00064 void cmd_ready_cb(int retcode) 00065 { 00066 tr_debug("cmd_ready_cb(%d)", retcode); 00067 arm_event_s event; 00068 event.sender = cmd_commands.tasklet_id; 00069 event.receiver = cmd_commands.tasklet_id; 00070 event.event_type = APPLICATION_EVENT; 00071 event.event_id = EVENT_DATA_COMMAND_EXECUTED; 00072 event.event_data = retcode; 00073 eventOS_event_send(&event); 00074 } 00075 00076 static void cmdline_event(arm_event_s *event) 00077 { 00078 switch( event->event_type ) 00079 { 00080 case ARM_LIB_TASKLET_INIT_EVENT: 00081 //tasklet up and running 00082 tr_warning("cmdline_event-ARM_LIB_TASKLET_INIT_EVENT"); 00083 break; 00084 00085 case APPLICATION_EVENT: 00086 if( event->event_id == EVENT_DATA_COMMAND_EXECUTED ) 00087 { 00088 int retcode = event->event_data; 00089 cmd_next( retcode ); 00090 } 00091 break; 00092 default: 00093 tr_warning("Unknown event type (type: %i, id: %i)", event->event_type, event->event_id); 00094 break; 00095 } 00096 } 00097 00098 void* __thread_poll_function(void*) 00099 { 00100 int16_t c = getchar(); 00101 while( c >= 0 ) { 00102 cmd_char_input(c); 00103 c = getchar(); 00104 } 00105 return NULL; 00106 }
Generated on Tue Jul 12 2022 12:28:27 by
