CH9126网口配置协议及说明

目录

1.CH9126简介及应用特点

2.通信相关结构体定义

3.通信流程解析

  3.1搜索设备

  3.2恢复出厂设置

  3.3获取设备配置

  3.4配置设备

本文通过wireshark抓包分析了官方配套CH9126搜索上位机软件的底层通信,简单分析了搜索,恢复出厂,配置,获取配置这四个操作。

1.CH9126---网络授时芯片

(1)CH9126简介

   CH9126 基于 SNTP 协议的网络授时芯片。主要解决单片机等嵌入式设备时间同步问题。CH9126 具有两种工作模式:①作为 SNTP 客户端,向 SNTP 服务器索取时间,并通过串口输出时间;②作为SNTP 时间服务器,以脉冲和串口数据作为基准时间,对 SNTP 客户端进行网络授时。 芯片内部还有一个独立的数据透传通道,可以实现以太网与串口数据透传。

(2)应用

  (3)特点

  • 内部自带以太网介质传输层(MAC)和物理层(PHY)。
  • 支持 10/100M,全双工/半双工自适应,兼容 802.3 协议。
  • 与 802.3x 全双工流控和半双工背压流控完全兼容。
  • 支持 MDI/MDIX 线路自动转换。
  • 支持 SNTP 服务器和 SNTP 客户端模式。
  • 可以通过网络和串口配置芯片参数。
  • 串口支持 5、6、7 或者 8 个数据位以及 1 或者 2 个停止位。
  • 支持奇、偶、无校验、空白 0、标志 1 等校验方式。
  • 波特率支持 300-921600bps。
  • 授时精度为 10ms。
  • 支持一个独立的数据通道,提供网络转串口的数据透传功能。

2.结构体定义

  1 #ifndef __SOCKET_H__
  2 #define __SOCKET_H__
  3 
  4 #include "RingMen.H"
  5 
  6 #define CFGAdd   0x1000    //参数存放地址4k
  7 
  8 #define COMMFLAG    "CH9126_MODULE_V1.03"  //"CH9126_UPDATA"  
  9 #define MODULENAME  "123456789"
 10 
 11 #define SNTP_PORT    123
 12 
 13 #define NetConfigPort   50000
 14 /*=============================================================================*/
 15 /*可设置的socket个数*/
 16 /*-----------------------------------------------------------------------------*/
 17 #define SocketNum   2
 18 /*=============================================================================*/
 19 /*通信命令码*/
 20 /*-----------------------------------------------------------------------------*/
 21 #define NET_MODULE_CMD_SET            0X01        //配置网络中的模块
 22 #define NET_MODULE_CMD_GET            0X02        //获取某个模块的配置
 23 #define NET_MODULE_CMD_RESET        0x03        //复位模块
 24 #define NET_MODULE_CMD_SEARCH        0X04        //搜索网络中的模块
 25 /*=============================================================================*/
 26 /*应答命令码*/
 27 /*-----------------------------------------------------------------------------*/
 28 #define NET_MODULE_ACK_SET            0X81        //回应配置命令码
 29 #define NET_MODULE_ACK_GET            0X82        //回应获取命令码
 30 #define NET_MODULE_ACK_RESEST        0X83        //回应复位命令码
 31 #define NET_MODULE_ACK_SEARCH        0X84        //回应所搜命令码
 32 /*=============================================================================*/
 33 /*开关*/
 34 /*-----------------------------------------------------------------------------*/
 35 #define Enable      1
 36 #define Disable     0
 37 /*=============================================================================*/
 38 /*PHY_Type*/
 39 /*-----------------------------------------------------------------------------*/
 40 #define HALF_10M    1
 41 #define FULL_10M    2
 42 #define HALF_100M   3
 43 #define FULL_100M   4
 44 /*=============================================================================*/
 45 /*CurrNetSta*/
 46 /*-----------------------------------------------------------------------------*/
 47 #define NET_Disconnect   0
 48 #define NET_Connect      1
 49 /*=============================================================================*/
 50 /*CommFormat*/
 51 /*-----------------------------------------------------------------------------*/
 52 #define Format_ASC       1
 53 #define Format_HEX       2
 54 /*=============================================================================*/
 55 /*TTL*/
 56 /*-----------------------------------------------------------------------------*/
 57 #define    TTL_Num        128
 58 
 59 //网络配置
 60 #pragma pack(1) 
 61 typedef struct _NET_CONFIG
 62 {
 63     UINT8  MACAddr[6];
 64     UINT8  IP[4];
 65     UINT8  Mask[4];
 66     UINT8  Gateway[4];
 67     UINT8  DNS1[4];
 68     UINT8  DNS2[4];
 69     UINT8  PHY_Type;                
 70     //UINT8  CurrNetSta;          //存放当前的网络状态
 71     UINT8  DHCPEn; 
 72     //UINT8  PulseOutEn;          //脉冲输出使能
 73     UINT8  TTLNum;                  
 74     UINT16 NetCfgPort;
 75     UINT32 CtrlPara;              //控制参数,byte0控制脉冲输出
 76     UINT8  KeepAliveEn;
 77     UINT32 KeepAliveIdleTime;     //空闲时间
 78     UINT32 KeepAliveIntervalTime; //间隔时间
 79     UINT32 KeepAliveOUTCount;     //超时次数
 80     
 81 }NET_CONFIG,*pnet_cfg;
 82 /*=============================================================================*/
 83 /* 串口参数 数据位 */
 84 /*-----------------------------------------------------------------------------*/
 85 #define UART_DATA_5BIT                           5                              /* 数据位5位,RT8711不支持 */
 86 #define UART_DATA_6BIT                           6                              /* 数据位6位,RT8711不支持 */
 87 #define UART_DATA_7BIT                           7                              /* 数据位7位 */
 88 #define UART_DATA_8BIT                           8                              /* 数据位8位 */
 89 /*=============================================================================*/
 90 /* 串口参数 校验 */
 91 /*-----------------------------------------------------------------------------*/
 92 #define UART_CHECK_NONE                          0                              /* 无校验 */
 93 #define UART_CHECK_ODD                           1                              /* 奇校验 */
 94 #define UART_CHECK_EVEN                          2                              /* 偶校验 */
 95 #define UART_CHECK_MARK                          3                              /* Mark校验,校验始终为1 */
 96 #define UART_CHECK_SPACE                         4                              /* Space校验,校验始终为0 */
 97 /*=============================================================================*/
 98 /* 串口参数 停止位 */
 99 /*-----------------------------------------------------------------------------*/
100 #define UART_STOP_1BIT                           1                              /* 1个停止位 */
101 #define UART_STOP_2BIT                           2                              /* 2个停止位 */
102 /*=============================================================================*/
103 /* 串口数据 通信格式 */
104 /*-----------------------------------------------------------------------------*/
105 #define UART_HEX                                 0                              /* HEX格式 */
106 #define UART_ASCII                               1                              /* ASCII格式 */
107 /*=============================================================================*/
108 //串口设置 
109 #pragma pack(1) 
110 typedef struct _UART_CONFIG
111 {
112     UINT32 UARTBps;
113     UINT8  DataBit;
114     UINT8  StopBit;
115      UINT8  VerifyBit;
116     UINT16 RXPacket;   //打包长度
117     UINT16 RXTimeOut;  //超时 
118     UINT8  CommFormat; 
119 }UART_CONFIG,*puart_cfg;
120 /*=============================================================================*/
121 /*socket type*/
122 /*-----------------------------------------------------------------------------*/
123 #define TCP_Server  1     //不显示该选项,放在第一位界面上好处理
124 #define TCP_Client  2
125 #define UDP_Server  3
126 #define UDP_Client  4
127 #define SNTP_Server 5
128 #define SNTP_Client 6
129 /*=============================================================================*/
130 /* socket TCP sta*/
131 /*-----------------------------------------------------------------------------*/
132 #define TCP_Disconnect   0
133 #define TCP_Connecting   1
134 #define TCP_Connect      2
135 /*=============================================================================*/
136 /*PHYOFFDealType*/
137 /*-----------------------------------------------------------------------------*/
138 #define KeepSocket       0       //保存连接
139 #define DiscardSocket    1       //丢弃连接
140 /*=============================================================================*/
141 /*OtherChannDeal*/
142 /*-----------------------------------------------------------------------------*/
143 #define StoreAllData     0       //全部保存(1K满)
144 #define StoreLastData    1       //保存上一包
145 #define StoreNoData      2       //不保存
146 
147 //socket配置
148 #pragma pack(1) 
149 typedef struct _SOCKET_CONFIG
150 {
151     UINT8  EnableF;           //
152     UINT8  Type;              //类型
153     UINT8  PHYOFFDealType;    //only tcp:网络断开的处理方式,1.丢弃连接 2.保持连接,默认:DiscardSocket
154     UINT8  OtherChannDeal;    //tcp&udp其他网络连接数据处理,1.全部保存(1k满),2.保存上一包数据,3.不保存  ,默认:StoreNoData
155     UINT8  DesIP[4];
156     UINT16 DesPort;           //SNTP模式下存储轮询间隔
157     UINT8  PortRandomEn;
158     UINT16 SourPort;          
159 }SOCKET_CONFIG,*psocket_cfg;
160 
161 //通讯参数整合
162 #pragma pack(1) 
163 typedef struct _PARA_CFG_MAN
164 {
165     UINT8  CommFlag[64];         //通讯、存储标志
166     UINT8  VerNum[4];            //增加一个版本信息     格式:v102(asc) = v1.02
167     UINT8  ModuleName[64];         //模块名称    
168     UINT8  ModuleID[8];          //模块的ID    
169     UINT8  cmd;                     //传输命令码
170     UINT8  mod_mac[6];        //模块的MAC
171     UINT8  cfg_mac[6];        //PC端的MAC
172     UART_CONFIG UARTCfg;    //串口配置
173     NET_CONFIG  NetCfg;      //网络参数配置
174     SOCKET_CONFIG  SocketConfig[SocketNum];        //配置
175     UINT8  Res[128];        //保留字
176 }PARA_CFG_MAN, *pnet_comm;    
177 
178 /**************************************************************/
179 /*============================================================*/
180 
181  //网络
182 typedef struct _NET_COMM
183 {
184     UINT8  CurrNetSta;            //存放当前的网络状态
185 }NET_COMM;
186 
187 //传输
188 typedef struct _SOCKET_TRAN_MANAGE
189 {
190     UINT8  SocketID;          //该Socket获取到的ID号
191     UINT8  TCPSta;            //TCP状态
192     UINT32 TCPTimeCount;      //TCP网络状态计时,初始化的时候赋值以便第一次直接连接
193     UINT8  *P_SocketBuf;      //库初始化的缓存地址
194     UINT8  *SendMem; //发送缓存
195     UINT8  *RecMem;     //接收缓存             
196     UINT8  *TempMen; //暂存缓存
197     RING_MEMORY *P_RingMen_Rec;         //接收环形缓存
198     RING_MEMORY *P_RingMen_Tran;     //发送环形缓存
199     UINT16 RecLen;
200     UINT16 SendLen;    
201     //UDP服务器时接收的客户端
202     UINT8  UDPClientIP[4];
203     UINT16 UDPClientPort;    
204 }SOCKET_TRAN_MANAGE;
205 
206 //通道管理
207 typedef struct _CHANNEL_MANAGE
208 {
209     UINT8  CurrChannel;    //当前通道 = Socket号
210 }CHANNEL_MANAGE;
211 
212 //SNTP一些配置管理
213 typedef struct _SNTP_MANAGE
214 {
215     UINT8  SNTPPulseOutEn;   //脉冲输出
216     UINT8  SNTPPulseInEn;    //脉冲输入,有服务器则该标志置位
217     UINT8  SNTPServerEn;     //有服务器则该标志置位
218     UINT8  SNTPClientEn;     //有客户端则该标志置位  
219     UINT8  PulseStaFlag;     //脉冲的一些状态标志
220     UINT32 PulseOUTTimCount; //用于脉冲检测计数
221     UINT32 PulseTimCount;    //用于脉冲检测计数
222 }SNTP_MANAGE;
223 
224 //通讯参数整合
225 typedef struct _PARA_COMM_MAN
226 {
227     NET_COMM NetCommPara;
228     SOCKET_TRAN_MANAGE SocketTranPara[SocketNum];
229     CHANNEL_MANAGE ChannelPara;
230     SNTP_MANAGE SNTPCommPara;
231 }PARA_COMM_MAN;  
232 
233 
234 //extern PARA_MAN ParaManage;
235 extern PARA_CFG_MAN CfgPara;
236 extern PARA_COMM_MAN CommPara;
237 
238 void InitPara(void);
239 
240 //void SocketUDPServerRecDeal(SOCK_INF *socinf,UINT8 *buf,UINT32 len);
241 //void SocketSNTPServerRecDeal(SOCK_INF *socinf,UINT8 *buf,UINT32 len);
242 
243 #endif

3.通信流程详解

(1)通讯方式
CH9126 通过 UDP 广播方式进行网络配置功能。
CH9126 广播本地接收端口:50000,软件上位机广播本地接收端口:60000。

(2)通讯过程

 CH9126上位机配置功能主要包括:①搜索,②获取配置,③配置网络参数,④恢复出厂设置。

 下面结合通讯过程中的数据包解析设置流程。(通过wireshark抓取到数据包来对上位机软件进行协议解析)

①搜索设备

-->PC下发的搜索包:

43 48 39 31 32 36 5f 4d 4f 44 55 4c 45 5f 56 31
2e 30 33 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   //64字节通讯、存储标志
00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
04                        //通信命令码:搜索网络中的模块
ff ff ff ff ff ff
00 e0 4c 36 35 5a                   //pc端MAC
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00

<--9121回复的应答包:

43 48 39 31 32 36 5f 4d 4f 44 55 4c 45 5f 56 31
2e 30 33 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00      //64字节通讯、存储标志
76 31 32 31                      //版本信息 格式:v121(asc) = v1.21
43 48 39 31 32 36 00 44 55 4c 45 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00      //模块名称,64字节
2f 8d 58 87 78 cc 66 d7                   //模块id,8字节
84                             //通信命令码:回应所搜命令码
84 c2 e4 e9 34 a2                   //模块MAC
00 e0 4c 36 35 5a                   //pc端MAC
    /****************************从这往下是串口配置*************************************/
80 25 00 00                      //波特率(9600)
08                           //数据位
01                          //停止位
00                          //校验位
00 04                        //打包长度(1024)
00 00                        //超时
00                          //通信数据格式(0为hex格式,1为ASCII格式)
    /******************************从这往下是网络配置*********************************/
84 c2 e4 e9 34 a2                      //模块MAC
c0 a8 01 c8                      //模块自身IP
ff ff ff 00                         //模块掩码
c0 a8 01 01                      //模块网关
00 00 00 00                      //DNS1
00 00 00 00                       //DNS2
04                                //当前PHY_Type(1为10M半双工,2为10兆全双工,3为百兆半双工,4为百兆全双工)
00                                //DHCP使能(0为不开启,1为开启)
80                                 //TTL值,默认128
50 c3                                 //NetConfigPort,默认50000
01 00 00 00                   //控制参数,byte0控制脉冲输出
01                        //KeepAliveEn(1为开启keepalive)
20 4e 00 00                   //空闲时间 20000ms
98 3a 00 00                   //间隔时间 15000ms
05 00 00 00                   //超时次数 5次
/***************************从这往下是socket配置(第一个是SNTP通道,第二个是数据通道)***************************/

01                          //使能(即启用SNTP通道)
06                          //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                          //only tcp网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                               //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 78                      //目的ip
0a 00                        //SNTP模式下存储轮询间隔
00                          //端口是否随机
7b 00                          //SNTP_PORT,默认123

01                         //使能(即启用数据通道)
02                          //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                          //only tcp网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                           //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 96                       //目的ip
d0 07                        //目的端口
00                          //本地端口是否随机(0为不随机,1为随机)
d0 07                               //本地端口

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 //128个保留字
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

 

 

②恢复出厂设置

-->PC下发的获取配置请求包

43 48 39 31 32 36 5f 4d 4f 44 55 4c 45 5f 56 31
2e 30 33 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00     //64字节通讯、存储标志
00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
03                          //通信命令码:复位模块
84 c2 e4 e9 34 a2                    //9126MAC
00 e0 4c 36 35 5a                    //pc端MAC
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00

<--9121的应答包:(从下面的数据包可以得到CH9126各网络参数的默认值)

43 48 39 31 32 36 5f 4d 4f 44 55 4c 45 5f 56 31
2e 30 33 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00      //64字节通讯、存储标志
76 31 32 31                        //版本信息 格式:v121(asc) = v1.21
53 4e 54 50 5f 4d 4f 44 55 4c 45  00  00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00     //模块名称,64字节

2f 8d 58 87 78 cc 66 d7                //模块id,8字节
83                          //通信命令码:回应复位命令码
84 c2 e4 e9 34 a2                   //模块MAC
00 e0 4c 36 35 5a                                                               //pc端MAC
      /****************************从这往下是串口配置*************************************/
80 25 00 00                      //波特率(9600)
08                          //数据位
01                          //停止位
00                          //校验位
00 02                          //打包长度(512)
0a 00                          //超时(10)
00                          //通信数据格式(0为hex格式,1为ASCII格式)
      /******************************从这往下是网络配置*********************************/
84 c2 e4 e9 34 a2                   //模块MAC
c0 a8 01 c8                        //模块自身IP
ff ff ff 00                       //模块掩码
c0 a8 01 01                         //模块网关
00 00 00 00                      //DNS1
00 00 00 00                      //DNS2
04                          //当前PHY_Type(1为10M半双工,2为10兆全双工,3为百兆半双工,4为百兆全双工)
00                          //DHCP使能(0为不开启,1为开启)
80                          //TTL值,默认128
50 c3                          //NetConfigPort,默认50000
00 00 00 00                     //byte0为脉冲输出使能位
01                         //KeepAliveEn(1为开启keepalive)
20 4e 00 00                     //空闲时间 20000ms
98 3a 00 00                           //间隔时间 15000ms
05 00 00 00                      //超时次数 5次

/***************************从这往下是socket配置(第一个是SNTP通道,第二个是数据通道)***************************/

01                         //使能
06                         //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                         //(only tcp)网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                         //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 64                     //目的ip
70 17                       //SNTP模式下存储轮询间隔(默认6000)
00                         //端口是否随机
7b 00                         //SNTP_PORT,默认123

00                         //默认禁用数据通道
02                         //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                         //(only tcp)网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                         //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 64                     //目的ip
88 13                          //目的端口(默认5000)
00                         //本地端口是否随机(0为不随机,1为随机)
d1 07                         //本地端口(2001)

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 //128个保留字
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

 

 

获取配置

-->PC下发的获取配置请求包

43 48 39 31 32 36 5f 4d 4f 44 55 4c 45 5f 56 31
2e 30 33 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00      //64字节通讯、存储标志
00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
02                            //通讯命令码:获取某个模块的配置
84 c2 e4 e9 34 a2                   //模块MAC
00 e0 4c 36 35 5a                   //pc端MAC
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00

<--9121的应答包:(因为本文是在恢复出厂设置后再去获取的配置参数,所以下面的数据和出厂数据一致)

43 48 39 31 32 36 5f 4d 4f 44 55 4c 45 5f 56 31
2e 30 33 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00      //64字节通讯、存储标志
76 31 32 31                        //版本信息 格式:v121(asc) = v1.21
53 4e 54 50 5f 4d 4f 44 55 4c 45  00  00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00     //模块名称,64字节

2f 8d 58 87 78 cc 66 d7                //模块id,8字节
82                         //通信命令码:回应获取命令码
84 c2 e4 e9 34 a2                   //模块MAC
00 e0 4c 36 35 5a                                                               //pc端MAC
      /****************************从这往下是串口配置*************************************/
80 25 00 00                      //波特率(9600)
08                          //数据位
01                          //停止位
00                          //校验位
00 02                          //打包长度(512)
0a 00                          //超时(10)
00                          //通信数据格式(0为hex格式,1为ASCII格式)
      /******************************从这往下是网络配置*********************************/
84 c2 e4 e9 34 a2                   //模块MAC
c0 a8 01 c8                        //模块自身IP
ff ff ff 00                       //模块掩码
c0 a8 01 01                         //模块网关
00 00 00 00                      //DNS1
00 00 00 00                      //DNS2
04                          //当前PHY_Type(1为10M半双工,2为10兆全双工,3为百兆半双工,4为百兆全双工)
00                          //DHCP使能(0为不开启,1为开启)
80                          //TTL值,默认128
50 c3                          //NetConfigPort,默认50000
00 00 00 00                     //byte0为脉冲输出使能位
01                         //KeepAliveEn(1为开启keepalive)
20 4e 00 00                     //空闲时间 20000ms
98 3a 00 00                           //间隔时间 15000ms
05 00 00 00                      //超时次数 5次

/***************************从这往下是socket配置(第一个是SNTP通道,第二个是数据通道)***************************/

01                         //使能
06                         //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                         //(only tcp)网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                         //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 64                     //目的ip
70 17                       //SNTP模式下存储轮询间隔(默认6000)
00                         //端口是否随机
7b 00                         //SNTP_PORT,默认123

00                         //默认禁用数据通道
02                         //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                         //(only tcp)网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                         //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 64                     //目的ip
88 13                          //目的端口(默认5000)
00                         //本地端口是否随机(0为不随机,1为随机)
d1 07                         //本地端口(2001)

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 //128个保留字
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

 

④进行网络参数配置

-->PC下发的配置包

43 48 39 31 32 36 5f 4d 4f 44 55 4c 45 5f 56 31
2e 30 33 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00      //64字节通讯、存储标志
76 31 32 31                        //版本信息 格式:v121(asc) = v1.21
53 4e 54 50 5f 4d 4f 44 55 4c 45  00  00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00     //模块名称,64字节

2f 8d 58 87 78 cc 66 d7                //模块id,8字节
01                          //通信命令码:配置网络中的模块
84 c2 e4 e9 34 a2                   //模块MAC
00 e0 4c 36 35 5a                                                               //pc端MAC
      /****************************从这往下是串口配置*************************************/
80 25 00 00                      //波特率(9600)
08                          //数据位
01                          //停止位
00                          //校验位
00 04                         //打包长度
0a 00                          //超时
00                          //通信数据格式(0为hex格式,1为ASCII格式)
      /******************************从这往下是网络配置*********************************/
84 c2 e4 e9 34 a2                   //模块MAC
c0 a8 01 c8                        //模块自身IP
ff ff ff 00                       //模块掩码
c0 a8 01 01                         //模块网关
00 00 00 00                      //DNS1
00 00 00 00                      //DNS2
04                          //当前PHY_Type(1为10M半双工,2为10兆全双工,3为百兆半双工,4为百兆全双工)
00                          //DHCP使能(0为不开启,1为开启)
80                          //TTL值,默认128
50 c3                          //NetConfigPort,默认50000
00 00 00 00                     //byte0为脉冲输出使能位
01                         //KeepAliveEn(1为开启keepalive)
20 4e 00 00                     //空闲时间 20000ms
98 3a 00 00                           //间隔时间 15000ms
05 00 00 00                      //超时次数 5次

/***************************从这往下是socket配置(第一个是SNTP通道,第二个是数据通道)***************************/

01                         //使能
06                         //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                         //(only tcp)网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                         //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 78                      //目的ip
0a 00                       //SNTP模式下存储轮询间隔(默认6000)
00                         //端口是否随机
7b 00                         //SNTP_PORT,默认123

01                         //使能数据通道
02                         //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                         //(only tcp)网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                         //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 96                     //目的ip
d0 07                          //目的端口
00                          //本地端口是否随机(0为不随机,1为随机)
d0 07                             //本地端口

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 //128个保留字
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

<--9121回复的应答包

43 48 39 31 32 36 5f 4d 4f 44 55 4c 45 5f 56 31
2e 30 33 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00      //64字节通讯、存储标志
76 31 32 31                        //版本信息 格式:v121(asc) = v1.21
53 4e 54 50 5f 4d 4f 44 55 4c 45  00  00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00     //模块名称,64字节

2f 8d 58 87 78 cc 66 d7                //模块id,8字节
81                         //通信命令码:回复配置命令
84 c2 e4 e9 34 a2                   //模块MAC
00 e0 4c 36 35 5a                                                               //pc端MAC
      /****************************从这往下是串口配置*************************************/
80 25 00 00                      //波特率(9600)
08                          //数据位
01                          //停止位
00                          //校验位
00 04                         //打包长度
00 00                          //超时
00                          //通信数据格式(0为hex格式,1为ASCII格式)
      /******************************从这往下是网络配置*********************************/
84 c2 e4 e9 34 a2                   //模块MAC
c0 a8 01 c8                        //模块自身IP
ff ff ff 00                       //模块掩码
c0 a8 01 01                         //模块网关
00 00 00 00                      //DNS1
00 00 00 00                      //DNS2
04                          //当前PHY_Type(1为10M半双工,2为10兆全双工,3为百兆半双工,4为百兆全双工)
00                          //DHCP使能(0为不开启,1为开启)
80                          //TTL值,默认128
50 c3                          //NetConfigPort,默认50000
00 00 00 00                     //byte0为脉冲输出使能位
01                         //KeepAliveEn(1为开启keepalive)
20 4e 00 00                     //空闲时间 20000ms
98 3a 00 00                           //间隔时间 15000ms
05 00 00 00                      //超时次数 5次

/***************************从这往下是socket配置(第一个是SNTP通道,第二个是数据通道)***************************/

01                         //使能
06                         //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                         //(only tcp)网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                         //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 78                      //目的ip
0a 00                       //SNTP模式下存储轮询间隔(默认6000)
00                         //端口是否随机
7b 00                         //SNTP_PORT,默认123

01                         //使能数据通道
02                         //模式类型(1为tcp_server;2为tcp_client;3为udp_server;4为udp_client;5为sntp_server;6为sntp_client)
01                         //(only tcp)网络断开的处理方式:00表示保存连接,01表示丢弃连接(默认丢弃)
02                         //tcp&udp其他网络连接数据处理:00为全部保存(1k满),01为保存上一包数据,02为不保存(默认不保存)
c0 a8 01 96                     //目的ip
d0 07                          //目的端口
00                          //本地端口是否随机(0为不随机,1为随机)
d0 07                             //本地端口

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   //128个保留字
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


 

上位机搜索软件及协议:https://files.cnblogs.com/files/blogs/808422/CH9126ConfigTool.zip?t=1709781664&download=true

CH9126技术文档搜索 ch9126 - 南京沁恒微电子股份有限公司 (wch.cn)

posted on 2024-03-07 13:19  Lqqq123  阅读(137)  评论(0编辑  收藏  举报

导航