#define TX2 17
#define RX2 19
char c;
uint8_t fix[100];
const uint8_t duma[110]={0xB5,0x62,0x01,0x07,  92,0x00,
/*payload: */ 0x04,0xD7,0xDF,0x03,0xE5,0x07,0x01,0x04,0x08,0x10,0x20,0x0F,0xC8,0x2F,0xBC,0x00,
              0xB1,0xDC,0xEC,0xFF,0x04,0xC8,0x41,0x0C,0x8E,0x42,0x84,0x02,0x63,0x1F,0xB7,0x02,
              0xA0,0x86,0x01,0x00,0xB0,0xAD,0x01,0x00,0xC4,0x09,0x00,0x00,0xAC,0x0D,0x00,0x00,
              0x10,0x27,0x00,0x00,0xF0,0xD8,0xFF,0xFF,0x38,0xFF,0xFF,0xFF,0xB0,0x36,0x00,0x00,
              0x60,0xFE,0xCD,0x00,0xE8,0x03,0x00,0x00,0xE8,0x03,0x00,0x00,0xE8,0x03,0xE8,0x03,
              0xC8,0x00,0x00,0x00,0x88,0x13,0x00,0x00,0x88,0x13,0x98,0x3A,
              };              
//uint8_t dumax[100];   
 

union gnss_t {
  uint8_t     dumax[100];
  struct{
    uint32_t  iTOW;   //ms    GPS time of week of the navigation epoch. See the description of iTOW for details.
    uint16_t  year;   //y     Year (UTC)
    uint8_t   month;  //m     month Month, range 1..12 (UTC)
    uint8_t   day;    //d     Day of month, range 1..31 (UTC)
    uint8_t   hour;   //h     Hour of day, range 0..23 (UTC)
    uint8_t   min;    //m     Minute of hour, range 0..59 (UTC)
    uint8_t   sec;    //s     Seconds of minute, range 0..60 (UTC)
    uint8_t   valid;  //      Validity flags (see graphic below)
    uint32_t  tAcc;   //ns    Time accuracy estimate (UTC)
    int32_t   nano;   //ns    Fraction of second, range -1e9 .. 1e9 (UTC)
    uint8_t   fixT;   //type  GNSSfix Type: 0: no fix 1: dead reckoning only 2: 2D-fix 3: 3D-fix 4: GNSS + dead reckoning combined 5: time only fix
    uint8_t   falgs;  // -    Fix status flags (see graphic below)
    uint8_t   flags2; // -    Additional flags (see graphic below
    uint8_t   numSV;  // -    Number of satellites used in Nav Solution
    int32_t   lon;    //°e-7  Longitude Degrees.
    int32_t   lat;    //°e-7  Latitude Degrees.
    int32_t   height; //mm    Height above ellipsoid
    int32_t   hMSL;   //mm    Height above mean sea level
    uint32_t  hAcc;   //mm    Horizontal accuracy estimate
    uint32_t  vAcc;   //mm    Vertical accuracy estimate
    int32_t   velN;   //mm/s  NED north velocity
    int32_t   velE;   //mm/s  NED east velocity
    int32_t   velD;   //mm/s  NED down velocity
    int32_t   gSpe;   //mm/s  Groundspeed (2-D)
    int32_t   headMot;//°e-5  Heading of motion (2-D)
    uint32_t  sAcc;   //mm/s  Speed accuracy estimate
    uint32_t  headAcc;//°e-5  Heading accuracy estimate (both motion and vehicle)
    uint16_t  pDOP;   //-     Position DOP
    uint16_t  flag;   //-     flag
    uint32_t  reser;  //      Reserved
    int32_t   headveh;//
    int16_t   magDec; //      Magnetic declination. Only supported in ADR 4.10 and later
    uint16_t  magAcc; //°     Magnetic declination accuracy. Only supported in ADR 4.10 and later
  }fx;
  uint8_t     chkA;   //      Checksum A
  uint8_t     chkB;   //      B
};

gnss_t gnss;
uint8_t* celhely=fix;    
uint8_t celpont=0;
void* x=fix;

/*void readLendian(uint8_t hossz, uint8_t* A,  uint8_t* B)
  { do
    { gnss.dumax[celpont++]=Serial.read();;
      *A +=gnss.dumax[celpont];
      *B += *A; 
    } while (--hossz);
  return;
  }
*/
void readPVT(uint8_t* A, uint8_t* B)                        //                    x2_|_helett x1 x1;
{ const uint8_t sorminta[]={4,2,1,1,1,1,1,1,4,4,1,1,1,1,4,4,4,4,4,4,4,4,4,4,4,4,4,2,1,1,4,4,2,2};
  *A += Serial.read();  /* length*/
  *B += *A;
  uint8_t i=Serial.read();  //Allways c=0; *A not change. no saving
  *B += *A;

  for( i=0; i<sizeof(sorminta); i++)   //{ readLendian(sorminta[i], A, B);  }
  { uint8_t k=sorminta[i]; 
    do
    { gnss.dumax[celpont++]=Serial.read();
     *A +=gnss.dumax[celpont];
     *B += *A; 
    } while (--k);
  }

return;
}

//***********************************
void setup() {
  Serial.begin(115200);  Serial.println("Indulunk...\n");
  Serial2.begin(115200, SERIAL_8N1, RX2, TX2);
  if (!Serial2) { // If the object did not initialize, then its configuration is invalid
    Serial.println("Invalid SoftwareSerial pin configuration, check config"); 
    while (1) { delay (1000);  }
  } 
Serial2.write(duma,98);

while (Serial.available())
{  uint8_t c=Serial.read();
  if(c==0xB5)
  { c=Serial.read();
    if(c==0x62)
    { c=Serial.read();
      if(c==0x01)
      { uint8_t chkA=0,chkB=0;
        c=Serial.read();
        chkA=c;
        chkB=chkA;
        if(c==0x07)
        { celpont=0;
           readPVT(&chkA, &chkB);
        }
      }
    }
  }
}
  for (int i=0;i<98; i++) 
  { Serial.print(gnss.dumax[i], HEX);
    Serial.print(" ");
  }
    Serial.println(gnss.fx.iTOW);
    Serial.println(gnss.fx.lat);
    Serial.println(gnss.fx.lon);
    Serial.println(gnss.fx.velE);
    Serial.println(gnss.fx.velD);
    Serial.println(gnss.fx.lat);
}
//*********************************
void loop() {
  // put your main code here, to run repeatedly:
}