void si_translate_bytes(void) {
    if (Serial1.available() >= 13) {  // Wait until at least 12 bytes are available
        for (int i = 0; i < 13; i++) {
            si_received_bytes[i] = Serial1.read();
        }
		
		si_check_byte = 0x00;
		for (count_var = 0; count_var <= 10; count_var++)si_check_byte ^= si_received_bytes[count_var];
		
		if (si_check_byte == si_received_bytes[11]) {
			if (si_received_bytes[0] == 'W' && si_received_bytes[1] == 'P') {
				new_waypoint_available = 1;
				si_received_bytes[0] = 0x00;
				
				wp_lat_gps = (int32_t)si_received_bytes[2] | (int32_t)si_received_bytes[3] << 8 |
							 (int32_t)si_received_bytes[4] << 16 | (int32_t)si_received_bytes[5] << 24;
				wp_lon_gps = (int32_t)si_received_bytes[6] | (int32_t)si_received_bytes[7] << 8 |
							 (int32_t)si_received_bytes[8] << 16 | (int32_t)si_received_bytes[9] << 24;
				
				if (waypoint_set == 1 && home_point_recorded == 1 && flight_mode == 3) {
					fly_to_new_waypoint = 1;
					fly_to_new_waypoint_step = 0;
					fly_to_waypoint_lat_factor = 0;
					fly_to_waypoint_lon_factor = 0;
				}
			}
		}
    }
}

/*void si_translate_bytes(void) {
  if (  millis() - si_last_input_change > 50 && si_print_flag == 0) {
    si_check_byte = 0x00;
    for (count_var = 0; count_var <= 10; count_var++)si_check_byte ^= si_received_bytes[count_var];

    if (si_check_byte == si_received_bytes[11]) {
      if (si_received_bytes[0] == 'W' && si_received_bytes[1] == 'P') {
        new_waypoint_available = 1;
        si_received_bytes[0] = 0x00;
        wp_lat_gps = (int32_t)si_received_bytes[2] | (int32_t)si_received_bytes[3] << 8 | (int32_t)si_received_bytes[4] << 16 | (int32_t)si_received_bytes[5] << 24;
        wp_lon_gps = (int32_t)si_received_bytes[6] | (int32_t)si_received_bytes[7] << 8 | (int32_t)si_received_bytes[8] << 16 | (int32_t)si_received_bytes[9] << 24;
        if (waypoint_set == 1 && home_point_recorded == 1 && flight_mode == 3) {
          fly_to_new_waypoint = 1;
          fly_to_new_waypoint_step = 0;
          fly_to_waypoint_lat_factor = 0;
          fly_to_waypoint_lon_factor = 0;
        }
      }
    }
    si_print_flag = 1;
  }

}*/

void Serial_input_handler(void) {
  /*if (si_rising_edge_set) {                                    //If the receiver channel 1 input pulse on A0 is high.
    TIMER3_BASE->CCER |= TIMER_CCER_CC1P;                   //Change the input capture mode to the falling edge of the pulse.
    si_rising_edge_set = 0;
  }
  else {
    TIMER3_BASE->CCER &= ~TIMER_CCER_CC1P;                  //Change the input capture mode to the rising edge of the pulse.
    si_rising_edge_set = 1;
  }

  si_measured_time = TIMER3_BASE->CCR1 - si_measured_time_start;
  if (si_measured_time < 0)si_measured_time += 0xFFFF;

  si_last_input_change = millis();
  if (si_last_input_change - si_last_input_change_previous > 50) {
    si_time_array_counter = 1;
    si_measured_time_start = TIMER3_BASE->CCR1;
  }
  else {
    si_time_array[si_time_array_counter] = si_measured_time;
    if (si_time_array_counter < 180)si_time_array_counter++;
  }
  si_last_input_change_previous = si_last_input_change;*/
}

