From 33c481b4cc52b37748324329fdd14720aa88bc56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Sat, 23 Aug 2025 15:25:48 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96gitdiff.py=E4=B8=AD=E6=96=87?= =?utf8?q?=E5=90=8D=E6=96=87=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...45\345\217\243\350\257\264\346\230\216.md" | 179 ++++++++++++++++++ gitdiff.py | 34 +++- 2 files changed, 207 insertions(+), 6 deletions(-) create mode 100644 "cat1modem/src/quecpPython_SLIP\346\216\245\345\217\243\350\257\264\346\230\216.md" diff --git "a/cat1modem/src/quecpPython_SLIP\346\216\245\345\217\243\350\257\264\346\230\216.md" "b/cat1modem/src/quecpPython_SLIP\346\216\245\345\217\243\350\257\264\346\230\216.md" new file mode 100644 index 000000000..5a7e909b7 --- /dev/null +++ "b/cat1modem/src/quecpPython_SLIP\346\216\245\345\217\243\350\257\264\346\230\216.md" @@ -0,0 +1,179 @@ +###SLIP-串口网卡协议 + +模块功能: 通过串口slip协议,建立网络通讯 +#### slip网卡构建 +> **slip.construct(uart, slip_type, external_ip)** + +构建串口网卡 +* 参数 + +| 参数 | 类型 | 说明 | +| ---- | ---- | ---| +| uart | int | 根据串口wiki说明,指定串口号 | +| slip_type | int | 网卡类型 | +| external_ip | int | 指令默认网卡的ip,默认填0 | + +* slip_type参数说明 + +| 序号 | 类型 | 说明 | +| ---- | ---- | ---- | +| 0 | SLIP_INNER | 作为内部网卡,此时使用lte连接外部网络 | +| 1 | SLIP_OUTER | 作为外部网卡,此时通过esp连接外部网络| + +* 返回值 + 成功返回整型值0,其他值表示失败。 +* 示例 +```python + import slip + ret=slip.construct(UART.UART2, slip.SLIP_INNER, 0) +``` +#### 获取slip网卡ip信息 +> **slipInfo=slip.ipconfig()** + +获取slip网卡ip信息 +* 参数 +无 +* 返回值 + +| 参数 | 类型 |说明| +| ---- | ---- | ---| +| slipInfo | tuple | -1或者tuple类型的ip信息 | +* slipInfo参数说明 + +| 序号 | 类型 | 说明 | +| ---- | ---- | ---- | +| 0 | string | slip网卡ip | +| 1 | string | slip网卡子网掩码 | +| 1 | string | slip网卡网关| +| 1 | int | mtu信息| +* 示例 +```python + import slip + slipInfo=slip.ipconfig() + print(slipInfo) +``` +#### 移除slip网卡 +> **slip.destroy()** + +移除slip网卡 +* 参数 +无 +* 返回值 +无 +* 示例 +```python + import slip + slip.destroy() +``` +###设置默认网卡 +> **slip.set_default_netif(ip_str)** + +通过ip信息设置默认网卡 +* 参数 + +| 参数 | 类型|说明| +| ---- | ---- | ---| +| ip_str | string | 网卡ip信息 | + +* 返回值 +成功返回整型值0,其他值表示失败。 +* 示例 +```python + import slip + ip_str='192.168.1.10' + slip.set_default_netif(ip_str) +``` + +#### slip路由添加 +> **slip.router_add(ip_str, netmask_str)** + +添加slip网卡路由信息,注意这部分只有在使用slip时生效 +* 参数 + +| 参数 | 类型 |说明| +| ---- | ---- | ---| +| ip_str | string | 设置slip万卡转发的ip | +| netmask_str | string | 设置对应的子网掩码 | + +* 返回值 +成功返回整型值0,其他值表示失败。 +* 示例 +```python + import slip + ip_str='192.168.1.0' + netmask_str='255.255.255.0' + slip.router_add(ip_str, netmask_str) +``` + +#### slip路由删除 +> **slip.router_add(ip_str, netmask_str)** + +删除slip网卡路由信息,注意这部分只有在使用slip时生效 +* 参数 + +| 参数 | 类型 |说明| +| ---- | ---- | ---| +| ip_str | string | 设置slip万卡转发的ip | +| netmask_str | string | 设置对应的子网掩码 | + +* 返回值 + 成功返回整型值0,其他值表示失败。 +* 示例 +```python + import slip + ip_str='192.168.1.0' + netmask_str='255.255.255.0' + slip.router_delete(ip_str, netmask_str) +``` + +####使用示例 +```python +import slip +import dataCall +import utime +from machine import UART + + +def wait_datacall_success(): + global lteInfo + print('waiting datacall success...') + while 1: + lteInfo = dataCall.getInfo(1, 0) + if lteInfo != -1: + break + utime.sleep(2) + print('success get dataCall info: ') + print(lteInfo) + +def slip_start(): + wait_datacall_success() + # 创建slip网卡 + ret=slip.construct(UART.UART2, slip.SLIP_INNER, 0) + if ret != 0: + print('slip netif construct fail') + return -1 + # 获取slip的网络配置 + slipInfo=slip.ipconfig() + print('slip ipconfig: ') + print(slipInfo) + if lteInfo != -1: + # 设置默认网卡,当设置slip作为上网卡时不设置该接口,即SLIP_OUTER类型 + ret = slip.set_default_netif(lteInfo[2][2]) + if ret != 0: + print('slip set default netif fail') + return -1 + # 添加路由信息,设置网卡转发规则192.168.4.0表示ap的网段,255.255.255.0子网掩码 + ret = slip.router_add('192.168.4.0', '255.255.255.0') + if ret != 0: + print('slip add subnet routers fail') + return -1 + return 0 +def slip_stop(): + slip.destroy() + +err = slip_start() +if err == 0: + print('slip network card create success') +else: + print('slip network card create fail') +``` \ No newline at end of file diff --git a/gitdiff.py b/gitdiff.py index 48529eae5..e580d4f74 100644 --- a/gitdiff.py +++ b/gitdiff.py @@ -6,21 +6,28 @@ from pathlib import Path def run_git_command(command): try: + # 设置环境变量以正确处理中文文件名 + env = os.environ.copy() + env['LC_ALL'] = 'C.UTF-8' + env['LANG'] = 'C.UTF-8' + result = subprocess.run( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', errors='replace', - check=True + check=True, + env=env ) return result.stdout.strip() except subprocess.CalledProcessError as e: print(f"Error executing git command: {e.stderr}") - sys.exit(1) + # 不要立即退出,让调用者处理错误 + raise except UnicodeDecodeError as e: print(f"Encoding error: {e}") - sys.exit(1) + raise def main(): if len(sys.argv) > 3: @@ -198,9 +205,24 @@ def main(): dst.write(src.read()) else: # 从暂存区提取文件内容 - blob_content = run_git_command( - ["git", "show", f":{file_path}"] - ) + # 对于包含特殊字符的文件名,使用更安全的方式 + try: + blob_content = run_git_command( + ["git", "show", f":{file_path}"] + ) + except: + # 如果pathspec失败,尝试使用git cat-file + try: + # 获取文件的blob hash + blob_hash = run_git_command( + ["git", "ls-files", "--stage", file_path] + ).split()[1] + blob_content = run_git_command( + ["git", "cat-file", "blob", blob_hash] + ) + except: + print(f"Warning: Could not extract staged content for {file_path}") + continue with open(target_file, "w", encoding='utf-8') as dst: dst.write(blob_content) except Exception as e: -- 2.17.1