# LWIP
**Repository Path**: SeeDeer/LWIP
## Basic Information
- **Project Name**: LWIP
- **Description**: No description available
- **Primary Language**: C
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2019-06-13
- **Last Updated**: 2021-02-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# LWIP
#### Description
OSI参考模型:
OSI | 说明
--- | ---
7 应用层
6 表示层
5 会话层 | SSH HTTP TLS FTP...
4 传输层 | TCP,UDP,SCTP,DCCP
3 网络层 | ARP,IPv4,IPv6,ICMP,IPsec
2 数据链路层 | MAC(介质访问控制)子层和LLC(逻辑链路控制)子层
1 物理层 | PHY
数据链路层的作用:将网络层发来的IP数据包,分包加上mac地址,重新组包发给物理层。
以太网和Wifi链路层机制也不相同,深入研究都需要一本书,这里从宏观描述。
https://blog.csdn.net/xiaomifengxxxx/article/details/79564133
开启流服务通道
功能 | 帧头 | 版本 | 命令字 | 数据长度 | 数据区 | 和校验 | 说明
--- | --- | --- | --- | --- | --- | --- | ---
开启流服务通道 | 55 AA | 03 | 26 | 00 00 | NULL | CK | MCU发送
开启流服务通道 | 55 AA | 00 | 26 | 00 01 | 0x00:开启成功
0x01:开启失败 | CK | 模块应答
开始新的清扫 | 55 AA | 03 | 27 | 00 02 | map_id | CK | MCU发送
开始新的清扫 | 55 AA | 00 | 27 | 00 01 | 0x00:成功
0x01:流服务功能未开启
0x02:流服务器未连接成功
0x03:数据推送超时 | CK | 模块应答
传输地图数据 | 55 AA | 03 | 28 | N | map_id(2Bytes) + offset(4Bytes) + 实体数据(大端) | CK | MCU发送
传输地图数据 | 55 AA | 00 | 28 | 00 01 | 0x00:成功
0x01:流服务功能未开启
0x02:流服务器未连接成功
0x03:数据推送超时 | CK | 模块应答
结束此次清扫 | 55 AA | 03 | 29 | 00 06 | map_id(2Bytes) + offset(4Bytes) | CK | MCU发送
结束此次清扫 | 55 AA | 00 | 29 | 00 01 | 0x00:成功
0x01:流服务功能未开启
0x02:流服务器未连接成功
0x03:数据推送超时 | CK | 模块应答
mqtt协议分析
### Clean Session(会话清除):
MQTT客户端向服务器发起CONNECT请求时,可以通过’Clean Session’标志设置会话
‘Clean Session’设置为0,表示创建一个持久会话,在客户端断开连接时,会话仍然保持并保存离线消息,直到会话超时注销。
‘Clean Session’设置为1,表示创建一个新的临时会话,在客户端断开时,会话自动销毁。
0: 异常断开后,会话状态保存
客户端A成功订阅了/home的主题,客户端异常断开后,只要没有主动取消订阅此主题;
发布者向/home pub_msg后,服务端会缓存/home的消息;
客户端A复活后,服务器会把缓存的/home消息发给客户端A。
1: 异常断开后,会话状态直接清除
官方协议说明:
3.1.2.4 Clean Session
Position: bit 1 of the Connect Flags byte.
This bit specifies the handling of the Session state.
The Client and Server can store Session state to enable reliable messaging to continue across a
sequence of Network Connections. This bit is used to control the lifetime of the Session state.
If CleanSession is set to 0, the Server MUST resume communications with the Client based on state from
the current Session (as identified by the Client identifier). If there is no Session associated with the Client
identifier the Server MUST create a new Session. The Client and Server MUST store the Session after
the Client and Server are disconnected [MQTT-3.1.2-4].
After the disconnection of a Session that had CleanSession set to 0,
断开CleanSession被设置为0的会话后,
the Server MUST store further QoS 1 and QoS 2 messages that match any subscriptions that the client had at the time of disconnection as part of the Session state.
If CleanSession is set to 1, the Client and Server MUST discard any previous Session and start a new
435 one. This Session lasts as long as the Network Connection. State data associated with this Session
436 MUST NOT be reused in any subsequent Session
客户端的会话状态组成:
* QoS 1 and QoS 2 messages which have been sent to the Server, but have not been completely acknowledged.
已发送到服务器但尚未完全确认的QoS 1和QoS 2消息。
* QoS 2 messages which have been received from the Server, but have not been completely acknowledged.
已从服务器接收到但尚未完全确认的QoS 2消息。
服务端的会话状态组成:
* The existence of a Session, even if the rest of the Session state is empty.
会话的存在,即使会话状态的其余部分为空。
* The Client’s subscriptions.
客户端的订阅存在。
* QoS 1 and QoS 2 messages which have been sent to the Client, but have not been completely acknowledged.
已发送到客户端但尚未收到完整ACK的QoS 1和QoS 2消息。
* QoS 1 and QoS 2 messages pending transmission to the Client.
传输到客户端的QoS 1和QoS 2消息挂起。
* QoS 2 messages which have been received from the Client, but have not been completely acknowledged.
已从客户端接收到但尚未完全确认的QoS 2消息。
* Optionally, QoS 0 messages pending transmission to the Client.