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 | #include "kpu_main.h"
|
---|
12 |
|
---|
13 | /*
|
---|
14 | * デバイスコマンド番号
|
---|
15 | */
|
---|
16 | static int_t led_func(int argc, char **argv);
|
---|
17 | #ifdef USE_PINGSEND
|
---|
18 | static int_t png_func(int argc, char **argv);
|
---|
19 | #endif
|
---|
20 | extern int iothub_client_main(int argc, char **argv);
|
---|
21 | extern int dps_csgen_main(int argc, char *argv[]);
|
---|
22 | extern int set_cs_main(int argc, char **argv);
|
---|
23 | extern int set_proxy_main(int argc, char **argv);
|
---|
24 | extern int clear_proxy_main(int argc, char **argv);
|
---|
25 | extern int set_wifi_main(int argc, char **argv);
|
---|
26 |
|
---|
27 | /*
|
---|
28 | * デバイスコマンドテーブル
|
---|
29 | */
|
---|
30 | static const COMMAND_INFO device_command_info[] = {
|
---|
31 | {"LED", led_func},
|
---|
32 | #ifdef USE_PINGSEND
|
---|
33 | {"PING", png_func},
|
---|
34 | #endif
|
---|
35 | {"IOT", iothub_client_main},
|
---|
36 | {"CSGEN", dps_csgen_main},
|
---|
37 | {"SETCS", set_cs_main},
|
---|
38 | {"PROXY", set_proxy_main},
|
---|
39 | {"CPRX", clear_proxy_main},
|
---|
40 | {"WIFI", set_wifi_main},
|
---|
41 | };
|
---|
42 |
|
---|
43 | #define NUM_DEVICE_CMD (sizeof(device_command_info)/sizeof(COMMAND_INFO))
|
---|
44 |
|
---|
45 | static const char device_name[] = "DEVICE";
|
---|
46 | static const char device_help[] =
|
---|
47 | " Device LED (no) (on-1,off-0) led control\n"
|
---|
48 | #ifdef USE_PINGSEND
|
---|
49 | " PING addr send ping \n"
|
---|
50 | #endif
|
---|
51 | " IOT connect azure\n"
|
---|
52 | " CSGEN provision device\n"
|
---|
53 | " SETCS set connection string\n"
|
---|
54 | " PROXY set proxy \n"
|
---|
55 | " CPRX clear proxy \n"
|
---|
56 | " WIFI set ssid pwd \n";
|
---|
57 |
|
---|
58 | static const uint16_t led_pattern[] = {
|
---|
59 | LED_G_PIN,
|
---|
60 | LED_R_PIN,
|
---|
61 | LED_B_PIN,
|
---|
62 | };
|
---|
63 |
|
---|
64 | static COMMAND_LINK device_command_link = {
|
---|
65 | NULL,
|
---|
66 | NUM_DEVICE_CMD,
|
---|
67 | device_name,
|
---|
68 | NULL,
|
---|
69 | device_help,
|
---|
70 | &device_command_info[0]
|
---|
71 | };
|
---|
72 |
|
---|
73 | static int a2i(char *str)
|
---|
74 | {
|
---|
75 | int num = 0;
|
---|
76 |
|
---|
77 | while(*str >= '0' && *str <= '9'){
|
---|
78 | num = num * 10 + *str++ - '0';
|
---|
79 | }
|
---|
80 | return num;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*
|
---|
84 | * DEVICEコマンド設定関数
|
---|
85 | */
|
---|
86 | void device_info_init(intptr_t exinf)
|
---|
87 | {
|
---|
88 | setup_command(&device_command_link);
|
---|
89 | }
|
---|
90 |
|
---|
91 | /*
|
---|
92 | * LED設定コマンド関数
|
---|
93 | */
|
---|
94 | static int_t led_func(int argc, char **argv)
|
---|
95 | {
|
---|
96 | int_t arg1=0, arg2;
|
---|
97 |
|
---|
98 | if(argc < 3)
|
---|
99 | return -1;
|
---|
100 | arg1 = a2i(argv[1]);
|
---|
101 | arg2 = a2i(argv[2]);
|
---|
102 | if(arg1 >= 1 && arg1 <= sizeof(led_pattern) / sizeof(led_pattern[0])){
|
---|
103 | if(arg2 != 0) {
|
---|
104 | digitalWrite(led_pattern[arg1-1], LOW);
|
---|
105 | syslog(LOG_NOTICE, "digitalWrite(%d,LOW)", arg1);
|
---|
106 | }
|
---|
107 | else {
|
---|
108 | digitalWrite(led_pattern[arg1-1], HIGH);
|
---|
109 | syslog(LOG_NOTICE, "digitalWrite(%d,HIGH)", arg1);
|
---|
110 | }
|
---|
111 | }
|
---|
112 | else{
|
---|
113 | syslog(LOG_NOTICE, "LED %d is not arival.", arg1);
|
---|
114 | }
|
---|
115 | return 0;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | #ifdef USE_PINGSEND
|
---|
120 | /*
|
---|
121 | * PING送信マンド関数
|
---|
122 | */
|
---|
123 | static int_t png_func(int argc, char **argv)
|
---|
124 | {
|
---|
125 | const char *addr;
|
---|
126 | uint32_t paddr = 0;
|
---|
127 | int a, i;
|
---|
128 |
|
---|
129 | if(argc < 2)
|
---|
130 | return -1;
|
---|
131 | addr = argv[1];
|
---|
132 | for(i = a = 0 ; i < 4 ; addr++){
|
---|
133 | if(*addr <= '9' && *addr >= '0'){
|
---|
134 | a *= 10;
|
---|
135 | a += *addr - '0';
|
---|
136 | }
|
---|
137 | else{
|
---|
138 | paddr |= a << (i * 8);
|
---|
139 | a = 0;
|
---|
140 | i++;
|
---|
141 | }
|
---|
142 | if(*addr == 0)
|
---|
143 | break;
|
---|
144 | }
|
---|
145 | set_pingaddr(paddr);
|
---|
146 | return 0;
|
---|
147 | }
|
---|
148 | #endif
|
---|