Forráskód Böngészése

在A1命令实装新设计的流水号与时间戳子命名数据包

xuy 3 éve%!(EXTRA string=óta)
szülő
commit
a114da5423
1 módosított fájl, 32 hozzáadás és 21 törlés
  1. 32 21
      Src/TerminalSlave485.c

+ 32 - 21
Src/TerminalSlave485.c

@@ -1112,10 +1112,11 @@ void Send_A1_Cmd(unsigned char scrAddr, unsigned char funCode, unsigned char scr
  * 输入:
  *    pBuf-构建数据的存放首地址
  *    pEmergy,如果是数据有变动,表示紧急上报,将标记存于此地址
+ *    flowID, 流水id值
  * 返回: 构建数据的字节总数
  ***************************************
  */
-int BuildA1Cmd(uint8_t *pBuf, uint8_t *pEmergy)
+int BuildA1Cmd(uint8_t *pBuf, uint32_t flowID, uint8_t *pEmergy)
 {
 	int send_pos=0;
 	unsigned char emergy=0;
@@ -1214,6 +1215,20 @@ int BuildA1Cmd(uint8_t *pBuf, uint8_t *pEmergy)
 			}
 		}
 	}
+
+	// 2022-8-25, 新增加的子命令
+	// 01, 流水号
+	// 02, 时间戳
+	do {
+		pBuf[send_pos++] = 0x01;
+		pBuf[send_pos++] = (flowID>>24) & 0xff;
+		pBuf[send_pos++] = (flowID>>16) & 0xff;
+		pBuf[send_pos++] = (flowID>>8) & 0xff;
+		pBuf[send_pos++] = (flowID>>0) & 0xff;
+	}while(0);
+	
+	send_pos += BuildTimeCmd(pBuf+send_pos);
+	
 	while (send_pos<(120+2))
 	{
 		pBuf[send_pos++] = 0;
@@ -1235,15 +1250,14 @@ int BuildTimeCmd(uint8_t *pBuf)
 {
 	int send_pos=0;
 	
-	pBuf[send_pos++] = 0x20;
-	pBuf[send_pos++] = 6;
-
-	pBuf[send_pos++] = m_datetime.year;
-	pBuf[send_pos++] = m_datetime.month;
-	pBuf[send_pos++] = m_datetime.day;
-	pBuf[send_pos++] = m_datetime.hour;
-	pBuf[send_pos++] = m_datetime.min;
-	pBuf[send_pos++] = m_datetime.sec;
+	pBuf[send_pos++] = 0x02;
+
+	pBuf[send_pos++] = HEXtoBCD(m_datetime.year);
+	pBuf[send_pos++] = HEXtoBCD(m_datetime.month);
+	pBuf[send_pos++] = HEXtoBCD(m_datetime.day);
+	pBuf[send_pos++] = HEXtoBCD(m_datetime.hour);
+	pBuf[send_pos++] = HEXtoBCD(m_datetime.min);
+	pBuf[send_pos++] = HEXtoBCD(m_datetime.sec);
 	
 	return send_pos;
 }
@@ -1319,13 +1333,9 @@ void DoInternalSensorScanAndPost()
 	uint8_t *pSendBuf = USART1_TX_BUF;
 	static int step = 0;
 	static int nstep = 0;
+	static uint32_t flowID = 0;
 
-	if(++step % SensorScanParam.step == 0){
-		pSendBuf[0] = 1;
-		pSendBuf[1] = SensorScanParam.cmd_num + 1;
-		pSendBuf += 2;
-		ylen += 2;
-
+	if(++step % SensorScanParam.step == 0){	
 		for(int n=0; n<SensorScanParam.cmd_num; n++) {
 			switch (SensorScanParam.cmd_arr[n]){
 			case 0x40:
@@ -1339,7 +1349,7 @@ void DoInternalSensorScanAndPost()
 			    ylen += xlen;
 				break;
 			case 0xA1:
-				xlen = BuildA1Cmd(pSendBuf, emergy?NULL:&emergy); 
+				xlen = BuildA1Cmd(pSendBuf, flowID, emergy?NULL:&emergy); 
 				pSendBuf += xlen;
 			    ylen += xlen;
 				break;
@@ -1348,15 +1358,16 @@ void DoInternalSensorScanAndPost()
 			}
 		}
 		
-		xlen = BuildTimeCmd(pSendBuf);   // 目前总是会附加时间戳命令数据
-		ylen += xlen;
-		
 		if(emergy) {
 			TerminalSlave485_Send_Data(USART1_TX_BUF,ylen);
 			nstep = 0;
 			emergy = 0;
+			flowID++;
 		} else {
-			if(++nstep % SensorScanParam.nstep == 0) TerminalSlave485_Send_Data(USART1_TX_BUF,ylen);
+			if(++nstep % SensorScanParam.nstep == 0) {
+				TerminalSlave485_Send_Data(USART1_TX_BUF,ylen);
+				flowID++;
+			}
 		}
 	}
 }