|
@@ -1,4 +1,13 @@
|
|
|
-#include "iic_decoder.h"
|
|
|
+// // ******************************************************************
|
|
|
+// // /\ /| @File iic_decoder.cc
|
|
|
+// // \ V/ @Brief
|
|
|
+// // | "") @Author lijinwen, ghz005@uni-trend.com.cn
|
|
|
+// // / | @Creation 2024-07-19
|
|
|
+// // / \\ @Modified 2024-07-25
|
|
|
+// // *(__\_\
|
|
|
+// // ******************************************************************
|
|
|
+
|
|
|
+#include "iic_decoder.h"
|
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
@@ -21,6 +30,13 @@ namespace Protocol
|
|
|
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)
|
|
|
{
|
|
|
// 检查是否取消
|
|
@@ -29,6 +45,10 @@ namespace Protocol
|
|
|
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))
|
|
|
{
|
|
@@ -168,10 +188,13 @@ namespace Protocol
|
|
|
//开始解析数据
|
|
|
while (true)
|
|
|
{
|
|
|
- int stop_index = 0;
|
|
|
- if (FindStopNode(start_index, edge_pulses_data_ptr, edge_pulses_clk_ptr))
|
|
|
+ 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;
|
|
|
+ //stop_index = edge_pulses_data_ptr->start_index;
|
|
|
if (stop_index > 0)
|
|
|
{
|
|
|
info.has_end = true;
|
|
@@ -183,7 +206,7 @@ namespace Protocol
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- break;
|
|
|
+ //break;
|
|
|
}
|
|
|
|
|
|
//下一帧 查找下一段启动信号
|
|
@@ -191,12 +214,16 @@ namespace Protocol
|
|
|
{
|
|
|
start_index = edge_pulses_clk_ptr->start_index;
|
|
|
}
|
|
|
- int32_t next_start_index = -1;
|
|
|
- if (FindStartNode(start_index, edge_pulses_data_ptr, edge_pulses_clk_ptr) || (is_cancel_ptr_ != nullptr && *is_cancel_ptr_))
|
|
|
+ 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_))
|
|
|
{
|
|
|
- next_start_index = edge_pulses_data_ptr->start_index;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ next_start_index = -1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (start_index >= next_start_index && next_start_index != -1)
|
|
|
{
|
|
|
start_index = next_start_index - 1;
|
|
@@ -213,12 +240,12 @@ namespace Protocol
|
|
|
start_index = data_len;
|
|
|
break;
|
|
|
}
|
|
|
- if (start_index >= stop_index && stop_index != -1)
|
|
|
+ if (start_index >= stop_index && stop_index > 0)
|
|
|
{
|
|
|
start_index = stop_index + 1;
|
|
|
break;
|
|
|
}
|
|
|
- if (start_index >= next_start_index && next_start_index != -1)
|
|
|
+ if (start_index >= next_start_index && next_start_index > 0)
|
|
|
{
|
|
|
start_index = next_start_index - 1;
|
|
|
break;
|
|
@@ -258,7 +285,7 @@ namespace Protocol
|
|
|
}
|
|
|
|
|
|
if (start_index >= data_len) break;
|
|
|
- if (start_index >= stop_index && stop_index != -1)
|
|
|
+ if (start_index >= stop_index && stop_index > 0)
|
|
|
{
|
|
|
start_index = stop_index + 1;
|
|
|
break;
|
|
@@ -269,7 +296,8 @@ namespace Protocol
|
|
|
break;
|
|
|
}
|
|
|
//计算长度
|
|
|
- data_info.length = stop_index - start_index;
|
|
|
+ //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))
|
|
@@ -277,7 +305,7 @@ namespace Protocol
|
|
|
start_index = data_len;
|
|
|
break;
|
|
|
}
|
|
|
- data_info.ack = edge_pulses_data_ptr->current_level == TwoLevelEdgePulseStatusType::High;
|
|
|
+ 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)
|
|
|
{
|
|
@@ -292,8 +320,8 @@ namespace Protocol
|
|
|
break;
|
|
|
}
|
|
|
data_info.ack_length = start_index - data_info.ack_index;
|
|
|
- data_info.success_ack = false;
|
|
|
- if (start_index >= stop_index && stop_index != -1)
|
|
|
+ data_info.success_ack = 0;
|
|
|
+ if (start_index >= stop_index && stop_index > 0)
|
|
|
{
|
|
|
start_index = stop_index + 1;
|
|
|
break;
|
|
@@ -322,18 +350,21 @@ namespace Protocol
|
|
|
//最后一个数据包的ACK信号为NACK
|
|
|
if (!temp_infos.empty())
|
|
|
{
|
|
|
- int32_t old_data_len = static_cast<int32_t>(packet_info_datas_.size());
|
|
|
+ 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.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_index = start_index;
|
|
|
+
|
|
|
info.end_len = 1;
|
|
|
|
|
|
- info.success_addr_ack = true;
|
|
|
+ //info.success_addr_ack = true;
|
|
|
}
|
|
|
|
|
|
packet_infos_.push_back(info);
|
|
@@ -344,52 +375,67 @@ namespace Protocol
|
|
|
}
|
|
|
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)
|
|
|
+ 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))
|
|
|
+ while (CommonHelper::CheckTwoLevelEdgePulseValid(node_sda_tmp))
|
|
|
{
|
|
|
// 找到SDA上升沿
|
|
|
// 寻找SCL高
|
|
|
- if (node_sda->start_index > start_index || node_sda->current_level != TwoLevelEdgePulseStatusType::High)
|
|
|
+ /*if (node_sda_tmp->start_index > start_index || node_sda_tmp->current_level != TwoLevelEdgePulseStatusType::High)
|
|
|
{
|
|
|
- node_sda++;
|
|
|
+ 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->start_index, node_scl))
|
|
|
+ if (!CommonHelper::FindNextNode(node_sda_tmp->start_index, node_scl_tmp))
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (node_sda->start_index > node_scl->start_index)
|
|
|
- {
|
|
|
- node_scl++;
|
|
|
- }
|
|
|
- if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_scl))
|
|
|
+ while (node_sda_tmp->start_index > node_scl_tmp->start_index)
|
|
|
{
|
|
|
- return false;
|
|
|
+ node_scl_tmp++;
|
|
|
+ if (!CommonHelper::CheckTwoLevelEdgePulseValid(node_scl))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+ //sda高
|
|
|
// 确认下一个SCL为低电平
|
|
|
- if (node_scl->current_level == TwoLevelEdgePulseStatusType::Low)
|
|
|
+ if (node_scl_tmp->current_level == TwoLevelEdgePulseStatusType::Low)
|
|
|
{
|
|
|
- if (node_sda->start_index < node_scl->start_index)
|
|
|
+ if (node_sda_tmp->start_index < node_scl_tmp->start_index)
|
|
|
{
|
|
|
// 找到目标停止条件
|
|
|
+ stop_index = node_sda_tmp->start_index;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- start_index = node_scl->end_index + 1;
|
|
|
- if (auto end_time = std::chrono::steady_clock::now(); std::chrono::duration_cast<std::chrono::nanoseconds>(
|
|
|
+ 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)
|
|
|
{
|
|
@@ -397,7 +443,7 @@ namespace Protocol
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- return CommonHelper::CheckTwoLevelEdgePulseValid(node_sda);
|
|
|
+ return CommonHelper::CheckTwoLevelEdgePulseValid(node_sda_tmp);
|
|
|
}
|
|
|
|
|
|
bool IicDecoder::FindStartNode(int32_t& start_index, TwoLevelEdgePulse* node_sda,
|
|
@@ -412,16 +458,36 @@ namespace Protocol
|
|
|
{
|
|
|
// 找到SDA下降沿
|
|
|
// 寻找SCL高
|
|
|
- if (node_sda->start_index < start_index || node_sda->current_level != TwoLevelEdgePulseStatusType::Low)
|
|
|
+ /* if (node_sda->start_index < start_index)
|
|
|
{
|
|
|
node_sda += 1;
|
|
|
- continue;
|
|
|
+ }
|
|
|
+ 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;
|
|
@@ -441,8 +507,15 @@ namespace Protocol
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- start_index = node_scl->end_index + 1;
|
|
|
- if (auto end_time = std::chrono::steady_clock::now(); std::chrono::duration_cast<std::chrono::nanoseconds>(
|
|
|
+ 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)
|
|
|
{
|