/**
   * Methode : analyzeDataReceived => Traitement des données recu
   *
   * @param received_data
   * @throws java.lang.InterruptedException
   */
  @Override
  public void analyzeDataReceived(String received_data) throws InterruptedException {
    super.setLastReceivedData(received_data);
    switch (received_data) {
      case BONJOUR:
        Thread.sleep(100);
        System.out.println("|BONJOUR| recu dans la classe herité");
        super.sendData(BONJOUR);
        break;

      case DEMANDE_SYNCHRONIZATION_APRES_PARTAGE_ACCES:
        Thread.sleep(100);
        System.out.println(
            "'DEMANDE_SYNCHRONIZATION_APRES_PARTAGE_ACCES' recu dans la classe herité");
        super.sendData(DEMANDE_SYNCHRONIZATION_APRES_PARTAGE_ACCES_AUTORISEE);
        break;

      case PREPARATION_ENREGISTREMENT_CLE_ACCES_ACCREDITEE:
        Thread.sleep(1000);
        System.out.println(
            "'PREPARATION_ENREGISTREMENT_CLE_ACCES_ACCREDITEE' recu dans la classe herité");
        super.sendData(SESAME_PRET_ENREGISTRE_CLE_ACCES);
        break;

      case BEGIN:
        System.out.println("|BEGIN| dans la classe hérité");
        Thread.sleep(100);
        // reset the buffer
        super.resetBufferReception();
        super.setSavingFlag(true);
        break;

      case END:
        Thread.sleep(100);
        System.out.println("|END| dans la classe hérité");
        super.setSavingFlag(false);
        this.checkBufferData();
        break;

      default:
        break;
    }
  }
  public SerialPortSynchronizationInstruction(
      int baudrate, String identifiant, DeviceLinkingData device) {
    super(baudrate);
    id_sesame_sharer = identifiant;
    this.device = device;

    try {
      Thread.sleep(1000);
      super.sendData(BONJOUR);
    } catch (InterruptedException ex) {
    }
  }
  /**
   * Methode : checkSavedData : Traitement des données recu et sauvegarder dans le buffer de
   * reception
   *
   * @param first_data
   * @param last_data
   * @param data
   * @return flag : if the data is saved correctly
   * @throws java.lang.InterruptedException
   */
  private boolean checkSavedData(String first_data, String last_data, String[] data)
      throws InterruptedException {
    System.out.println("<--- BEGIN OF THE checkSavedData() methode --->");
    boolean flag = false;

    if ((first_data != null && first_data.equals(DEBUT_ENVOIE_INFORMATION_ACCREDITEE))
        && (last_data != null && last_data.equals(FIN_ENVOIE_INFORMATION_ACCREDITEE))) {
      System.out.println("First if");
      if (data != null) {

        System.out.println("Before calling saveAccreditedInformation()");
        flag = saveAccreditedInformation(data);
        System.out.println("After calling saveAccreditedInformation()");

        if (flag) {
          System.out.println("The data is saved correctly");
          Thread.sleep(500);
          super.sendData(INFORMATION_ACCREDITEE_ENREGISTRE_CORRECTEMENT);
        } else {
          System.out.println("The data is not saved because it contains some invalid data");
          Thread.sleep(500);
          super.sendData(INFORMATION_ACCREDITEE_DONNEES_ERONEES);
        }
      } else {
        System.out.println("The data is not saved because it contains some invalid data");
        Thread.sleep(500);
        super.sendData(INFORMATION_ACCREDITEE_DONNEES_ERONEES);
        System.out.println("Le buffer est invalide");
        flag = false;
      }
    }
    if ((first_data != null && first_data.equals(DEBUT_ENVOIE_CLE_ACCES_ACCREDITEE))
        && (last_data != null && last_data.equals(FIN_ENVOIE_CLE_ACCES_ACCREDITEE))) {
      System.out.println("First if");
      if (data != null) {

        System.out.println("Before calling checkSharingConfirmation()");
        flag = addDeviceLink(data);
        System.out.println("After calling checkSharingConfirmation()");

        if (flag) {
          System.out.println("The data is saved correctly");
          Thread.sleep(500);
          super.sendData(CLE_ACCES_ACCREDITEE_ENREGISTREE_CORRECTEMENT);
          this.getSerial().shutdown();
          super.openUartPort();
        } else {
          System.out.println("The data is not saved because it contains some invalid data");
          Thread.sleep(500);
          super.sendData(CLE_ACCES_ACCREDITEE_DONNEES_ERONNEES);
        }
      } else {
        System.out.println("The data is not saved because it contains some invalid data");
        Thread.sleep(500);
        super.sendData(CLE_ACCES_ACCREDITEE_DONNEES_ERONNEES);
        System.out.println("Le buffer est invalide");
        flag = false;
      }
    }
    // ===>
    else {
      flag = false;
      System.out.println("First Else ");
    }

    System.out.println("<--- END OF THE checkSavedData() methode -->");
    return flag;
  }