好的,作为一名高级嵌入式软件开发工程师,我将为您详细阐述针对 “YuzukiRuler 随身Linux小尺子” 项目的最佳代码设计架构,并提供具体的C代码实现示例。这个项目旨在构建一个可靠、高效、可扩展的嵌入式系统平台,我们将从需求分析出发,贯穿系统实现、测试验证到维护升级的整个流程,并确保所采用的技术和方法都经过实践验证。
关注微信公众号,提前获取相关推文
项目概述:YuzukiRuler 随身Linux小尺子
YuzukiRuler 是一款便携式的嵌入式Linux设备,它集成了以下关键功能:
- 尺子功能:核心功能,用于测量长度。
- 1.14英寸小屏幕:用于显示测量结果、系统信息和用户界面。
- 板载UART:用于串口通信,例如调试、数据传输等。
- OTG USB:支持USB On-The-Go,可以作为USB设备或主机使用,例如连接电脑或外部设备。
- 2.4G Wi-Fi:支持无线网络连接,用于网络冲浪、数据传输、远程控制等。
- Linux操作系统:运行在嵌入式处理器上,提供丰富的软件生态和灵活性。
系统架构设计
为了实现 YuzukiRuler 的功能并满足可靠性、高效性和可扩展性的要求,我们将采用分层架构的设计模式。这种架构将系统划分为多个独立的层次,每个层次负责特定的功能,并通过清晰定义的接口与其他层次进行交互。分层架构的优点包括:
- 模块化:每个层次都是一个独立的模块,易于开发、测试和维护。
- 可重用性:不同层次的模块可以被重用在其他项目中。
- 可扩展性:可以方便地添加新的层次或模块来扩展系统功能。
- 易于理解:清晰的层次结构使得系统更易于理解和维护。
针对 YuzukiRuler 项目,我们设计如下分层架构:
1 | +---------------------+ |
各层详细说明:
**硬件层 (Hardware Layer)**:
- 这是系统的最底层,包括嵌入式处理器(例如基于 ARM Cortex-A 系列的处理器),以及各种外围硬件组件,如:
- 1.14英寸 LCD 屏幕 (SPI接口)
- UART 接口
- OTG USB 接口
- 2.4G Wi-Fi 模块 (通常是 SDIO 或 SPI/UART 接口)
- GPIO 用于控制 LED、按钮等
- 存储器 (Flash, RAM)
- 电源管理电路
- 这是系统的最底层,包括嵌入式处理器(例如基于 ARM Cortex-A 系列的处理器),以及各种外围硬件组件,如:
**硬件抽象层 (HAL - Hardware Abstraction Layer)**:
- HAL 层位于硬件层之上,操作系统层之下。它的主要目的是隔离硬件差异,为上层软件提供统一的硬件访问接口。
- HAL 层包含各种硬件驱动程序,例如:
- GPIO 驱动:控制 GPIO 引脚的输入输出,用于控制屏幕背光、读取按键状态等。
- UART 驱动:实现串口通信,用于调试信息输出和数据传输。
- SPI 驱动:驱动 SPI 总线,通常用于控制 LCD 屏幕和 Wi-Fi 模块。
- I2C 驱动:如果使用 I2C 设备,则需要 I2C 驱动。
- USB 驱动:支持 USB OTG 功能,作为设备或主机。
- Wi-Fi 驱动:驱动 Wi-Fi 模块,实现无线网络连接。
- HAL 层提供的接口应该是平台无关的,这样当底层硬件发生变化时,只需要修改 HAL 层,而上层软件不需要修改。
**操作系统层 (Operating System Layer)**:
- YuzukiRuler 采用 Linux 操作系统。Linux 内核提供了进程管理、内存管理、文件系统、网络协议栈等核心功能。
- Linux 操作系统为上层软件提供了丰富的系统调用接口和驱动框架,极大地简化了嵌入式系统的开发。
- 我们可以选择一个轻量级的 Linux 发行版,例如 Buildroot 或 Yocto Project 构建定制化的 Linux 系统镜像,以满足 YuzukiRuler 的特定需求。
**中间件层 (Middleware Layer)**:
- 中间件层构建在操作系统层之上,为应用层提供常用的服务和功能组件。
- 常见的中间件组件包括:
- 设备管理:管理系统中的各种设备,例如屏幕、Wi-Fi 模块等。
- 网络协议栈:TCP/IP 协议栈,用于实现网络通信。
- 图形库:例如 Framebuffer 或 SDL,用于在屏幕上绘制图形和文本。
- 文件系统:用于管理存储在 Flash 中的文件,例如配置文件、用户数据等。
- **GUI 框架 (可选)**:例如 Qt Embedded 或 **GTK+**,如果需要更复杂的图形用户界面。
- **加密库 (可选)**:例如 OpenSSL,用于网络安全通信。
- **JSON/XML 解析库 (可选)**:用于处理网络数据格式。
**应用层 (Application Layer)**:
- 应用层是系统的最高层,包含运行在 YuzukiRuler 上的应用程序。
- 对于 YuzukiRuler 项目,应用层主要包括:
- **用户界面 (UI)**:负责用户交互,例如显示测量结果、系统菜单、Wi-Fi 设置等。
- 尺子逻辑:处理尺子功能的核心逻辑,例如读取传感器数据、计算长度、校准等 (如果采用传感器辅助测量)。 在 YuzukiRuler 的情况下,尺子功能更偏向于视觉尺,屏幕上的刻度显示和触摸交互是重点。
- 网络应用:基于 Wi-Fi 实现的网络功能,例如:
- 网页浏览 (如果硬件性能允许,可以集成轻量级浏览器)。
- 数据同步:将测量数据同步到云端服务器或电脑。
- 远程控制:通过网络远程控制 YuzukiRuler。
- OTA 升级:通过网络下载和更新系统固件。
代码实现 (C 语言示例)
为了演示上述架构,我将提供一些 C 语言代码示例,涵盖各个层次的关键功能。由于 3000 行代码的篇幅限制,我将重点展示核心模块的代码结构和关键接口,并使用伪代码或注释来简化一些细节。
1. 硬件抽象层 (HAL) 示例:
hal_gpio.h
1 |
|
hal_gpio.c
1 |
|
hal_uart.h
1 |
|
hal_uart.c
1 |
|
hal_spi.h (类似 GPIO 和 UART,此处省略具体代码)
hal_spi.c (类似 GPIO 和 UART,此处省略具体代码)
2. 板级支持包 (BSP) 示例:
bsp.h
1 |
|
bsp.c
1 |
|
3. 中间件层示例:
lcd_driver.h (简化版的 LCD 驱动头文件)
1 |
|
lcd_driver.c (简化版的 LCD 驱动实现)
1 |
|
wifi_driver.h (简化版的 Wi-Fi 驱动头文件)
1 |
|
wifi_driver.c (简化版的 Wi-Fi 驱动实现,实际 Wi-Fi 驱动会非常复杂,通常需要调用厂商提供的 SDK 或使用 Linux 网络接口)
1 |
|
4. 应用层示例:
main.c (主应用程序)
1 |
|
构建和编译
要构建和编译 YuzukiRuler 的嵌入式 Linux 系统,通常需要以下步骤:
- 选择嵌入式 Linux 构建工具: 例如 Buildroot 或 Yocto Project。
- 配置构建环境: 配置目标处理器架构、Linux 内核版本、根文件系统类型、软件包选择等。
- 编写设备树 (Device Tree): 描述硬件平台的硬件资源配置,例如 CPU、内存、外设等。
- 编译 Linux 内核: 使用交叉编译工具链为目标架构编译 Linux 内核。
- 编译驱动程序和应用程序: 编译 HAL 驱动、中间件组件和应用程序代码。
- 构建根文件系统: 将编译好的内核、驱动、库、应用程序等打包到根文件系统中。
- 生成系统镜像: 将内核、设备树和根文件系统打包成可烧录到 Flash 存储器的系统镜像。
- 烧录系统镜像: 使用烧录工具将系统镜像烧录到 YuzukiRuler 的 Flash 存储器中。
测试验证
在开发过程中,需要进行全面的测试验证,以确保系统的可靠性和稳定性。测试包括:
- 单元测试: 针对各个模块 (例如 HAL 驱动、LCD 驱动、Wi-Fi 驱动) 进行单元测试,验证模块的功能是否正确。
- 集成测试: 将各个模块集成起来进行测试,验证模块之间的交互是否正常。
- 系统测试: 对整个系统进行功能测试、性能测试、压力测试、可靠性测试等,验证系统是否满足需求。
- 用户验收测试 (UAT): 邀请用户参与测试,收集用户反馈,确保系统满足用户需求。
维护升级
为了保持 YuzukiRuler 的功能和性能,需要进行维护升级。维护升级包括:
- Bug 修复: 修复系统中发现的 bug。
- 安全更新: 更新系统安全补丁,防止安全漏洞。
- 功能增强: 添加新的功能或改进现有功能。
- 性能优化: 优化系统性能,提高运行效率。
对于嵌入式 Linux 系统,常用的升级方式包括:
- 本地升级: 通过 USB 或 UART 接口连接电脑,使用烧录工具更新系统镜像。
- OTA (Over-The-Air) 升级: 通过 Wi-Fi 网络下载新的系统镜像,并自动更新系统。OTA 升级是更方便用户的方式,但需要设计可靠的升级流程和安全机制。
总结
YuzukiRuler 随身Linux小尺子项目采用分层架构进行代码设计,将系统划分为硬件层、HAL 层、操作系统层、中间件层和应用层,实现了模块化、可重用性、可扩展性和易于维护性。代码示例展示了各层次的关键模块和接口,涵盖了 GPIO、UART、SPI 驱动、LCD 驱动、Wi-Fi 驱动以及主应用程序的框架。
为了构建一个可靠、高效、可扩展的系统平台,还需要关注以下方面:
- 代码规范: 遵循统一的代码风格和编码规范,提高代码可读性和可维护性。
- 错误处理: 完善的错误处理机制,增强系统的鲁棒性。
- 资源管理: 合理的资源管理,例如内存管理、文件系统管理等,提高系统效率。
- 安全性: 考虑系统安全性,例如数据加密、访问控制、安全启动等。
- 文档: 编写清晰的文档,包括设计文档、API 文档、用户手册等,方便开发、维护和使用。
通过以上架构设计和代码实现,并结合实践验证的技术和方法,我们可以构建一个功能完善、性能优良、可靠稳定的 YuzukiRuler 随身Linux小尺子产品。 实际项目中,代码量会远超 3000 行,包含更完善的驱动、更丰富的功能和更复杂的逻辑。这里提供的代码示例旨在展示整体架构和关键模块的设计思路。
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
Error executing command: Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 652, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connection.py”, line 805, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 465, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/ssl.py”, line 509, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File “/usr/lib/python3.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1071, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 789, in urlopen
response = self._make_request(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 490, in _make_request
raise new_e
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 667, in send
resp = conn.urlopen(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/connectionpool.py”, line 843, in urlopen
retries = retries.increment(
File “/home/tong/.local/lib/python3.10/site-packages/urllib3/util/retry.py”, line 519, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/tong/bin/desc_img3.py”, line 73, in
for chunk in client.models.generate_content_stream(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/models.py”, line 3722, in generate_content_stream
for response_dict in self.api_client.request_streamed(
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 341, in request_streamed
session_response = self._request(http_request, stream=True)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 263, in _request
return self._request_unauthorized(http_request, stream)
File “/home/tong/.local/lib/python3.10/site-packages/google/genai/_api_client.py”, line 284, in _request_unauthorized
response = http_session.send(request, stream=stream)
File “/home/tong/.local/lib/python3.10/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/tong/.local/lib/python3.10/site-packages/requests/adapters.py”, line 698, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’generativelanguage.googleapis.com’, port=443): Max retries exceeded with url: /v1beta/models/gemini-2.0-flash-thinking-exp-01-21:streamGenerateContent?alt=sse (Caused by SSLError(SSLZeroReturnError(6, ‘TLS/SSL connection has been closed (EOF) (_ssl.c:997)’)))