[457] | 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 | static int_t dip_func(int argc, char **argv);
|
---|
| 17 | #ifdef USE_PINGSEND
|
---|
| 18 | static int_t png_func(int argc, char **argv);
|
---|
| 19 | #endif
|
---|
| 20 | static int_t cup_func(int argc, char **argv);
|
---|
| 21 | extern int iothub_client_main(int argc, char **argv);
|
---|
| 22 | extern int dps_csgen_main(int argc, char *argv[]);
|
---|
| 23 | extern int set_cs_main(int argc, char **argv);
|
---|
| 24 | extern int set_proxy_main(int argc, char **argv);
|
---|
| 25 | extern int clear_proxy_main(int argc, char **argv);
|
---|
| 26 | extern int set_wifi_main(int argc, char **argv);
|
---|
| 27 | extern int pinkit_main(int argc, char **argv);
|
---|
| 28 |
|
---|
| 29 | /*
|
---|
| 30 | * デバイスコマンドテーブル
|
---|
| 31 | */
|
---|
| 32 | static 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 |
|
---|
| 50 | static const char device_name[] = "DEVICE";
|
---|
| 51 | static 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 |
|
---|
| 66 | static const uint16_t led_pattern[4] = {
|
---|
| 67 | LED01, LED02, LED03, LED04
|
---|
| 68 | };
|
---|
| 69 |
|
---|
| 70 | static 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 |
|
---|
| 79 | static uint8_t cup_command;
|
---|
| 80 |
|
---|
| 81 | static 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 | */
|
---|
| 94 | void device_info_init(intptr_t exinf)
|
---|
| 95 | {
|
---|
| 96 | setup_command(&device_command_link);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /*
|
---|
| 100 | * LED設定コマンド関数
|
---|
| 101 | */
|
---|
| 102 | static 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 | */
|
---|
| 125 | static 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 | */
|
---|
| 154 | static 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 | */
|
---|
| 184 | static 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 | */
|
---|
| 194 | int8_t
|
---|
| 195 | get_cup_command(void)
|
---|
| 196 | {
|
---|
| 197 | uint8_t cmd = cup_command;
|
---|
| 198 | cup_command = 0;
|
---|
| 199 | return cmd;
|
---|
| 200 | }
|
---|