• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <math.h>
19 #include <string.h>
20 #include "at_api.h"
21 #ifdef ALIOS_SUPPORT
22 #include "aos/cli.h"
23 #endif
24 #include "sonata_ble_api.h"
25 #ifdef ALIOS_SUPPORT
26 #include "lega_rhino.h"
27 #else
28 #include "lega_rtos.h"
29 #endif
30 
31 #ifdef CFG_MRFOTA_TEST
32 uint8_t rfota_ble_open = 0;
33 extern uint8_t rfota_wifi_open;
34 
35 extern uint8_t rfota_ble_test;
36 
lega_at_ble_start(char * pwbuf,int blen,int argc,char ** argv)37 static void lega_at_ble_start(char *pwbuf, int blen, int argc, char **argv)
38 {
39     if (rfota_wifi_open > 0) {
40         printf("please close wifi before test ble!");
41         return;
42     }
43 
44     if (rfota_ble_open == 0) {
45         lega_rtos_delay_milliseconds(1000);
46         extern void hci_uart_deinit(void);
47         hci_uart_deinit();
48         init_ble_task();
49         rfota_ble_open = 0x1;
50     } else {
51         printf("ble is alread open!\n");
52     }
53     return 0;
54 
55 }
56 #ifdef ALIOS_SUPPORT
57 static struct cli_command rfota_ble_start = {
58     .name     = "rfota_ble_start",
59     .help     = "rfota_ble_start",
60     .function = lega_at_ble_start,
61 };
62 #endif
lega_at_ble_stop(char * pwbuf,int blen,int argc,char ** argv)63 static void lega_at_ble_stop(char *pwbuf, int blen, int argc, char **argv)
64 {
65     if (rfota_ble_open == 0x1) {
66         rfota_ble_open = 0;
67         ble_close();
68     } else if (rfota_ble_open == 0) {
69         printf("ble don't need close!\n");
70     }
71 
72     return 0;
73 }
74 #ifdef ALIOS_SUPPORT
75 static struct cli_command rfota_ble_stop = {
76     .name     = "rfota_ble_stop",
77     .help     = "rfota_ble_stop for hci test",
78     .function = lega_at_ble_stop,
79 };
80 #endif
lega_enable_rfota_ble_test(char * pwbuf,int blen,int argc,char ** argv)81 static void lega_enable_rfota_ble_test(char *pwbuf, int blen, int argc, char **argv)
82 {
83     int c = 1;
84     if (strcmp(argv[c], "on") == 0) {
85         rfota_ble_test = 1;
86         printf("rfota ble test begin\n");
87     } else if (strcmp(argv[c], "off") == 0) {
88         rfota_ble_test = 0;
89         printf("rfota ble test end\n");
90     }
91 }
92 #ifdef ALIOS_SUPPORT
93 static struct cli_command rfota_ble_cmd = {
94     .name     = "rfota_ble_test",
95     .help     = "rfota_ble_test on/off",
96     .function = lega_enable_rfota_ble_test,
97 };
98 
lega_rfota_ble_test_at_init(void)99 void lega_rfota_ble_test_at_init(void)
100 {
101     aos_cli_register_command(&rfota_ble_cmd);
102     aos_cli_register_command(&rfota_ble_start);
103     aos_cli_register_command(&rfota_ble_stop);
104 }
105 #endif
106 #endif
107