From fe4d335b54ede7a47fd4bcf5c228fb427cbcc8c9 Mon Sep 17 00:00:00 2001
From: chenlh <2008get@163.com>
Date: 星期二, 20 一月 2026 14:46:01 +0800
Subject: [PATCH] 新增通道参数拷贝功能

---
 src/var_state.h     |    2 
 src/tob.h           |    5 
 src/tob.cpp         |   19 ++--
 inc/IModule.h       |    2 
 src/param_ctrl.h    |   42 +++++-----
 src/messageproc.cpp |  129 +++++++++++++++++++++++++++++++
 src/messageproc.h   |    5 -
 src/scene.h         |   10 ++
 src/scene.cpp       |   11 ++
 9 files changed, 181 insertions(+), 44 deletions(-)

diff --git a/inc/IModule.h b/inc/IModule.h
index 2696e53..dde5359 100644
--- a/inc/IModule.h
+++ b/inc/IModule.h
@@ -54,7 +54,7 @@
 	inline ErrStatus SetOutputChannelDataPtr(u16 index, Frame* data)
 	{
 		if (index >= mOutputPortNum) {
-			return ERR_PARAM;
+			return ErrStatus::ERR_PARAM;
 		}
 		mDataOut[index] = data;
 		return ErrStatus::SUCCESS;
diff --git a/src/messageproc.cpp b/src/messageproc.cpp
index 64028c0..b1704aa 100644
--- a/src/messageproc.cpp
+++ b/src/messageproc.cpp
@@ -96,7 +96,7 @@
 
 		s16* data = (s16*)(ptr + 1);
 
-		data_num = (data_num - sizeof(struct ParamCtrl))/sizeof(s16);
+		data_num = (data_num - sizeof(struct ParamCtrl)) / sizeof(s16);
 //		ptr->mid = var.pscene->get_module_id(ptr->mid, type, ptr->cmd) ;
 //		dbg_printf("mID:%d pID:%d val[0]:%d val[1]:%d\n",ptr->mid, ptr->cmd, data[0], data[1]);
 		tob->toCtrl(ptr->mid, ptr->cmd, data, data_num);
@@ -204,11 +204,133 @@
 	return 0;
 }
 
+// section equal - ret:1
+// section not equal - ret:0
+bool decide_modu_type_equal(ptag_module pmodu, s16 dst_ch, s16 src_ch)
+{
+	bool ret = 0;
+	if (pmodu[dst_ch].proc_type == pmodu[src_ch].proc_type) {
+		if (PROC_EQ == pmodu[dst_ch].proc_type) {
+			ptag_eq proc_eq = (ptag_eq)&pmodu[dst_ch].proc_ins;
+			u16 section_dst = proc_eq->nsection;
+			proc_eq = (ptag_eq)&pmodu[src_ch].proc_ins;
+			u16 section_src = proc_eq->nsection;
+			if (section_src == section_dst)
+				ret = 1;
+		}
+		else if (PROC_GEQ == pmodu[dst_ch].proc_type) {
+			ptag_geq proc_geq = (ptag_geq)&pmodu[dst_ch].proc_ins;
+			u16 section_dst = proc_geq->nsections;
+			proc_geq = (ptag_geq)&pmodu[src_ch].proc_ins;
+			u16 section_src = proc_geq->nsections;
+			if (section_src == section_dst)
+				ret = 1;
+		}
+		else
+			ret = 1;
+	}
+	return ret;
+}
+
+s32 Message::ChannelParamCopy(MSG* pmag)
+{
+	s32 len = 0;
+	ptag_ch_param_copy ch_copy = (ptag_ch_param_copy)pmag->data;
+	VarState& var = VarState::GetInstance();
+	void* params_ptr = var.pscene->get_parameters();
+	if (params_ptr == nullptr) {
+		return -1;
+	}
+	ptag_parameters params = static_cast<ptag_parameters>(params_ptr);
+	ToB* tob = ToB::GetInstance();
+	param_ctrl_t* paramset = tob->GetParamCtrl();
+	s32** chin_mid = var.pscene->get_chin_mid();
+	s32** chout_mid = var.pscene->get_chout_mid();
+	tg_param_ctrl_t paramctrl;
+
+	s32 max_ch = ch_copy->bOutput ? var.pscene->get_output_num() : var.pscene->get_input_num();
+	if (ch_copy->src_ch_index >= max_ch || ch_copy->dst_ch_index >= max_ch || ch_copy->src_ch_index < 0 || ch_copy->dst_ch_index < 0) {
+		dbg_printf("ch %s copy channel index error\n",  ch_copy->bOutput ? "out" : "in");
+		return false;
+	}
+
+	if (!ch_copy->bOutput) {
+		memcpy(&params->input.input[ch_copy->dst_ch_index], &params->input.input[ch_copy->src_ch_index], sizeof(params->input.input[0]));
+		IModule* m = tob->GetModule(chin_mid[ch_copy->dst_ch_index][0]);	// [ch_idx][0] is the input type
+		ParamCtrl_fn paramEntry = paramset->GetParamEntry(PROC_INPUT);
+		paramEntry(m, (uvoid*)&params->input, len);
+
+		ptag_module inmod_params[5] = {params->in1, params->in2, params->in3, params->in4, params->in5};
+		for (s32 i = 0; i < 5; i++) {
+			if (paramctrl.decide_modu_type_equal(static_cast<ptag_module>(inmod_params[i]), ch_copy->dst_ch_index, ch_copy->src_ch_index)) {	// 1
+				memcpy(&inmod_params[i][ch_copy->dst_ch_index], &inmod_params[i][ch_copy->src_ch_index], sizeof(tag_module));
+			}
+			else {
+				dbg_printf("ch dst module in%d type != src.\n", i+1);
+				continue;
+			}
+
+			paramEntry = paramset->GetParamEntry(inmod_params[i][ch_copy->dst_ch_index].proc_type);
+			if(paramEntry == NULL) {
+				dbg_printf("paramEntry is NULL!\n");
+				return -1;
+			}
+			m = tob->GetModule(chin_mid[ch_copy->dst_ch_index][i + 1]);
+			u32 result = paramEntry(m, (uvoid*)&inmod_params[i][ch_copy->dst_ch_index].proc_ins, len);
+		}
+	}
+	else {
+		memcpy(&params->output.output[ch_copy->dst_ch_index], &params->output.output[ch_copy->src_ch_index], sizeof(params->output.output[0]));
+		IModule* m = tob->GetModule(chout_mid[ch_copy->dst_ch_index][0]);	// [ch_idx][0] is the output type
+		ParamCtrl_fn paramEntry = paramset->GetParamEntry(PROC_OUTPUT);
+		paramEntry(m, (uvoid*)&params->output, len);
+
+		ptag_module outmod_params[3] = {params->out1, params->out3, params->out4};
+		for (s32 i = 0; i < 3; i++) {
+			if (paramctrl.decide_modu_type_equal(static_cast<ptag_module>(outmod_params[i]), ch_copy->dst_ch_index, ch_copy->src_ch_index)) {	// 2
+				memcpy(&outmod_params[i][ch_copy->dst_ch_index], &outmod_params[i][ch_copy->src_ch_index], sizeof(tag_module));
+			}
+			else {
+				dbg_printf("ch dst module out%d type != src.\n", i+1);
+				continue;
+			}
+
+			paramEntry = paramset->GetParamEntry(outmod_params[i][ch_copy->dst_ch_index].proc_type);
+			if(paramEntry == NULL) {
+				dbg_printf("paramEntry is NULL!\n");
+				return -1;
+			}
+			m = tob->GetModule(chout_mid[ch_copy->dst_ch_index][(0==i) ? (i+1) : (i+2)]);
+			u32 result = paramEntry(m, (uvoid*)&outmod_params[i][ch_copy->dst_ch_index].proc_ins, len);
+//			printf("dst p adr:0x%x\n", (uvoid*)&outmod_params[i][ch_copy->dst_ch_index]);
+		}
+
+		ptag_module_fir outmod2_param = params->out2;
+		if (paramctrl.decide_modu_type_equal(static_cast<ptag_module_fir>(outmod2_param), ch_copy->dst_ch_index, ch_copy->src_ch_index)) {	// 3
+			memcpy(&outmod2_param[ch_copy->dst_ch_index], &outmod2_param[ch_copy->src_ch_index], sizeof(tag_module_fir));
+		}
+		else {
+			dbg_printf("ch dst module out2 type != src.\n");
+			return -1;
+		}
+
+		paramEntry = paramset->GetParamEntry(outmod2_param[ch_copy->dst_ch_index].proc_type);
+		if(paramEntry == NULL) {
+			dbg_printf("paramEntry is NULL!\n");
+			return -1;
+		}
+		m = tob->GetModule(chout_mid[ch_copy->dst_ch_index][2]);
+		u32 result = paramEntry(m, (uvoid*)&outmod2_param[ch_copy->dst_ch_index].proc_ins, len);
+	}
+
+	return 0;
+}
+
 s32 Message::RxMessageHandler(MSG* pmsg)
 {
 	extern ubool  systemMute;
 	if(pmsg->magic != 0x5aa5) {
-		//dbg_printf("magic error.\n");
+//		dbg_printf("magic error.\n");
 		return -1;
 	}
 
@@ -226,6 +348,9 @@
 	case MsgType::MSG_ACK_REQ:
 		HandshakeMessageProcess(pmsg);
 		break;
+	case MsgType::MSG_CHANNEL_COPY_REQ:
+		ChannelParamCopy(pmsg);
+		break;
 	default:
 		break;
 	}
diff --git a/src/messageproc.h b/src/messageproc.h
index 74a9970..cb201bd 100644
--- a/src/messageproc.h
+++ b/src/messageproc.h
@@ -26,13 +26,10 @@
 	u32 levels_max_len;
 
 	s32 PresetProcess(MSG* pmsg);
-
 	s32 ParamCtrl(MSG* pmsg);
-
 	s32 HandshakeMessageProcess(MSG* pmsg);
-
 	s32 RxMessageHandler(MSG* pmsg);
-
+	s32 ChannelParamCopy(MSG* pmsg);
 	void param_init(ptag_device_config pDevCfg);
 
 public:
diff --git a/src/param_ctrl.h b/src/param_ctrl.h
index 35046d0..57a4b76 100644
--- a/src/param_ctrl.h
+++ b/src/param_ctrl.h
@@ -14,7 +14,7 @@
 //预设参数解析用
 typedef u32 (*ParamCtrl_fn)(IModule* m, void* handle, int &plen);
 //参数控制用
-typedef u32 (*Ctrl_fn)(IModule* m, u32 pID, s16* val_c, u32 num);
+typedef u32 (*Ctrl_fn)(IModule* m, u32 pID, s16* val_c, u32 num, void* param);
 
 class ParamEntry {
 private:
@@ -71,26 +71,26 @@
         return mctrl_list.find(mtype) != mctrl_list.end();
     }
 };
-/*class param_ctrl_t{
-protected:
-	std::map<u32, ParamEntry> mctrl_list;
-public:
-	ParamCtrl_fn GetParamEntry(u32 mtype)
-	{
-		if(mctrl_list.count(mtype))
-			return mctrl_list[mtype].GetParamEntry();
-		else
-			return NULL;
-	}
-
-	Ctrl_fn GetCtrlEntry(u32 mtype)
-	{
-		if(mctrl_list.count(mtype))
-			return mctrl_list[mtype].GetCtrlEntry();
-		else
-			return NULL;
-	}
-};*/
+//class param_ctrl_t{
+//protected:
+//	std::map<u32, ParamEntry> mctrl_list;
+//public:
+//	ParamCtrl_fn GetParamEntry(u32 mtype)
+//	{
+//		if(mctrl_list.count(mtype))
+//			return mctrl_list[mtype].GetParamEntry();
+//		else
+//			return NULL;
+//	}
+//
+//	Ctrl_fn GetCtrlEntry(u32 mtype)
+//	{
+//		if(mctrl_list.count(mtype))
+//			return mctrl_list[mtype].GetCtrlEntry();
+//		else
+//			return NULL;
+//	}
+//};
 
 
 
diff --git a/src/scene.cpp b/src/scene.cpp
index b47dacc..0aeb71e 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -50,7 +50,16 @@
 	}
 }
 
-
+void *Scene::get_param(s32 proc_id)
+{
+	for (auto& proc : proc_list) {
+		if (proc.proc_id == proc_id) {
+//			printf("proc:%d,addr:0x%x\n", proc_id, proc.parameters);
+			return proc.parameters;
+		}
+	}
+	return nullptr;
+}
 
 s32 Scene::convert_to_bin(u8* bin)
 {
diff --git a/src/scene.h b/src/scene.h
index fa4401c..ab6de97 100644
--- a/src/scene.h
+++ b/src/scene.h
@@ -75,10 +75,16 @@
 	virtual s32 update_module() =0;
 	//成功返回0,失败返回-1(内容错误、大小不匹配等).
 	virtual s32 set_parameters_content(uvoid* param, s32 size) =0;
-
+	// 返回通道参数
+	virtual void* get_parameters() = 0;
+	// 返回输入输出通道的模块ID
+	virtual s32** get_chin_mid() = 0;
+	virtual s32** get_chout_mid() = 0;
+	virtual s32 get_input_num() = 0;
+	virtual s32 get_output_num() = 0;
 //	virtual u32 get_module_id(u32 mid, s32 mtype ,u32 pid) =0;
-
 	s32 convert_to_bin(u8* bin);
+	void *get_param(s32 proc_id);
 };
 
 #endif
diff --git a/src/tob.cpp b/src/tob.cpp
index c853129..1c90427 100644
--- a/src/tob.cpp
+++ b/src/tob.cpp
@@ -13,6 +13,7 @@
 #include "protocol_internal.h"
 #include "IModule.h"
 #include "f2f.h"
+#include "var_state.h"
 #include "../drv/memory.h"
 
 
@@ -409,16 +410,16 @@
 	return ErrStatus::SUCCESS;
 }
 
-u32 ToB::GetModuleType(u32 mID)
+IModule* ToB::GetModule(u32 mID)
 {
 	if(mID >= mModuleIndex.size() || mModuleIndex[mID] == 0) {
-		return ErrStatus::ERR_PARAM;
+		return NULL;
 	}
 	IModule* m = mList[mModuleIndex[mID]-1];
 	if( m != NULL) {
-		return m->GetModuleType();
+		return m;
 	}
-	return 0;
+	return NULL;
 }
 
 /*ErrStatus ToB::toCtrl(u32 mID, u32 pID, const s16* val, u32 num)
@@ -448,16 +449,14 @@
 	if(mID >= mModuleIndex.size() || mModuleIndex[mID] == 0) {
 		return ErrStatus::ERR_PARAM;
 	}
+//	VarState& var = VarState::GetInstance();
+//	printf("mID:%d\n", mID);
+	void *paramPtr = VarState::GetInstance().pscene->get_param(mID);
 
 	IModule* m = mList[mModuleIndex[mID]-1];
-//	if (m->GetModuleType() == PROC_CONTINUNOUS_SPL && pID == 9) {
-//		mID += 320;
-//		m = mList[mModuleIndex[mID]-1];
-//	}
-
 	if( m != NULL) {
 //		m->Ctrl(pID, val, num);
-		paramset->GetCtrlEntry(m->GetModuleType())(m, pID, (s16*)val, num);
+		paramset->GetCtrlEntry(m->GetModuleType())(m, pID, (s16*)val, num, paramPtr);
 	}
 //	dbg_printf("mID:%d pID:%d val[0]:%d val[1]:%d\n",mID, pID, val[0], val[1]);
 	return ErrStatus::SUCCESS;
diff --git a/src/tob.h b/src/tob.h
index 49f09c1..5c40fd6 100644
--- a/src/tob.h
+++ b/src/tob.h
@@ -51,9 +51,10 @@
 	ErrStatus toAnalysis(const u8* bin, u32 nbytes);
 	u32 GetLevels(s16* buffer, u32 levels_len);
 	u16 GetModuleNum() {return mModuleNum;}
+	u32 GetDSPIndex() {return dsp_index;}
+	param_ctrl_t *GetParamCtrl() {return paramset;}
+	IModule* GetModule(u32 mID);
 
-	u32 GetDSPIndex(){return dsp_index ;}
-	u32 GetModuleType(u32 mID);
 };
 
 #endif
diff --git a/src/var_state.h b/src/var_state.h
index ce6647a..0d900de 100644
--- a/src/var_state.h
+++ b/src/var_state.h
@@ -28,7 +28,7 @@
 	u32 master_intr =0; //主中断号,存在多个中断只有在主中断号下才进行模块处理.
 
 	static VarState& GetInstance(){
-		static VarState _var ;
+		static VarState _var;
 		return _var;
 	}
 

--
Gitblit v1.9.3