/* #include */ #include #include #include #include "xil_printf.h" #include "process_GPS_data.h" #define TEST_data /* Zakomentovanim vypnuty vypisy */ /* lokalni promenne */ uint8_t decoded_array[30]; /* ulozeni dekodovaneho podramce */ /* globalni promenne */ uint8_t new_data_subframe; /* promennou znacena aktualizace struktur */ /* efemeridy - data z jednotlivych druzic */ extern struct subframe1 sub1[30]; /* pracovní struktury, data se porovnávají s aktuálními */ extern struct subframe1 sub1_act[30]; /* aktuální data */ extern struct subframe1 sub1_2act[30]; /* druhá aktuální data */ extern struct subframe2 sub2[30]; extern struct subframe2 sub2_act[30]; extern struct subframe2 sub2_2act[30]; extern struct subframe3 sub3[30]; extern struct subframe3 sub3_act[30]; extern struct subframe3 sub3_2act[30]; /* almanachy - spolecna data ze vsech druzic */ extern struct subframe4and5 sub4and5; extern struct subframe4and5 sub4and5_act; extern struct subframe4and5 sub4and5_2act; extern struct subframe4page18 sub4p18; extern struct subframe4page18 sub4p18_act; extern struct subframe4page18 sub4p18_2act; extern struct subframe4page25 sub4p25; extern struct subframe4page25 sub4p25_act; extern struct subframe4page25 sub4p25_2act; extern struct subframe5page25 sub5p25; extern struct subframe5page25 sub5p25_act; extern struct subframe5page25 sub5p25_2act; /* vypocet promennych klasicky - bez znamenka */ double calculate(uint8_t position, uint8_t bit_number, int MSB){ /*par: prvni bit promenne (pole zacina 0), pocet bitu promenne, exponent u nejvyssiho bitu */ double total_result = 0; double result = 0; uint8_t i; uint8_t index = (position/8); uint8_t mask = 0x80; mask >>= (position%8); int exponent; for(i = 0; i < bit_number; i++){ if((((position+i)%8) == 0) && (i != 0)){ mask = 0x80; index++; } exponent = MSB - i; if(exponent == 0){ /* exponent roven nule */ if((decoded_array[index]&mask) == 0){ result = 0; }else{ result = 1; } } else if(exponent > 0){ /* kladny exponent */ if((decoded_array[index]&mask) == 0){ result = 0; }else{ result = 2; while(exponent > 1){ result = result * 2; exponent--; } } } else{ /* zaporny exponent */ if((decoded_array[index]&mask) == 0){ result = 0; }else{ exponent = exponent*(-1); result = 2; while(exponent > 1){ result = result * 2; exponent--; } result = 1/result; } } total_result = total_result + result; mask >>= 1; } return total_result; } /* vypocet promennych pres dvojkovy doplnek - se znamenkem */ double calculate_binary(uint8_t position, uint8_t bit_number, int MSB){ /*par: prvni bit promenne (pole zacina 0), pocet bitu promenne, exponent u nejvyssiho bitu */ double total_result = 0; uint8_t i; uint8_t index = (position/8); uint8_t mask = 0x80; mask >>= (position%8); if((decoded_array[index]&mask) == 0){ /* prvni bit promenne je nulovy (cislo je kladne) -> klasicke reseni */ total_result = calculate(position, bit_number, MSB); }else{ /* prvni bit pole je nenulovy (cislo je zaporne) -> binarni doplnek */ index = ((position+bit_number-1)/8); mask = 0x80; mask >>= ((position+bit_number-1)%8); while((decoded_array[index]&mask) == 0){ /* odecteni jednicky od daneho binarniho cisla */ decoded_array[index] = (decoded_array[index]|mask); mask <<= 1; if(mask == 0){ mask = 0x01; index--; } } decoded_array[index] = (decoded_array[index]^mask); index = (position/8); mask = 0x80; mask >>= (position%8); for(i = 0; i < bit_number; i++){ /* prepis pole na inverzni */ decoded_array[index] = (decoded_array[index]^mask); mask >>= 1; if(mask == 0){ mask = 0x80; index++; } } total_result = calculate(position, bit_number, MSB); /* prepocet binarniho cisla na dekadicke */ total_result = total_result*(-1); /* zaporne znamenko */ } return total_result; } /* hledani preambule */ int find_preamble(uint64_t * buffer){ /* par: ukazatel na buffer predany do fce process_GPS_data */ int is_pream = 0; uint8_t preamble_normal = 0x8b; /* normalni preambule, binarne 10001011 */ uint8_t preamble_invers = 0x74; /* inverzni preambule, binarne 01110100 */ uint8_t preamble1; uint8_t preamble2; uint8_t mask = 0xff; uint64_t buffer4 = buffer[4]; preamble1 = mask&buffer[0]; buffer4>>=44; preamble2 = mask&buffer4; if(preamble1 == preamble_normal){ /* hledani posledni preambule v bufferu (p. v normalni forme) */ if(preamble2 == preamble_normal) /* hledani predposledni preambule v bufferu (p. v normalni forme) */ is_pream = 1; if(preamble2 == preamble_invers) /* hledani predposledni preambule v bufferu (p. v inverzni forme) */ is_pream = 1; } if(preamble1 == preamble_invers){ /* hledani posledni preambule v bufferu (p. v inverzni forme) */ if(preamble2 == preamble_normal) /* hledani predposledni preambule v bufferu (p. v normalni forme) */ is_pream = 1; if(preamble2 == preamble_invers) /* hledani predposledni preambule v bufferu (p. v inverzni forme) */ is_pream = 1; } return is_pream; /* is_pream = 0 -> nezasynchronizovan podramec, is_pream = 1 -> pravdepodobne zasynchronizovan podramec */ } /* dekodovani a pripadna oprava jednoho zasynchronizovaneho podramce */ uint8_t decode(uint64_t * coded_array){ /* par: odkaz na kodovany podramec */ uint8_t parity_received; uint8_t parity_calculated; uint64_t bits, y64; uint64_t mask64; uint32_t coded_word; uint32_t mask32 = 0xffffffff; uint8_t mask8; uint8_t i,j,x,y,check; uint8_t position_array; uint8_t position_bit; uint8_t error_word = 0; for(i = 0; i < 10; i++){ /* kopirovani jednoho kodoveho slova do promenne coded_word */ coded_word = 0; mask64 = 0x00000000ffffffff; if(i == 0){ /* prvni slovo */ bits = coded_array[0]; bits >>= 32; coded_word = (bits&mask64); }else if((i%2) == 1){ /* suda slova */ bits = coded_array[(30*i/64)]; bits >>= (2*i); coded_word = (bits&mask64); }else{ /* licha slova */ bits = coded_array[(30*i/64)]; bits <<= (32-2*i); coded_word = (bits&mask64); bits = coded_array[(30*i/64)+1]; bits >>= (32+2*i); coded_word = (coded_word|bits); } mask32 = 0x0000003f; parity_received = (coded_word&mask32); /* ulozeni prijate parity */ mask32 = 0x40000000; mask8 = 0xff; if((coded_word&mask32) == 0){ /* dekodovani slova pro pripad D30* = 0 */ coded_word >>= 6; for(j = 3; j > 0; j--){ decoded_array[j-1+(i*3)] = coded_word&mask8; coded_word >>= 8; } }else{ /* dekodovani slova pro pripad D30* = 1 */ coded_word >>= 6; for(j = 3; j > 0; j--){ decoded_array[j-1+(i*3)] = ~(coded_word&mask8); coded_word >>= 8; } } /* vypocet parity z dekodovaneho slova */ parity_calculated = 0; j = (((decoded_array[i*3]&0x80)>>7)+((decoded_array[i*3]&0x40)>>6)+((decoded_array[i*3]&0x20)>>5)+((decoded_array[i*3]&0x08)>>3)+((decoded_array[i*3]&0x04)>>2)+((decoded_array[i*3+1]&0x40)>>6)+((decoded_array[i*3+1]&0x20)>>5)+((decoded_array[i*3+1]&0x10)>>4)+((decoded_array[i*3+1]&0x08)>>3)+((decoded_array[i*3+1]&0x04)>>2)+((decoded_array[i*3+2]&0x80)>>7)+((decoded_array[i*3+2]&0x40)>>6)+((decoded_array[i*3+2]&0x10)>>4)+((decoded_array[i*3+2]&0x02)>>1)+((coded_word&0x02)>>1))%2; j <<= 5; parity_calculated = (parity_calculated|j); j = (((decoded_array[i*3]&0x40)>>6)+((decoded_array[i*3]&0x20)>>5)+((decoded_array[i*3]&0x10)>>4)+((decoded_array[i*3]&0x04)>>2)+((decoded_array[i*3]&0x02)>>1)+((decoded_array[i*3+1]&0x20)>>5)+((decoded_array[i*3+1]&0x10)>>4)+((decoded_array[i*3+1]&0x08)>>3)+((decoded_array[i*3+1]&0x04)>>2)+((decoded_array[i*3+1]&0x02)>>1)+((decoded_array[i*3+2]&0x40)>>6)+((decoded_array[i*3+2]&0x20)>>5)+((decoded_array[i*3+2]&0x08)>>3)+(decoded_array[i*3+2]&0x01)+(coded_word&0x01))%2; j <<= 4; parity_calculated = (parity_calculated|j); j = (((decoded_array[i*3]&0x80)>>7)+((decoded_array[i*3]&0x20)>>5)+((decoded_array[i*3]&0x10)>>4)+((decoded_array[i*3]&0x08)>>3)+((decoded_array[i*3]&0x02)>>1)+(decoded_array[i*3]&0x01)+((decoded_array[i*3+1]&0x10)>>4)+((decoded_array[i*3+1]&0x08)>>3)+((decoded_array[i*3+1]&0x04)>>2)+((decoded_array[i*3+1]&0x02)>>1)+(decoded_array[i*3+1]&0x01)+((decoded_array[i*3+2]&0x20)>>5)+((decoded_array[i*3+2]&0x10)>>4)+((decoded_array[i*3+2]&0x04)>>2)+((coded_word&0x02)>>1))%2; j <<= 3; parity_calculated = (parity_calculated|j); j = (((decoded_array[i*3]&0x40)>>6)+((decoded_array[i*3]&0x10)>>4)+((decoded_array[i*3]&0x08)>>3)+((decoded_array[i*3]&0x04)>>2)+(decoded_array[i*3]&0x01)+((decoded_array[i*3+1]&0x80)>>7)+((decoded_array[i*3+1]&0x08)>>3)+((decoded_array[i*3+1]&0x04)>>2)+((decoded_array[i*3+1]&0x02)>>1)+(decoded_array[i*3+1]&0x01)+((decoded_array[i*3+2]&0x80)>>7)+((decoded_array[i*3+2]&0x10)>>4)+((decoded_array[i*3+2]&0x08)>>3)+((decoded_array[i*3+2]&0x02)>>1)+(coded_word&0x01))%2; j <<= 2; parity_calculated = (parity_calculated|j); j = (((decoded_array[i*3]&0x80)>>7)+((decoded_array[i*3]&0x20)>>5)+((decoded_array[i*3]&0x08)>>3)+((decoded_array[i*3]&0x04)>>2)+((decoded_array[i*3]&0x02)>>1)+((decoded_array[i*3+1]&0x80)>>7)+((decoded_array[i*3+1]&0x40)>>6)+((decoded_array[i*3+1]&0x04)>>2)+((decoded_array[i*3+1]&0x02)>>1)+(decoded_array[i*3+1]&0x01)+((decoded_array[i*3+2]&0x80)>>7)+((decoded_array[i*3+2]&0x40)>>6)+((decoded_array[i*3+2]&0x08)>>3)+((decoded_array[i*3+2]&0x04)>>2)+(decoded_array[i*3+2]&0x01)+(coded_word&0x01))%2; j <<= 1; parity_calculated = (parity_calculated|j); j = (((decoded_array[i*3]&0x20)>>5)+((decoded_array[i*3]&0x08)>>3)+((decoded_array[i*3]&0x04)>>2)+(decoded_array[i*3]&0x01)+((decoded_array[i*3+1]&0x80)>>7)+((decoded_array[i*3+1]&0x40)>>6)+((decoded_array[i*3+1]&0x20)>>5)+((decoded_array[i*3+1]&0x08)>>3)+((decoded_array[i*3+1]&0x02)>>1)+((decoded_array[i*3+2]&0x20)>>5)+((decoded_array[i*3+2]&0x04)>>2)+((decoded_array[i*3+2]&0x02)>>1)+(decoded_array[i*3+2]&0x01)+((coded_word&0x02)>>1))%2; parity_calculated = (parity_calculated|j); if(parity_calculated != parity_received){ /* porovnani vypoctene a prijate parity, pokud se lisi, dochazi k oprave dekodovaneho slova */ x = 0; x = (parity_calculated^parity_received); if(x == 1){ /* oprava bitu D30 v kodovanem poli (dulezite pro dekodovani dalsiho slova) */ mask64 = 0x8000000000000000; position_array = ((i+1)*30+1)/64; position_bit = ((i+1)*30+1)%64; mask64 >>= position_bit; y64 = ((~coded_array[position_array])&mask64); coded_array[position_array] = (coded_array[position_array]&(~mask64)); coded_array[position_array] = (coded_array[position_array]|y64); }else{ mask8 = 0x01; check = 0; for(j = 0; j < 6; j++){ check = check + (x&mask8); x >>= 1; } if((check%2) == 0){ /* sudy pocet chyb v parite */ error_word = 1; }else{ /* lichy pocet chyb v parite */ x = (parity_calculated^parity_received); x >>= 1; switch(x){ /* oprava dekodovaneho slova dle tabulky viz bakalarska prace */ case 1: /* bit D29 */ mask64 = 0x8000000000000000; position_array = ((i+1)*30)/64; position_bit = ((i+1)*30)%64; mask64 >>= position_bit; y64 = ((~coded_array[position_array])&mask64); coded_array[position_array] = (coded_array[position_array]&(~mask64)); coded_array[position_array] = (coded_array[position_array]|y64); break; case 2: /* bit D28 */ break; case 3: /* bit d9 */ mask8 = 0x80; y = ((~decoded_array[i*3+1])&mask8); decoded_array[i*3+1] = (decoded_array[i*3+1]&(~mask8)); decoded_array[i*3+1] = (decoded_array[i*3+1]|y); break; case 4: /* bit D27 */ break; case 5: /* bit d22 */ mask8 = 0x04; y = ((~decoded_array[i*3+2])&mask8); decoded_array[i*3+2] = (decoded_array[i*3+2]&(~mask8)); decoded_array[i*3+2] = (decoded_array[i*3+2]|y); break; case 6: /* bit d8 */ mask8 = 0x01; y = ((~decoded_array[i*3])&mask8); decoded_array[i*3] = (decoded_array[i*3]&(~mask8)); decoded_array[i*3] = (decoded_array[i*3]|y); break; case 7: /* bit d16 */ mask8 = 0x01; y = ((~decoded_array[i*3+1])&mask8); decoded_array[i*3+1] = (decoded_array[i*3+1]&(~mask8)); decoded_array[i*3+1] = (decoded_array[i*3+1]|y); break; case 8: /* bit D26 */ break; case 9: /* bit d24 */ mask8 = 0x01; y = ((~decoded_array[i*3+2])&mask8); decoded_array[i*3+2] = (decoded_array[i*3+2]&(~mask8)); decoded_array[i*3+2] = (decoded_array[i*3+2]|y); break; case 11: /* bit d21 */ mask8 = 0x08; y = ((~decoded_array[i*3+2])&mask8); decoded_array[i*3+2] = (decoded_array[i*3+2]&(~mask8)); decoded_array[i*3+2] = (decoded_array[i*3+2]|y); break; case 12: /* bit d19 */ mask8 = 0x20; y = ((~decoded_array[i*3+2])&mask8); decoded_array[i*3+2] = (decoded_array[i*3+2]&(~mask8)); decoded_array[i*3+2] = (decoded_array[i*3+2]|y); break; case 13: /* bit d7 */ mask8 = 0x02; y = ((~decoded_array[i*3])&mask8); decoded_array[i*3] = (decoded_array[i*3]&(~mask8)); decoded_array[i*3] = (decoded_array[i*3]|y); break; case 14: /* bit d4 */ mask8 = 0x10; y = ((~decoded_array[i*3])&mask8); decoded_array[i*3] = (decoded_array[i*3]&(~mask8)); decoded_array[i*3] = (decoded_array[i*3]|y); break; case 15: /* bit d15 */ mask8 = 0x02; y = ((~decoded_array[i*3+1])&mask8); decoded_array[i*3+1] = (decoded_array[i*3+1]&(~mask8)); decoded_array[i*3+1] = (decoded_array[i*3+1]|y); break; case 16: /* bit D25 */ break; case 17: /* bit d10 */ mask8 = 0x40; y = ((~decoded_array[i*3+1])&mask8); decoded_array[i*3+1] = (decoded_array[i*3+1]&(~mask8)); decoded_array[i*3+1] = (decoded_array[i*3+1]|y); break; case 18: /* bit d23 */ mask8 = 0x02; y = ((~decoded_array[i*3+2])&mask8); decoded_array[i*3+2] = (decoded_array[i*3+2]&(~mask8)); decoded_array[i*3+2] = (decoded_array[i*3+2]|y); break; case 19: /* bit d17 */ mask8 = 0x80; y = ((~decoded_array[i*3+2])&mask8); decoded_array[i*3+2] = (decoded_array[i*3+2]&(~mask8)); decoded_array[i*3+2] = (decoded_array[i*3+2]|y); break; case 21: /* bit d1 */ mask8 = 0x80; y = ((~decoded_array[i*3])&mask8); decoded_array[i*3] = (decoded_array[i*3]&(~mask8)); decoded_array[i*3] = (decoded_array[i*3]|y); break; case 22: /* bit d20 */ mask8 = 0x10; y = ((~decoded_array[i*3+2])&mask8); decoded_array[i*3+2] = (decoded_array[i*3+2]&(~mask8)); decoded_array[i*3+2] = (decoded_array[i*3+2]|y); break; case 23: /* bit d5 */ mask8 = 0x08; y = ((~decoded_array[i*3])&mask8); decoded_array[i*3] = (decoded_array[i*3]&(~mask8)); decoded_array[i*3] = (decoded_array[i*3]|y); break; case 24: /* bit d11 */ mask8 = 0x20; y = ((~decoded_array[i*3+1])&mask8); decoded_array[i*3+1] = (decoded_array[i*3+1]&(~mask8)); decoded_array[i*3+1] = (decoded_array[i*3+1]|y); break; case 25: /* bit d18 */ mask8 = 0x40; y = ((~decoded_array[i*3+2])&mask8); decoded_array[i*3+2] = (decoded_array[i*3+2]&(~mask8)); decoded_array[i*3+2] = (decoded_array[i*3+2]|y); break; case 26: /* bit d2 */ mask8 = 0x40; y = ((~decoded_array[i*3])&mask8); decoded_array[i*3] = (decoded_array[i*3]&(~mask8)); decoded_array[i*3] = (decoded_array[i*3]|y); break; case 27: /* bit d6 */ mask8 = 0x04; y = ((~decoded_array[i*3])&mask8); decoded_array[i*3] = (decoded_array[i*3]&(~mask8)); decoded_array[i*3] = (decoded_array[i*3]|y); break; case 28: /* bit d12 */ mask8 = 0x10; y = ((~decoded_array[i*3+1])&mask8); decoded_array[i*3+1] = (decoded_array[i*3+1]&(~mask8)); decoded_array[i*3+1] = (decoded_array[i*3+1]|y); break; case 29: /* bit d3 */ mask8 = 0x20; y = ((~decoded_array[i*3])&mask8); decoded_array[i*3] = (decoded_array[i*3]&(~mask8)); decoded_array[i*3] = (decoded_array[i*3]|y); break; case 30: /* bit d13 */ mask8 = 0x08; y = ((~decoded_array[i*3+1])&mask8); decoded_array[i*3+1] = (decoded_array[i*3+1]&(~mask8)); decoded_array[i*3+1] = (decoded_array[i*3+1]|y); break; case 31: /* bit d14 */ mask8 = 0x04; y = ((~decoded_array[i*3+1])&mask8); decoded_array[i*3+1] = (decoded_array[i*3+1]&(~mask8)); decoded_array[i*3+1] = (decoded_array[i*3+1]|y); break; default: /* v dekodovanem slove je vic nez 1 chyba */ error_word = 1; } } } } } return error_word; /* error_word = 1 -> v podramci se nachazi minimalne jedno chybove slovo */ } /* vypocet promennych v jednotlivych podramcich (strukturach) */ void data_subframe1(uint8_t SV_number){ /* par: promenna SV_number predana do fce process_GPS_data */ sub1[SV_number-1].WN = calculate(48,10,9); sub1[SV_number-1].kod_L2 = calculate(58,2,1); sub1[SV_number-1].URA_index = calculate(60,4,3); sub1[SV_number-1].SV_health = calculate(64,6,5); sub1[SV_number-1].IODC = (calculate(70,2,9) + calculate(168,8,7)); sub1[SV_number-1].L2 = calculate(72,1,0); sub1[SV_number-1].TGD = calculate_binary(160,8,-24); sub1[SV_number-1].toc = calculate(176,16,19); sub1[SV_number-1].af2 = calculate_binary(192,8,-48); sub1[SV_number-1].af1 = calculate_binary(200,16,-28); sub1[SV_number-1].af0 = calculate_binary(216,22,-10); } void data_subframe2(uint8_t SV_number){ /* par: promenna SV_number predana do fce process_GPS_data */ sub2[SV_number-1].IODE = calculate(48,8,7); sub2[SV_number-1].Crs = calculate_binary(56,16,10); sub2[SV_number-1].delta_n = calculate_binary(72,16,-28); sub2[SV_number-1].M0 = calculate_binary(88,32,0); sub2[SV_number-1].Cuc = calculate_binary(120,16,-14); sub2[SV_number-1].e = calculate(136,32,-2); sub2[SV_number-1].Cus = calculate_binary(168,16,-14); sub2[SV_number-1].odm_A = calculate(184,32,12); sub2[SV_number-1].toe = calculate(216,16,19); sub2[SV_number-1].fit_interval_flag = calculate(232,1,0); sub2[SV_number-1].AODO = calculate(233,5,4); } void data_subframe3(uint8_t SV_number){ /* par: promenna SV_number predana do fce process_GPS_data */ sub3[SV_number-1].Cic = calculate_binary(48,16,-14); sub3[SV_number-1].OMG0 = calculate_binary(64,32,0); sub3[SV_number-1].Cis = calculate_binary(96,16,-14); sub3[SV_number-1].i0 = calculate_binary(112,32,0); sub3[SV_number-1].Crc = calculate_binary(144,16,10); sub3[SV_number-1].omg = calculate_binary(160,32,0); sub3[SV_number-1].OMGd = calculate_binary(192,24,-20); sub3[SV_number-1].IODE = calculate(216,8,7); sub3[SV_number-1].idot = calculate_binary(224,14,-30); } void data_subframe4and5(){ sub4and5.data_ID = calculate(48,2,1); sub4and5.SV_ID = calculate(50,6,5); sub4and5.e = calculate(56,16,-6); sub4and5.toa = calculate(72,8,19); sub4and5.delta_i = calculate_binary(80,16,-4); sub4and5.OMGd = calculate_binary(96,16,-23); sub4and5.SV_health = calculate(112,8,7); sub4and5.odm_A = calculate(120,24,12); sub4and5.OMG0 = calculate_binary(144,24,0); sub4and5.omg = calculate_binary(168,24,0); sub4and5.M0 = calculate_binary(192,24,0); sub4and5.af0 = (calculate_binary(216,8,-10) + calculate(235,3,-18)); sub4and5.af1 = calculate_binary(224,11,-28); } void data_subframe4page18(){ sub4p18.data_ID = calculate(48,2,1); sub4p18.SV_ID = calculate(50,6,5); sub4p18.alfa0 = calculate_binary(56,8,-23); sub4p18.alfa1 = calculate_binary(64,8,-20); sub4p18.alfa2 = calculate_binary(72,8,-17); sub4p18.alfa3 = calculate_binary(80,8,-17); sub4p18.beta0 = calculate_binary(88,8,18); sub4p18.beta1 = calculate_binary(96,8,21); sub4p18.beta2 = calculate_binary(104,8,23); sub4p18.beta3 = calculate_binary(112,8,23); sub4p18.A1 = calculate_binary(120,24,-27); sub4p18.A0 = calculate_binary(144,32,1); sub4p18.tot = calculate(176,8,19); sub4p18.WNt = calculate(184,8,7); sub4p18.delta_tLS = calculate_binary(192,8,7); sub4p18.WNLSF = calculate(200,8,7); sub4p18.DN = calculate(208,8,7); sub4p18.delta_tLSF = calculate_binary(216,8,7); } void data_subframe4page25(){ uint8_t i; sub4p25.data_ID = calculate(48,2,1); sub4p25.SV_ID = calculate(50,6,5); for(i = 0; i < 32; i++){ sub4p25.AS_config[i] = calculate((56+i*4),4,3); } for(i = 0; i < 8; i++){ sub4p25.SV_health[i] = calculate((186+i*6),6,5); } } void data_subframe5page25(){ uint8_t i; sub5p25.data_ID = calculate(48,2,1); sub5p25.SV_ID = calculate(50,6,5); sub5p25.toa = calculate(56,8,19); sub5p25.WNa = calculate(64,8,7); for(i = 0; i < 24; i++){ sub5p25.SV_health[i] = calculate((72+i*6),6,5); } } /* aktualizace promennych v jednotlivych podramcich (strukturach) */ void compare_subframe1(uint8_t SV_number){ /* par: promenna SV_number predana do fce process_GPS_data */ uint8_t x = 0; if(sub1[SV_number-1].WN == sub1_act[SV_number-1].WN) x++; if(sub1[SV_number-1].kod_L2 == sub1_act[SV_number-1].kod_L2) x++; if(sub1[SV_number-1].URA_index == sub1_act[SV_number-1].URA_index) x++; if(sub1[SV_number-1].SV_health == sub1_act[SV_number-1].SV_health) x++; if(sub1[SV_number-1].IODC == sub1_act[SV_number-1].IODC) x++; if(sub1[SV_number-1].L2 == sub1_act[SV_number-1].L2) x++; if(sub1[SV_number-1].TGD == sub1_act[SV_number-1].TGD) x++; if(sub1[SV_number-1].toc == sub1_act[SV_number-1].toc) x++; if(sub1[SV_number-1].af0 == sub1_act[SV_number-1].af0) x++; if(sub1[SV_number-1].af1 == sub1_act[SV_number-1].af1) x++; if(sub1[SV_number-1].af2 == sub1_act[SV_number-1].af2) x++; if(x < 11){ sub1_2act[SV_number-1].WN = sub1_act[SV_number-1].WN; sub1_2act[SV_number-1].kod_L2 = sub1_act[SV_number-1].kod_L2; sub1_2act[SV_number-1].URA_index = sub1_act[SV_number-1].URA_index; sub1_2act[SV_number-1].SV_health = sub1_act[SV_number-1].SV_health; sub1_2act[SV_number-1].IODC = sub1_act[SV_number-1].IODC; sub1_2act[SV_number-1].L2 = sub1_act[SV_number-1].L2; sub1_2act[SV_number-1].TGD = sub1_act[SV_number-1].TGD; sub1_2act[SV_number-1].toc = sub1_act[SV_number-1].toc; sub1_2act[SV_number-1].af0 = sub1_act[SV_number-1].af0; sub1_2act[SV_number-1].af1 = sub1_act[SV_number-1].af1; sub1_2act[SV_number-1].af2 = sub1_act[SV_number-1].af2; sub1_act[SV_number-1].WN = sub1[SV_number-1].WN; sub1_act[SV_number-1].kod_L2 = sub1[SV_number-1].kod_L2; sub1_act[SV_number-1].URA_index = sub1[SV_number-1].URA_index; sub1_act[SV_number-1].SV_health = sub1[SV_number-1].SV_health; sub1_act[SV_number-1].IODC = sub1[SV_number-1].IODC; sub1_act[SV_number-1].L2 = sub1[SV_number-1].L2; sub1_act[SV_number-1].TGD = sub1[SV_number-1].TGD; sub1_act[SV_number-1].toc = sub1[SV_number-1].toc; sub1_act[SV_number-1].af0 = sub1[SV_number-1].af0; sub1_act[SV_number-1].af1 = sub1[SV_number-1].af1; sub1_act[SV_number-1].af2 = sub1[SV_number-1].af2; new_data_subframe = 1; } } void compare_subframe2(uint8_t SV_number){ /* par: promenna SV_number predana do fce process_GPS_data */ uint8_t x = 0; if(sub2[SV_number-1].IODE == sub2_act[SV_number-1].IODE) x++; if(sub2[SV_number-1].Crs == sub2_act[SV_number-1].Crs) x++; if(sub2[SV_number-1].delta_n == sub2_act[SV_number-1].delta_n) x++; if(sub2[SV_number-1].M0 == sub2_act[SV_number-1].M0) x++; if(sub2[SV_number-1].Cuc == sub2_act[SV_number-1].Cuc) x++; if(sub2[SV_number-1].e == sub2_act[SV_number-1].e) x++; if(sub2[SV_number-1].Cus == sub2_act[SV_number-1].Cus) x++; if(sub2[SV_number-1].odm_A == sub2_act[SV_number-1].odm_A) x++; if(sub2[SV_number-1].toe == sub2_act[SV_number-1].toe) x++; if(sub2[SV_number-1].fit_interval_flag == sub2_act[SV_number-1].fit_interval_flag) x++; if(sub2[SV_number-1].AODO == sub2_act[SV_number-1].AODO) x++; if(x < 11){ sub2_2act[SV_number-1].IODE = sub2_act[SV_number-1].IODE; sub2_2act[SV_number-1].Crs = sub2_act[SV_number-1].Crs; sub2_2act[SV_number-1].delta_n = sub2_act[SV_number-1].delta_n; sub2_2act[SV_number-1].M0 = sub2_act[SV_number-1].M0; sub2_2act[SV_number-1].Cuc = sub2_act[SV_number-1].Cuc; sub2_2act[SV_number-1].e = sub2_act[SV_number-1].e; sub2_2act[SV_number-1].Cus = sub2_act[SV_number-1].Cus; sub2_2act[SV_number-1].odm_A = sub2_act[SV_number-1].odm_A; sub2_2act[SV_number-1].toe = sub2_act[SV_number-1].toe; sub2_2act[SV_number-1].fit_interval_flag = sub2_act[SV_number-1].fit_interval_flag; sub2_2act[SV_number-1].AODO = sub2_act[SV_number-1].AODO; sub2_act[SV_number-1].IODE = sub2[SV_number-1].IODE; sub2_act[SV_number-1].Crs = sub2[SV_number-1].Crs; sub2_act[SV_number-1].delta_n = sub2[SV_number-1].delta_n; sub2_act[SV_number-1].M0 = sub2[SV_number-1].M0; sub2_act[SV_number-1].Cuc = sub2[SV_number-1].Cuc; sub2_act[SV_number-1].e = sub2[SV_number-1].e; sub2_act[SV_number-1].Cus = sub2[SV_number-1].Cus; sub2_act[SV_number-1].odm_A = sub2[SV_number-1].odm_A; sub2_act[SV_number-1].toe = sub2[SV_number-1].toe; sub2_act[SV_number-1].fit_interval_flag = sub2[SV_number-1].fit_interval_flag; sub2_act[SV_number-1].AODO = sub2[SV_number-1].AODO; new_data_subframe = 2; } } void compare_subframe3(uint8_t SV_number){ /* par: promenna SV_number predana do fce process_GPS_data */ uint8_t x = 0; if(sub3[SV_number-1].Cic == sub3_act[SV_number-1].Cic) x++; if(sub3[SV_number-1].OMG0 == sub3_act[SV_number-1].OMG0) x++; if(sub3[SV_number-1].Cis == sub3_act[SV_number-1].Cis) x++; if(sub3[SV_number-1].i0 == sub3_act[SV_number-1].i0) x++; if(sub3[SV_number-1].Crc == sub3_act[SV_number-1].Crc) x++; if(sub3[SV_number-1].omg == sub3_act[SV_number-1].omg) x++; if(sub3[SV_number-1].OMGd == sub3_act[SV_number-1].OMGd) x++; if(sub3[SV_number-1].IODE == sub3_act[SV_number-1].IODE) x++; if(sub3[SV_number-1].idot == sub3_act[SV_number-1].idot) x++; if(x < 9){ sub3_2act[SV_number-1].Cic = sub3_act[SV_number-1].Cic; sub3_2act[SV_number-1].OMG0 = sub3_act[SV_number-1].OMG0; sub3_2act[SV_number-1].Cis = sub3_act[SV_number-1].Cis; sub3_2act[SV_number-1].i0 = sub3_act[SV_number-1].i0; sub3_2act[SV_number-1].Crc = sub3_act[SV_number-1].Crc; sub3_2act[SV_number-1].omg = sub3_act[SV_number-1].omg; sub3_2act[SV_number-1].OMGd = sub3_act[SV_number-1].OMGd; sub3_2act[SV_number-1].IODE = sub3_act[SV_number-1].IODE; sub3_2act[SV_number-1].idot = sub3_act[SV_number-1].idot; sub3_act[SV_number-1].Cic = sub3[SV_number-1].Cic; sub3_act[SV_number-1].OMG0 = sub3[SV_number-1].OMG0; sub3_act[SV_number-1].Cis = sub3[SV_number-1].Cis; sub3_act[SV_number-1].i0 = sub3[SV_number-1].i0; sub3_act[SV_number-1].Crc = sub3[SV_number-1].Crc; sub3_act[SV_number-1].omg = sub3[SV_number-1].omg; sub3_act[SV_number-1].OMGd = sub3[SV_number-1].OMGd; sub3_act[SV_number-1].IODE = sub3[SV_number-1].IODE; sub3_act[SV_number-1].idot = sub3[SV_number-1].idot; new_data_subframe = 3; } } void compare_subframe4and5(){ uint8_t x = 0; if(sub4and5.data_ID == sub4and5_act.data_ID) x++; if(sub4and5.SV_ID == sub4and5_act.SV_ID) x++; if(sub4and5.e == sub4and5_act.e) x++; if(sub4and5.toa == sub4and5_act.toa) x++; if(sub4and5.delta_i == sub4and5_act.delta_i) x++; if(sub4and5.OMGd == sub4and5_act.OMGd) x++; if(sub4and5.SV_health == sub4and5_act.SV_health) x++; if(sub4and5.odm_A == sub4and5_act.odm_A) x++; if(sub4and5.OMG0 == sub4and5_act.OMG0) x++; if(sub4and5.omg == sub4and5_act.omg) x++; if(sub4and5.M0 == sub4and5_act.M0) x++; if(sub4and5.af0 == sub4and5_act.af0) x++; if(sub4and5.af1 == sub4and5_act.af1) x++; if(x < 13){ sub4and5_2act.data_ID = sub4and5_act.data_ID; sub4and5_2act.SV_ID = sub4and5_act.SV_ID; sub4and5_2act.e = sub4and5_act.e; sub4and5_2act.toa = sub4and5_act.toa; sub4and5_2act.delta_i = sub4and5_act.delta_i; sub4and5_2act.OMGd = sub4and5_act.OMGd; sub4and5_2act.SV_health = sub4and5_act.SV_health; sub4and5_2act.odm_A = sub4and5_act.odm_A; sub4and5_2act.OMG0 = sub4and5_act.OMG0; sub4and5_2act.omg = sub4and5_act.omg; sub4and5_2act.M0 = sub4and5_act.M0; sub4and5_2act.af0 = sub4and5_act.af0; sub4and5_2act.af1 = sub4and5_act.af1; sub4and5_act.data_ID = sub4and5.data_ID; sub4and5_act.SV_ID = sub4and5.SV_ID; sub4and5_act.e = sub4and5.e; sub4and5_act.toa = sub4and5.toa; sub4and5_act.delta_i = sub4and5.delta_i; sub4and5_act.OMGd = sub4and5.OMGd; sub4and5_act.SV_health = sub4and5.SV_health; sub4and5_act.odm_A = sub4and5.odm_A; sub4and5_act.OMG0 = sub4and5.OMG0; sub4and5_act.omg = sub4and5.omg; sub4and5_act.M0 = sub4and5.M0; sub4and5_act.af0 = sub4and5.af0; sub4and5_act.af1 = sub4and5.af1; new_data_subframe = 4; } } void compare_subframe4page18(){ uint8_t x = 0; if(sub4p18.data_ID == sub4p18_act.data_ID) x++; if(sub4p18.SV_ID == sub4p18_act.SV_ID) x++; if(sub4p18.alfa0 == sub4p18_act.alfa0) x++; if(sub4p18.alfa1 == sub4p18_act.alfa1) x++; if(sub4p18.alfa2 == sub4p18_act.alfa2) x++; if(sub4p18.alfa3 == sub4p18_act.alfa3) x++; if(sub4p18.beta0 == sub4p18_act.beta0) x++; if(sub4p18.beta1 == sub4p18_act.beta1) x++; if(sub4p18.beta2 == sub4p18_act.beta2) x++; if(sub4p18.beta3 == sub4p18_act.beta3) x++; if(sub4p18.A1 == sub4p18_act.A1) x++; if(sub4p18.A0 == sub4p18_act.A0) x++; if(sub4p18.tot == sub4p18_act.tot) x++; if(sub4p18.WNt == sub4p18_act.WNt) x++; if(sub4p18.delta_tLS == sub4p18_act.delta_tLS) x++; if(sub4p18.WNLSF == sub4p18_act.WNLSF) x++; if(sub4p18.DN == sub4p18_act.DN) x++; if(sub4p18.delta_tLSF == sub4p18_act.delta_tLSF) x++; if(x < 18){ sub4p18_2act.data_ID = sub4p18_act.data_ID; sub4p18_2act.SV_ID = sub4p18_act.SV_ID; sub4p18_2act.alfa0 = sub4p18_act.alfa0; sub4p18_2act.alfa1 = sub4p18_act.alfa1; sub4p18_2act.alfa2 = sub4p18_act.alfa2; sub4p18_2act.alfa3 = sub4p18_act.alfa3; sub4p18_2act.beta0 = sub4p18_act.beta0; sub4p18_2act.beta1 = sub4p18_act.beta1; sub4p18_2act.beta2 = sub4p18_act.beta2; sub4p18_2act.beta3 = sub4p18_act.beta3; sub4p18_2act.A1 = sub4p18_act.A1; sub4p18_2act.A0 = sub4p18_act.A0; sub4p18_2act.tot = sub4p18_act.tot; sub4p18_2act.WNt = sub4p18_act.WNt; sub4p18_2act.delta_tLS = sub4p18_act.delta_tLS; sub4p18_2act.WNLSF = sub4p18_act.WNLSF; sub4p18_2act.DN = sub4p18_act.DN; sub4p18_2act.delta_tLSF = sub4p18_act.delta_tLSF; sub4p18_act.data_ID = sub4p18.data_ID; sub4p18_act.SV_ID = sub4p18.SV_ID; sub4p18_act.alfa0 = sub4p18.alfa0; sub4p18_act.alfa1 = sub4p18.alfa1; sub4p18_act.alfa2 = sub4p18.alfa2; sub4p18_act.alfa3 = sub4p18.alfa3; sub4p18_act.beta0 = sub4p18.beta0; sub4p18_act.beta1 = sub4p18.beta1; sub4p18_act.beta2 = sub4p18.beta2; sub4p18_act.beta3 = sub4p18.beta3; sub4p18_act.A1 = sub4p18.A1; sub4p18_act.A0 = sub4p18.A0; sub4p18_act.tot = sub4p18.tot; sub4p18_act.WNt = sub4p18.WNt; sub4p18_act.delta_tLS = sub4p18.delta_tLS; sub4p18_act.WNLSF = sub4p18.WNLSF; sub4p18_act.DN = sub4p18.DN; sub4p18_act.delta_tLSF = sub4p18.delta_tLSF; new_data_subframe = 5; } } void compare_subframe4page25(){ uint8_t x = 0; uint8_t i; if(sub4p25.data_ID == sub4p25_act.data_ID) x++; if(sub4p25.SV_ID == sub4p25_act.SV_ID) x++; for(i = 0; i < 32; i++){ if(sub4p25.AS_config[i] == sub4p25_act.AS_config[i]) x++; } for(i = 0; i < 8; i++){ if(sub4p25.SV_health[i] == sub4p25_act.SV_health[i]) x++; } if(x < 42){ sub4p25_2act.data_ID = sub4p25_act.data_ID; sub4p25_2act.SV_ID = sub4p25_act.SV_ID; for(i = 0; i < 32; i++) sub4p25_2act.AS_config[i] = sub4p25_act.AS_config[i]; for(i = 0; i > 8; i++) sub4p25_2act.SV_health[i] = sub4p25_act.SV_health[i]; sub4p25_act.data_ID = sub4p25.data_ID; sub4p25_act.SV_ID = sub4p25.SV_ID; for(i = 0; i < 32; i++) sub4p25_act.AS_config[i] = sub4p25.AS_config[i]; for(i = 0; i < 8; i++) sub4p25_act.SV_health[i] = sub4p25.SV_health[i]; new_data_subframe = 6; } } void compare_subframe5page25(){ uint8_t x = 0; uint8_t i; if(sub5p25.data_ID == sub5p25_act.data_ID) x++; if(sub5p25.SV_ID == sub5p25_act.SV_ID) x++; if(sub5p25.toa == sub5p25_act.toa) x++; if(sub5p25.WNa == sub5p25_act.WNa) x++; for(i = 0; i < 24; i++){ if(sub5p25.SV_health[i] == sub5p25_act.SV_health[i]) x++; } if(x < 28){ sub5p25_2act.data_ID = sub5p25_act.data_ID; sub5p25_2act.SV_ID = sub5p25_act.SV_ID; sub5p25_2act.toa = sub5p25_act.toa; sub5p25_2act.WNa = sub5p25_act.WNa; for(i = 0; i < 24; i++) sub5p25_2act.SV_health[i] = sub5p25_act.SV_health[i]; sub5p25_act.data_ID = sub5p25.data_ID; sub5p25_act.SV_ID = sub5p25.SV_ID; sub5p25_act.toa = sub5p25.toa; sub5p25_act.WNa = sub5p25.WNa; for(i = 0; i < 24; i++) sub5p25_act.SV_health[i] = sub5p25.SV_health[i]; new_data_subframe = 7; } } /* trideni podramcu (dat) */ void separate(uint8_t SV_number){ /* par: promenna SV_number predana do fce process_GPS_data */ uint8_t switch_case; uint8_t subframe; uint8_t SV_ID; subframe = calculate(43,3,2); /* vypocet cisla podramce */ SV_ID = calculate(50,6,5); /* vypocet SV_ID */ if(subframe <= 3){ /* podramce 1, 2 a 3 */ switch_case = subframe; } else if(subframe == 4){ /* podramec 4 */ if(SV_ID == 63){ /* 25. stranka */ switch_case = 6; } else if(SV_ID == 56){ /* 18. stranka */ switch_case = 5; } else if(SV_ID >= 52 && SV_ID <= 62 && SV_ID != 56){ switch_case = 8; } else{ /* stranky 2 - 5 a 7 - 10 */ switch_case = 4; } } else if(subframe == 5){ /* podramec 5 */ if(SV_ID == 51){ switch_case = 7; /* 25. stranka */ }else{ switch_case = 4; /* 1. - 24. stranka */ } } else{ /* jina, chybna varianta */ switch_case = 9; } switch(switch_case){ case 0: #ifdef TEST_data xil_printf("Neplatny vstup! \n"); #endif break; case 1: data_subframe1(SV_number); compare_subframe1(SV_number); break; case 2: data_subframe2(SV_number); compare_subframe2(SV_number); break; case 3: data_subframe3(SV_number); compare_subframe3(SV_number); break; case 4: data_subframe4and5(); compare_subframe4and5(); break; case 5: data_subframe4page18(); compare_subframe4page18(); break; case 6: data_subframe4page25(); compare_subframe4page25(); break; case 7: data_subframe5page25(); compare_subframe5page25(); break; case 8: #ifdef TEST_data xil_printf("Tento podramec obsahuje pouze rezervovane nebo nevyuzite bity, tj. neobsahuje data. \n"); #endif break; default: #ifdef TEST_data xil_printf("Neplatny vstup! \n"); #endif } } /* zpracovani dat z nav. zpravy GPS */ int32_t process_GPS_data(uint64_t * buffer, uint8_t SV_number){ /* par: odkaz na buffer s demodulovanymi bity, cislo druzice */ uint8_t is_preamble; int32_t zcount; is_preamble = find_preamble(buffer); /* vyhledavani preambule */ if(is_preamble == 1){ uint64_t memory[5]; /* definice mezipameti */ uint64_t bits; uint8_t i, error_word; uint8_t mask = 0x80; uint8_t zcount_array[3]; for(i = 0; i < 5; i++){ /* naplneni mezipameti kodovanym podramcem */ memory[i] = buffer[4-i]; memory[i] <<= 10; if(i != 4){ bits = buffer[4-i-1]; bits >>= 54; memory[i] = (memory[i]|bits); } } error_word = decode(memory); /* dekodovani podramce */ zcount = calculate(24,17,16); /* vypocet z-countu */ if(error_word == 0){ /* trideni podramce, pokud neobsahuje chybove slovo */ separate(SV_number); } }else{ zcount = -1; } return zcount; /* z-count = -1 -> nezasynchronizovan podramec, z-count >= 0 -> pravdepodobne zasynchronizovan podramec */ }