Skip to content

Commit 56fac4c

Browse files
committed
siwisdk framework for siwi gsm modules
Initial commit Signed-off-by: Ajay Bhargav <[email protected]>
0 parents  commit 56fac4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+10838
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.bat eol=crlf

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
docs/_build
2+
docs/xml
3+
docs/inc
4+
__pycache__/
5+
.vscode/

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SIWISDK
2+
3+
Software development kit for SIWI GSM modules

docs/Doxyfile

Lines changed: 2661 additions & 0 deletions
Large diffs are not rendered by default.

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/_ext/gen_include.py

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
#file modified from esp-idf extension
2+
import os
3+
import os.path
4+
import re
5+
import subprocess
6+
#from util import copy_if_modified
7+
8+
ALL_KINDS = [
9+
("function", "Functions"),
10+
("union", "Unions"),
11+
("struct", "Structures"),
12+
("define", "Macros"),
13+
("typedef", "Type Definitions"),
14+
("enum", "Enumerations")
15+
]
16+
"""list of items that will be generated for a single API file
17+
"""
18+
19+
def setup(app):
20+
app.connect('builder-inited', run_doxygen)
21+
return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '1.0'}
22+
23+
def run_doxygen(app):
24+
print("Running doxygen with Doxyfile")
25+
# note: run Doxygen in the build directory, so the xml & xml_in files end up in there
26+
subprocess.check_call(["doxygen", "Doxyfile"])
27+
# Generate 'api_name.inc' files from the Doxygen XML files
28+
convert_api_xml_to_inc(app, "Doxyfile")
29+
30+
def convert_api_xml_to_inc(app, doxyfile):
31+
""" Generate header_file.inc files
32+
with API reference made of doxygen directives
33+
for each header file
34+
specified in the 'INPUT' statement of the Doxyfile.
35+
"""
36+
37+
xml_directory_path = "xml"
38+
inc_directory_path = "inc"
39+
40+
if not os.path.isdir(xml_directory_path):
41+
raise RuntimeError("Directory {} does not exist!".format(xml_directory_path))
42+
43+
if not os.path.exists(inc_directory_path):
44+
os.makedirs(inc_directory_path)
45+
46+
header_paths = get_doxyfile_input_paths(app, doxyfile)
47+
print("Generating 'api_name.inc' files with Doxygen directives")
48+
for header_file_path in header_paths:
49+
api_name = get_api_name(header_file_path)
50+
inc_file_path = inc_directory_path + "/" + api_name + ".inc"
51+
rst_output = generate_directives(header_file_path, xml_directory_path)
52+
53+
previous_rst_output = ''
54+
if os.path.isfile(inc_file_path):
55+
with open(inc_file_path, "r", encoding='utf-8') as inc_file_old:
56+
previous_rst_output = inc_file_old.read()
57+
58+
if previous_rst_output != rst_output:
59+
with open(inc_file_path, "w", encoding='utf-8') as inc_file:
60+
inc_file.write(rst_output)
61+
62+
63+
def get_doxyfile_input_paths(app, doxyfile_path):
64+
"""Get contents of Doxyfile's INPUT statement.
65+
66+
Returns:
67+
Contents of Doxyfile's INPUT.
68+
69+
"""
70+
if not os.path.isfile(doxyfile_path):
71+
raise RuntimeError("Doxyfile '{}' does not exist!".format(doxyfile_path))
72+
73+
print("Getting Doxyfile's INPUT")
74+
75+
with open(doxyfile_path, "r", encoding='utf-8') as input_file:
76+
line = input_file.readline()
77+
# read contents of Doxyfile until 'INPUT' statement
78+
while line:
79+
if line.find("INPUT") == 0:
80+
break
81+
line = input_file.readline()
82+
83+
doxyfile_INPUT = []
84+
line = input_file.readline()
85+
# skip input_file contents until end of 'INPUT' statement
86+
while line:
87+
if line.isspace():
88+
# we have reached the end of 'INPUT' statement
89+
break
90+
# process only lines that are not comments
91+
if line.find("#") == -1:
92+
# extract header file path inside components folder
93+
m = re.search("include/(.*\.h)", line) # noqa: W605 - regular expression
94+
header_file_path = m.group(0)
95+
96+
doxyfile_INPUT.append(header_file_path)
97+
98+
# proceed reading next line
99+
line = input_file.readline()
100+
101+
return doxyfile_INPUT
102+
103+
104+
def get_api_name(header_file_path):
105+
"""Get name of API from header file path.
106+
107+
Args:
108+
header_file_path: path to the header file.
109+
110+
Returns:
111+
The name of API.
112+
113+
"""
114+
api_name = ""
115+
regex = r".*/(.*)\.h"
116+
m = re.search(regex, header_file_path)
117+
if m:
118+
api_name = m.group(1)
119+
120+
return api_name
121+
122+
123+
def generate_directives(header_file_path, xml_directory_path):
124+
"""Generate API reference with Doxygen directives for a header file.
125+
126+
Args:
127+
header_file_path: a path to the header file with API.
128+
129+
Returns:
130+
Doxygen directives for the header file.
131+
132+
"""
133+
134+
api_name = get_api_name(header_file_path)
135+
136+
# in XLT file name each "_" in the api name is expanded by Doxygen to "__"
137+
xlt_api_name = api_name.replace("_", "__")
138+
xml_file_path = "%s/%s_8h.xml" % (xml_directory_path, xlt_api_name)
139+
140+
rst_output = ""
141+
rst_output = ".. File automatically generated by 'gen-dxd.py'\n"
142+
rst_output += "\n"
143+
rst_output += get_rst_header("Header File")
144+
rst_output += "* :header_src_file:`" + header_file_path + "`\n"
145+
rst_output += "\n"
146+
147+
try:
148+
import xml.etree.cElementTree as ET
149+
except ImportError:
150+
import xml.etree.ElementTree as ET
151+
152+
tree = ET.ElementTree(file=xml_file_path)
153+
for kind, label in ALL_KINDS:
154+
rst_output += get_directives(tree, kind)
155+
156+
return rst_output
157+
158+
159+
def get_rst_header(header_name):
160+
"""Get rst formatted code with a header.
161+
162+
Args:
163+
header_name: name of header.
164+
165+
Returns:
166+
Formatted rst code with the header.
167+
168+
"""
169+
170+
rst_output = ""
171+
rst_output += header_name + "\n"
172+
rst_output += "^" * len(header_name) + "\n"
173+
rst_output += "\n"
174+
175+
return rst_output
176+
177+
178+
def select_unions(innerclass_list):
179+
"""Select unions from innerclass list.
180+
181+
Args:
182+
innerclass_list: raw list with unions and structures
183+
extracted from Dogygen's xml file.
184+
185+
Returns:
186+
Doxygen directives with unions selected from the list.
187+
188+
"""
189+
190+
rst_output = ""
191+
for line in innerclass_list.splitlines():
192+
# union is denoted by "union" at the beginning of line
193+
if line.find("union") == 0:
194+
union_id, union_name = re.split(r"\t+", line)
195+
rst_output += ".. doxygenunion:: "
196+
rst_output += union_name
197+
rst_output += "\n"
198+
199+
return rst_output
200+
201+
202+
def select_structs(innerclass_list):
203+
"""Select structures from innerclass list.
204+
205+
Args:
206+
innerclass_list: raw list with unions and structures
207+
extracted from Dogygen's xml file.
208+
209+
Returns:
210+
Doxygen directives with structures selected from the list.
211+
Note: some structures are excluded as described on code below.
212+
213+
"""
214+
215+
rst_output = ""
216+
for line in innerclass_list.splitlines():
217+
# structure is denoted by "struct" at the beginning of line
218+
if line.find("struct") == 0:
219+
# skip structures that are part of union
220+
# they are documented by 'doxygenunion' directive
221+
if line.find("::") > 0:
222+
continue
223+
struct_id, struct_name = re.split(r"\t+", line)
224+
rst_output += ".. doxygenstruct:: "
225+
rst_output += struct_name
226+
rst_output += "\n"
227+
rst_output += " :members:\n"
228+
rst_output += "\n"
229+
230+
return rst_output
231+
232+
233+
def get_directives(tree, kind):
234+
"""Get directives for specific 'kind'.
235+
236+
Args:
237+
tree: the ElementTree 'tree' of XML by Doxygen
238+
kind: name of API "kind" to be generated
239+
240+
Returns:
241+
Doxygen directives for selected 'kind'.
242+
Note: the header with "kind" name is included.
243+
244+
"""
245+
246+
rst_output = ""
247+
if kind in ["union", "struct"]:
248+
innerclass_list = ""
249+
for elem in tree.iterfind('compounddef/innerclass'):
250+
innerclass_list += elem.attrib["refid"] + "\t" + elem.text + "\n"
251+
if kind == "union":
252+
rst_output += select_unions(innerclass_list)
253+
else:
254+
rst_output += select_structs(innerclass_list)
255+
else:
256+
for elem in tree.iterfind(
257+
'compounddef/sectiondef/memberdef[@kind="%s"]' % kind):
258+
name = elem.find('name')
259+
rst_output += ".. doxygen%s:: " % kind
260+
rst_output += name.text + "\n"
261+
if rst_output:
262+
all_kinds_dict = dict(ALL_KINDS)
263+
rst_output = get_rst_header(all_kinds_dict[kind]) + rst_output + "\n"
264+
265+
return rst_output

docs/_ext/link_roles.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#based on https://protips.readthedocs.io/link-roles.html
2+
#some part taken from esp-idf extension link-roles.py
3+
4+
import os
5+
import subprocess
6+
from docutils import nodes
7+
8+
def get_github_rev():
9+
try:
10+
path = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
11+
try:
12+
tag = subprocess.check_output(['git', 'describe', '--exact-match']).strip().decode('utf-8')
13+
except subprocess.CalledProcessError:
14+
tag = None
15+
print('Git commit ID: ', path)
16+
if tag:
17+
print('Git tag: ', tag)
18+
return tag
19+
except subprocess.CalledProcessError:
20+
path = "test"
21+
return path
22+
23+
def setup(app):
24+
app.add_role('github', autolink('https://github.com/%s'))
25+
app.add_role('header_src_file', autolink('https://github.com/ajaybhargav/siwisdk/blob/%s/%s'))
26+
return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '1.0'}
27+
28+
def autolink(pattern):
29+
def role(name, rawtext, text, lineno, inliner, options={}, content=[]):
30+
rev = get_github_rev()
31+
url = pattern % (rev,text,)
32+
node = nodes.reference(rawtext, text, refuri=url, **options)
33+
return [node], []
34+
return role

docs/_static/.empty

Whitespace-only changes.

docs/_templates/.empty

Whitespace-only changes.

docs/book/api/crypto/aes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AES Encryption API
2+
==================

0 commit comments

Comments
 (0)