chenlh
2025-09-18 8445c54f01777513912d4c6d36c28e92a0ff33a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * scene.cpp
 *
 *  Created on: 2025Äê7ÔÂ21ÈÕ
 *      Author: 86189
 */
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include "config.h"
#include "ModuleExport.h"
#include "f2f.h"
#include "scene.h"
#include "protocol_internal.h"
#include "moduleexport.h"
#include "crc.h"
#include "../drv/memory.h"
 
s32 Scene::str_delim(const s8* str, u16 logic_channel[])
{
    s8 pstr[32];
    s8 * ptr;
    s32 i = 0;
 
    strcpy(pstr, str);
    ptr = strtok(pstr, "|");
 
    if (strcmp(ptr, str) == 0) {
        s8 start, end;
        ptr = strtok(pstr, "-");
        start = atoi(ptr);
 
        ptr = strtok(NULL, "-");
        end = atoi(ptr);
        if(start==end) return 0;
        while (start <= end)
        {
            logic_channel[i++] = start++;
        }
        return i;
    }
    else
    {
        while (ptr)
        {
            logic_channel[i++] = atoi(ptr);
            ptr = strtok(NULL, "|");
        }
        return i;
    }
}
 
 
 
s32 Scene::convert_to_bin(u8* bin)
{
    s32 i ,j;
    struct FlowChartHead* flowchart = (struct FlowChartHead*)bin;
    u32 size =  sizeof(struct FlowChartHead);
    s32 ninports,noutports;
    u16 rxBufID[64],txBufID[64];
    u32 dsp_index ;
 
    u16 dsp_input_num[2] ={0,0};
    u16 dsp_output_num[2] ={0,0};
 
    s32 crc = 0xFFFFFFFF;
    if (!bin) return 0;
 
    struct Module *m  = (struct Module *)(bin + size);
    printf("proc list size %d\n", proc_list.size());
 
    for (i=0; i< proc_list.size(); i++) {
        Module *m  = (struct Module *)(bin + size);
        proc_field * p = &proc_list[i];
 
        ninports = str_delim(p->inportstr, rxBufID) ;
        noutports = str_delim(p->outportstr , txBufID) ;
 
        if(p->proc_type == ModuleType::PROC_NONE){
            continue;
        }
 
        //ducker & spl.
        if(p->proc_type == PROC_DUCKER || p->proc_type == PROC_CONTINUNOUS_SPL) {
            //insert a mixer.
            struct Module *mixer  = (struct Module *)(bin + size);
            u16 channelID[64];
 
            mixer->mDsp = 0;
            mixer->mID = p->proc_id + 320;
            mixer->mType = ModuleType::PROC_MIXER;
            mixer->mTag = 0;
            mixer->mPhyModule = 0;
            mixer->mParamaddr = (s32)get_module_param_ptr(mixer->mType, p->parameters, p->fixed);
 
            size += sizeof(struct Module);
 
            mixer->mRxNum = str_delim(proc_list[1].inportstr, channelID) ;
            memcpy(bin + size , channelID, mixer->mRxNum*sizeof(u16)); size += mixer->mRxNum*sizeof(u16);
            mixer->mTxNum = 1;
            memcpy(bin + size , &rxBufID[1], mixer->mTxNum*sizeof(u16)); size += mixer->mTxNum*sizeof(u16);
        }
        if(hw_adapter->get_system_is_dual_dsp()){
            dsp_index = p->dsp_index ;
        }
        else {
            dsp_index = 0;
        }
 
 
        m  = (struct Module *)(bin + size);
        for(j = 0 ; j< ninports ;j ++) {
            if(rxBufID[j] > dsp_input_num[dsp_index]) {
                dsp_input_num[dsp_index] = rxBufID[j];
            }
        }
        for(j = 0 ; j< noutports ;j ++) {
            if(txBufID[j] > dsp_output_num[dsp_index]) {
                dsp_output_num[dsp_index] = txBufID[j];
            }
        }
 
        m->mDsp = dsp_index;
        m->mID = p->proc_id;
        m->mType = p->proc_type;
        m->mTag = p->tag;
        m->mPhyModule = p->physic_type;
        m->mParamaddr = (s32)get_module_param_ptr(m->mType, p->parameters, p->fixed);
 
        size += sizeof(struct Module);
        m->mRxNum = ninports;
        memcpy(bin + size , rxBufID, m->mRxNum*sizeof(u16)); size += m->mRxNum*sizeof(u16);
        m->mTxNum = noutports;
        memcpy(bin + size , txBufID, m->mTxNum*sizeof(u16)); size += m->mTxNum*sizeof(u16);
 
        if(p->physic_type == ModuleInterfaceType::PHY_INPUT) {
            PhyPort* phy_id = (PhyPort*)(bin + size);
            for(j = 0 ; j< ninports ;j ++, phy_id++) {
                phy_id->mIntType = 0;
                phy_id->mPhyID = hw_adapter->get_physical_channel(1, rxBufID[j]-1);
<<<<<<< HEAD
//                printf("PhyID:%d\n", phy_id->mPhyID);
=======
>>>>>>> 0d5b7df96a2ee186b7b085dca9cf9a33f791c430
            }
            size += ninports*sizeof(PhyPort);
        }
        else if(p->physic_type == ModuleInterfaceType::PHY_OUTPUT){
            PhyPort* phy_id = (PhyPort*)(bin + size);
            for(j = 0 ; j< noutports ;j ++, phy_id++) {
                phy_id->mIntType = 0;
                phy_id->mPhyID = hw_adapter->get_physical_channel(0, txBufID[j]-1);
            }
            size += noutports*sizeof(PhyPort);
        }
    }
 
    //dual_dsp for 2 DSP,else 1 DSP.
    for (i =0 ;i < hw_adapter->get_system_is_dual_dsp() + 1 ;i ++) {
        flowchart->dsp_buffer_num[i] = std::max(dsp_input_num[i], dsp_output_num[i]);
    }
 
    flowchart->module_num = proc_list.size();
    flowchart->compress = 0;
    flowchart->version = 1;
    flowchart->crc = 0;
 
    crc = CRC::crc32((const u8*)bin, size);
 
    flowchart->crc = crc;
    return size;
}