source: azure_iot_hub_f767zi/trunk/app_iothub_client/src/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: 4.0 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);
21extern int iothub_client_main(int argc, char **argv);
22extern int dps_csgen_main(int argc, char *argv[]);
23extern int set_cs_main(int argc, char **argv);
24extern int set_proxy_main(int argc, char **argv);
25extern int clear_proxy_main(int argc, char **argv);
26extern int set_wifi_main(int argc, char **argv);
27extern int pinkit_main(int argc, char **argv);
28
29/*
30 * デバイスコマンドテーブル
31 */
32static const COMMAND_INFO device_command_info[] = {
33 {"LED", led_func},
34 {"DIP", dip_func},
35#ifdef USE_PINGSEND
36 {"PING", png_func},
37#endif
38 {"CUP", cup_func},
39 {"IOT", iothub_client_main},
40 {"CSGEN", dps_csgen_main},
41 {"SETCS", set_cs_main},
42 {"PROXY", set_proxy_main},
43 {"CPRX", clear_proxy_main},
44 {"WIFI", set_wifi_main},
45 {"PINKIT", pinkit_main},
46};
47
48#define NUM_DEVICE_CMD (sizeof(device_command_info)/sizeof(COMMAND_INFO))
49
50static const char device_name[] = "DEVICE";
51static const char device_help[] =
52" Device LED (no) (on-1,off-0) led control\n"
53" DIP (no) (on-1,off-0) dipsw control\n"
54#ifdef USE_PINGSEND
55" PING addr send ping \n"
56#endif
57" CUP command cup control\n"
58" IOT connect azure\n"
59" CS set connection string\n"
60" CSGEN provision device\n"
61" PROXY set proxy \n"
62" CPRX clear proxy \n"
63" WIFI set ssid pwd \n"
64" PINKIT test pinkit \n";
65
66static const uint16_t led_pattern[4] = {
67 LED01, LED02, LED03, LED04
68};
69
70static COMMAND_LINK device_command_link = {
71 NULL,
72 NUM_DEVICE_CMD,
73 device_name,
74 NULL,
75 device_help,
76 &device_command_info[0]
77};
78
79static uint8_t cup_command;
80
81static int a2i(char *str)
82{
83 int num = 0;
84
85 while(*str >= '0' && *str <= '9'){
86 num = num * 10 + *str++ - '0';
87 }
88 return num;
89}
90
91/*
92 * DEVICEコマンド設定関数
93 */
94void device_info_init(intptr_t exinf)
95{
96 setup_command(&device_command_link);
97}
98
99/*
100 * LED設定コマンド関数
101 */
102static int_t led_func(int argc, char **argv)
103{
104 int_t arg1=0, arg2;
105 uint16_t reg;
106
107 if(argc < 3)
108 return -1;
109 arg1 = a2i(argv[1]);
110 arg2 = a2i(argv[2]);
111 if(arg1 >= 1 && arg1 <= 4){
112 reg = led_in();
113 if(arg2 != 0)
114 reg |= led_pattern[arg1-1];
115 else
116 reg &= ~led_pattern[arg1-1];
117 led_out(reg);
118 }
119 return 0;
120}
121
122/*
123 * DIPSW設定コマンド関数
124 */
125static int_t dip_func(int argc, char **argv)
126{
127 int_t arg1=0, arg2=0, i;
128
129 if(argc > 1)
130 arg1 = a2i(argv[1]);
131 if(argc > 2)
132 arg2 = a2i(argv[2]);
133 if(arg1 >= 1 && arg1 <= 8){
134 if(arg2 != 0)
135 dipsw_value |= (0x1<<(arg1-1));
136 else
137 dipsw_value &= ~(0x1<<(arg1-1));
138 }
139 printf("dipsw\n1 2 3 4 5 6 7 8\n");
140 for(i = 0 ; i < 8 ; i++){
141 if(dipsw_value & (1<<i))
142 printf("ON ");
143 else
144 printf("OFF ");
145 }
146 printf("\n");
147 return 0;
148}
149
150#ifdef USE_PINGSEND
151/*
152 * PING送信マンド関数
153 */
154static int_t png_func(int argc, char **argv)
155{
156 const char *addr;
157 uint32_t paddr = 0;
158 int a, i;
159
160 if(argc < 2)
161 return -1;
162 addr = argv[1];
163 for(i = a = 0 ; i < 4 ; addr++){
164 if(*addr <= '9' && *addr >= '0'){
165 a *= 10;
166 a += *addr - '0';
167 }
168 else{
169 paddr |= a << (i * 8);
170 a = 0;
171 i++;
172 }
173 if(*addr == 0)
174 break;
175 }
176 set_pingaddr(paddr);
177 return 0;
178}
179#endif
180
181/*
182 * カップラーメンタイマ補助コマンド関数
183 */
184static int_t cup_func(int argc, char **argv)
185{
186 if(argc > 1)
187 cup_command = *argv[1];
188 return 0;
189}
190
191/*
192 * CUPラーメンコマンド
193 */
194int8_t
195get_cup_command(void)
196{
197 uint8_t cmd = cup_command;
198 cup_command = 0;
199 return cmd;
200}
Note: See TracBrowser for help on using the repository browser.