Ram Gandikota
/
ABCD
A metronome using the FRDM K64F board
mbed-client/test/lwm2mtestapplication/cmd_commands.cpp@0:a7a43371b306, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:40:18 2017 +0000
- Revision:
- 0:a7a43371b306
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a7a43371b306 | 1 | /* |
ram54288 | 0:a7a43371b306 | 2 | * Copyright (c) 2014-2015 ARM Limited. All rights reserved. |
ram54288 | 0:a7a43371b306 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:a7a43371b306 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:a7a43371b306 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:a7a43371b306 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:a7a43371b306 | 7 | * |
ram54288 | 0:a7a43371b306 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:a7a43371b306 | 9 | * |
ram54288 | 0:a7a43371b306 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:a7a43371b306 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:a7a43371b306 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:a7a43371b306 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:a7a43371b306 | 14 | * limitations under the License. |
ram54288 | 0:a7a43371b306 | 15 | */ |
ram54288 | 0:a7a43371b306 | 16 | #include <string.h> |
ram54288 | 0:a7a43371b306 | 17 | #include <stdarg.h> |
ram54288 | 0:a7a43371b306 | 18 | #include <stdio.h> |
ram54288 | 0:a7a43371b306 | 19 | |
ram54288 | 0:a7a43371b306 | 20 | #include "ns_types.h" |
ram54288 | 0:a7a43371b306 | 21 | #include "eventOS_event.h" |
ram54288 | 0:a7a43371b306 | 22 | #include "eventOS_event_timer.h" |
ram54288 | 0:a7a43371b306 | 23 | #include "net_interface.h" |
ram54288 | 0:a7a43371b306 | 24 | #include "socket_api.h" |
ram54288 | 0:a7a43371b306 | 25 | #include "mbed-trace/mbed_trace.h" |
ram54288 | 0:a7a43371b306 | 26 | #include "common_functions.h" |
ram54288 | 0:a7a43371b306 | 27 | |
ram54288 | 0:a7a43371b306 | 28 | #include "ns_cmdline.h" |
ram54288 | 0:a7a43371b306 | 29 | #include "cmd_commands.h" |
ram54288 | 0:a7a43371b306 | 30 | #include "cmd_lwm2m.h" |
ram54288 | 0:a7a43371b306 | 31 | |
ram54288 | 0:a7a43371b306 | 32 | #define TRACE_GROUP "cApp" |
ram54288 | 0:a7a43371b306 | 33 | |
ram54288 | 0:a7a43371b306 | 34 | #define ESC 0x03 |
ram54288 | 0:a7a43371b306 | 35 | #define EVENT_DATA_COMMAND_EXECUTED 6 |
ram54288 | 0:a7a43371b306 | 36 | |
ram54288 | 0:a7a43371b306 | 37 | // Prototypes |
ram54288 | 0:a7a43371b306 | 38 | void cmd_ready_cb(int retcode); |
ram54288 | 0:a7a43371b306 | 39 | |
ram54288 | 0:a7a43371b306 | 40 | static void cmdline_event(arm_event_s *event); |
ram54288 | 0:a7a43371b306 | 41 | |
ram54288 | 0:a7a43371b306 | 42 | /** |
ram54288 | 0:a7a43371b306 | 43 | * Callback function for thread handling. |
ram54288 | 0:a7a43371b306 | 44 | */ |
ram54288 | 0:a7a43371b306 | 45 | void* __thread_poll_function(void*); |
ram54288 | 0:a7a43371b306 | 46 | |
ram54288 | 0:a7a43371b306 | 47 | typedef struct { |
ram54288 | 0:a7a43371b306 | 48 | uint8_t tasklet_id; |
ram54288 | 0:a7a43371b306 | 49 | } cmd_commands_t; |
ram54288 | 0:a7a43371b306 | 50 | |
ram54288 | 0:a7a43371b306 | 51 | cmd_commands_t cmd_commands; |
ram54288 | 0:a7a43371b306 | 52 | pthread_t input_thread; /* Thread for input_terminal-function */ |
ram54288 | 0:a7a43371b306 | 53 | |
ram54288 | 0:a7a43371b306 | 54 | void initialize_app_commands(int8_t /*rf_driver_id*/) |
ram54288 | 0:a7a43371b306 | 55 | { |
ram54288 | 0:a7a43371b306 | 56 | //initialize ready cb |
ram54288 | 0:a7a43371b306 | 57 | cmd_set_ready_cb( cmd_ready_cb ); |
ram54288 | 0:a7a43371b306 | 58 | lwm2m_command_init(); |
ram54288 | 0:a7a43371b306 | 59 | |
ram54288 | 0:a7a43371b306 | 60 | cmd_commands.tasklet_id = eventOS_event_handler_create(&cmdline_event, EVENT_TYPE_CMDLINE); |
ram54288 | 0:a7a43371b306 | 61 | pthread_create(&input_thread, NULL,__thread_poll_function, NULL); |
ram54288 | 0:a7a43371b306 | 62 | } |
ram54288 | 0:a7a43371b306 | 63 | |
ram54288 | 0:a7a43371b306 | 64 | void cmd_ready_cb(int retcode) |
ram54288 | 0:a7a43371b306 | 65 | { |
ram54288 | 0:a7a43371b306 | 66 | tr_debug("cmd_ready_cb(%d)", retcode); |
ram54288 | 0:a7a43371b306 | 67 | arm_event_s event; |
ram54288 | 0:a7a43371b306 | 68 | event.sender = cmd_commands.tasklet_id; |
ram54288 | 0:a7a43371b306 | 69 | event.receiver = cmd_commands.tasklet_id; |
ram54288 | 0:a7a43371b306 | 70 | event.event_type = APPLICATION_EVENT; |
ram54288 | 0:a7a43371b306 | 71 | event.event_id = EVENT_DATA_COMMAND_EXECUTED; |
ram54288 | 0:a7a43371b306 | 72 | event.event_data = retcode; |
ram54288 | 0:a7a43371b306 | 73 | eventOS_event_send(&event); |
ram54288 | 0:a7a43371b306 | 74 | } |
ram54288 | 0:a7a43371b306 | 75 | |
ram54288 | 0:a7a43371b306 | 76 | static void cmdline_event(arm_event_s *event) |
ram54288 | 0:a7a43371b306 | 77 | { |
ram54288 | 0:a7a43371b306 | 78 | switch( event->event_type ) |
ram54288 | 0:a7a43371b306 | 79 | { |
ram54288 | 0:a7a43371b306 | 80 | case ARM_LIB_TASKLET_INIT_EVENT: |
ram54288 | 0:a7a43371b306 | 81 | //tasklet up and running |
ram54288 | 0:a7a43371b306 | 82 | tr_warning("cmdline_event-ARM_LIB_TASKLET_INIT_EVENT"); |
ram54288 | 0:a7a43371b306 | 83 | break; |
ram54288 | 0:a7a43371b306 | 84 | |
ram54288 | 0:a7a43371b306 | 85 | case APPLICATION_EVENT: |
ram54288 | 0:a7a43371b306 | 86 | if( event->event_id == EVENT_DATA_COMMAND_EXECUTED ) |
ram54288 | 0:a7a43371b306 | 87 | { |
ram54288 | 0:a7a43371b306 | 88 | int retcode = event->event_data; |
ram54288 | 0:a7a43371b306 | 89 | cmd_next( retcode ); |
ram54288 | 0:a7a43371b306 | 90 | } |
ram54288 | 0:a7a43371b306 | 91 | break; |
ram54288 | 0:a7a43371b306 | 92 | default: |
ram54288 | 0:a7a43371b306 | 93 | tr_warning("Unknown event type (type: %i, id: %i)", event->event_type, event->event_id); |
ram54288 | 0:a7a43371b306 | 94 | break; |
ram54288 | 0:a7a43371b306 | 95 | } |
ram54288 | 0:a7a43371b306 | 96 | } |
ram54288 | 0:a7a43371b306 | 97 | |
ram54288 | 0:a7a43371b306 | 98 | void* __thread_poll_function(void*) |
ram54288 | 0:a7a43371b306 | 99 | { |
ram54288 | 0:a7a43371b306 | 100 | int16_t c = getchar(); |
ram54288 | 0:a7a43371b306 | 101 | while( c >= 0 ) { |
ram54288 | 0:a7a43371b306 | 102 | cmd_char_input(c); |
ram54288 | 0:a7a43371b306 | 103 | c = getchar(); |
ram54288 | 0:a7a43371b306 | 104 | } |
ram54288 | 0:a7a43371b306 | 105 | return NULL; |
ram54288 | 0:a7a43371b306 | 106 | } |