开发自己的 Web 框架
开发自己的 Web 框架
- 开发Web服务器主体程序
- 开发Web框架程序
- 使用模板来展示响应内容
- 开发框架的路由列表功能
- 采用装饰器的方式添加路由
- 电影列表页面的开发案例
接收web服务器的动态资源请求,给web服务器提供处理动态资源请求的服务。根据请求资源路径的后缀名进行判断
- 如果请求资源路径的后缀名是.html则是动态资源请求,让web框架程序进行处理。
- 否则是静态资源请求,让web服务器程序进行处理。
开发Web服务器主体程序
- 接受客户端 HTTP 请求(底层是 TCP)
- 判断请求是否是静态资源还是动态资源
- 如果是静态资源怎么处理
- 如果是动态资源怎么处理
- 关闭 Web 服务器
"""
#!/usr/bin/python3
# coding:utf-8
#
# Copyright (C) 2024 - 2024 Jasonakeke, Inc. All Rights Reserved
# @Desc :我们自己开发的 web 服务器
# @Time : 2024/7/31 22:17
# @Author : Code_By_Jasonakeke
# @Email : 2284037977@qq.com
# @File : my_web.py
# @IDE : PyCharm
"""
from socket import socket, AF_INET, SOCK_STREAM
from threading import Thread
from time import strftime, localtimefrom _socket import SOL_SOCKET, SO_REUSEADDRfrom MyFramework import handle_request# 开发自己的 web 服务器主类
class MyWebHttpServer(object):def __init__(self, port):# 创建 HTTP 服务器的套接字server_socket = socket(AF_INET, SOCK_STREAM)# 设置端口号复用,出现退出之后,不需要等待几分钟,直接释放端口server_socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, True)server_socket.bind(('', port))server_socket.listen(128)self.server_socket = server_socket# 处理请求的函数@staticmethoddef hande_browser_request(new_socket):# 接收客户端的请求recv_data = new_socket.recv(4096)# 如果没有收到数据,那么请求无效,关闭套接字,直接退出if len(recv_data) == 0:new_socket.close()return# 对接收的字节数据,转换成字符request_data = recv_data.decode('utf-8')print("浏览器请求的数据:", request_data)request_array = request_data.split(' ', maxsplit = 2)# 得到请求路径request_path = request_array[1]print("请求路径是:", request_path)# 如果请求路径是 /,自动设置为 /index.htmlif request_path == '/':request_path = '/index.html'# 根据请求路径来判断是否是动态资源函数静态资源if request_path.endswith('.html'):''' 动态资源的请求 '''# 动态资源的处理交给 Web 框架来处理,需要把请求参数传给 Web 框架,可能会有多个参数,所以采用字典结果params = {'request_path': request_path}# Web 框架处理动态资源请求之后,返回一个响应response = handle_request(params)new_socket.send(response)new_socket.close()else:''' 静态资源的请求 '''# 响应主体页面response_body = None# 响应头response_header = Noneresponse_type = 'text/html'# 响应头第一行response_first_line = None# 其实就是根据请求路径读取 /static/ 目录中静态的文件数据,响应给客户端try:# 读取 static 目录中的文件数据,rb 模式是一种兼容模式,可以打开图片,也可以打开 jswith open('static' + request_path, 'rb') as f:response_body = f.read()if request_path.endswith('.jpg'):response_type = 'image/wbep'response_first_line = 'HTTP/1.1 200 OK\r\n'# 响应头response_header = ('Content-Length: ' + str(len(response_body)) + '\r\n'+ 'Content-Type: ' + response_type + '; charset=iso-8859-1\r\n'+ 'Date: ' + strftime('%Y-%m-%d %H:%M:%S', localtime()) + '\r\n'+ 'Server: keke\r\n')except Exception as e:# 浏览器想读取的文件可能不存在with open('static/404.html', 'rb') as f:# 响应主体页面response_body = f.read()response_first_line = 'HTTP/1.1 404 Not Found\r\n'# 响应头response_header = ('Content-Length: ' + str(len(response_body)) + '\r\n'+ 'Content-Type: ' + response_type + '; charset=iso-8859-1\r\n'+ 'Date: ' + strftime('%Y-%m-%d %H:%M:%S', localtime()) + '\r\n'+ 'Server: keke\r\n')finally:# 组成响应数据,发给客户端response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_bodynew_socket.send(response)# 关闭套接字new_socket.close()# 启动服务器 ,并且接收客户端的请求def start(self):# 循环并且多线程来接收客户端的请求while True:new_socket, ip_port = self.server_socket.accept()print("客户端的 ip 和端口是:", ip_port)# 一个客户端请求交给一个线程处理sub_thread = Thread(target = self.hande_browser_request, args = (new_socket,))# 设置守护线程sub_thread.daemon = Truesub_thread.start()def main():# 创建服务器对象web_server = MyWebHttpServer(8080)# 启动服务器web_server.start()if __name__ == '__main__':main()
开发Web框架程序
- 根据请求路径,动态响应对应的数据
- 如果请求路径,没有对应的响应数据也需要返回404页面
"""
# coding:utf-8
#
# Copyright (C) 2024 - 2024 Jasonakeke, Inc. All Rights Reserved
# @Desc :自定义 Web 框架
# @Time : 2024/8/1 22:07
# @Author : Code_By_Jasonakeke
# @Email : 2284037977@qq.com
# @File : MyFramework.py
# @IDE : PyCharm
"""
from time import strftime, localtime# 处理动态资源请求
def handle_request(params):request_path = params['request_path']# 当前的请求路径有与之对应的动态响应if request_path == '/index.html':response = index()return responseelse:# 没有动态资源的数据,返回 404页面return page_not_found()# 专门处理 index.html 的请求
def index():data = strftime('%Y-%m-%d %H:%M:%S', localtime())response_body = dataresponse_first_line = 'HTTP/1.1 200 OK\r\n'# 响应头response_header = ('Content-Length: ' + str(len(response_body)) + '\r\n'+ 'Content-Type: text/html; charset=iso-8859-1\r\n'+ 'Date: ' + strftime('%Y-%m-%d %H:%M:%S', localtime()) + '\r\n'+ 'Server: keke\r\n')response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')return response# 处理没有找到对应的动态资源
def page_not_found():# 浏览器想读取的文件可能不存在with open('static/404.html', 'rb') as f:# 响应主体页面response_body = f.read()response_first_line = 'HTTP/1.1 404 Not Found\r\n'# 响应头response_header = ('Content-Length: ' + str(len(response_body)) + '\r\n'+ 'Content-Type: text/html; charset=iso-8859-1\r\n'+ 'Date: ' + strftime('%Y-%m-%d %H:%M:%S', localtime()) + '\r\n'+ 'Server: keke\r\n')response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_bodyreturn response
使用模板来展示响应内容
- 自己设计一个模板,中有一些地方采用动态的数据替代
- 怎么替代,替代什么数据
<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>首页 - 电影列表</title><link href="/css/bootstrap.min.css" rel="stylesheet"><script src="/js/jquery-1.12.4.min.js"></script><script src="/js/bootstrap.min.js"></script></head><body><div class="navbar navbar-inverse navbar-static-top "><div class="container"><div class="navbar-header"><button class="navbar-toggle" data-toggle="collapse" data-target="#mymenu"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a href="#" class="navbar-brand">电影列表</a></div><div class="collapse navbar-collapse" id="mymenu"><ul class="nav navbar-nav"><li class="active"><a href="">电影信息</a></li><li><a href="">个人中心</a></li></ul></div></div></div><div class="container"><div class="container-fluid"><table class="table table-hover"><tr><th>序号</th><th>名称</th><th>导演</th><th>上映时间</th><th>票房</th><th>电影时长</th><th>类型</th><th>备注</th><th>删除电影</th></tr>{%datas%}</table></div></div></body>
</html>
开发框架的路由列表功能
- 以后开发新的动作资源的功能只需要增加一个条件判断分支和一个专门处理的函数
- 路由:就是请求的 URL 路径和处理函数直接的映射
- 路由表
请求路径 处理函数 /index.html index /userinfo.html user_info
注意:用户的动态资源请求通过遍历路由表找到对应的处理函数来完成的
"""
#!/usr/bin/python3
# coding:utf-8
#
# Copyright (C) 2024 - 2024 Jasonakeke, Inc. All Rights Reserved
# @Desc :自定义 Web 框架
# @Time : 2024/8/1 22:07
# @Author : Code_By_Jasonakeke
# @Email : 2284037977@qq.com
# @File : MyFramework.py
# @IDE : PyCharm
"""
from time import strftime, localtime# 处理动态资源请求
def handle_request(params):request_path = params['request_path']for path, func in route_list:if request_path == path:return func()else:return page_not_found()# 当前的请求路径有与之对应的动态响应# if request_path == '/index.html':# response = index()# return response# elif request_path == '/userinfo.html':# response = user_info()# return response# else:# return page_not_found()# 专门处理 index.html 的请求
def index():response_body = Nonedate = strftime('%Y-%m-%d %H:%M:%S', localtime())# response_body = datawith open('template/index.html', 'r', encoding = 'utf-8') as f:response_body = f.read()response_body = response_body.replace('{%datas%}', date)response_first_line = 'HTTP/1.1 200 OK\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')return response# 处理没有找到对应的动态资源
def page_not_found():# 浏览器想读取的文件可能不存在with open('static/404.html', 'rb') as f:# 响应主体页面response_body = f.read()response_first_line = 'HTTP/1.1 404 Not Found\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_bodyreturn responsedef user_info():response_body = Nonedate = strftime('%Y-%m-%d %H:%M:%S', localtime())# response_body = datawith open('template/user_info.html', 'r', encoding = 'utf-8') as f:response_body = f.read()response_body = response_body.replace('{%datas%}', date)response_first_line = 'HTTP/1.1 200 OK\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')return response# 定义路由表
route_list = {('/index.html', index),('/userinfo.html', user_info),
}
采用装饰器的方式添加路由
- 采用带参数的装饰器
- 在任何一个处理函数的基础上增加一个添加路由的功能
"""
#!/usr/bin/python3
# coding:utf-8
#
# Copyright (C) 2024 - 2024 Jasonakeke, Inc. All Rights Reserved
# @Desc :自定义 Web 框架
# @Time : 2024/8/1 22:07
# @Author : Code_By_Jasonakeke
# @Email : 2284037977@qq.com
# @File : MyFramework.py
# @IDE : PyCharm
"""
from functools import wraps
from time import strftime, localtime# 定义路由表
route_list = []# route_list = {
# ('/index.html', index),
# ('/userinfo.html', user_info),
# }# 调用一个带参数的装饰器
def route(request_path):""":param request_path: URL 请求:return:"""def add_route(func):# 添加路由到路由表route_list.append((request_path, func))@wraps(func)def invoke(*arg, **kwargs):# 调用指定的处理函数并返回return func(*arg, **kwargs)return invokereturn add_route# 处理动态资源请求
def handle_request(params):request_path = params['request_path']for path, func in route_list:if request_path == path:return func()else:return page_not_found()# 当前的请求路径有与之对应的动态响应
# if request_path == '/index.html':
# response = index()
# return response
# elif request_path == '/userinfo.html':
# response = user_info()
# return response
# else:
# return page_not_found()# 专门处理 index.html 的请求
@route('/index.html')
def index():response_body = Nonedate = strftime('%Y-%m-%d %H:%M:%S', localtime())# response_body = datawith open('template/index.html', 'r', encoding = 'utf-8') as f:response_body = f.read()response_body = response_body.replace('{%datas%}', date)response_first_line = 'HTTP/1.1 200 OK\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')return response# 处理没有找到对应的动态资源
def page_not_found():# 浏览器想读取的文件可能不存在with open('static/404.html', 'rb') as f:# 响应主体页面response_body = f.read()response_first_line = 'HTTP/1.1 404 Not Found\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_bodyreturn response@route('/userinfo.html')
def user_info():response_body = Nonedate = strftime('%Y-%m-%d %H:%M:%S', localtime())# response_body = datawith open('template/user_info.html', 'r', encoding = 'utf-8') as f:response_body = f.read()response_body = response_body.replace('{%datas%}', date)response_first_line = 'HTTP/1.1 200 OK\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')return response
小结:使用带参数的装饰器,可以把路由自动的添加到路由列表中
电影列表页面的开发案例
- 查询数据
- 根据查询的数据得到动态的内容
"""
#!/usr/bin/python3
# coding:utf-8
#
# Copyright (C) 2024 - 2024 Jasonakeke, Inc. All Rights Reserved
# @Desc :自定义 Web 框架
# @Time : 2024/8/1 22:07
# @Author : Code_By_Jasonakeke
# @Email : 2284037977@qq.com
# @File : MyFramework.py
# @IDE : PyCharm
"""
from functools import wraps
from time import strftime, localtimefrom pymysql import connect# 定义路由表
route_list = []# route_list = {
# ('/index.html', index),
# ('/userinfo.html', user_info),
# }# 调用一个带参数的装饰器
def route(request_path):""":param request_path: URL 请求:return:"""def add_route(func):# 添加路由到路由表route_list.append((request_path, func))@wraps(func)def invoke(*arg, **kwargs):# 调用指定的处理函数并返回return func(*arg, **kwargs)return invokereturn add_route# 处理动态资源请求
def handle_request(params):request_path = params['request_path']for path, func in route_list:if request_path == path:return func()else:return page_not_found()# 当前的请求路径有与之对应的动态响应
# if request_path == '/index.html':
# response = index()
# return response
# elif request_path == '/userinfo.html':
# response = user_info()
# return response
# else:
# return page_not_found()# 专门处理 index.html 的请求
@route('/index.html')
def index():response_body = None# date = strftime('%Y-%m-%d %H:%M:%S', localtime())# response_body = data# 1.从 MySQL 中查询数据conn = connect(host = '127.0.0.1', port = 3306, user = 'root', password = '123456', database = 'test', charset = 'utf8')cursor = conn.cursor()cursor.execute('select * from t_movies')result = cursor.fetchall()print(result)datas = ''for row in result:datas += '''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s元</td><td>%s</td><td>%s</td><td>%s</td><td> <input type='button' value='删除'/></td></tr>''' % rowprint(datas)with open('template/index.html', 'r', encoding = 'utf-8') as f:response_body = f.read()response_body = response_body.replace('{%datas%}', datas)response_first_line = 'HTTP/1.1 200 OK\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')return response# 处理没有找到对应的动态资源
def page_not_found():# 浏览器想读取的文件可能不存在with open('static/404.html', 'rb') as f:# 响应主体页面response_body = f.read()response_first_line = 'HTTP/1.1 404 Not Found\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_bodyreturn response@route('/userinfo.html')
def user_info():response_body = Nonedate = strftime('%Y-%m-%d %H:%M:%S', localtime())# response_body = datawith open('template/user_info.html', 'r', encoding = 'utf-8') as f:response_body = f.read()response_body = response_body.replace('{%datas%}', date)response_first_line = 'HTTP/1.1 200 OK\r\n'# 响应头response_header = 'Server: keke\r\n'response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')return response
相关文章:
开发自己的 Web 框架
开发自己的 Web 框架 开发Web服务器主体程序开发Web框架程序使用模板来展示响应内容开发框架的路由列表功能采用装饰器的方式添加路由电影列表页面的开发案例 接收web服务器的动态资源请求,给web服务器提供处理动态资源请求的服务。根据请求资源路径的后缀名进行判断…...

用于自动驾驶的基于立体视觉的语义 3D 对象和自我运动跟踪
Stereo Vision-based Semantic 3D Object and Ego-motion Tracking for Autonomous Driving 论文 摘要: 我们提出了一种基于立体视觉的方法,用于在动态自动驾驶场景中跟踪相机自我运动和 3D 语义对象。我们建议使用易于标记的 2D 检测和离散视点分类以及…...

Spring@Autowired注解
Autowired顾名思义,就是自动装配,其作用是为了消除代码Java代码里面的getter/setter与bean属性中的property。当然,getter看个人需求,如果私有属性需要对外提供的话,应当予以保留。 因此,引入Autowired注解…...

32.x86游戏实战-使用物品call
免责声明:内容仅供学习参考,请合法利用知识,禁止进行违法犯罪活动! 本次游戏没法给 内容参考于:微尘网络安全 工具下载: 链接:https://pan.baidu.com/s/1rEEJnt85npn7N38Ai0_F2Q?pwd6tw3 提…...

Prometheus+Alertmanager+邮件告警
参考node_exporter-CSDN博客,球球不要断更!!!! 大致流程 1.部署promethus 可以写一个自定义的 systemd 服务启动文档,详情见自定义的 systemd 服务启动方式-CSDN博客 [rootlocalhost system]# sudo tee /e…...

upload-labs漏洞靶场~文件上传漏洞
寻找测试网站的文件上传的模块,常见:头像上传,修改上传,文件编辑器中文件上传,图片上传、媒体上传等,通过抓包上传恶意的文件进行测试,上传后缀名 asp php aspx 等的动态语言脚本,查…...
PostgreSQL 高阶函数详解:全面深入的功能与实用示例
PostgreSQL 高阶函数详解 PostgreSQL 是一款功能强大的开源关系数据库管理系统,以其丰富的功能和高扩展性著称。在数据处理和分析方面,PostgreSQL 提供了一系列高阶函数,可以极大地简化和优化各种复杂操作。本文将详细介绍 PostgreSQL 的高阶…...

Redis——集合 SET
目录 1. 添加元素 SADD 2. 查看元素 SMEMBERS 3. 判断元素是否存在该集合 SISMEMBER 4. 删除元素 SREM 集合 SET 是一种无序集合;因此其与列表有以下区别: (1)列表是有序的,集合是无序的; ࿰…...

openEuler安装docker
1.下载地址 搜索docker 寻找docker-ce 复制地址 2.配置仓库 [rootlocalhost yum.repos.d]# pwd /etc/yum.repos.d [rootlocalhost yum.repos.d]# vim docker-ce.repo [docker-ce] namedocker baseurlhttps://mirrors.aliyun.com/docker-ce/linux/rhel/9/x86_64/stable/ gpgche…...
每天一个数据分析题(四百六十五)- 缺失值
某连续型变量的数据集存在缺失值,可以采用哪种方法处理? A. 插值法填补 B. EM算法填补 C. 随机森林填补 D. 以上均不对 数据分析认证考试介绍:点击进入 题目来源于CDA模拟题库 点击此处获取答案 数据分析专项练习题库 内容涵盖Pytho…...

干货 | 变频器的详细介绍
变频器简述 变频器是电机控制领域中常见的一种设备,也称变频调节器,是一种将固定频率的交流电转换为可调频率的交流电的电力电子设备,用于控制交流电机的转速和输出功率。变频器通过调节输出电源的电压和频率,从而控制电动机的转速…...

Linux线程2
线程相关函数 线程分离--pthread_detach(后面会详细讲) 函数原型:int pthread_datach(pthread_t thread); 调用该函数之后不需要 pthread_join 子线程会自动回收自己的PCB 杀死(取消)线程--pthread_cancel 取…...

乱弹篇(40)人类追求长寿
不要认为只有中国的老龄化才严重,实际上全球都面临老龄化,其中日本最为严重。 这是随着人类生活和医学水平的不断提高,寿命才会比过去数十年有了大幅度的提升。据资料显示,目前全球平均预期寿命估计为73岁。与百年之前相比&#…...

技术详解:互联网医院系统源码与医保购药APP的整合开发策略
本篇文章,小编将从系统架构、数据安全、用户体验和技术实现等方面详细探讨互联网医院系统与医保购药APP的整合开发策略。 一、系统架构 1.模块化设计 互联网医院系统与医保购药APP的整合需要采用模块化设计。 2.微服务架构 每个功能模块作为一个独立的微服务&am…...

N4 - Pytorch实现中文文本分类
🍨 本文为🔗365天深度学习训练营 中的学习记录博客🍖 原作者:K同学啊 目录 任务描述步骤环境设置数据准备模型设计模型训练模型效果展示 总结与心得体会 任务描述 在上周的任务中,我们使用torchtext下载了托管的英文的…...
centos 如何安装sox音视频处理工具
要在 CentOS 系统上安装 Sox 音频处理软件,你可以遵循以下步骤。请注意,这些说明适用于 CentOS 7,对于 CentOS 8 及更高版本,某些包管理命令可能略有不同。 第一步:安装所需的依赖库 首先,你需要安装一系列…...

Java语言程序设计——篇十一(2)
🌿🌿🌿跟随博主脚步,从这里开始→博主主页🌿🌿🌿 欢迎大家:这里是我的学习笔记、总结知识的地方,喜欢的话请三连,有问题可以私信🌳🌳&…...

Linux 应急响应靶场练习 1
靶场在知攻善防实验室公众号中可以获取 前景需要:小王急匆匆地找到小张,小王说"李哥,我dev服务器被黑了",快救救我!! 挑战内容: (1)黑客的IP地址 (2࿰…...

AWS-Lambda的使用
介绍 Lambda 是一种无服务器(Serverless), 而且设计成事件驱动的计算服务器. 简单来说, 你可以将你的 code 上传, 当有事件产生(例如cronjob , 或者S3有新的文件被上传上來) , 你的code 就会在瞬间(零点几秒以內)被叫起來执行. 由于你不用管 Server如何维护, 或者自动扩展之类…...
python3.12 搭建MinerU 环境遇到的问题解决
报错: AttributeError: module pkgutil has no attribute ImpImporter. Did you mean: zipimporter? ERROR: Exception: Traceback (most recent call last):File "D:\ipa_workspace\MinerU\Lib\site-packages\pip\_internal\cli\base_command.py", …...

C++初阶-list的底层
目录 1.std::list实现的所有代码 2.list的简单介绍 2.1实现list的类 2.2_list_iterator的实现 2.2.1_list_iterator实现的原因和好处 2.2.2_list_iterator实现 2.3_list_node的实现 2.3.1. 避免递归的模板依赖 2.3.2. 内存布局一致性 2.3.3. 类型安全的替代方案 2.3.…...
日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする
日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする 1、前言(1)情况说明(2)工程师的信仰2、知识点(1) にする1,接续:名词+にする2,接续:疑问词+にする3,(A)は(B)にする。(2)復習:(1)复习句子(2)ために & ように(3)そう(4)にする3、…...
AtCoder 第409场初级竞赛 A~E题解
A Conflict 【题目链接】 原题链接:A - Conflict 【考点】 枚举 【题目大意】 找到是否有两人都想要的物品。 【解析】 遍历两端字符串,只有在同时为 o 时输出 Yes 并结束程序,否则输出 No。 【难度】 GESP三级 【代码参考】 #i…...
React Native在HarmonyOS 5.0阅读类应用开发中的实践
一、技术选型背景 随着HarmonyOS 5.0对Web兼容层的增强,React Native作为跨平台框架可通过重新编译ArkTS组件实现85%以上的代码复用率。阅读类应用具有UI复杂度低、数据流清晰的特点。 二、核心实现方案 1. 环境配置 (1)使用React Native…...

STM32标准库-DMA直接存储器存取
文章目录 一、DMA1.1简介1.2存储器映像1.3DMA框图1.4DMA基本结构1.5DMA请求1.6数据宽度与对齐1.7数据转运DMA1.8ADC扫描模式DMA 二、数据转运DMA2.1接线图2.2代码2.3相关API 一、DMA 1.1简介 DMA(Direct Memory Access)直接存储器存取 DMA可以提供外设…...

学习STC51单片机31(芯片为STC89C52RCRC)OLED显示屏1
每日一言 生活的美好,总是藏在那些你咬牙坚持的日子里。 硬件:OLED 以后要用到OLED的时候找到这个文件 OLED的设备地址 SSD1306"SSD" 是品牌缩写,"1306" 是产品编号。 驱动 OLED 屏幕的 IIC 总线数据传输格式 示意图 …...

C# 类和继承(抽象类)
抽象类 抽象类是指设计为被继承的类。抽象类只能被用作其他类的基类。 不能创建抽象类的实例。抽象类使用abstract修饰符声明。 抽象类可以包含抽象成员或普通的非抽象成员。抽象类的成员可以是抽象成员和普通带 实现的成员的任意组合。抽象类自己可以派生自另一个抽象类。例…...

uniapp微信小程序视频实时流+pc端预览方案
方案类型技术实现是否免费优点缺点适用场景延迟范围开发复杂度WebSocket图片帧定时拍照Base64传输✅ 完全免费无需服务器 纯前端实现高延迟高流量 帧率极低个人demo测试 超低频监控500ms-2s⭐⭐RTMP推流TRTC/即构SDK推流❌ 付费方案 (部分有免费额度&#x…...

IoT/HCIP实验-3/LiteOS操作系统内核实验(任务、内存、信号量、CMSIS..)
文章目录 概述HelloWorld 工程C/C配置编译器主配置Makefile脚本烧录器主配置运行结果程序调用栈 任务管理实验实验结果osal 系统适配层osal_task_create 其他实验实验源码内存管理实验互斥锁实验信号量实验 CMISIS接口实验还是得JlINKCMSIS 简介LiteOS->CMSIS任务间消息交互…...

华为OD机考-机房布局
import java.util.*;public class DemoTest5 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseSystem.out.println(solve(in.nextLine()));}}priv…...