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