int TestMod11B(PDOT11_MOD_ARGS pArgs) { MDL Mdl; PACKET_BASE Packet; DOT11B_PLCP_TXVECTOR Dot11BTxVector; Dot11BTxVector.PreambleType = DOT11B_PLCP_IS_LONG_PREAMBLE; Dot11BTxVector.ModSelect = DOT11B_PLCP_IS_CCK; if (!Dot11BRate_KbpsValid(pArgs->nBitRate)) { printf("Data rate %d kbps is not supported by 802.11b mode\n", pArgs->nBitRate); return -1; } Dot11BTxVector.DateRate = Dot11BDataRate_Kbps2Code(pArgs->nBitRate); // Measure modulation speed const int RUN_TIMES = 100; ULONGLONG ts1 = SoraGetCPUTimestamp ( &tsinfo ); for (int ii = 0; ii < RUN_TIMES; ii++) { if (PreparePacket(pArgs->pcInFileName, &Mdl, &Packet, DataBuffer, (PUCHAR)SymbolBuffer, SAMPLE_BUFFER_SIZE) < 0) return -1; // Note: BB11BPMDPacketGenSignal() will modify Packet.pMdl and Packet.pReserved (data crc) // so if run multiple times, please reload these data before calling it. BB11BPMDPacketGenSignal(&Packet, &Dot11BTxVector, (PUCHAR)TempBuffer, sizeof(TempBuffer)/sizeof(COMPLEX8)); } ULONGLONG ts2 = SoraGetCPUTimestamp ( &tsinfo ); printf("Signal data rate: %d kbps\n", Dot11BDataRate_Code2Kbps(Dot11BTxVector.DateRate)); printf("Signal packet size: %d\n", Packet.PacketSize); printf("Signal encoded size: %d\n", Packet.Reserved3); printf("Time cost average: %.3f us \n", SoraTimeElapsed (ts2-ts1, &tsinfo) * 1.0 / 1000 / RUN_TIMES); FILE* pOut = NULL; #pragma warning (push) #pragma warning (disable:4996) pOut = fopen(pArgs->pcOutFileName, "w+b"); #pragma warning (pop) if (!pOut) { printf("Cannot create output file.\n"); return -1; } fwrite(Packet.pReserved, Packet.Reserved3, 1, pOut); fclose(pOut); return 0; }
void Dot11BTxApp(const Config& config) { HRESULT hr; if (Dot11BTxInit() < 0) return; Dot11BPreparePacket(config, (PVOID)SampleBuffer, (ULONG)SampleBufferSize); do { // Generate Signal hr = BB11BPMDPacketGenSignal(&Packet, &TxVector, (PUCHAR)TempBuffer, TempBufferSize); printf("[dot11b:tx] GenSignal return %08x\n", hr); printf("[dot11b:tx] Signal bytes=%d\n", Packet.Reserved3); hr = SoraURadioTransferEx(TARGET_RADIO, SampleBuffer, Packet.Reserved3, &TxID); printf("[dot11b:tx] transfer, hr=%08x, id=%d\n", hr, TxID); FAILED_BREAK(hr); Monitor monitor; TxContext ctx(config, monitor); HANDLE hTxThread = AllocStartThread(DoDot11BTx, &ctx); if (SUCCEEDED(hr)) { printf("\n\nPress any key to exit the program\n"); time_t start = time(NULL); while(!_kbhit()) { if (config.Interval() != 0 && difftime(time(NULL), start) >= config.Interval()) break; } StopFreeThread(hTxThread); hr = SoraURadioTxFree(TARGET_RADIO, TxID); printf("[dot11b:tx] tx free return %08x\n", hr); } } while(false); Dot11BTxClean(); printf("[dot11b:tx] Tx out.\n"); }