📄 testin.cpp
字号:
WaitForSingleObject(ovl[(c + v) % 5].hEvent, INFINITE);
CloseHandle(ovl[(c + v) % 5].hEvent);
}
t = GetTickCount() - t;
printf("transfer rate: %fbps\n", (double)MaxTransferSize * loopcount * 8.0 * 1000 / t);
//return;
printf("time used: %d ms\n", t);
//printf("press enter to continue\n", t);
//getchar();
bool bSuccess = true;
int nSkipped = MaxTransferSize;
PWORD p = (PWORD)inBuffer + nSkipped;
while (!(*p & 0x1))
{
nSkipped ++;
p ++;
}
PWORD pTX = (PWORD)txBuffer;
PWORD pRX = (PWORD)inBuffer;
double dRxEnergy = 0;
UINT nRxCount = 10000;
double dTxEnergy = 0;
UINT nTxCount = 80000;
WORD wAnd = 0xFF, wOr = 0;
for (unsigned int i = 0; i < (MaxTransferSize * loopcount / 2 - nSkipped) / 2; i ++)
{
if (!(*p & 0x1))
{
printf("Error! data lost at %X\n", (i + nSkipped) * 2);
bSuccess = false;
break;
}
*p = (*p & 0xFFFC) >> 2;
wAnd &= *p;
wOr |= *p;
if (*p & 0x2000)
*p |= 0xC000;
if (i < nTxCount)
{
double temp = (short)(*p);
dTxEnergy += temp * temp;
}
*pTX = *p;
pTX ++;
p ++;
if (*p & 0x1)
{
printf("Error! data lost at %X\n", (i + nSkipped) * 2);
bSuccess = false;
break;
}
*p = (*p & 0xFFFC) >> 2;
if (*p & 0x2000)
*p |= 0xC000;
if (i < nRxCount)
{
double temp = (short)(*p);
dRxEnergy += temp * temp;
}
*pRX = *p;
pRX ++;
p ++;
}
printf("wAnd = %x, wOr = %x\n", wAnd, wOr);
#if 0
if (nTone == 72)
nTone = nTone;
char name[255];
sprintf(name, "D:\\test_data_up%d.dat", nTone);
FILE * fx1;
fx1 = fopen(name, "rb");
fread((PWORD)txBuffer, sizeof(WORD), 294912 / 2, fx1);
fclose(fx1);
#endif
Complex f[512];
Complex ff[512];
for (int k = 0; k < 200; k ++)
{
ff[k].r = 0;
ff[k].i = 0;
}
for (k = 0; k < 200; k ++)
{
FFT(512, (signed short *)txBuffer + k * 512, f);
for (int m = 0; m < 512; m ++)
{
ff[m].r += f[m].r;
ff[m].i += f[m].i;
}
if (nTone == 70)
{
//printf("phase = %f\n", ff[nTone].Phase());
}
}
/*
int nSkipped = 16384;
PWORD p = (PWORD)inBuffer + nSkipped;
for (unsigned int i = 0; i < (MaxTransferSize * loopcount / 2 - nSkipped); i++)
{
if (*p != ((*(p - 1) + 1) % 65536))
{
printf("Error! data lost at %X\n", (i + nSkipped) * 2);
printf("%x -> %x\n", ((*(p - 1) + 1) % 65536), *p);
bSuccess = false;
//break;
}
p ++;
}
*/
/*
int nSkipped = 16384 * 2;
PWORD p = (PWORD)inBuffer + nSkipped;
unsigned short nAnd = 0xFFFF, nOr = 0;
for (unsigned int i = 0; i < (MaxTransferSize * loopcount / 2 - nSkipped); i++)
{
*p = (*p & 0xFFFC) >> 2;
nAnd &= *p;
nOr |= *p;
if (*p & 0x2000)
*p |= 0xC000;
p ++;
}
printf("nAnd = %x, nOr= %x\n", nAnd, nOr);
{
float t[512];
short ts[512];
Complex f[512];
for (unsigned int i = 0; i < 512; i ++)
t[i] = 0;
p = (PWORD)inBuffer + nSkipped;
for (i = 0; i < MaxTransferSize; i++)
{
t[i % 512] += *((signed short *)p);
p ++;
}
for (i = 0; i < 512; i ++)
{
//float v = t[i] / (loopcount - 2);
float v = t[i] / 100;
ts[i] = (signed short)((v > 0) ? ( v + 0.5) : (v - 0.5));
}
FFT(512, ts, f);
//FFT(512, (signed short *)p, f);
CPRBS prbs;
prbs.Initialize(1, 512);
int bits;
Complex Cbits;
CConstellation cons;
//cons.Map(bits, 0, Cbits);
FILE * fp = fopen("D:\\filter_down.txt", "wb");
for (i = 0; i < 256; i ++)
{
bits = prbs.GetReverbPRBSBits(i);
cons.Map(bits, 0, Cbits);
f[i] = Devided(f[i], Cbits);
fprintf(fp, "%f\n", f[i].Magnitude());
}
fclose(fp);
}
*/
/*
if (bSuccess)
{
char name[255];
sprintf(name, "D:\\test_data_up%d.dat", nTone);
FILE * fx1;
fx1 = fopen(name, "wb");
fwrite((PWORD)txBuffer, sizeof(WORD), (MaxTransferSize * loopcount / 2 - nSkipped) / 2, fx1);
fclose(fx1);
FILE * fx2;
//fx2 = fopen("D:\\test_data_down.dat", "wb");
//fwrite((PWORD)inBuffer + nSkipped, sizeof(WORD), (MaxTransferSize * loopcount / 2 - nSkipped) / 2, fx2);
//fwrite((PWORD)inBuffer, sizeof(WORD), (MaxTransferSize * loopcount / 2 - nSkipped) / 2, fx2);
//fclose(fx2);
}
*/
VirtualFree(inBuffer, 0, MEM_RELEASE);
CloseHandle(hInDevice);
return ff[nTone].Magnitude();
}
// liuyunxiang
DWORD __stdcall WriteConfData(LPVOID lpParameter)
{
HANDLE hInDevice = NULL;
PUCHAR outBuffer = NULL; ///outBuffer points to the Unsigned CHAR
//PUSHORT outBuffer = NULL;
ULONG MaxTransferSize;
ULONG OutPipeNum;
char DeviceName[255] = "";
BULK_TRANSFER_CONTROL outBulkControl; //defined by EZUSB
ULONG BytesTransmitted;
ULONG BytesRead;
int status;
int loopcount = 1;
OVERLAPPED ovl[5];
//
// get the device handle
//
if (bOpenDriver (&hInDevice, "EZUSB-0") != TRUE)
{
printf("Failed to Open Device\n");
return 0;
}
OutPipeNum = 0;
//
// get the transfer size and allocate the transfer buffers
//
MaxTransferSize = 512;
outBuffer = (UCHAR *)VirtualAlloc(NULL, ///addr of region to reserve or commit
MaxTransferSize, ///size of region
MEM_RESERVE | MEM_COMMIT, ///type of region
PAGE_READWRITE); ///type of access protection
outBulkControl.pipeNum = OutPipeNum; ///defined by EZUSB
HANDLE rbfFileHandle;
// rbfFileHandle = CreateFile( "F:\\pp.rbf", ///point to the name of file
// GENERIC_READ, ///access to the file
// 0, //FILE_SHARE_WRITE, ///share write mode
// NULL, ///NULL means the default safe description
// OPEN_EXISTING, ///Open the file, If the file is not exist, the calling fail
// 0,//FILE_FLAG_OVERLAPPED, ///file attribute
// NULL); ///handle to file with attributes to copy
rbfFileHandle = CreateFile( (char *)lpParameter, ///point to the name of file
GENERIC_READ, ///access to the file
0, //FILE_SHARE_WRITE, ///share write mode
NULL, ///NULL means the default safe description
OPEN_EXISTING, ///Open the file, If the file is not exist, the calling fail
0,//FILE_FLAG_OVERLAPPED, ///file attribute
NULL); ///handle to file with attributes to copy
ULONG rbfFileSize = GetFileSize(rbfFileHandle,NULL);
printf("file size is %lu\n",rbfFileSize);
VendorRequest(hInDevice, 0xBE, (rbfFileSize / MaxTransferSize) + (rbfFileSize % MaxTransferSize ? 0 : 1));
printf("send be done\n");
for (ULONG ii = 0; ii < rbfFileSize / MaxTransferSize; ii++)
{
ReadFile(rbfFileHandle, outBuffer, MaxTransferSize, &BytesRead, NULL);
status = DeviceIoControl (hInDevice,
IOCTL_EZUSB_BULK_WRITE,
(PVOID)&outBulkControl,
sizeof(BULK_TRANSFER_CONTROL),
outBuffer,
MaxTransferSize,
&BytesTransmitted,
NULL);
printf("%lu has transfered\n", (ii + 1) * MaxTransferSize);
memset(outBuffer, 0, MaxTransferSize);
}
ReadFile(rbfFileHandle, outBuffer, MaxTransferSize, &BytesRead, NULL);
status = DeviceIoControl (hInDevice,
IOCTL_EZUSB_BULK_WRITE,
(PVOID)&outBulkControl,
sizeof(BULK_TRANSFER_CONTROL),
outBuffer,
BytesRead,
&BytesTransmitted,
NULL);
printf("%lu has transfered\n", ii * MaxTransferSize + BytesRead);
printf("done\n");
return 0;
}
int main(int argc, char* argv[])
{
//FILE * fp = fopen("d:\\filter.txt", "wt");
// for (nTone = 0; nTone < 256; nTone ++)
// //for (nTone = 255; nTone < 256; nTone ++)
// // for (nTone = 20; nTone < 21; nTone ++)
// {
// printf("Testing tone %d\n", nTone);
//
//
//
// WriteData(NULL);
//
// Sleep(500);
//
// //fprintf(fp, "%f\n", log10(ReadData(NULL)));
// }
//fclose(fp);
WriteConfData("f:\\pp.rbf.bak");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -