📄 carl.c
字号:
//msn = (char)malloc(100);
//======================================================
//GenHostID(mainsn, hostid);
strcpy(msn,hostid);
strcat(msn,"AMA");
MDString(msn, &md5);
secret_AMA = (POINTER)malloc(32);
for(index=0;index<32;index++) *(secret_AMA+index)=0;
for(index=0;index<16;index++)
for(i=0;i<8;i++)
{
*(secret_AMA+index)+=*(md5+index) ^ hostid[i];
//(secret_PA[i])+=(md5[i]) ^ mainsn[i];
}
for(index=0; index<16; index++)
{
*(secret_AMA+index) = *(secret_AMA+index) % 36;
if(*(secret_AMA+index)<10)
*(secret_AMA+index) += '0';
else
{
*(secret_AMA+index) -= 10;
*(secret_AMA+index) += 'A';
}
}
//======================================================
// sprintf(msn,"%s"," ");
strcpy(msn,hostid);
strcat(msn,"DMA");
MDString(msn, &md5);
secret_DMA = (POINTER)malloc(32);
for(index=0;index<32;index++) *(secret_DMA+index)=0;
for(index=0;index<16;index++)
for(i=0;i<8;i++)
{
*(secret_DMA+index)+=*(md5+index) ^ hostid[i];
}
for(index=0; index<16; index++)
{
*(secret_DMA+index) = *(secret_DMA+index) % 36;
if(*(secret_DMA+index)<10)
*(secret_DMA+index) += '0';
else
{
*(secret_DMA+index) -= 10;
*(secret_DMA+index) += 'A';
}
}
//----------------------------
sprintf(userstring,"%s",secret_AMA);
sprintf(userstring2,"%s",secret_DMA);
return 0;
}
/* Main function used to qualify the user right
**Return: 1 : PA , 2 : TG , 0 : option Code error.***/
int Codequalificationoption(unsigned char * userstring,unsigned char *userstring2,unsigned char *hostid)
{
int index, i;
//char** car;
POINTER secret_PA,secret_TG,md5;
//char *md5[15];
char msn[50];
md5=malloc(100);
//msn = (char)malloc(100);
//======================================================
//GenHostID(mainsn, hostid);
strcpy(msn,hostid);
strcat(msn,"PA3");
MDString(msn, &md5);
secret_PA = (POINTER)malloc(32);
for(index=0;index<32;index++) *(secret_PA+index)=0;
for(index=0;index<16;index++)
for(i=0;i<8;i++)
{
*(secret_PA+index)+=*(md5+index) ^ hostid[i];
//(secret_PA[i])+=(md5[i]) ^ mainsn[i];
}
for(index=0; index<16; index++)
{
*(secret_PA+index) = *(secret_PA+index) % 36;
if(*(secret_PA+index)<10)
*(secret_PA+index) += '0';
else
{
*(secret_PA+index) -= 10;
*(secret_PA+index) += 'A';
}
}
//======================================================
// sprintf(msn,"%s"," ");
strcpy(msn,hostid);
strcat(msn,"TG3");
MDString(msn, &md5);
secret_TG = (POINTER)malloc(32);
for(index=0;index<32;index++) *(secret_TG+index)=0;
for(index=0;index<16;index++)
for(i=0;i<8;i++)
{
*(secret_TG+index)+=*(md5+index) ^ hostid[i];
}
for(index=0; index<16; index++)
{
*(secret_TG+index) = *(secret_TG+index) % 36;
if(*(secret_TG+index)<10)
*(secret_TG+index) += '0';
else
{
*(secret_TG+index) -= 10;
*(secret_TG+index) += 'A';
}
}
//----------------------------
sprintf(userstring,"%s",secret_PA);
sprintf(userstring2,"%s",secret_TG);
if (strcmp(userstring, secret_PA)==0)
{
return 1;
}
else
if (strcmp(userstring, secret_TG)==0)
{
return 2;
}
else
{
return 0;
}
}
int Password(unsigned char * userstring,unsigned char *hostid,unsigned char *user,unsigned char *password)
{
int index, i;
//char** car;
POINTER secret_PA,md5;
//char *md5[15];
char msn[50];
md5=malloc(100);
//msn = (char)malloc(100);
//======================================================
GenHostID(user, hostid);
strcpy(msn,hostid);
strcat(msn,"PA3");
MDString(msn, &md5);
secret_PA = (POINTER)malloc(32);
for(index=0;index<32;index++) *(secret_PA+index)=0;
for(index=0;index<16;index++)
for(i=0;i<8;i++)
{
*(secret_PA+index)+=*(md5+index) ^ hostid[i];
//(secret_PA[i])+=(md5[i]) ^ mainsn[i];
}
for(index=0; index<16; index++)
{
*(secret_PA+index) = *(secret_PA+index) % 36;
if(*(secret_PA+index)<10)
*(secret_PA+index) += '0';
else
{
*(secret_PA+index) -= 10;
*(secret_PA+index) += 'A';
}
}
sprintf(userstring,"%s",secret_PA);
//printf("%s",userstring);
return 0;
}
int calstation(int panel,int control)
{
ViSession handle_ss;
ViSession rmsession;
ViRsrc EPMaddress="4419b";
ViStatus status;
//ViSession analyzerid;
//ViSession houyiid;
//ViSession attnid;
//ViSession sweepid;
ViSession EPMid;
ViBoolean calpass;
ViReal64 valueA, valueB;
int i;
int pass=1;
char string[256];
int file;
double PowerA[FreqNum],PowerB[FreqNum];
double siglevel ;
//double marker = 0;
char filename[256];
//double ampmeter;
int stop=0;
double frequency[FreqNum]={10.0,50.0,150.0,370.0,500.0,710.0,900.0,1080.0,
1200.0,1500.0,1700.0,1820.0,2000.0,2110.0,2450.0,
2500.0,2690.0,2800.0,3000.0};
double SplitterError[FreqNum]={0};
status = viOpenDefaultRM (&rmsession);
status = viOpen (rmsession,"4438c", VI_NULL, VI_NULL, &handle_ss);
if ( status != 0)
{
showmessage(3);
goto error;
}
status = age441x_init (EPMaddress, VI_OFF, VI_OFF, &EPMid);
if ( status != 0)
{
showmessage(5);
goto error;
}
Delay(0.5);
//agesg_reset (handle_ss);
viPrintf(handle_ss,"*RST\n");
status = age441x_reset (EPMid);
Delay(2);
showmessage(15);
status = age441x_calibration (EPMid, AGE441X_CHANNEL_A, AGE441X_CAL_ALL, &calpass);
Delay(1);
showmessage(16);
status = age441x_calibration (EPMid, AGE441X_CHANNEL_B, AGE441X_CAL_ALL, &calpass);
Delay(1);
showmessage(57);
sprintf (string, " Freq channel A Channel B Power spiltter\n");
SetCtrlVal (panel, control, string);
sprintf (string, " (MHz) (dBm) (dBm) (dB)\n");
SetCtrlVal (panel, control, string);
//setup the power mwter
status =age441x_configureAveraging (EPMid, AGE441X_CHANNEL_B, VI_ON, 4);
Delay(0.1);
status =age441x_configureAveraging (EPMid, AGE441X_CHANNEL_A, VI_ON, 4);
Delay(0.1);
status =age441x_linearityCorrection (EPMid, AGE441X_CHANNEL_B, AGE441X_LINCORR_DTYP);
Delay(0.1);
status =age441x_linearityCorrection (EPMid, AGE441X_CHANNEL_A, AGE441X_LINCORR_DTYP);
Delay(2);
siglevel=-12;
//MessagePopup("", "连接8648D输出至功分器输入\n连接Power Sensor A至功分器A输出\n连接Power Sensor B至功分器B输出 ");
//开文件,存储校准数据
sprintf(filename, "%s\\tt.dat", DataDirName);
file = OpenFile (filename, VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_BINARY);
for(i=0;i<FreqNum;i++)
{
if(stop==1)
{
pass = -1;
return pass;
}
status = viPrintf(handle_ss,":FREQuency:FIXed %lf MHz\n",frequency[i]);
status = viPrintf(handle_ss,":POWer %lf dBm\n",siglevel);
status = viPrintf(handle_ss,":OUTPut ON\n");
Delay(2);
status = age441x_configureMeasurement (EPMid, 2, AGE441X_MEAS_SINGLE, AGE441X_CHANNEL_A,
AGE441X_CHANNEL_B, 4, AGE441X_UNIT_DBM);
//Delay(1);
status = age441x_read (EPMid, 2, AGE441X_MEAS_SINGLE, &valueA);
//Delay(1);
status = age441x_configureMeasurement (EPMid, 2, AGE441X_MEAS_SINGLE, AGE441X_CHANNEL_B,
AGE441X_CHANNEL_A, 4, AGE441X_UNIT_DBM);
Delay(0.1);
status = age441x_read (EPMid, 2, AGE441X_MEAS_SINGLE, &valueB);
PowerA[i] = valueA, PowerB[i] = valueB;
SplitterError[i] = valueA - valueB;
//if ( fabs(SplitterError[i])>7 ||
sprintf (string, " %10.1lf %lf %lf %lf\n",frequency[i],valueA,valueB,SplitterError[i]);
SetCtrlVal (panel, control, string);
FmtFile (file, "%f,%f\n", frequency[i],SplitterError[i]);
}
CloseFile (file);
if ( stop == 1)
{
return -1 ;
}
return pass;
error:
return -999;
}
int test(int panel,int control,int panel2,int control2)
{
ViUInt32 returncount;
char temperature[300];
ViSession handle_ss;
char time[300];
double teststoptime=0.0;
double teststarttime=0.0;
int datafile;
ViSession analyzerid;
char VISAaddress[300];
ViSession houyisession;
ViSession EPMid;
ViRsrc EPMaddress="4419b";
double frequency[19]={10.0,50.0,150.0,370.0,500.0,710.0,900.0,1080.0,
1200.0,1500.0,1700.0,1820.0,2000.0,2110.0,2450.0,
2500.0,2690.0,2800.0,3000.0};
//int tem[7]={-10,0,10,20,30,40,50};
int ss[2]={0,-10};
int atten[2]={20,10};
int a,b,c,status;
char temp[900]={0},filename[300]={0};
double SplitterError[FreqNum];
GetCtrlVal(panel2,control2,serial );
//read splitter error
{
sprintf(filename, "%s\\tt.dat", DataDirName);
datafile = OpenFile (filename, VAL_READ_ONLY, VAL_TRUNCATE, VAL_BINARY);
for(a=0;a<FreqNum;a++)
{
ScanFile (datafile, "%f,%f\n", &frequency[a], &SplitterError[a]);
// printf("%lf %lf \n",frequency[i], SplitterError[i]);
}
CloseFile (datafile);
}
//init file
sprintf (temp, "D:\\testdata\\%s",serial);
status = SetDir(temp);
if (status !=0)
{
MakeDir(temp);
}
sprintf (filename, "%s\\tt-report.txt", temp);
datafile = OpenFile (filename, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
//save start time
GetCurrentDateTime (&teststarttime);
FormatDateTimeString (teststarttime, "%Y-%m-%d %H:%M:%S", time, sizeof(time));
sprintf (temp, " STARTTime: %s ", time);
WriteFile (datafile, temp, StringLength(temp));
sprintf(VISAaddress,"USB0::2391::65519::%s::0::INSTR",serial);
status = viOpenDefaultRM (&houyisession);
status = viOpen (houyisession, VISAaddress, VI_NULL, VI_NULL, &analyzerid);
if ( status != 0)
{
showmessage(14);
return 0;
}
Reset(analyzerid,panel,control);
//WEN DU AND VERSION
viWrite (analyzerid, ":DEBug:REMote:VERsion?\n", sizeof(":DEBug:REMote:VERsion?\n"), &returncount);
Delay(1);
viRead (analyzerid, temperature, 100, &returncount);
sprintf (temp, "****HouYi Version: %s\n",temperature);
SetCtrlVal (panel, control, temp);
WriteFile (datafile, temp, StringLength(temp));
status = viOpen (houyisession,"4438c", VI_NULL, VI_NULL, &handle_ss);
if ( status != 0)
{
showmessage(3);
return 0;
}
status = age441x_init (EPMaddress, VI_OFF, VI_OFF, &EPMid);
if ( status != 0)
{
showmessage(5);
return 0;
}
Delay(0.5);
// status = hp8648a_reset (sweepid);
viPrintf(handle_ss,"*RST\n");
status = age441x_reset (EPMid);
Delay(2);
//init houyi
{
status = viPrintf (analyzerid, ":SENSe:FREQuency:SPAN 10 kHz\n"); //span
Delay(0.5);
status = viPrintf (analyzerid, ":DISPlay:WINDow:TRACe:Y:RLEVel 0 dBm\n"); // reference level
Delay(0.5);
status = viPrintf (analyzerid, ":SENSe:BANDwidth:RESolution 100 Hz\n"); // RBW=100Hz
Delay(0.5);
status = viPrintf (analyzerid, ":SENSe:BANDwidth:VIDeo 30 Hz\n"); //VBW=100Hz
Delay(0.5);
status = viPrintf (analyzerid, ":POWer:GAIN OFF\n"); //preamp off
Delay(0.5);
status = viPrintf (analyzerid, ":DETector POSitive\n"); //set the dector type
Delay(0.5);
status = viPrintf (analyzerid, ":CALCulate:MARKer:STATe ON\n"); //open marker
Delay(0.5);
status = viPrintf (analyzerid, ":SYSTem:CONFigure:PORT REF\n"); //open marker
Delay(0.5);
}
//init power meter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -