int getBlock_GPS(){ // block 2,3: GPS pos+vel1, vel2 unsigned byte; unsigned checksum; int chk = 0, err = 0; byte = check16(frame_bytes+pos_chkGPS1-47, 47); checksum = (frame_bytes[pos_chkGPS1]<<8) | frame_bytes[pos_chkGPS1+1]; if (byte != checksum) chk |= (0x1 << 2); byte = check16(frame_bytes+pos_chkGPS2-18, 18); checksum = (frame_bytes[pos_chkGPS2]<<8) | frame_bytes[pos_chkGPS2+1]; if (byte != checksum) chk |= (0x1 << 3); err |= get_GPSweek(); err |= get_GPStime(); err |= get_GPSkoord(); err |= get_GPSvel(); return chk | (err<<8); }
bool Control::check(std::vector<int> &n) { getOutCard(n); bool result=false; switch (n.size()) { case 1: result=check1(); break; case 2: result=check2(); break; case 3: result=check3(); break; case 4: result=check4(); break; case 5: result=check5(); break; case 6: result=check6(); break; case 7: case 11: case 13: result=check7(); break; case 8: result=check8(); break; case 9: result=check9(); break; case 10: result=check10(); break; case 12: result=check12(); break; case 14: result=check14(); break; case 15: result=check15(); break; case 16: result=check16(); break; } return result; }
int getBlock_PTU(){ // block 1: sensors P, T, U1, U2 unsigned byte; unsigned checksum; int chk = 0; byte = check16(frame_bytes+pos_chkPTU-17, 17); checksum = (frame_bytes[pos_chkPTU]<<8) | frame_bytes[pos_chkPTU+1]; if (byte != checksum) chk |= (0x1 << 1); get_Sensors1(); return chk; }
int getBlock_Int(){ // block 4: SondeID, internalTemp, battery unsigned byte; unsigned checksum; int chk = 0; byte = check16(frame_bytes+pos_chkInt-21, 21); checksum = (frame_bytes[pos_chkInt]<<8) | frame_bytes[pos_chkInt+1]; if (byte != checksum) chk |= (0x1 << 4); get_ID(); //if (option_verbose) get_Sensors2(); return chk; }
int getBlock_FrNb(){ // block 0: frame counter unsigned byte; unsigned checksum; int chk = 0; // header (next frame) if ( frame_bytes[OFS+116] != 0x1A ) { chk |= (0x1 << 6); } if ( frame_bytes[OFS+117] != 0xCF ) { chk |= (0x1 << 7); } byte = check16(frame_bytes+pos_chkFrNb-3, 3); checksum = (frame_bytes[pos_chkFrNb]<<8) | frame_bytes[pos_chkFrNb+1]; if (byte != checksum) chk |= (0x1 << 0); get_FrameNb(); return chk; }
void print_frame() { int i, err=0; unsigned chk=0; if (option_raw) { for (i = 0; i < FRAME_LEN; i++) { fprintf(stdout, "%02x", frame_bytes[i]); //fprintf(stdout, "%02X ", frame_bytes[i]); if (option_raw == 2) { if ( i==OFS-1 || i==OFS+0 || i==OFS+2 // frame-counter || i==OFS+4 || i==OFS+8 || i==OFS+12 || i==OFS+16 // sensors (P,T,U1,U2) || i==OFS+20 || i==OFS+21 || i==OFS+23 || i==OFS+27 // TOW || i==OFS+31 || i==OFS+33 // week || i==OFS+35 || i==OFS+39 || i==OFS+43 // ECEF-pos || i==OFS+47 || i==OFS+51 || i==OFS+55 || i==OFS+59 // ECEF-vel1 || i==OFS+63 || i==OFS+67 || i==OFS+69 || i==OFS+70 // sats-1 || i==OFS+72 || i==OFS+73 || i==OFS+77 || i==OFS+81 // ECEF-vel2 || i==OFS+85 || i==OFS+89 || i==OFS+90 // sats-2 || i==OFS+92 || i==OFS+96 || i==OFS+98 // SondeID, Rev? || i==OFS+101 // bat || i==OFS+103 || i==OFS+107 // internT || i==OFS+113 || i==OFS+115 ) fprintf(stdout, " "); if ( i==pos_chkFrNb -4 ) fprintf(stdout, " "); if ( i==pos_chkFrNb +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkFrNb-3, 3)); if ( i==pos_chkPTU -18 ) fprintf(stdout, " "); if ( i==pos_chkPTU +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkPTU-17, 17)); if ( i==pos_chkGPS1 -48 ) fprintf(stdout, " "); if ( i==pos_chkGPS1 +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkGPS1-47, 47)); if ( i==pos_chkGPS2 -19 ) fprintf(stdout, " "); if ( i==pos_chkGPS2 +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkGPS2-18, 18)); if ( i==pos_chkInt -22 ) fprintf(stdout, " "); if ( i==pos_chkInt +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkInt-21, 21)); if ( i==pos_chkInt +1 ) fprintf(stdout, " "); } } /* // chk = checkBlocks(); if (option_raw == 2) { printf(" # check: "); // blocks: 0=F, 1=S, 2=G1, 3=G2, 4=I, 6=H1, 7=H2 for (i = 0; i < 5; i++) fprintf(stdout, "%d", (chk>>i)&1); fprintf(stdout, "_"); for (i = 6; i < 8; i++) fprintf(stdout, "%d", (chk>>i)&1); } */ fprintf(stdout, "\n"); } else { err = 0; err |= getBlock_FrNb(); err |= getBlock_PTU(); err |= getBlock_GPS(); err |= getBlock_Int(); if (! (err & 0xFF00) ) { Gps2Date(gpx.week, gpx.gpstow/1000, &gpx.jahr, &gpx.monat, &gpx.tag); fprintf(stdout, "[%5d] ", gpx.frnr); fprintf(stdout, "%s ", weekday[gpx.wday]); fprintf(stdout, "%04d-%02d-%02d %02d:%02d:%02d.%03d", gpx.jahr, gpx.monat, gpx.tag, gpx.std, gpx.min, gpx.sek, gpx.ms); if (option_verbose) fprintf(stdout, " (W %d)", gpx.week); fprintf(stdout, " "); fprintf(stdout, " lat: %.5f° ", gpx.lat); fprintf(stdout, " lon: %.5f° ", gpx.lon); fprintf(stdout, " alt: %.2fm ", gpx.alt); if (option_verbose == 2) { //fprintf(stdout," (%7.2f,%7.2f,%7.2f) ", gpx.X, gpx.Y, gpx.Z); fprintf(stdout, " (E:%.2fm) ", gpx.pAcc); } if (option_verbose) fprintf(stdout," sats: %2d ", gpx.sats1); if (option_verbose == 2) { fprintf(stdout," V1: (%5.2f,%5.2f,%5.2f) ", gpx.vX1, gpx.vY1, gpx.vZ1); fprintf(stdout, "(E:%.2fm/s) ", gpx.sAcc1); } fprintf(stdout," vH: %.1fm/s D: %.1f° vV: %.1fm/s ", gpx.vH, gpx.vD, gpx.vU); if (option_verbose == 2) { fprintf(stdout," ENU=(%.2f,%.2f,%.2f) ", gpx.vE, gpx.vN, gpx.vU); fprintf(stdout," V2: (%5.2f,%5.2f,%5.2f) ", gpx.vX2, gpx.vY2, gpx.vZ2); fprintf(stdout, "(E:%.2fm/s) ", gpx.sAcc2); fprintf(stdout," sats: %2d ", gpx.sats2); } fprintf(stdout, " "); fprintf(stdout, " P=%.2fhPa ", gpx.P); fprintf(stdout, " T=%.2f°C ", gpx.T); fprintf(stdout, " H1=%.2f%% ", gpx.U1); fprintf(stdout, " H2=%.2f%% ", gpx.U2); fprintf(stdout, " "); fprintf(stdout, " (%09d) ", gpx.id); if (option_verbose) { fprintf(stdout, " "); fprintf(stdout, " Ti=%.2f°C ", gpx.iT); fprintf(stdout, " Bat=%.2fV ", gpx.bat); } chk = err & 0xFF; printf(" # check: "); // blocks: 0=F, 1=S, 2=G1, 3=G2, 4=I, 6=H1, 7=H2 for (i = 0; i < 5; i++) fprintf(stdout, "%d", (chk>>i)&1); fprintf(stdout, "_"); for (i = 6; i < 8; i++) fprintf(stdout, "%d", (chk>>i)&1); fprintf(stdout, "\n"); // fflush(stdout); } }
int main(int argc,char *argv[]) { int status,b1,b2,digit,scanfStatus; //char ch[]; unsigned long place=1; unsigned long num,output=0; //printf("\n\tconver"); //scanf("%d %d",&b1,&b2); b1=atoi(argv[1]); b2=atoi(argv[2]); num=atoi(argv[3]); char e[100]; strcpy(e,argv[3]); int we=0; if(b1==b2) { if(b1==16) {if(check16(e)==1) {for(we=0;we<strlen(e);we++) {printf("%c",e[we]); } return 0; } else { printf("0"); return 0; } } else { if(vallidation(b1,num)==1) {for(we=0;we<strlen(e);we++) {printf("%c",e[we]); } return 0; } else { printf("0"); return 0; } } } //scanfStatus=scanf("%lu",&num); if (b1==2||b1==8||b1==10) { int ctr=0; for(ctr=0;ctr<strlen(e);ctr++) { if(e[ctr]<48||e[ctr]>57) { printf("0"); return 0; } } status=vallidation(b1,num); } else { status=check16(e); } if(status==0){printf("%d",status);return 0;} if(status==1) { // if(b1==16) // making hexa to decimal... { int i,s=strlen(e),d=0,l; for(i=0;i<s;i++) { if(e[i]>=65&&e[i]<=70) { l=e[i]-55; d=d+l*pwr(16,s-(i+1)); } else { l=e[i]-48; d=d+l*pwr(16,s-(i+1)); } } b1=10; if(b2==10) { printf("%d",d); return 0; } } if(b1==2&&b2==16 ||b1==8&&b2==16) //bin to hex and oct to hex { while(num!=0) { output=output+(num%10)*place; num/=10; if(b1==2)place*=2; else place*=8; } num=output; goto sos; // calling dec to hexa } if((b1==10&&b2==2)||(b1==10&&b2==8)||(b1==10&&b2==16)) { sos: // for goto if(b2==16) { char dig,ans[100]; int remainder,t=0; while(num) { remainder=num%16; num=num/16; if(remainder<10&&remainder>=0) { ans[t]=remainder+48; } else if(remainder>9&&remainder<16) { ans[t]=remainder+55; } t++; } for(t=t-1;t>=0;t--) { printf("%c",ans[t]); } return 0; } else while(num>0) { if(b1==10&&b2==2)output=output+(num%2)*place; else output=output+(num%8)*place; if(b1==10&&b2==2)num/=2; else num/=8; place*=10; } printf("%lu",output); } // // else if((b1==2&&b2==10)||(b1==8&&b2==10)) { while(num!=0) { output=output+(num%10)*place; num/=10; if(b1==2&&b2==10)place*=2; else place*=8; } printf("%lu",output); } // // else if((b1==2&&b2==8)||(b1==8&&b2==2)) { while(num>0) { if(b1==2&&b2==8)digit=num%1000; else digit=num%10; int place2=1; int deci=0; while(digit!=0) { if(b1==2&&b2==8)deci=deci+(digit%10)*place2; else deci=deci+(digit%2)*place2; if(b1==2&&b2==8)digit/=10; else digit/=2; if(b1==2&&b2==8)place2*=2; else place2*=10; } output=output+(deci*place); if(b1==2&&b2==8)num/=1000; else num/=10; if(b1==2&&b2==8)place*=10; else place*=1000; } printf("%lu",output); } // } return 0; }