Browse Source

232未完成

lijinwen 1 month ago
parent
commit
1f529d9c40

+ 515 - 512
ProtocolIIC/iic_decoder.cc

@@ -13,516 +13,519 @@
 
 namespace Protocol
 {
-	bool IicDecoder::DecodeIic(const IicDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_clk,
-		const EdgePulseDataTwoLevels& edge_pulses_data, IicDecodeResult& result)
-	{
-		result = {};
-		result.decoder_ptr = reinterpret_cast<intptr_t>(this);
-		is_cancel_ptr_ = option.is_cancel;
-		wave_data_len_ = static_cast<int32_t>(
-			std::min(edge_pulses_clk.waveform_data_count, edge_pulses_data.waveform_data_count));
-		bit_width_ = option.data_bit_width;
-		const int32_t addr_len = bit_width_ == IicEnums::DataBitWidth::DATA_BIT_WIDTH_7_BIT ? 7 : 10;
-		int32_t start_index = 0;
-
-		packet_infos_.clear();
-		packet_info_datas_.clear();
-		TwoLevelEdgePulse* edge_pulses_data_ptr = edge_pulses_data.GetDataAddrPtr();
-		TwoLevelEdgePulse* edge_pulses_clk_ptr = edge_pulses_clk.GetDataAddrPtr();
-
-		/*auto t1 = offsetof(IicDataInfo, data);
-		auto t2 = offsetof(IicDataInfo, ack);
-		auto t3 = offsetof(IicDataInfo, ack_index);
-		auto t4 = offsetof(IicDataInfo, ack_length);
-		auto t5 = offsetof(IicDataInfo, success_ack);
-		auto t6 = offsetof(IicDataInfo, has_ack);*/
-
-		while (true)
-		{
-			// 检查是否取消
-			if (is_cancel_ptr_ != nullptr && *is_cancel_ptr_)
-			{
-				WriteLog(LogLevel::Level2, "AsyncFunction canceled");
-				return false;
-			}
-			while (start_index > 0 && edge_pulses_clk_ptr->start_index > start_index)
-			{
-				edge_pulses_clk_ptr--;
-			}
-			// find start index
-			if (!FindStartNode(start_index, edge_pulses_data_ptr, edge_pulses_clk_ptr))
-			{
-				break;
-			}
-			//start_index = edge_pulses_data_ptr->start_index;
-			int32_t data_len = wave_data_len_;
-			IicEvent info = {};
-			info.has_start = true;
-			info.start_index = start_index;
-			info.start_len = 1;
-
-			//start_index = edge_pulses_clk_ptr++->start_index;
-			if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-			start_index = edge_pulses_clk_ptr->start_index;
-			//if (start_index <= 0) break;
-			//start_index = edge_pulses_clk_ptr++->start_index;
-			if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-			start_index = edge_pulses_clk_ptr->start_index;
-			//if (start_index <= 0) break;
-
-			info.addr_index = start_index;
-			for (int index = 0; index < addr_len; ++index)
-			{
-				if (start_index >= data_len)
-				{
-					start_index = data_len;
-					break;
-				}
-				if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
-				{
-					start_index = data_len;
-					break;
-				}
-				const bool bit = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High;
-				info.addr_data = static_cast<uint16_t>(info.addr_data << 1 | (bit ? 1 : 0));
-				if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-				{
-					start_index = data_len;
-					break;
-				}
-				start_index = edge_pulses_clk_ptr->start_index;
-				if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-				{
-					start_index = data_len;
-					break;
-				}
-				start_index = edge_pulses_clk_ptr->start_index;
-			}
-			info.addr_len = start_index - info.addr_index;
-
-			// 解析RW标识位
-			info.rw_index = start_index;
-			if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-			info.rw = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High ? 1 : 0;//get level
-			start_index = edge_pulses_clk_ptr->start_index;
-			if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-
-			if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-			start_index = edge_pulses_clk_ptr->start_index;
-			if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-			start_index = edge_pulses_clk_ptr->start_index;
-
-			info.rw_len = start_index - info.rw_index;
-
-			//解析Addr后的ACK信号
-			info.addr_ack_index = start_index;
-			info.success_addr_ack = false;
-			if (start_index >= data_len) {
-				packet_infos_.push_back(info);
-				break;
-			}
-			if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-			info.addr_ack = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High;  //get level
-			if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-			start_index = edge_pulses_clk_ptr->start_index;
-
-			info.addr_ack_len = start_index - info.addr_ack_index;
-
-
-			if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-			start_index = edge_pulses_clk_ptr->start_index;
-
-			if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
-			{
-				start_index = data_len;
-				packet_infos_.push_back(info);
-				break;
-			}
-
-			std::vector<IicDataInfo> temp_infos;
-			//开始解析数据
-			while (true)
-			{
-				int32_t stop_index = 0;
-				if (info.end_index > 0) {
-					stop_index = info.end_index;
-				}
-				else if (FindStopNode(start_index, edge_pulses_data_ptr, edge_pulses_clk_ptr, stop_index))
-				{
-					//stop_index = edge_pulses_data_ptr->start_index;
-					if (stop_index > 0)
-					{
-						info.has_end = true;
-						info.end_index = stop_index;
-						info.end_len = 1;
-						if (start_index >= stop_index)
-						{
-							start_index = stop_index + 1;
-							break;
-						}
-					}
-					//break;
-				}
-
-				//下一帧 查找下一段启动信号
-				if (start_index > edge_pulses_clk_ptr->start_index)
-				{
-					start_index = edge_pulses_clk_ptr->start_index;
-				}
-				int32_t next_start_index = start_index;
-				if (FindStartNode(next_start_index, edge_pulses_data_ptr, edge_pulses_clk_ptr) || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
-				{
-
-				}
-				else
-				{
-					next_start_index = -1;
-				}
-
-				if (start_index >= next_start_index && next_start_index != -1)
-				{
-					start_index = next_start_index - 1;
-					break;
-				}
-				IicDataInfo data_info = {};
-				data_info.index = start_index;
-
-				//解析数据
-				for (int32_t index = 0; index < 8; index++)
-				{
-					if (start_index >= data_len)
-					{
-						start_index = data_len;
-						break;
-					}
-					if (start_index >= stop_index && stop_index > 0)
-					{
-						start_index = stop_index + 1;
-						break;
-					}
-					if (start_index >= next_start_index && next_start_index > 0)
-					{
-						start_index = next_start_index - 1;
-						break;
-					}
-					data_info.data <<= 1;
-					if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
-					{
-						start_index = data_len;
-						break;
-					}
-					bool bit = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High;
-					data_info.data |= static_cast<uint8_t>(bit ? 1 : 0);
-
-					if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-					{
-						start_index = data_len;
-						break;
-					}
-					start_index = edge_pulses_clk_ptr->start_index;
-					if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
-					{
-						start_index = data_len;
-						break;
-					}
-
-					if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-					{
-						start_index = data_len;
-						break;
-					}
-					start_index = edge_pulses_clk_ptr->start_index;
-					if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
-					{
-						start_index = data_len;
-						break;
-					}
-				}
-
-				if (start_index >= data_len) break;
-				if (start_index >= stop_index && stop_index > 0)
-				{
-					start_index = stop_index + 1;
-					break;
-				}
-				if (start_index >= next_start_index && next_start_index != -1)
-				{
-					start_index = next_start_index - 1;
-					break;
-				}
-				//计算长度
-				//data_info.length = stop_index - start_index;
-				data_info.length = start_index - data_info.index;
-				//解析数据包后的ACK信号
-				data_info.ack_index = start_index;
-				if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
-				{
-					start_index = data_len;
-					break;
-				}
-				data_info.ack = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High ? 1 : 0;
-
-				if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-				{
-					start_index = data_len;
-					break;
-				}
-				start_index = edge_pulses_clk_ptr->start_index;
-
-				if (start_index <= 0 /*|| token.IsCancellationRequested || needclear*/)
-				{
-					start_index = data_len;
-					break;
-				}
-				data_info.ack_length = start_index - data_info.ack_index;
-				data_info.success_ack = 0;
-				if (start_index >= stop_index && stop_index > 0)
-				{
-					start_index = stop_index + 1;
-					break;
-				}
-				if (start_index >= next_start_index && next_start_index != -1)
-				{
-					start_index = next_start_index - 1;
-					break;
-				}
-				temp_infos.push_back(data_info);
-
-				if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
-				{
-					start_index = data_len;
-					break;
-				}
-				start_index = edge_pulses_clk_ptr->start_index;
-
-				if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
-				{
-					start_index = data_len;
-					break;
-				}
-			}
-			//info.data_infos = temp_infos;
-			//最后一个数据包的ACK信号为NACK
-			if (!temp_infos.empty())
-			{
-				info.data_infos_index = packet_info_datas_.size() + 1;
-				//int32_t old_data_len = static_cast<int32_t>(packet_info_datas_.size());
-				info.data_infos_count = static_cast<int32_t>(temp_infos.size());
-				// 使用std::move将temp_infos的内容移动到packet_info_datas_的末尾
-				packet_info_datas_.insert(packet_info_datas_.end(),
-					std::make_move_iterator(temp_infos.begin()), std::make_move_iterator(temp_infos.end()));
-				//info.data_infos_ptr = reinterpret_cast<intptr_t> (packet_info_datas_.data() + old_data_len - 1);
-
-				info.has_end = true;
-
-				//info.end_index = start_index;
-
-				info.end_len = 1;
-
-				//info.success_addr_ack = true;
-			}
-
-			packet_infos_.push_back(info);
-		}
-		if (!packet_infos_.empty())
-		{
-			result.decode_event_need_update = true;
-		}
-		result.decode_event_count = packet_infos_.size();
-		result.decode_events_ptr = packet_infos_.data();
-		result.decode_data_cell_ptr = packet_info_datas_.data();
-		return true;
-	}
-	bool IicDecoder::FindStopNode(int32_t start_index, TwoLevelEdgePulse* node_sda,
-		TwoLevelEdgePulse* node_scl, int32_t& stop_index)
-	{
-		if (start_index < 0)
-		{
-			return false;
-		}
-		TwoLevelEdgePulse* node_sda_tmp = node_sda;
-		TwoLevelEdgePulse* node_scl_tmp = node_scl;
-		const auto start_time = std::chrono::steady_clock::now();
-		while (CommonHelper::CheckTwoLevelEdgePulseValid(node_sda_tmp))
-		{
-			// 找到SDA上升沿
-			// 寻找SCL高
-			/*if (node_sda_tmp->start_index > start_index || node_sda_tmp->current_level != TwoLevelEdgePulseStatusType::High)
-			{
-				node_sda_tmp++;
-				continue;
-			}*/
-			while (node_sda_tmp->start_index < start_index || node_sda_tmp->current_level != TwoLevelEdgePulseStatusType::High)
-			{
-				node_sda_tmp++;
-				if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_sda_tmp))
-				{
-					return false;
-				}
-			}
-			if (!CommonHelper::FindNextNode(node_sda_tmp->start_index, node_scl_tmp))
-			{
-				return false;
-			}
-
-			while (node_sda_tmp->start_index > node_scl_tmp->start_index)
-			{
-				node_scl_tmp++;
-				if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_scl))
-				{
-					return false;
-				}
-			}
-			//sda高
-			// 确认下一个SCL为低电平
-			if (node_scl_tmp->current_level == TwoLevelEdgePulseStatusType::Low)
-			{
-				if (node_sda_tmp->start_index < node_scl_tmp->start_index)
-				{
-					// 找到目标停止条件
-					stop_index = node_sda_tmp->start_index;
-					return true;
-				}
-			}
-			node_scl_tmp++;
-			start_index = node_scl_tmp->end_index;
-			//start_index = node_scl_tmp->end_index + 1;
-		/*	auto end_time = std::chrono::steady_clock::now();
-			auto tmp = std::chrono::duration_cast<std::chrono::seconds>(
-				end_time - start_time).count();*/
-			if (auto end_time = std::chrono::steady_clock::now(); std::chrono::duration_cast<std::chrono::seconds>(
-				end_time - start_time).count() >
-				DECODE_OUT_TIME_BY_SEC)
-			{
-				WriteLog(LogLevel::Level2, "IIC FindStopNode TimeOut");
-				return false;
-			}
-		}
-		return CommonHelper::CheckTwoLevelEdgePulseValid(node_sda_tmp);
-	}
-
-	bool IicDecoder::FindStartNode(int32_t& start_index, TwoLevelEdgePulse* node_sda,
-		TwoLevelEdgePulse* node_scl)
-	{
-		if (start_index < 0)
-		{
-			return false;
-		}
-		const auto start_time = std::chrono::steady_clock::now();
-		while (CommonHelper::CheckTwoLevelEdgePulseValid(node_sda))
-		{
-			// 找到SDA下降沿
-			// 寻找SCL高
-		/*	if (node_sda->start_index < start_index)
-			{
-				node_sda += 1;
-			}
-			if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_sda))
-			{
-				return false;
-			}
-			if (node_sda->current_level != TwoLevelEdgePulseStatusType::Low)
-			{
-				node_sda += 1;
-			}*/
-			while (node_sda->start_index < start_index || node_sda->current_level != TwoLevelEdgePulseStatusType::Low)
-			{
-				node_sda++;
-				if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_sda))
-				{
-					return false;
-				}
-			}
-
-			while (node_scl->start_index < start_index)
-			{
-				node_scl++;
-				if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_scl))
-				{
-					return false;
-				}
-			}
-			//sda 低 
-			if (node_sda->start_index > node_scl->start_index)
-			{
-				node_scl += 1;
-			}
-			if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_scl))
-			{
-				return false;
-			}
-
-			//找到SCL下降沿
-			if (node_scl->current_level == TwoLevelEdgePulseStatusType::Low)
-			{
-				if (node_sda->start_index < node_scl->start_index)
-				{
-					//找到目标头
-					start_index = node_sda->start_index;
-					return true;
-				}
-			}
-			if (node_sda->end_index < start_index)
-			{
-				node_sda++;
-			}
-			start_index = node_sda->end_index + 1;
-			/*auto end_time = std::chrono::steady_clock::now();
-			auto tmp = std::chrono::duration_cast<std::chrono::seconds>(
-				end_time - start_time).count();*/
-			if (auto end_time = std::chrono::steady_clock::now(); std::chrono::duration_cast<std::chrono::seconds>(
-				end_time - start_time).count() >
-				DECODE_OUT_TIME_BY_SEC)
-			{
-				WriteLog(LogLevel::Level2, "IIC FindStartNode TimeOut");
-				return false;
-			}
-		}
-		return CommonHelper::CheckTwoLevelEdgePulseValid(node_sda);
-	}
+    bool IicDecoder::DecodeIic(const IicDecodeOptions& option, const EdgePulseDataTwoLevels& edge_pulses_clk,
+                               const EdgePulseDataTwoLevels& edge_pulses_data, IicDecodeResult& result)
+    {
+        result = {};
+        result.decoder_ptr = reinterpret_cast<intptr_t>(this);
+        is_cancel_ptr_ = option.is_cancel;
+        wave_data_len_ = static_cast<int32_t>(
+            std::min(edge_pulses_clk.waveform_data_count, edge_pulses_data.waveform_data_count));
+        bit_width_ = option.data_bit_width;
+        const int32_t addr_len = bit_width_ == IicEnums::DataBitWidth::DATA_BIT_WIDTH_7_BIT ? 7 : 10;
+        int32_t start_index = 0;
+
+        packet_infos_.clear();
+        packet_info_datas_.clear();
+        TwoLevelEdgePulse* edge_pulses_data_ptr = edge_pulses_data.GetDataAddrPtr();
+        TwoLevelEdgePulse* edge_pulses_clk_ptr = edge_pulses_clk.GetDataAddrPtr();
+
+        /*auto t1 = offsetof(IicDataInfo, data);
+        auto t2 = offsetof(IicDataInfo, ack);
+        auto t3 = offsetof(IicDataInfo, ack_index);
+        auto t4 = offsetof(IicDataInfo, ack_length);
+        auto t5 = offsetof(IicDataInfo, success_ack);
+        auto t6 = offsetof(IicDataInfo, has_ack);*/
+
+        while (true)
+        {
+            // 检查是否取消
+            if (is_cancel_ptr_ != nullptr && *is_cancel_ptr_)
+            {
+                WriteLog(LogLevel::Level2, "AsyncFunction canceled");
+                return false;
+            }
+            while (start_index > 0 && edge_pulses_clk_ptr->start_index > start_index)
+            {
+                edge_pulses_clk_ptr--;
+            }
+            // find start index
+            if (!FindStartNode(start_index, edge_pulses_data_ptr, edge_pulses_clk_ptr))
+            {
+                break;
+            }
+            //start_index = edge_pulses_data_ptr->start_index;
+            int32_t data_len = wave_data_len_;
+            IicEvent info = {};
+            info.has_start = true;
+            info.start_index = start_index;
+            info.start_len = 1;
+
+            //start_index = edge_pulses_clk_ptr++->start_index;
+            if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+            start_index = edge_pulses_clk_ptr->start_index;
+            //if (start_index <= 0) break;
+            //start_index = edge_pulses_clk_ptr++->start_index;
+            if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+            start_index = edge_pulses_clk_ptr->start_index;
+            //if (start_index <= 0) break;
+
+            info.addr_index = start_index;
+            for (int index = 0; index < addr_len; ++index)
+            {
+                if (start_index >= data_len)
+                {
+                    start_index = data_len;
+                    break;
+                }
+                if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
+                {
+                    start_index = data_len;
+                    break;
+                }
+                const bool bit = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High;
+                info.addr_data = static_cast<uint16_t>(info.addr_data << 1 | (bit ? 1 : 0));
+                if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+                {
+                    start_index = data_len;
+                    break;
+                }
+                start_index = edge_pulses_clk_ptr->start_index;
+                if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+                {
+                    start_index = data_len;
+                    break;
+                }
+                start_index = edge_pulses_clk_ptr->start_index;
+            }
+            info.addr_len = start_index - info.addr_index;
+
+            // 解析RW标识位
+            info.rw_index = start_index;
+            if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+            info.rw = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High ? 1 : 0;//get level
+            start_index = edge_pulses_clk_ptr->start_index;
+            if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+
+            if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+            start_index = edge_pulses_clk_ptr->start_index;
+            if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+            start_index = edge_pulses_clk_ptr->start_index;
+
+            info.rw_len = start_index - info.rw_index;
+
+            //解析Addr后的ACK信号
+            info.addr_ack_index = start_index;
+            info.success_addr_ack = false;
+            if (start_index >= data_len)
+            {
+                packet_infos_.push_back(info);
+                break;
+            }
+            if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+            info.addr_ack = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High;  //get level
+            if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+            start_index = edge_pulses_clk_ptr->start_index;
+
+            info.addr_ack_len = start_index - info.addr_ack_index;
+
+
+            if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+            start_index = edge_pulses_clk_ptr->start_index;
+
+            if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
+            {
+                start_index = data_len;
+                packet_infos_.push_back(info);
+                break;
+            }
+
+            std::vector<IicDataInfo> temp_infos;
+            //开始解析数据
+            while (true)
+            {
+                int32_t stop_index = 0;
+                if (info.end_index > 0)
+                {
+                    stop_index = info.end_index;
+                }
+                else if (FindStopNode(start_index, edge_pulses_data_ptr, edge_pulses_clk_ptr, stop_index))
+                {
+                    //stop_index = edge_pulses_data_ptr->start_index;
+                    if (stop_index > 0)
+                    {
+                        info.has_end = true;
+                        info.end_index = stop_index;
+                        info.end_len = 1;
+                        if (start_index >= stop_index)
+                        {
+                            start_index = stop_index + 1;
+                            break;
+                        }
+                    }
+                    //break;
+                }
+
+                //下一帧 查找下一段启动信号
+                if (start_index > edge_pulses_clk_ptr->start_index)
+                {
+                    start_index = edge_pulses_clk_ptr->start_index;
+                }
+                int32_t next_start_index = start_index;
+                if (FindStartNode(next_start_index, edge_pulses_data_ptr, edge_pulses_clk_ptr) || (is_cancel_ptr_ != nullptr && *
+                    is_cancel_ptr_))
+                {
+                }
+                else
+                {
+                    next_start_index = -1;
+                }
+
+                if (start_index >= next_start_index && next_start_index != -1)
+                {
+                    start_index = next_start_index - 1;
+                    break;
+                }
+                IicDataInfo data_info = {};
+                data_info.index = start_index;
+
+                //解析数据
+                for (int32_t index = 0; index < 8; index++)
+                {
+                    if (start_index >= data_len)
+                    {
+                        start_index = data_len;
+                        break;
+                    }
+                    if (start_index >= stop_index && stop_index > 0)
+                    {
+                        start_index = stop_index + 1;
+                        break;
+                    }
+                    if (start_index >= next_start_index && next_start_index > 0)
+                    {
+                        start_index = next_start_index - 1;
+                        break;
+                    }
+                    data_info.data <<= 1;
+                    if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
+                    {
+                        start_index = data_len;
+                        break;
+                    }
+                    bool bit = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High;
+                    data_info.data |= static_cast<uint8_t>(bit ? 1 : 0);
+
+                    if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+                    {
+                        start_index = data_len;
+                        break;
+                    }
+                    start_index = edge_pulses_clk_ptr->start_index;
+                    if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
+                    {
+                        start_index = data_len;
+                        break;
+                    }
+
+                    if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+                    {
+                        start_index = data_len;
+                        break;
+                    }
+                    start_index = edge_pulses_clk_ptr->start_index;
+                    if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
+                    {
+                        start_index = data_len;
+                        break;
+                    }
+                }
+
+                if (start_index >= data_len) break;
+                if (start_index >= stop_index && stop_index > 0)
+                {
+                    start_index = stop_index + 1;
+                    break;
+                }
+                if (start_index >= next_start_index && next_start_index != -1)
+                {
+                    start_index = next_start_index - 1;
+                    break;
+                }
+                //计算长度
+                //data_info.length = stop_index - start_index;
+                data_info.length = start_index - data_info.index;
+                //解析数据包后的ACK信号
+                data_info.ack_index = start_index;
+                if (!CommonHelper::GetNodeByIndex(start_index, edge_pulses_data_ptr))
+                {
+                    start_index = data_len;
+                    break;
+                }
+                data_info.ack = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High ? 1 : 0;
+
+                if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+                {
+                    start_index = data_len;
+                    break;
+                }
+                start_index = edge_pulses_clk_ptr->start_index;
+
+                if (start_index <= 0 /*|| token.IsCancellationRequested || needclear*/)
+                {
+                    start_index = data_len;
+                    break;
+                }
+                data_info.ack_length = start_index - data_info.ack_index;
+                data_info.success_ack = 0;
+                if (start_index >= stop_index && stop_index > 0)
+                {
+                    start_index = stop_index + 1;
+                    break;
+                }
+                if (start_index >= next_start_index && next_start_index != -1)
+                {
+                    start_index = next_start_index - 1;
+                    break;
+                }
+                temp_infos.push_back(data_info);
+
+                if (!CommonHelper::FindNextNode(start_index, edge_pulses_clk_ptr) || edge_pulses_clk_ptr->start_index <= 0)
+                {
+                    start_index = data_len;
+                    break;
+                }
+                start_index = edge_pulses_clk_ptr->start_index;
+
+                if (start_index <= 0 || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
+                {
+                    start_index = data_len;
+                    break;
+                }
+            }
+            //info.data_infos = temp_infos;
+            //最后一个数据包的ACK信号为NACK
+            if (!temp_infos.empty())
+            {
+                info.data_infos_index = static_cast<int32_t>(packet_info_datas_.size() + 1);
+                //int32_t old_data_len = static_cast<int32_t>(packet_info_datas_.size());
+                info.data_infos_count = static_cast<int32_t>(temp_infos.size());
+                // 使用std::move将temp_infos的内容移动到packet_info_datas_的末尾
+                packet_info_datas_.insert(packet_info_datas_.end(),
+                                          std::make_move_iterator(temp_infos.begin()),
+                                          std::make_move_iterator(temp_infos.end()));
+                //info.data_infos_ptr = reinterpret_cast<intptr_t> (packet_info_datas_.data() + old_data_len - 1);
+
+                info.has_end = true;
+
+                //info.end_index = start_index;
+
+                info.end_len = 1;
+
+                //info.success_addr_ack = true;
+            }
+
+            packet_infos_.push_back(info);
+        }
+        if (!packet_infos_.empty())
+        {
+            result.decode_event_need_update = true;
+        }
+        result.decode_event_count = packet_infos_.size();
+        result.decode_events_ptr = packet_infos_.data();
+        result.decode_data_cell_ptr = packet_info_datas_.data();
+        return true;
+    }
+    bool IicDecoder::FindStopNode(int32_t start_index, TwoLevelEdgePulse* node_sda,
+                                  TwoLevelEdgePulse* node_scl, int32_t& stop_index)
+    {
+        if (start_index < 0)
+        {
+            return false;
+        }
+        TwoLevelEdgePulse* node_sda_tmp = node_sda;
+        TwoLevelEdgePulse* node_scl_tmp = node_scl;
+        const auto start_time = std::chrono::steady_clock::now();
+        while (CommonHelper::CheckTwoLevelEdgePulseValid(node_sda_tmp))
+        {
+            // 找到SDA上升沿
+            // 寻找SCL高
+            /*if (node_sda_tmp->start_index > start_index || node_sda_tmp->current_level != TwoLevelEdgePulseStatusType::High)
+            {
+                node_sda_tmp++;
+                continue;
+            }*/
+            while (node_sda_tmp->start_index < start_index || node_sda_tmp->current_level != TwoLevelEdgePulseStatusType::High)
+            {
+                node_sda_tmp++;
+                if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_sda_tmp))
+                {
+                    return false;
+                }
+            }
+            if (!CommonHelper::FindNextNode(node_sda_tmp->start_index, node_scl_tmp))
+            {
+                return false;
+            }
+
+            while (node_sda_tmp->start_index > node_scl_tmp->start_index)
+            {
+                node_scl_tmp++;
+                if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_scl))
+                {
+                    return false;
+                }
+            }
+            //sda高
+            // 确认下一个SCL为低电平
+            if (node_scl_tmp->current_level == TwoLevelEdgePulseStatusType::Low)
+            {
+                if (node_sda_tmp->start_index < node_scl_tmp->start_index)
+                {
+                    // 找到目标停止条件
+                    stop_index = node_sda_tmp->start_index;
+                    return true;
+                }
+            }
+            node_scl_tmp++;
+            start_index = node_scl_tmp->end_index;
+            //start_index = node_scl_tmp->end_index + 1;
+            /*	auto end_time = std::chrono::steady_clock::now();
+                auto tmp = std::chrono::duration_cast<std::chrono::seconds>(
+                    end_time - start_time).count();*/
+            if (auto end_time = std::chrono::steady_clock::now(); std::chrono::duration_cast<std::chrono::seconds>(
+                    end_time - start_time).count() >
+                DECODE_OUT_TIME_BY_SEC)
+            {
+                WriteLog(LogLevel::Level2, "IIC FindStopNode TimeOut");
+                return false;
+            }
+        }
+        return CommonHelper::CheckTwoLevelEdgePulseValid(node_sda_tmp);
+    }
+
+    bool IicDecoder::FindStartNode(int32_t& start_index, TwoLevelEdgePulse* node_sda,
+                                   TwoLevelEdgePulse* node_scl)
+    {
+        if (start_index < 0)
+        {
+            return false;
+        }
+        const auto start_time = std::chrono::steady_clock::now();
+        while (CommonHelper::CheckTwoLevelEdgePulseValid(node_sda))
+        {
+            // 找到SDA下降沿
+            // 寻找SCL高
+            /*	if (node_sda->start_index < start_index)
+                {
+                    node_sda += 1;
+                }
+                if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_sda))
+                {
+                    return false;
+                }
+                if (node_sda->current_level != TwoLevelEdgePulseStatusType::Low)
+                {
+                    node_sda += 1;
+                }*/
+            while (node_sda->start_index < start_index || node_sda->current_level != TwoLevelEdgePulseStatusType::Low)
+            {
+                node_sda++;
+                if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_sda))
+                {
+                    return false;
+                }
+            }
+
+            while (node_scl->start_index < start_index)
+            {
+                node_scl++;
+                if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_scl))
+                {
+                    return false;
+                }
+            }
+            //sda 低 
+            if (node_sda->start_index > node_scl->start_index)
+            {
+                node_scl += 1;
+            }
+            if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_scl))
+            {
+                return false;
+            }
+
+            //找到SCL下降沿
+            if (node_scl->current_level == TwoLevelEdgePulseStatusType::Low)
+            {
+                if (node_sda->start_index < node_scl->start_index)
+                {
+                    //找到目标头
+                    start_index = node_sda->start_index;
+                    return true;
+                }
+            }
+            if (node_sda->end_index < start_index)
+            {
+                node_sda++;
+            }
+            start_index = node_sda->end_index + 1;
+            /*auto end_time = std::chrono::steady_clock::now();
+            auto tmp = std::chrono::duration_cast<std::chrono::seconds>(
+                end_time - start_time).count();*/
+            if (auto end_time = std::chrono::steady_clock::now(); std::chrono::duration_cast<std::chrono::seconds>(
+                    end_time - start_time).count() >
+                DECODE_OUT_TIME_BY_SEC)
+            {
+                WriteLog(LogLevel::Level2, "IIC FindStartNode TimeOut");
+                return false;
+            }
+        }
+        return CommonHelper::CheckTwoLevelEdgePulseValid(node_sda);
+    }
 }

+ 1 - 1
ProtocolRS232/protocol_rs232_options.h

@@ -26,7 +26,7 @@ namespace Protocol
 
         Rs232Enums::DataBitWidth data_bit_width; //数据位宽
         Rs232Enums::StopBit stop_bit; //停止位
-        float threshold; //电平阈值
+         
         bool* is_cancel;
     };
 }

+ 112 - 111
ProtocolRS232/rs232_decoder.cc

@@ -31,12 +31,12 @@ namespace Protocol
             if (node->current_level != start_status && node->start_index >= start_index)
             {
                 //计算该脉宽中,最大包括几个bit信息宽度
-                const double bitCount = std::round(node->GetLength() / count);
-                if (bitCount > 0 && bitCount < static_cast<int32_t>(options.data_bit_width) + 4)
+                const double bit_count = std::round(node->GetLength() / count);
+                if (bit_count > 0 && bit_count < static_cast<int32_t>(options.data_bit_width) + 4)
                 {
-                    real_count = node->GetLength() / bitCount;
+                    real_count = node->GetLength() / bit_count;
                 }
-                if (bitCount > 0) break;
+                if (bit_count > 0) break;
             }
 
             node++;
@@ -65,10 +65,10 @@ namespace Protocol
         decode_events_ = {};
         decode_result_units_ = {};
 
-        auto decodeResultUnitsPtr = &decode_result_units_;
-        auto decodeEvents_Ptr = &decode_events_;
-        WriteLog(LogLevel::LevelDebug, "  decodeResultUnitsPtr:0x%X\n", static_cast<void*>(decodeResultUnitsPtr));
-        WriteLog(LogLevel::LevelDebug, "  decodeEvents_Ptr:0x%X\n", static_cast<void*>(decodeEvents_Ptr));
+        auto decode_result_units_ptr = &decode_result_units_;
+        auto decode_events_ptr = &decode_events_;
+        WriteLog(LogLevel::LevelDebug, "  decodeResultUnitsPtr:0x%X\n", static_cast<void*>(decode_result_units_ptr));
+        WriteLog(LogLevel::LevelDebug, "  decodeEvents_Ptr:0x%X\n", static_cast<void*>(decode_events_ptr));
 
         if (options.is_cancel)
         {
@@ -88,40 +88,40 @@ namespace Protocol
             return false;
         }
 
-        int32_t dataBitCount = 0;
+        int32_t data_bit_count = 0;
         switch (options.data_bit_width)
         {
         case Rs232Enums::DataBitWidth::DATA_BIT_WIDTH_5_BIT:
-            dataBitCount = 5;
+            data_bit_count = 5;
             break;
         case Rs232Enums::DataBitWidth::DATA_BIT_WIDTH_6_BIT:
-            dataBitCount = 6;
+            data_bit_count = 6;
             break;
         case Rs232Enums::DataBitWidth::DATA_BIT_WIDTH_7_BIT:
-            dataBitCount = 7;
+            data_bit_count = 7;
             break;
         case Rs232Enums::DataBitWidth::DATA_BIT_WIDTH_8_BIT:
-            dataBitCount = 8;
+            data_bit_count = 8;
             break;
         }
 
 
-        uint64_t edgePulseIndex = 0;
+        uint64_t edge_pulse_index = 0;
 
         //每bit理论长度
         const double count = 1.0 / options.baud_rate * sample_rate;
         WriteLog(LogLevel::LevelDebug, "  bit count:%f", count);
         //const double count = static_cast<double>(dataCount);
         //每bit实际长度
-        double realCount = count;
+        double real_count = count;
 
-        const int32_t stopBitCount = options.stop_bit == Rs232Enums::StopBit::STOP_BIT_1_BIT
+        const int32_t stop_bit_count = options.stop_bit == Rs232Enums::StopBit::STOP_BIT_1_BIT
                                          ? 1
                                          : options.stop_bit == Rs232Enums::StopBit::STOP_BIT_2_BIT
                                          ? 2
                                          : 1;
 
-        WriteLog(LogLevel::LevelDebug, "  realCount:%f", realCount);
+        WriteLog(LogLevel::LevelDebug, "  realCount:%f", real_count);
         WriteLog(LogLevel::LevelDebug, "  edgePulsePointer:0x%x", reinterpret_cast<void*>(edge_pulses));
         //WriteLog("  edgePulsePointer:0x%x", edgePulses);
         WriteLog(LogLevel::LevelDebug, "  edgePulse StartIndex:%d", edge_pulses->start_index);
@@ -130,15 +130,15 @@ namespace Protocol
 
         try
         {
-            int32_t startIndex = 0;
+            int32_t start_index = 0;
 
-            while (edge_pulses != nullptr && edgePulseIndex < edge_pulse_count)
+            while (edge_pulses != nullptr && edge_pulse_index < edge_pulse_count)
             {
                 if (count <= 2) break;
-                TwoLevelEdgePulseStatusType levelState;
+                TwoLevelEdgePulseStatusType level_state;
                 //找到帧头 根据帧头得到实际bit宽度realCount  帧头起始位置startIndex 电平状态levelState
-                int32_t packetStartIndex =
-                    GetStartIndex(options, edge_pulses, count, realCount, startIndex, levelState);
+                int32_t packet_start_index =
+                    GetStartIndex(options, edge_pulses, count, real_count, start_index, level_state);
                 //WriteLog("  GetStartIndex PacketStartIndex:%d\n", packetStartIndex);
                 if (options.is_cancel)
                 {
@@ -146,38 +146,38 @@ namespace Protocol
                     return false;
                 }
 
-                if (packetStartIndex == -1) break;
+                if (packet_start_index == -1) break;
                 //std::cout << " packetStartIndex:" << packetStartIndex << " ,realCount:" << realCount << "\n";
                 //构造帧
                 Rs232Packet packet = {};
-                packetStartIndex += static_cast<int32_t>(std::round(realCount / 2));
+                packet_start_index += static_cast<int32_t>(std::round(real_count / 2));
 
                 if (edge_pulses->start_index >= edge_pulses->end_index)
                 {
                     std::ostringstream msg;
-                    msg << " =>178 loop break Index:" << packetStartIndex << " ,dataCount:" <<
+                    msg << " =>178 loop break Index:" << packet_start_index << " ,dataCount:" <<
                         waveform_data_count << "\n";
                     WriteLog(LogLevel::LevelDebug, msg.str().c_str());
                     break;
                 }
-                if (packetStartIndex >= static_cast<int32_t>(waveform_data_count))
+                if (packet_start_index >= static_cast<int32_t>(waveform_data_count))
                 {
                     std::ostringstream msg;
-                    msg << " =>186 loop break Index:" << packetStartIndex << " ,dataCount:" <<
+                    msg << " =>186 loop break Index:" << packet_start_index << " ,dataCount:" <<
                         waveform_data_count << "\n";
                     WriteLog(LogLevel::LevelDebug, msg.str().c_str());
                     break;
                 }
 
-                if (startIndex == static_cast<int32_t>(waveform_data_count)) break;
+                if (start_index == static_cast<int32_t>(waveform_data_count)) break;
 
-                packet.start_bit = levelState == TwoLevelEdgePulseStatusType::High;
-                packet.start_index = packetStartIndex - static_cast<int32_t>(std::round(realCount / 2));
-                packet.data_index = packetStartIndex + static_cast<int32_t>(std::round(realCount / 2));
-                packet.per_bit_length = realCount;
+                packet.start_bit = level_state == TwoLevelEdgePulseStatusType::High;
+                packet.start_index = packet_start_index - static_cast<int32_t>(std::round(real_count / 2));
+                packet.data_index = packet_start_index + static_cast<int32_t>(std::round(real_count / 2));
+                packet.per_bit_length = real_count;
 
-                WriteLog(LogLevel::LevelDebug, "=> Tst  StartIndex:%d,dataBitCount:%d", packet.start_index, dataBitCount);
-                for (int32_t dataBitIndex = 0; dataBitIndex < dataBitCount; dataBitIndex++)
+                WriteLog(LogLevel::LevelDebug, "=> Tst  StartIndex:%d,dataBitCount:%d", packet.start_index, data_bit_count);
+                for (int32_t data_bit_index = 0; data_bit_index < data_bit_count; data_bit_index++)
                 {
                     if (options.is_cancel)
                     {
@@ -185,18 +185,18 @@ namespace Protocol
                         return false;
                     }
 
-                    packetStartIndex += static_cast<int32_t>(std::round(realCount));
+                    packet_start_index += static_cast<int32_t>(std::round(real_count));
 
                     //std::cout << "  P150 Test" << "\n";
-                    if (packetStartIndex >= static_cast<int32_t>(waveform_data_count))
+                    if (packet_start_index >= static_cast<int32_t>(waveform_data_count))
                     {
-                        startIndex = static_cast<int32_t>(waveform_data_count);
+                        start_index = static_cast<int32_t>(waveform_data_count);
                         WriteLog(LogLevel::LevelDebug, "  =>%d break \n", __LINE__);
                         break;
                     }
                     //std::cout << "  P157 Test" << "\n";
-                    TwoLevelEdgePulseStatusType bitStatus;
-                    if (!GetRs232Bit(edge_pulses, packetStartIndex, bitStatus))
+                    TwoLevelEdgePulseStatusType bit_status;
+                    if (!GetRs232Bit(edge_pulses, packet_start_index, bit_status))
                     {
                         //gMutex.unlock(); // 执行完操作后手动释放锁
                         return false;
@@ -205,51 +205,51 @@ namespace Protocol
                     if (options.msb_or_lsb == MSBOrLSB::MSB)
                     {
                         packet.data = static_cast<uint8_t>(packet.data << 1);
-                        packet.data |= bitStatus == TwoLevelEdgePulseStatusType::High ? 1 : 0;
+                        packet.data |= bit_status == TwoLevelEdgePulseStatusType::High ? 1 : 0;
                     }
                     else
                     {
-                        packet.data |= static_cast<uint8_t>((bitStatus ==
+                        packet.data |= static_cast<uint8_t>((bit_status ==
                                                              TwoLevelEdgePulseStatusType::High
                                                                  ? 1
-                                                                 : 0) << dataBitIndex);
+                                                                 : 0) << data_bit_index);
                     }
                     WriteLog(LogLevel::LevelDebug, "Tst CurrentLevel:%d, bitStatus:%d", edge_pulses->current_level,
-                             bitStatus);
+                             bit_status);
                 }
                 //std::cout << "  P177 Test" << "\n";
-                if (startIndex == static_cast<int32_t>(waveform_data_count)) break;
+                if (start_index == static_cast<int32_t>(waveform_data_count)) break;
                 //校验位
                 if (options.odd_even_check_type != OddEvenCheck::None)
                 {
-                    packetStartIndex += static_cast<int32_t>(std::round(realCount));
+                    packet_start_index += static_cast<int32_t>(std::round(real_count));
 
-                    if (packetStartIndex >= static_cast<int32_t>(waveform_data_count))
+                    if (packet_start_index >= static_cast<int32_t>(waveform_data_count))
                     {
                         //startIndex = static_cast<int32_t>(bufferLength);
                         rs232_packets.push_back(packet);
                         WriteLog(LogLevel::LevelDebug, "  =>%d break \n", __LINE__);
                         break;
                     }
-                    TwoLevelEdgePulseStatusType bitStatus;
-                    if (!GetRs232Bit(edge_pulses, packetStartIndex, bitStatus))
+                    TwoLevelEdgePulseStatusType bit_status;
+                    if (!GetRs232Bit(edge_pulses, packet_start_index, bit_status))
                     {
                         //gMutex.unlock(); // 执行完操作后手动释放锁
                         return false;
                     }
                     packet.parity_find = true;
-                    packet.parity_bit = bitStatus == TwoLevelEdgePulseStatusType::High;
+                    packet.parity_bit = bit_status == TwoLevelEdgePulseStatusType::High;
                     packet.parity_result = DataCheckHelper::CheckDataByOddEven(
-                        packet.data, dataBitCount, options.odd_even_check_type);
+                        packet.data, data_bit_count, options.odd_even_check_type);
                     packet.parity_index = packet.data_index + static_cast<int32_t>(
-                        std::round(realCount * dataBitCount));
+                        std::round(real_count * data_bit_count));
                 }
                 //std::cout << "  P203 Test" << "\n";
                 rs232_packets.push_back(packet);
 
-                packetStartIndex += static_cast<int32_t>(realCount * stopBitCount);
-                startIndex = packetStartIndex;
-                edgePulseIndex++;
+                packet_start_index += static_cast<int32_t>(real_count * stop_bit_count);
+                start_index = packet_start_index;
+                edge_pulse_index++;
             }
         }
         catch (const char* ex)
@@ -260,7 +260,7 @@ namespace Protocol
 
         {
             std::ostringstream msg;
-            msg << "  edgePulseIndex:" << edgePulseIndex << ",";
+            msg << "  edgePulseIndex:" << edge_pulse_index << ",";
             msg << "  rs232Packets count:" << rs232_packets.size() << ",";
             msg << "  get events && results";
             WriteLog(LogLevel::Level2, msg.str().c_str());
@@ -279,83 +279,84 @@ namespace Protocol
                     //gMutex.unlock(); // 执行完操作后手动释放锁
                     return false;
                 }
-                Rs232DecodeResultCell resultUnit;
-                Rs232DecodeEvent decodeEvent = {};
-                auto eventPtr = &decodeEvent;
-                Rs232DecodeEventUnit eventStart;
-                Rs232DecodeEventUnit eventData;
-                int64_t eventStartIndex = packet.start_index;
-                int64_t oneBitLength = static_cast<int64_t>(packet.per_bit_length);
+                Rs232DecodeResultCell result_unit;
+                Rs232DecodeEvent decode_event = {};
+                Rs232DecodeEvent* event_ptr;
+                event_ptr = &decode_event;
+                Rs232DecodeEventUnit event_start;
+                Rs232DecodeEventUnit event_data;
+                int64_t event_start_index = packet.start_index;
+                int64_t one_bit_length = static_cast<int64_t>(packet.per_bit_length);
 
-                eventPtr->start_index = packet.start_index;
+                event_ptr->start_index = packet.start_index;
 
-                eventStart.start_index = packet.start_index;
-                eventStart.length = oneBitLength;
-                eventStartIndex += 1;
-                eventStart.event_type = Rs232Enums::Rs232DecodeEventType::START;
+                event_start.start_index = packet.start_index;
+                event_start.length = one_bit_length;
+                event_start_index += 1;
+                event_start.event_type = Rs232Enums::Rs232DecodeEventType::START;
 
-                eventData.start_index = eventStart.start_index;
-                eventData.length = oneBitLength * dataBitCount;
-                eventData.data = packet.data;
-                eventData.event_type = Rs232Enums::Rs232DecodeEventType::DATA;
-                eventStartIndex += 8;
+                event_data.start_index = event_start.start_index;
+                event_data.length = one_bit_length * data_bit_count;
+                event_data.data = packet.data;
+                event_data.event_type = Rs232Enums::Rs232DecodeEventType::DATA;
+                event_start_index += 8;
 
 
                 //std::cout << "  P249 Test I:" << i << "\n";
                 if (packet.parity_find)
                 {
-                    Rs232DecodeEventUnit eventUints[3];
-                    eventUints[0] = eventStart;
-                    eventUints[1] = eventData;
-                    Rs232DecodeEventUnit eventParity;
+                    Rs232DecodeEventUnit event_uints[3];
+                    event_uints[0] = event_start;
+                    event_uints[1] = event_data;
+                    Rs232DecodeEventUnit event_parity;
                     //std::cout << "  P253 Test I:" << i << "\n";
-                    eventParity.data = packet.parity_result ? 1 : 0;
-                    eventParity.start_index = eventStartIndex;
-                    eventParity.length = oneBitLength;
-                    eventParity.event_type = Rs232Enums::Rs232DecodeEventType::PARITY;
-                    eventPtr->parity_result = packet.parity_result ? 1 : 0;
-                    eventUints[2] = eventParity;
+                    event_parity.data = packet.parity_result ? 1 : 0;
+                    event_parity.start_index = event_start_index;
+                    event_parity.length = one_bit_length;
+                    event_parity.event_type = Rs232Enums::Rs232DecodeEventType::PARITY;
+                    event_ptr->parity_result = packet.parity_result ? 1 : 0;
+                    event_uints[2] = event_parity;
                     //eventPtr->EventData = eventUints;
-                    eventStartIndex += 8;
-                    eventPtr->event_data_count = 3;
-                    eventPtr->end_index = packet.start_index + oneBitLength * (dataBitCount + 1);
+                    event_start_index += 8;
+                    event_ptr->event_data_count = 3;
+                    event_ptr->end_index = packet.start_index + one_bit_length * (data_bit_count + 1);
                     // 将eventUints复制到decodeEventUnitsStorage中
-                    decode_event_units_storage_.insert(decode_event_units_storage_.end(), std::begin(eventUints),
-                                                   std::end(eventUints));
+                    decode_event_units_storage_.insert(decode_event_units_storage_.end(), std::begin(event_uints),
+                                                   std::end(event_uints));
                     //最后来赋值
                     //decodeEvent.EventData = decodeEventUnitsStorage_.data() + decodeEventUnitsStorage_.size() - 3;
                 }
                 else
                 {
-                    Rs232DecodeEventUnit eventUints[2];
-                    eventUints[0] = eventStart;
-                    eventUints[1] = eventData;
-                    eventPtr->event_data_count = 2;
+                    Rs232DecodeEventUnit event_uints[2];
+                    event_uints[0] = event_start;
+                    event_uints[1] = event_data;
+                    event_ptr->event_data_count = 2;
 
                     //eventPtr->EventData = eventUints;
                     //std::cout << "  P263 Test I:" << i << "\n";
-                    eventPtr->parity_result = 0;
-                    eventPtr->end_index = packet.start_index + oneBitLength * (dataBitCount);
+                    event_ptr->parity_result = 0;
+                    event_ptr->end_index = packet.start_index + one_bit_length * (data_bit_count);
                     // 将eventUints复制到decodeEventUnitsStorage中
-                    decode_event_units_storage_.insert(decode_event_units_storage_.end(), std::begin(eventUints),
-                                                   std::end(eventUints));
+                    decode_event_units_storage_.insert(decode_event_units_storage_.end(), std::begin(event_uints),
+                                                   std::end(event_uints));
                     //最后来赋值
                     //decodeEvent.EventData = decodeEventUnitsStorage_.data() + decodeEventUnitsStorage_.size() - 2;
                 }
 
                 //std::cout << "  P266 Test I:" << i << "\n";
-                resultUnit.startIndex = packet.start_index;
+                result_unit.start_index = packet.start_index;
                 //最后来赋值
                 //resultUnit.data = &packet.data;
-                WriteLog(LogLevel::LevelDebug, "  Tst Data Ptr:0x%x , Data:%d", static_cast<void*>(resultUnit.data),
+                WriteLog(LogLevel::LevelDebug, "  Tst Data Ptr:0x%x , Data:%d", static_cast<void*>(result_unit.data),
                          packet.data);
-                resultUnit.dataCount = 1;
-                resultUnit.length = eventStartIndex - packet.start_index;
+                result_unit.data_count = 1;
+                result_unit.length = event_start_index - packet.start_index;
 
-                eventPtr->event_index = static_cast<int64_t>(decodeEvents_Ptr->size());
+                event_ptr->event_index = static_cast<int64_t>(decode_events_ptr->size());
 
-                decode_events_.push_back(decodeEvent);
-                decode_result_units_.push_back(resultUnit);
+                decode_events_.push_back(decode_event);
+                decode_result_units_.push_back(result_unit);
 
                 decode_result.decode_event_need_update = true;
                 decode_result.decode_result_need_update = true;
@@ -363,19 +364,19 @@ namespace Protocol
         }
 
         /////////////////////////// 指针赋值 /////////////////////////////////
-        int64_t eventDataIndex = 0;
+        int64_t event_data_index = 0;
         for (int i = 0; i < decode_events_.size(); i++) // NOLINT(modernize-loop-convert, clang-diagnostic-sign-compare)
         {
-            decode_events_[i].event_data = decode_event_units_storage_.data() + eventDataIndex;
-            eventDataIndex += decode_events_[i].event_data_count;
+            decode_events_[i].event_data = decode_event_units_storage_.data() + event_data_index;
+            event_data_index += decode_events_[i].event_data_count;
         }
 
         for (int i = 0; i < decode_result_units_.size(); i++)  // NOLINT(clang-diagnostic-sign-compare)
         {
-            int64_t startIndex = decode_result_units_[i].startIndex;
+            int64_t start_index = decode_result_units_[i].start_index;
             for (int x = 0; i < rs232_packets.size(); x++) // NOLINT(clang-diagnostic-sign-compare)
             {
-                if (rs232_packets[x].start_index == startIndex)
+                if (rs232_packets[x].start_index == start_index)
                 {
                     decode_result_units_[i].data = &(rs232_packets[x].data);
                     break;
@@ -383,10 +384,10 @@ namespace Protocol
             }
         }
 
-        decode_result.decode_events_ptr = decodeEvents_Ptr->data();
-        decode_result.decode_result_cells_ptr = decodeResultUnitsPtr->data();
-        decode_result.decode_event_count = decodeEvents_Ptr->size();
-        decode_result.decode_result_count = decodeResultUnitsPtr->size();
+        decode_result.decode_events_ptr = decode_events_ptr->data();
+        decode_result.decode_result_cells_ptr = decode_result_units_ptr->data();
+        decode_result.decode_event_count = decode_events_ptr->size();
+        decode_result.decode_result_count = decode_result_units_ptr->size();
 
         WriteLog(LogLevel::Level1, "  Cpp ParsingData Done,return True \n\n");
 

+ 5 - 5
ProtocolSPI/spi_decoder.cc

@@ -50,7 +50,7 @@ namespace Protocol
             need_update_view_info_ = true;
             /*miso_data.clear();
             mosi_data.clear();*/
-            data_packet_info.clear();
+            data_packet_info_.clear();
             packet_infos_.clear();
             return false;
         }
@@ -60,7 +60,7 @@ namespace Protocol
             {
                 /*	miso_data.clear();
                     mosi_data.clear();*/
-                data_packet_info.clear();
+                data_packet_info_.clear();
                 packet_infos_.clear();
                 need_decode_data_ = false;
                 need_update_view_info_ = true;
@@ -280,12 +280,12 @@ namespace Protocol
                         packet_info.data_count = static_cast<int32_t>(temp_data_packets.size());
                         if (packet_info.data_count > 0)
                         {
-                            int32_t last_data_count = static_cast<int32_t>(data_packet_info.size());
+                            int32_t last_data_count = static_cast<int32_t>(data_packet_info_.size());
                             // 复制到末尾
-                            data_packet_info.insert(data_packet_info.end(),
+                            data_packet_info_.insert(data_packet_info_.end(),
                                                     std::make_move_iterator(temp_data_packets.begin()),
                                                     std::make_move_iterator(temp_data_packets.end()));
-                            packet_info.data_ptr = reinterpret_cast<intptr_t>(data_packet_info.data() + last_data_count - 1);
+                            packet_info.data_ptr = reinterpret_cast<intptr_t>(data_packet_info_.data() + last_data_count - 1);
                             packet_info.data_info = temp_data_packets[0];
                         }
 

+ 1 - 1
ProtocolSPI/spi_decoder.h

@@ -44,7 +44,7 @@ namespace Protocol
         int32_t data_len_ = 0;
         /*std::vector<uint8_t> miso_data = {};
         std::vector<uint8_t> mosi_data = {};*/
-        std::vector<DataPacketInfo> data_packet_info = {};
+        std::vector<DataPacketInfo> data_packet_info_ = {};
 
         bool FindStartNode(int32_t& start_index, int32_t& cs_start_index, TwoLevelEdgePulse*& node_cs,
                            TwoLevelEdgePulse*& node_clk, Polarity polarity_cs, Polarity polarity_clk) const;

+ 6 - 6
decode_result.h

@@ -17,21 +17,21 @@ namespace Protocol
 {
     struct DecodeResultCell
     {
-        int64_t startIndex = -1; //结果时域起始帧
+        int64_t start_index = -1; //结果时域起始帧
         int64_t length = -1; //结果时域帧长度
         uint8_t* data = {}; //结果数据数组
-        int64_t dataCount; //数据数组长度
-        bool isEventInfo = false; //是否是事件帧
+        int64_t data_count; //数据数组长度
+        bool is_event_info = false; //是否是事件帧
     };
 
     struct DecodeResult
     {
         //协议类型
         //virtual SerialProtocolType GetProtocolType();
-        SerialProtocolType ProtocolType;
+        SerialProtocolType protocol_type;
         //结果有效
-        bool ResultValid = false;
+        bool result_valid = false;
         //结果数据 子协议实现扩展
-        void* ResultDataPtr;
+        void* result_data_ptr;
     };
 }

+ 1 - 1
edge_pulse.cc

@@ -28,7 +28,7 @@ namespace Protocol
 
     ThreeLevelEdgePulse::ThreeLevelEdgePulse(const ThreeLevelEdgePulseStatusType current)
     {
-        CurrentLevel = current;
+        current_level = current;
     }
 
     bool CheckNodeValid(const EdgePulse* edge)

+ 1 - 1
edge_pulse.h

@@ -57,7 +57,7 @@ namespace Protocol
         static uint32_t LevelCount() { return 3; }
         explicit ThreeLevelEdgePulse(ThreeLevelEdgePulseStatusType current);
 
-        ThreeLevelEdgePulseStatusType CurrentLevel = ThreeLevelEdgePulseStatusType::None;
+        ThreeLevelEdgePulseStatusType current_level = ThreeLevelEdgePulseStatusType::None;
     };
 
     //初查节点有效

+ 4 - 2
edge_pulse_data.cc

@@ -16,13 +16,15 @@ namespace ProtocolBase
 Protocol::EdgePulseDataTwoLevels::EdgePulseDataTwoLevels(const uint64_t edge_pulses_count, const uint64_t data_count,
                                                          const double sample_rate,
                                                          EdgePulse* edge_pulses_ptr): EdgePulseData(
-    edge_pulses_count, data_count, sample_rate, edge_pulses_ptr)
+    edge_pulses_count, data_count, sample_rate, edge_pulses_ptr), edge_pulses_count_(edge_pulses_count),
+    sample_rate_(sample_rate)
 {
 }
 
 Protocol::EdgePulseDataThreeLevels::EdgePulseDataThreeLevels(const uint64_t edge_pulses_count, const uint64_t data_count,
                                                              const double sample_rate,
                                                              EdgePulse* edge_pulses_ptr): EdgePulseData(edge_pulses_count,
-                                                                                                        data_count, sample_rate, edge_pulses_ptr)
+                                                                                                        data_count, sample_rate, edge_pulses_ptr),
+    edge_pulses_count_(edge_pulses_count), sample_rate_(sample_rate)
 {
 }

+ 4 - 0
edge_pulse_data.h

@@ -59,6 +59,8 @@ namespace Protocol
         }
 
         __readonly int32_t levelCount = 2;
+        const uint64_t edge_pulses_count_;
+        const double sample_rate_;
     };
 
     struct EdgePulseDataThreeLevels : EdgePulseData
@@ -72,5 +74,7 @@ namespace Protocol
         }
 
         __readonly int32_t levelCount = 3;
+        const uint64_t edge_pulses_count_;
+        const double sample_rate_;
     };
 }

BIN
x64/Debug/ProtocolDecoder.dll


BIN
x64/Debug/ProtocolDecoder.pdb