root/ossiedev/branches/hvolos/packetwfrm/components/FrameAssembler/src/FrameAssemblerDSP.cpp @ 8831

Revision 8831, 7.2 KB (checked in by hvolos, 4 years ago)

remove metadata, add frame size properties

  • Property svn:eol-style set to native
Line 
1/****************************************************************************
2
3Copyright 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE FrameAssembler.
6
7OSSIE FrameAssembler is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12OSSIE FrameAssembler is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OSSIE FrameAssembler; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21****************************************************************************/
22
23
24#include <iostream>
25#include "FrameAssemblerDSP.h"
26#include <math.h>
27
28using namespace SigProc;
29
30// Default constructor
31FrameAssemblerDSP::FrameAssemblerDSP()
32{
33    // Initialize control block pointers
34    controlBlock = new char*[8];
35
36    // Default control block codes to be all positive
37    for (unsigned int i=0; i<8; i++)
38        controlBlock[i] = pnControlCode;
39
40    numFrameSymbolsAssembled = 0;
41   
42    FRAME_SIZE_1=512;            ///< Frame size option 1
43    FRAME_SIZE_2=2048;           ///< Frame size option 2
44    FRAME_SIZE_3=4096;           ///< Frame size option 3
45    FRAME_SIZE_4=8192;           ///< Frame size option 4
46   
47    ConfigureModulationScheme( BPSK );
48    ConfigureFrameSize(1);
49    ConfigureFrameType( FRAME_TYPE_DATA );
50}
51
52// Destructor
53FrameAssemblerDSP::~FrameAssemblerDSP()
54{
55    delete [] controlBlock;
56}
57
58void FrameAssemblerDSP::ConfigureModulationScheme(ModulationScheme _ms)
59{
60    // Set appropriate modulation function
61    switch (_ms) {
62    case BPSK:
63        controlBlock[0] = pnControlCodeInv; // 0
64        controlBlock[1] = pnControlCodeInv; // 0
65        controlBlock[2] = pnControlCodeInv; // 0
66        break;
67    case QPSK:
68        controlBlock[0] = pnControlCodeInv; // 0
69        controlBlock[1] = pnControlCodeInv; // 0
70        controlBlock[2] = pnControlCode;    // 1
71        break;
72    case PSK8:
73        controlBlock[0] = pnControlCodeInv; // 0
74        controlBlock[1] = pnControlCode;    // 1
75        controlBlock[2] = pnControlCodeInv; // 0
76        break;
77    case QAM16:
78        controlBlock[0] = pnControlCodeInv; // 0
79        controlBlock[1] = pnControlCode;    // 1
80        controlBlock[2] = pnControlCode;    // 1
81        break;
82    case PAM4:
83        controlBlock[0] = pnControlCode;    // 1
84        controlBlock[1] = pnControlCodeInv; // 0
85        controlBlock[2] = pnControlCodeInv; // 0
86        break;
87    default:
88        // unknown property
89        std::cerr << "ERROR: FrameAssemblerDSP::ConfigureModulationScheme(): "
90                  << "unsupported mod. scheme " << _ms << std::endl;
91        throw 0;
92    }
93}
94
95
96void FrameAssemblerDSP::ConfigureFrameType(unsigned int _ft)
97{
98    switch (_ft) {
99    case FRAME_TYPE_DATA:
100        controlBlock[5] = pnControlCodeInv; // 0
101        controlBlock[6] = pnControlCodeInv; // 0
102        frameType = FRAME_TYPE_DATA;
103        break;
104    case FRAME_TYPE_CONTROL:
105        controlBlock[5] = pnControlCodeInv; // 0
106        controlBlock[6] = pnControlCode;    // 1
107        frameType = FRAME_TYPE_CONTROL;
108        ConfigureFrameSize(1);
109        break;
110    default:
111        // unsupported frame size
112        std::cout << "WARNING: FrameAssemblerDSP::ConfigureFrameType(): "
113                  << "unsupported frame type (" << _ft << ")" << std::endl;
114        std::cout << "  => using FRAME_TYPE_DATA instead" << std::endl;
115        ConfigureFrameType(FRAME_TYPE_DATA);
116        return;
117    }
118   
119}
120
121void FrameAssemblerDSP::ConfigureFrameSize(unsigned int _fs)
122{
123    switch (_fs){
124    case 1:
125        frameSize = FRAME_SIZE_1;
126        controlBlock[3] = pnControlCodeInv;
127        controlBlock[4] = pnControlCodeInv;
128        break;
129    case 2:
130        frameSize = FRAME_SIZE_2;
131        controlBlock[3] = pnControlCodeInv;
132        controlBlock[4] = pnControlCode;
133        break;
134    case 3:
135        frameSize = FRAME_SIZE_3;
136        controlBlock[3] = pnControlCode;
137        controlBlock[4] = pnControlCodeInv;
138        break;
139    case 4:
140        frameSize = FRAME_SIZE_4;
141        controlBlock[3] = pnControlCode;
142        controlBlock[4] = pnControlCode;
143        break;
144    default:
145        // unsupported frame size
146        std::cout << "WARNING: FrameAssemblerDSP::ConfigureFrameSize(): "
147                  << "unsupported frame size (" << _fs << ")" << std::endl;
148        std::cout << "  => using " << FRAME_SIZE_1 << " instead" << std::endl;
149        ConfigureFrameSize(1);
150    }
151   
152     //std::cout << "FrameAssemblerDSP::ConfigureFrameSize(): "<<frameSize<<std::endl;
153}
154
155
156// Generates 10101010 phasing pattern
157void FrameAssemblerDSP::AssemblePhasingPattern(
158    short * I_out,
159    short * Q_out)
160{
161    bool bitFlag(true);
162
163    for (unsigned int i=0; i<512; i++) {
164
165        if ( bitFlag ) {
166            I_out[i] =  BPSK_LEVEL;
167            Q_out[i] =  0;
168        } else {
169            I_out[i] = -BPSK_LEVEL;
170            Q_out[i] =  0;
171        }
172
173        bitFlag = !bitFlag;
174    }
175}
176
177// Generates header
178void FrameAssemblerDSP::AssembleHeader(
179    short * I_out,
180    short * Q_out)
181{
182    // Write tail end of phasing pattern
183    char phasingTail[9] = {1, 0, 1, 0, 1, 0, 1, 0, 1};
184    WriteSequence(phasingTail, 9, I_out, Q_out);
185    I_out += 9;
186    Q_out += 9;
187
188    // Write P/N Sync code
189    WriteSequence(pnFrameSyncCode, 255, I_out, Q_out);
190    I_out += 255;
191    Q_out += 255;
192
193    // Write control blocks
194    for (unsigned int i=0; i<8; i++) {
195        WriteSequence(controlBlock[i], 31, I_out, Q_out);
196        I_out += 31;
197        Q_out += 31;
198    }
199
200}
201
202// Generates postamble...
203void FrameAssemblerDSP::AssemblePostamble()
204{
205}
206
207//
208void FrameAssemblerDSP::WriteSequence(
209    char * bits_in,
210    unsigned int N_in,
211    short * I_out,
212    short * Q_out)
213{
214    //
215    for (unsigned int i=0; i<N_in; i++) {
216        I_out[i] = ( bits_in[i] ) ? BPSK_LEVEL : -BPSK_LEVEL;
217        Q_out[i] = 0;
218    }
219}
220
221void FrameAssemblerDSP::SetFrameSize(unsigned int inframesize, unsigned int inframesizeno)
222{
223 switch ( inframesizeno ) {
224    case 0:
225       std::cerr << "ERROR: FrameSynchronizerDSP::SetFrameSize:0 frame size option not allowed to be set"<<std::endl;
226      throw 0;
227      break;
228   case 1:
229      FRAME_SIZE_1=inframesize;
230      break;
231   case 2:
232      FRAME_SIZE_2=inframesize;
233      break;
234   case 3:
235      FRAME_SIZE_3=inframesize;
236      break;
237   case 4:
238      FRAME_SIZE_4=inframesize;
239      break;
240   default:
241      std::cerr << "ERROR: FrameSynchronizerDSP::SetFrameSize:Invalid frame size option"<<std::endl;
242      throw 0;
243   }
244
245}
246
247
248unsigned int FrameAssemblerDSP::GetFrameSize(unsigned int inframesizeno)
249{
250  switch ( inframesizeno ) {
251    case 0:
252      return frameSize;
253      break;
254   case 1:
255      return FRAME_SIZE_1;
256      break;
257   case 2:
258      return FRAME_SIZE_2;
259      break;
260   case 3:
261      return FRAME_SIZE_3;
262      break;
263   case 4:
264      return FRAME_SIZE_4;
265      break;
266   default:
267      std::cerr << "ERROR: FrameSynchronizerDSP::GetFrameSize:Invalid frame size option"<<std::endl;
268      throw 0;
269   }
270
271}
272
Note: See TracBrowser for help on using the browser.