Skip to content

Commit bccf73d

Browse files
committed
Initial commit.
0 parents  commit bccf73d

Some content is hidden

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

63 files changed

+6722
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.log
2+
dist
3+
quecpython.egg-info
4+
build/
5+
.idea
6+
__pycache__

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# pyi文件介绍
2+
3+
本文件主要简单介绍pyi文件如何编写。详细介绍请参阅:<https://peps.python.org/pep-0484/>
4+
5+
什么是pyi文件?
6+
在Python3中,`.pyi`文件是存根文件(stub file)。这个"pyi"中的"i"代表接口即interface,作为公共接口。
7+
**存根文件仅包含模块公共接口的描述,没有任何实现。**
8+
9+
编写请参考模板:`usocket.pyi`
10+
11+
# 示例讲解
12+
13+
## 示例一
14+
15+
以下是pyi文件的函数定义
16+
17+
- 1、如下参数后通过冒号标识该参数的类型(python基础类型:str、int、list、tuple...更多自定义类型参阅PEP484)。
18+
- 2、函数定义关键字def语句中,形参列表后,冒号前通过`-> {类型}`来标识当前函数的返回值类型。
19+
- 3、函数体首行注释(注:必须是三对双引号的注释且必须是函数体首行)
20+
- 4、文档建议采用reStructuredText风格。详细请参阅:<https://wiki.python.org/moin/reStructuredText>
21+
22+
```python
23+
def getaddrinfo(host: str, port: int = 8080):
24+
"""Parses the domain name of DNS. —— (此处是当前函数的简略注释信息。)
25+
26+
Parses the domain name of the host (host) and port (port) into a 5-tuple sequence used to create the socket. The structure of the tuple is below:
27+
(family, type, proto, canonname, sockaddr) —— (此处是当前函数的详细注释信息。)
28+
29+
@param host: The domain name of the host.
30+
@param port: The port.
31+
@return: (family, type, proto, canonname, sockaddr)
32+
"""
33+
... # 注:pyi文件中允许使用"..."代替任何实现细节。它是仅包含类型信息的文件,没有运行时代码。另,此处函数体可以留空,`...`是非必要的。
34+
```
35+
36+
## 示例二
37+
38+
该示例表示一个只有单行文档注释的函数定义。
39+
40+
```python
41+
def allocate_lock():
42+
"""Creates and Return a mutex object."""
43+
```
44+
45+
46+
## 示例三
47+
48+
```python
49+
AF_INET = ... # 地址族,IPV4类型。
50+
AF_INET6 = ... # 地址族,IPV6类型。
51+
SOCK_STREAM = ... # socket类型,TCP的流式套接字。
52+
IPPROTO_TCP = ... # 协议号,TCP协议。
53+
IPPROTO_UDP = ... # 协议号,UDP协议。
54+
55+
56+
class socket(object):
57+
"""Socket"""
58+
59+
def __init__(self, af=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP):
60+
"""Socket对象初始化函数。
61+
62+
NOTE:
63+
根据给定的地址族、套接字类型以及协议类型参数,创建一个新的套接字对象。
64+
在大多数情况下不需要指定proto,也不建议这样做,因为某些MicroPython端口可能会省略IPPROTO_*常量。
65+
66+
@af:地址族(参考常量说明)。
67+
@type:socket类型(参考常量说明)。
68+
@proto:协议号(参考常量说明)。
69+
"""
70+
71+
def bind(self, address: tuple = ("192.168.0.1", 80)):
72+
"""该方法用于套接字绑定指定address,必须尚未绑定。
73+
74+
NOTE:
75+
1、作为服务器时,需要进行绑定,以固定服务器的address。
76+
2、作为客户端时,绑定address用来指定套接字进行数据处理(配合usocket.TCP_CUSTOMIZE_PORT使用)。
77+
78+
@address:包含地址和端口号的元组或列表。
79+
"""
80+
81+
def listen(self, backlog: int):
82+
"""该方法用于套接字服务端开启监听客户端连接,可指定最大客户端连接数。
83+
84+
@backlog:接受套接字的最大个数,至少为0。
85+
"""
86+
87+
def accept(self):
88+
"""该方法用于套接字服务端接受连接请求。
89+
90+
@return:成功返回元组,包含新的套接字和客户端地址以及客户端端口,形式为:(conn,address,port)。
91+
conn,新的套接字对象,用来和客户端交互;
92+
address,连接到服务器的客户端地址;
93+
port,连接到服务器的客户端端口。
94+
"""
95+
```

README.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
News
2+
====
3+
4+
- October 2023: quecpython_api_stubs 0.1.1 released!
5+
6+
Overview
7+
========
8+
9+
Provides a programing autocomplete of QuecPython for IDE.It is pure Python and works on
10+
Python 3.7+.
11+
12+
Install most recent stable with "pip install quecpython_api_stubs".
13+
14+
Useful links:
15+
16+
- Project on PyPI: https://pypi.org/project/quecpython_api_stubs/
17+
- The documentation for latest code is at: https://github.com/QuecPython/quecpython_api_stubs

VERSION

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

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# enter `thonny-quecpython_stubs` dir then execute below shell command
2+
python setup.py sdist bdist_wheel

quecpython_stubs/__init__.pyi

Whitespace-only changes.

quecpython_stubs/__main__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import win32api
2+
import win32con
3+
from pathlib import Path
4+
5+
6+
def load():
7+
# 获取QuecPython的环境变量
8+
QUECPYTHON_PATH = str(Path(__file__).parent)
9+
# 打开环境变量键
10+
key = win32api.RegOpenKeyEx(
11+
win32con.HKEY_LOCAL_MACHINE,
12+
'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',
13+
0,
14+
win32con.KEY_ALL_ACCESS
15+
)
16+
# 更新环境变量值
17+
win32api.RegSetValueEx(key, 'PYTHONPATH', 0, 2, QUECPYTHON_PATH)
18+
# 关闭键
19+
win32api.RegCloseKey(key)
20+
21+
22+
if __name__ == '__main__':
23+
load()

quecpython_stubs/_thread.pyi

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
"""
2+
Function:
3+
_thread module contains features related to thread operations, and provides methods for creating and deleting threads, and interfaces related to mutex and semaphore.
4+
5+
Descriptions taken from:
6+
https://python.quectel.com/doc/API_reference/en/stdlib/_thread.html
7+
"""
8+
9+
10+
def get_ident():
11+
"""Requires the current thread number.
12+
13+
@return: Returns the current thread number.
14+
"""
15+
16+
def stack_size(size):
17+
""" set thread stack size
18+
Setting or getting the stack size which is used to create a thread (Unit: byte) depends on whether size is provided. The stack size is 8448 bytes by default, with a minimum of 8192 bytes.
19+
20+
@param size: Sets the stack size which is used to create a thread when size is provided.
21+
@return: Returns the stack size which is used to create a thread when size is not provided.
22+
"""
23+
24+
def start_new_thread(function, args):
25+
"""create new thread.
26+
Creates a thread to receive the executing function and the parameter of the executed function, and passes an empty tuple if function has no parameters.
27+
28+
@param function: The executing function of the thread.
29+
@param args: The parameter of the executing function of the thread, which passes an empty tuple when the function has no parameters.
30+
@return: Returns the ID of the created thread.
31+
"""
32+
33+
def threadIsRunning(thread_id):
34+
"""check if thread is running or not according to `thread_id`.
35+
36+
:param thread_id: thread ident, a int type.
37+
:return: True or False
38+
"""
39+
40+
def stop_thread(thread_id):
41+
"""Deletes a thread. The main thread cannot be deleted.
42+
43+
@param thread_id: The returned ID when the thread is created. If the value is 0, the current thread is deleted.
44+
@return: None
45+
"""
46+
47+
def get_heap_size():
48+
"""Gets the remaining size of heap in the system.
49+
50+
@return: Returns the remaining size of heap in the system. (Unit: byte)
51+
"""
52+
53+
class Lock(object):
54+
55+
def acquire(self):
56+
"""Acquires the lock.
57+
58+
@return: True-Successful execution; False-Failed execution.
59+
"""
60+
61+
def release(self):
62+
"""Releases the lock."""
63+
64+
def locked(self):
65+
"""Returns the status of the lock.
66+
67+
@return: True indicates the status of the lock has been required by some thread; False indicates the status of the lock has not been required by the thread.
68+
"""
69+
70+
def allocate_lock() -> Lock:
71+
"""Creates a mutex object.
72+
73+
@return: Returns the created mutex object.
74+
"""
75+
76+
def delete_lock(lock):
77+
"""Deletes the created mutex.
78+
79+
@param lock: The returned mutex object when the mutex is created.
80+
@return: None
81+
"""
82+
83+
class Semphore(object):
84+
85+
86+
def acquire(self):
87+
"""Acquires the semphore."""
88+
89+
def release(self):
90+
"""Releases the semphore."""
91+
92+
def getCnt(self):
93+
"""Gets the maximum value of the semaphore count and the current remaining count value.
94+
95+
@return: (maxCnt, curCnt)-tuple: maxCnt is the maximum count value, and curCnt is the current remaining count value.
96+
"""
97+
98+
def allocate_semphore(initcount) -> Semphore:
99+
"""Creates a semphore object.
100+
101+
@param initcount: The initial count value and also the maximum value of the semaphore.
102+
@return: Returns the created semphore object.
103+
"""
104+
105+
def delete_semphore(semphore):
106+
"""Deletes the created semphore.
107+
108+
@param semphore: The returned semphore object when the semphore is created.
109+
@return: None
110+
"""

quecpython_stubs/app_fota.pyi

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Function:
3+
The app_fota module is used for user file upgrades.
4+
5+
Descriptions taken from:
6+
https://python.quectel.com/doc/API_reference/en/syslib/app_fota.html
7+
"""
8+
9+
10+
class new(object):
11+
12+
def __init__(self):
13+
"""Creates an app_fota object."""
14+
15+
def download(self, url, file_name):
16+
"""Downloads a single file.
17+
18+
:param url: String type. The URL of the file to be downloaded.
19+
:param file_name: String type. The absolute path of the local file to be upgraded.
20+
:return: 0-Successful execution; -1-Failed execution.
21+
"""
22+
23+
def bulk_download(self, info):
24+
"""Downloads bulk files.
25+
26+
:param info: List type. The bulk download lists. Each element of the list is a dictionary containing url and file_name.
27+
:return: Returns the list of failed downloads in list type when the download fails.Returns NULL when the download succeeds.
28+
"""
29+
30+
def set_update_flag(self):
31+
"""Sets the upgrade flag.
32+
33+
fter the upgrade flag is set, call the restart interface to restart the module.
34+
After that, the upgrade process can be started.
35+
You can enter the application once the upgrade completes.
36+
"""

quecpython_stubs/atcmd.pyi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Function:
3+
This module provides a method for sending AT commands, allowing the QuecPython module to send AT commands through Python code.
4+
5+
Descriptions taken from:
6+
https://python.quectel.com/doc/API_reference/en/syslib/atcmd.html
7+
"""
8+
9+
10+
def sendSync(atcmd, resp, include_str, timeout):
11+
"""Sends an AT command to the module.
12+
13+
:param atcmd: String type. The AT command to be sent, and '\r\n' should be included.
14+
:param resp: String type. The string content returned by the AT command.
15+
:param include_str: String type. Keyword. The specific values are shown in the table below
16+
Value Description
17+
Empty string Gets all data returned by the AT command (excluding result data such as 'OK') and puts the data into the resp parameter.
18+
None-empty string Filter data containing the keyword and puts the data into the resp parameter.
19+
:param timeout: Integer type. Timeout. Unit: second.
20+
:return: Returns an integer value. 0 indicates successful execution and other values indicate failed execution.
21+
"""

0 commit comments

Comments
 (0)