1 /*
2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3 */
4
5 #include "aos/init.h"
6 #include "board.h"
7 #include <aos/errno.h>
8 #include <aos/kernel.h>
9 #include <k_api.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <uservice/uservice.h>
13 #include <uservice/eventid.h>
14 #include "aos/cli.h"
15 #include "haas_main.h"
16
17 #define AMP_TYPE_MAX_LEN 32
18 #define AMP_TYPE_JS "JS"
19 #define AMP_TYPE_PYTHON "Python"
20
21 extern int amp_main(void);
22
amp_set_command(int argc,char ** argv)23 static void amp_set_command(int argc, char **argv)
24 {
25 if (argc < 2) {
26 printf("Usge: amp_set [JS/Python]\r\n");
27 return;
28 }
29
30 if (strcmp(argv[1], AMP_TYPE_JS) == 0) {
31 aos_kv_set("amp_type", AMP_TYPE_JS, strlen(AMP_TYPE_JS));
32 } else if (strcmp(argv[1], AMP_TYPE_PYTHON) == 0) {
33 aos_kv_set("amp_type", AMP_TYPE_PYTHON, strlen(AMP_TYPE_PYTHON));
34 }
35 }
36
37 /* reg args: fun, cmd, description*/
ALIOS_CLI_CMD_REGISTER(amp_set_command,amp_set,set amp startup type)38 ALIOS_CLI_CMD_REGISTER(amp_set_command, amp_set, set amp startup type)
39
40 int application_start(int argc, char *argv[])
41 {
42 int len = 0;
43 int ret = 0;
44 aos_task_t amp_task;
45 char amp_type[AMP_TYPE_MAX_LEN] = {0};
46
47 printf("haas dev demp entry here!\r\n");
48
49 len = 32;
50 ret = aos_kv_get("amp_type", amp_type, &len);
51 if ((ret == 0) && (strcmp(amp_type, AMP_TYPE_JS) == 0)) {
52 /* Start JS engine. */
53 aos_task_new_ext(&_task, "amp_task", amp_main, NULL, 8192, AOS_DEFAULT_APP_PRI - 2);
54 } else {
55 /* Start Python engine. */
56 haas_main(argc, argv);
57 }
58
59 while (1) {
60 aos_msleep(10000);
61 };
62 }
63