1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #include <stdio.h>
6 #include <string.h>
7 
8 #include "aos_system.h"
9 #include "py_defines.h"
10 
11 #define MOD_STR "AMP_UTILS"
12 
13 // unsigned char hex2num(unsigned char ch)
14 // {
15 //     if (ch >= 'a') {
16 //         return ch - 'a' + 10;
17 //     }
18 //     else if (ch >= 'A') {
19 //         return ch - 'A' + 10;
20 //     }
21 
22 //     return ch - '0';
23 // }
24 
25 // char itoch(int val)
26 // {
27 //     if (val < 10) {
28 //         return (char)('0' + val);
29 //     }
30 
31 //     return (char)('a' + val - 10);
32 // }
33 
34 // void num2hex(unsigned char ch, unsigned char *hex)
35 // {
36 //     hex[0] = itoch(ch / 16);
37 //     hex[1] = itoch(ch % 16);
38 // }
39 
40 /*****************************************************************************
41  *Function:    end_with
42  *Description: check if str1 end with str2
43  *Input:       str1 and str2
44  *Output:      if str1 end with str2,return 1 else return 0
45  *****************************************************************************/
46 // int end_with(char *str1, char *str2)
47 // {
48 //     if (!str1 || !str2) {
49 //         return 0;
50 //     }
51 
52 //     int len1 = strlen(str1);
53 //     int len2 = strlen(str2);
54 
55 //     if (len1 >= len2) {
56 //         if (strcmp(str1 + len1 - len2, str2) == 0) {
57 //             return 1;
58 //         }
59 //     }
60 
61 //     return 0;
62 // }
63 
64 /*****************************************************************************
65  *Function:    hexdump
66  *Description: print buff with hex style
67  *Input:       title: a string, buff: the dest buff for dump,len:the buffer len
68  *Output:      none
69  *****************************************************************************/
70 // void amp_dump(const char *title, const void *buff, const int len)
71 // {
72 //     int i, j, written;
73 //     unsigned char ascii[16 + 1] = {0};
74 //     // char header[64]             = {0};
75 //     unsigned char *buf          = (unsigned char *)buff;
76 
77 //     written = 0;
78 
79 //     amp_debug(MOD_STR, "%s : ", title);
80 //     for (i = 0; i < len; ++i) {
81 //         if (i % 16 == 0) {
82 //             amp_debug(MOD_STR, "| %08X: ", (unsigned int)(i + (long)buff));
83 //             written += 8;
84 //         }
85 
86 //         amp_debug(MOD_STR, "%02X", buf[i]);
87 //         written += 2;
88 
89 //         if (i % 2 == 1) {
90 //             amp_debug(MOD_STR, " ");
91 //             written += 1;
92 //         }
93 //         sprintf((char *)ascii + i % 16, "%c",
94 //                 ((buf[i] >= ' ' && buf[i] <= '~') ? buf[i] : '.'));
95 
96 //         if (((i + 1) % 16 == 0) || (i == len - 1)) {
97 //             for (j = 0; j < 48 - written; ++j) {
98 //                 amp_debug(MOD_STR, " ");
99 //             }
100 
101 //             amp_debug(MOD_STR, " %s", ascii);
102 //             amp_debug(MOD_STR, "");
103 
104 //             written = 0;
105 //             memset(ascii, 0, sizeof(ascii));
106 //         }
107 //     }
108 //     amp_debug(MOD_STR, "%s",
109 //            "+"
110 //            "-----------------------"
111 //            "-----------------------"
112 //            "-----------------------");
113 
114 //     return;
115 // }
116 
py_version_get(char * version)117 int py_version_get(char *version)
118 {
119     const char *amp_version_fmt = "amp-v%s-g%s-%s-%s";
120 
121     aos_snprintf(version, AMP_VERSION_LENGTH, amp_version_fmt, AMP_VERSION_NUMBER, AMP_GIT_COMMIT, AMP_MODULE_HARDWARE,
122                  AMP_MODULE_SOFTWARE);
123     return 0;
124 }
125 
py_app_version_get(char * version)126 int py_app_version_get(char *version)
127 {
128     const char *amp_version_fmt = "amp-v%s";
129     aos_snprintf(version, 64, amp_version_fmt, AMP_VERSION_NUMBER);
130     return 0;
131 }
132