Skip to content

Commit 53ac345

Browse files
committed
Initial commit.
0 parents  commit 53ac345

File tree

122 files changed

+4935
-0
lines changed

Some content is hidden

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

122 files changed

+4935
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.log

BUILD.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
构建python源码包与二进制包
2+
>>> python -m build

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# thonny_quecpython

setup.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from setuptools import setup, find_packages
2+
3+
4+
def readme():
5+
with open('README.md', encoding='utf-8') as f:
6+
content = f.read()
7+
return content
8+
9+
10+
setup(
11+
name='thonny-quecpython',
12+
version='0.1.0',
13+
description='quecpython programing kits',
14+
long_description=readme(),
15+
long_description_content_type='text/markdown',
16+
python_requires='>=3.7',
17+
license="MIT License",
18+
author='dustin.wei',
19+
author_email='dustin.wei@quectel.com',
20+
keywords=["QuecPython", "quecpython", "QuecPython Kits", "quecpython kits"],
21+
url='http://github.com/quecpython',
22+
classifiers=[
23+
"Programming Language :: Python :: 3",
24+
"License :: OSI Approved :: MIT License",
25+
"Operating System :: OS Independent",
26+
],
27+
platforms=["windows"],
28+
packages=find_packages(),
29+
package_data={
30+
"thonnycontrib.quecpython.fw": [
31+
"fw_config.json",
32+
"exes/aboot/*",
33+
"exes/blf_tools/*",
34+
"exes/NB/*",
35+
"exes/rda/*",
36+
],
37+
},
38+
install_requires=[
39+
'thonny>=4.1.1',
40+
'Pypubsub>=4.0.3'
41+
],
42+
)

thonnycontrib/__init__.py

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from thonny import get_workbench
2+
from thonny.languages import tr
3+
from thonny.plugins.micropython.mp_front import (
4+
add_micropython_backend,
5+
GenericBareMetalMicroPythonConfigPage,
6+
GenericBareMetalMicroPythonProxy,
7+
)
8+
from .view import QuecView, open_quecview
9+
10+
11+
def load_plugin():
12+
add_micropython_backend(
13+
"GenericQuecPython",
14+
GenericBareMetalMicroPythonProxy,
15+
tr("QuecPython (generic)"),
16+
GenericBareMetalMicroPythonConfigPage,
17+
sort_key="51",
18+
)
19+
20+
get_workbench().add_view(QuecView, tr("QuecPython Kits"), "s")
21+
get_workbench().add_command(
22+
'quecpython_kits',
23+
'tools',
24+
tr('QuecPython Kits'),
25+
open_quecview
26+
)

thonnycontrib/quecpython/api.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from collections import namedtuple
2+
from logging import getLogger
3+
from pubsub import pub
4+
from .fw import FwDownloadHandler, DownloadLogFile
5+
6+
logger = getLogger(__name__)
7+
8+
9+
class BaseApi(object):
10+
# communicate topic
11+
UPDATE_TOPIC = 'update' # must be different
12+
13+
# status code
14+
OK = 0x00
15+
ERROR = 0x01
16+
EXIT = 0x02
17+
18+
# transmission payload
19+
Payload = namedtuple('Payload', ['code', 'data', 'exec'])
20+
21+
@classmethod
22+
def bind(cls, handler):
23+
pub.subscribe(handler, cls.UPDATE_TOPIC)
24+
25+
def emit(self, data):
26+
pub.sendMessage(
27+
self.UPDATE_TOPIC,
28+
payload=self.Payload(code=self.OK, data=data, exec=None)
29+
)
30+
31+
def error(self, e):
32+
pub.sendMessage(
33+
self.UPDATE_TOPIC,
34+
payload=self.Payload(code=self.ERROR, data=None, exec=e)
35+
)
36+
37+
def exit(self):
38+
pub.sendMessage(
39+
self.UPDATE_TOPIC,
40+
payload=self.Payload(code=self.EXIT, data=None, exec=None)
41+
)
42+
43+
def run(self):
44+
raise NotImplementedError('you must implement this method in sub class.')
45+
46+
def __call__(self):
47+
try:
48+
self.run()
49+
except Exception as e:
50+
self.error(e)
51+
finally:
52+
self.exit()
53+
54+
55+
class DownLoadFWApi(BaseApi):
56+
UPDATE_TOPIC = 'UPDATE_PROGRESS'
57+
58+
def __init__(self, firmware_file_path, comport):
59+
self.firmware_file_path = firmware_file_path
60+
self.comport = comport
61+
62+
def run(self):
63+
logger.info('enter download_firmware_api function. args: {}'.format((self.firmware_file_path, self.comport)))
64+
fw_download_handler = FwDownloadHandler(self.firmware_file_path, self.comport)
65+
for data in fw_download_handler.download():
66+
self.emit(data)
67+
68+
def error(self, e):
69+
error_message = '{}\nsee log: {}'.format(str(e), DownloadLogFile.log_file_path)
70+
super().error(Exception(error_message))

0 commit comments

Comments
 (0)