| | 193 | portAppDataIn->getData(app_data_in, tx_metadata); |
| | 194 | N_in = app_data_in->length(); |
| | 195 | |
| | 196 | // process data here |
| | 197 | app_type = tx_metadata->app_id; |
| | 198 | switch (app_type) { |
| | 199 | case 1: |
| | 200 | // audio data: just copy data to output port |
| | 201 | N_out = N_in; |
| | 202 | packet_data_out.length(N_out); |
| | 203 | for (i=0; i<N_in; i++) |
| | 204 | packet_data_out[i] = (*app_data_in)[i]; |
| | 205 | |
| | 206 | break; |
| | 207 | case 2: |
| | 208 | // text data: unpack ASCII to bits and push to output port |
| | 209 | ///\todo: break up into pieces |
| | 210 | if (N_in > 64) { |
| | 211 | std::cerr << "ERROR! CIREN_CE::ProcessPacketTx(): " |
| | 212 | << "too many input text characters!" << std::endl; |
| | 213 | portAppDataIn->bufferEmptied(); |
| | 214 | continue; |
| | 215 | } |
| | 216 | |
| | 217 | if (N_in / 8 > buf_len) { |
| | 218 | std::cerr << "ERROR! CIREN_CE::ProcessPacketTx(): " |
| | 219 | << "input ASCII data too large!" << std::endl; |
| | 220 | throw 0; |
| | 221 | } |
| | 222 | |
| | 223 | // copy ASCII data to buf1 |
| | 224 | for (i=0; i<N_in; i++) |
| | 225 | buf1[i] = (*app_data_in)[i]; |
| | 226 | |
| | 227 | // unpack bytes and store in buf2 |
| | 228 | ///\todo: unpack only 7 bits? |
| | 229 | SigProc::unpack_bytes(buf1, N_in, buf2, buf_len, &nw); |
| | 230 | // NOTE: nw (num bits written) should be 8*N_in |
| | 231 | |
| | 232 | // copy unpacked bits to output buffer |
| | 233 | N_out = nw; |
| | 234 | packet_data_out.length(N_out); |
| | 235 | for (i=0; i<N_out; i++) |
| | 236 | packet_data_out[i] = buf2[i]; |
| | 237 | |
| | 238 | break; |
| | 239 | default: |
| | 240 | std::cout << "WARNING! CIREN_CE::ProcessPacketTx(): " |
| | 241 | << "unknown/unsupported application type " |
| | 242 | << app_type << std::endl; |
| | 243 | } |
| | 244 | |
| | 245 | // configure metadata properties |
| | 246 | tx_metadata->packet_type = 1; |
| | 247 | |
| | 248 | portAppDataIn->bufferEmptied(); |
| | 249 | portPacketDataOut->pushPacket(packet_data_out, *tx_metadata); |
| | 250 | } |
| | 251 | |
| | 252 | // delete buffers |
| | 253 | delete [] buf1; |
| | 254 | delete [] buf2; |
| | 255 | } |
| | 256 | |
| | 257 | |
| | 258 | void CIREN_CE_i::ProcessPacketRx() |
| | 259 | { |
| | 260 | DEBUG(3, CIREN_CE, "ProcessPacketRx() invoked"); |
| | 261 | |
| | 262 | unsigned int i; |
| | 263 | unsigned int N_in(0); |
| | 264 | unsigned int N_out(0); |
| | 265 | |
| | 266 | unsigned int app_type; |
| | 267 | |
| | 268 | unsigned int nr; |
| | 269 | unsigned int nw; |
| | 270 | |
| | 271 | unsigned int buf_len = 1024; |
| | 272 | unsigned char * buf1 = new unsigned char[buf_len]; |
| | 273 | unsigned char * buf2 = new unsigned char[buf_len]; |
| | 274 | |
| | 275 | while(true) { |
| | 276 | portPacketDataIn->getData(packet_data_in, rx_metadata); |
| | 277 | N_in = packet_data_in->length(); |
| | 278 | //standardInterfaces::PrintMetaData(*tx_metadata); |
| | 279 | |
| | 280 | // process data here |
| | 281 | app_type = rx_metadata->app_id; |
| | 282 | switch (app_type) { |
| | 283 | case 1: |
| | 284 | // audio data: just copy data to output port |
| | 285 | ///\todo: set eom flag appropriately |
| | 286 | N_out = N_in; |
| | 287 | app_data_out.length(N_out); |
| | 288 | for (i=0; i<N_in; i++) |
| | 289 | app_data_out[i] = (*packet_data_in)[i]; |
| | 290 | |
| | 291 | break; |
| | 292 | case 2: |
| | 293 | // text data: pack ASCII from bits and push to output port |
| | 294 | ///\todo: combine pieces into block |
| | 295 | |
| | 296 | // copy bits to buf1 |
| | 297 | for (i=0; i<N_in; i++) |
| | 298 | buf1[i] = (*packet_data_in)[i]; |
| | 299 | |
| | 300 | // pack bytes and store in buf2 |
| | 301 | ///\todo: pack only 7 bits? |
| | 302 | SigProc::pack_bytes(buf1, N_in, buf2, buf_len, &nw); |
| | 303 | // NOTE: nw (num bits written) should be N_in/8 |
| | 304 | |
| | 305 | // copy packed ASCII bytes to output buffer |
| | 306 | N_out = nw; |
| | 307 | app_data_out.length(N_out); |
| | 308 | for (i=0; i<N_out; i++) |
| | 309 | app_data_out[i] = buf2[i]; |
| | 310 | |
| | 311 | break; |
| | 312 | default: |
| | 313 | std::cout << "WARNING! CIREN_CE::ProcessPacketRx(): " |
| | 314 | << "unknown/unsupported application type " |
| | 315 | << app_type << std::endl; |
| | 316 | portPacketDataIn->bufferEmptied(); |
| | 317 | continue; |
| | 318 | } |
| | 319 | |
| | 320 | portPacketDataIn->bufferEmptied(); |
| | 321 | DEBUG(7, CIREN_CE::RX, "pushing " << N_out << " samples") |
| | 322 | portAppDataOut->pushPacket(app_data_out, *rx_metadata); |
| | 323 | } |
| | 324 | |
| | 325 | // delete buffers |
| | 326 | delete [] buf1; |
| | 327 | delete [] buf2; |
| | 328 | } |
| | 329 | |
| | 330 | |
| | 331 | void CIREN_CE_i::ProcessControl() |
| | 332 | { |
| | 333 | DEBUG(3, CIREN_CE, "ProcessControl() invoked"); |
| | 334 | |
| | 335 | //unsigned int i; |
| | 336 | //unsigned int N_in; |
| | 337 | //unsigned int N_out; |
| | 338 | |
| | 339 | while(true) { |
| | 340 | /* |
| 199 | | portAppDataIn->bufferEmptied(); |
| 200 | | portPacketDataOut->pushPacket(packet_data_out, *tx_metadata); |
| 201 | | } |
| 202 | | } |
| 203 | | |
| 204 | | |
| 205 | | void CIREN_CE_i::ProcessPacketRx() |
| 206 | | { |
| 207 | | DEBUG(3, CIREN_CE, "ProcessPacketRx() invoked"); |
| 208 | | |
| 209 | | unsigned int i; |
| 210 | | unsigned int N_in; |
| 211 | | unsigned int N_out; |
| 212 | | |
| 213 | | while(true) { |
| 214 | | portPacketDataIn->getData(packet_data_in, rx_metadata); |
| 215 | | N_in = packet_data_in->length(); |
| 216 | | |
| 217 | | // process data here |
| 218 | | |
| 219 | | // just copy data to output port |
| 220 | | N_out = N_in; |
| 221 | | app_data_out.length(N_out); |
| 222 | | for (i=0; i<N_in; i++) |
| 223 | | app_data_out[i] = (*packet_data_in)[i]; |
| 224 | | |
| 225 | | // configure metadata properties |
| 226 | | //rx_metadata->packet_type = 1; |
| 227 | | |
| 228 | | portPacketDataIn->bufferEmptied(); |
| 229 | | portAppDataOut->pushPacket(app_data_out, *rx_metadata); |
| 230 | | } |
| 231 | | } |
| 232 | | |
| 233 | | |
| 234 | | void CIREN_CE_i::ProcessControl() |
| 235 | | { |
| 236 | | DEBUG(3, CIREN_CE, "ProcessControl() invoked"); |
| 237 | | |
| 238 | | //unsigned int i; |
| 239 | | //unsigned int N_in; |
| 240 | | //unsigned int N_out; |
| 241 | | |
| 242 | | while(true) { |
| 243 | | /* |
| 244 | | portAppDataIn->getData(app_data_in, tx_metadata); |
| 245 | | N_in = app_data_in->length(); |
| 246 | | |
| 247 | | // process data here |
| 248 | | |
| 249 | | // just copy data to output port |
| 250 | | N_out = N_in; |
| 251 | | packet_data_out.length(N_out); |
| 252 | | for (i=0; i<N_in; i++) |
| 253 | | packet_data_out[i] = (*app_data_in)[i]; |
| 254 | | |
| 255 | | // configure metadata properties |
| 256 | | tx_metadata->packet_type = 1; |
| 257 | | |