source: azure_iot_hub_f767zi/trunk/asp_baseplatform/OBJ/STM32F767NUCLEO144_GCC/MAC/command.c@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 3.1 KB
Line 
1#include <kernel.h>
2#include <t_syslog.h>
3#include <stdio.h>
4#include <t_stdlib.h>
5#include <stdlib.h>
6#include "syssvc/serial.h"
7#include "syssvc/syslog.h"
8#include "kernel_cfg.h"
9#include "monitor.h"
10#include "device.h"
11
12/*
13 * デバイスコマンド番号
14 */
15static int_t led_func(int argc, char **argv);
16static int_t dip_func(int argc, char **argv);
17#ifdef USE_PINGSEND
18static int_t png_func(int argc, char **argv);
19#endif
20static int_t cup_func(int argc, char **argv);
21
22/*
23 * デバイスコマンドテーブル
24 */
25static const COMMAND_INFO device_command_info[] = {
26 {"LED", led_func},
27 {"DIP", dip_func},
28#ifdef USE_PINGSEND
29 {"PING", png_func},
30#endif
31 {"CUP", cup_func}
32};
33
34#define NUM_DEVICE_CMD (sizeof(device_command_info)/sizeof(COMMAND_INFO))
35
36static const char device_name[] = "DEVICE";
37static const char device_help[] =
38" Device LED (no) (on-1,off-0) led control\n"
39" DIP (no) (on-1,off-0) dipsw control\n"
40#ifdef USE_PINGSEND
41" PING addr send ping \n"
42#endif
43" CUP command cup control\n";
44
45static const uint16_t led_pattern[4] = {
46 LED01, LED02, LED03, LED04
47};
48
49static COMMAND_LINK device_command_link = {
50 NULL,
51 NUM_DEVICE_CMD,
52 device_name,
53 NULL,
54 device_help,
55 &device_command_info[0]
56};
57
58static uint8_t cup_command;
59
60static int a2i(char *str)
61{
62 int num = 0;
63
64 while(*str >= '0' && *str <= '9'){
65 num = num * 10 + *str++ - '0';
66 }
67 return num;
68}
69
70/*
71 * DEVICEコマンド設定関数
72 */
73void device_info_init(intptr_t exinf)
74{
75 setup_command(&device_command_link);
76}
77
78/*
79 * LED設定コマンド関数
80 */
81static int_t led_func(int argc, char **argv)
82{
83 int_t arg1=0, arg2;
84 uint16_t reg;
85
86 if(argc < 3)
87 return -1;
88 arg1 = a2i(argv[1]);
89 arg2 = a2i(argv[2]);
90 if(arg1 >= 1 && arg1 <= 4){
91 reg = led_in();
92 if(arg2 != 0)
93 reg |= led_pattern[arg1-1];
94 else
95 reg &= ~led_pattern[arg1-1];
96 led_out(reg);
97 }
98 return 0;
99}
100
101/*
102 * DIPSW設定コマンド関数
103 */
104static int_t dip_func(int argc, char **argv)
105{
106 int_t arg1=0, arg2=0, i;
107
108 if(argc > 1)
109 arg1 = a2i(argv[1]);
110 if(argc > 2)
111 arg2 = a2i(argv[2]);
112 if(arg1 >= 1 && arg1 <= 8){
113 if(arg2 != 0)
114 dipsw_value |= (0x1<<(arg1-1));
115 else
116 dipsw_value &= ~(0x1<<(arg1-1));
117 }
118 printf("dipsw\n1 2 3 4 5 6 7 8\n");
119 for(i = 0 ; i < 8 ; i++){
120 if(dipsw_value & (1<<i))
121 printf("ON ");
122 else
123 printf("OFF ");
124 }
125 printf("\n");
126 return 0;
127}
128
129#ifdef USE_PINGSEND
130/*
131 * PING送信マンド関数
132 */
133static int_t png_func(int argc, char **argv)
134{
135 const char *addr;
136 uint32_t paddr = 0;
137 int a, i;
138
139 if(argc < 2)
140 return -1;
141 addr = argv[1];
142 for(i = a = 0 ; i < 4 ; addr++){
143 if(*addr <= '9' && *addr >= '0'){
144 a *= 10;
145 a += *addr - '0';
146 }
147 else{
148 paddr |= a << (i * 8);
149 a = 0;
150 i++;
151 }
152 if(*addr == 0)
153 break;
154 }
155 set_pingaddr(paddr);
156 return 0;
157}
158#endif
159
160/*
161 * カップラーメンタイマ補助コマンド関数
162 */
163static int_t cup_func(int argc, char **argv)
164{
165 if(argc > 1)
166 cup_command = *argv[1];
167 return 0;
168}
169
170/*
171 * CUPラーメンコマンド
172 */
173int8_t
174get_cup_command(void)
175{
176 uint8_t cmd = cup_command;
177 cup_command = 0;
178 return cmd;
179}
180
181
Note: See TracBrowser for help on using the repository browser.