1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| public void run(){
while(fin != 1){
try{
cmd = getCommand();
log.debug("On a une commande recue....");
cmd.print();
//Si on est dans le cas d'une commande de sortie pour le Thread USB
if(fin == 1){
//on sort de la boucle d'attente sans traitement.
log.debug("Commande de Sortie du Thread USB");
break;
}
//on rajoute la commande dans la collection
addCommand(cmd);
//on envoit la commande a la carte USB
process();
//on attend le Ack de la carte USB
String rec = getCommandAck();
Integer id = (int)rec.charAt(0);
if(id == Integer.parseInt(cmd.getSession_id())){
cmd.setValue(rec.substring(1));
cmd.setStatus(OperativeConstants.SUCCESS);
log.debug("ACK ["+cmd.getSession_id()+"]["+cmd.getCommand()+"]"+"]["+cmd.getStatus()+"]"+"]["+cmd.getValue()+"]");
//cmd.print();
if(cmd.getCommand().equals(OperativeConstants.LED1_ON))
XMLActuators.updateValue(ModuleActuators.LED1, cmd.getValue());
if(cmd.getCommand().equals(OperativeConstants.LED2_ON))
XMLActuators.updateValue(ModuleActuators.LED2, cmd.getValue());
//log.debug("Supression Commande dans collection");
deleteCommand(cmd);
printCommands();
}
else{
log.debug("Commande ACK Recue n'est pas la commande envoyee:"+id+"/"+cmd.getSession_id());
}
}catch(Exception e){
log.error("Erreur de Thread USB: "+e.toString());
}
}
log.debug("[USB Thread]: Fin USB Thread...");
}
...
protected OperativeCommand getCommand() {
try {
return this.queue.take();
} catch (InterruptedException e) {
log.debug("Erreur de GetCommand");
throw new RuntimeException(e);
}
} |