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