package art.servers.etdserver.protocols.diamond.files;
|
|
import java.text.DecimalFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.Calendar;
|
|
public final class DIAMOND_Subdirectory
|
{
|
|
private static final int END[] = {3};
|
private static final int NACK[] = {21};
|
private static final int ACK[] = {6};
|
private static final int CANCEL[] = {3};
|
private DecimalFormat formatter = new DecimalFormat("00");
|
|
public static final int ESTADO_NORMAL = 0;
|
public static final int ESTADO_PENDIENTE_DESCARGA = 1;
|
public static final int ESTADO_DESCARGANDO = 2;
|
public static final int ESTADO_DESCARGA_CORRECTO = 3;
|
public static final int ESTADO_DESCARGA_INCORRECTO = 4;
|
public static final int ESTADO_PENDIENTE_BORRAR = 5;
|
|
|
public String site;
|
public int state = ESTADO_NORMAL;
|
public int number;
|
public int length;
|
public int lanes;
|
public int storemode;
|
public boolean retrieved;
|
public int startmonth;
|
public int startday;
|
public int startyear;
|
public int starthour;
|
public int startminute;
|
public int stopmonth;
|
public int stopday;
|
public int stopyear;
|
public int stophour;
|
public int stopminute;
|
public Calendar calendarStart;
|
public Calendar calendarStop;
|
public String timestampStart;
|
public String timestampStop;
|
|
// Datos de descarga
|
|
|
public long descarga_timestampinicio = 0;
|
public int descarga_totalbytes = 0;
|
public int descarga_totalpaquetescorrectos = 0;
|
public int descarga_totalpaqueteserroneos = 0;
|
|
|
// Datos privados
|
|
private boolean cancel = false;
|
|
|
|
|
|
|
public boolean iguales (DIAMOND_Subdirectory subdirectorio)
|
{
|
try
|
{
|
if (subdirectorio.site.equalsIgnoreCase(site) == false) return false;
|
if (subdirectorio.number != number) return false;
|
if (subdirectorio.length != length) return false;
|
if (subdirectorio.startyear != startyear) return false;
|
if (subdirectorio.startday != startday) return false;
|
if (subdirectorio.starthour != starthour) return false;
|
if (subdirectorio.startminute != startminute) return false;
|
if (subdirectorio.stopyear != stopyear) return false;
|
if (subdirectorio.stopday != stopday) return false;
|
if (subdirectorio.stophour != stophour) return false;
|
if (subdirectorio.stopminute != stopminute) return false;
|
return true;
|
}
|
catch (Exception e)
|
{
|
}
|
|
return false;
|
}
|
|
|
|
|
public void cancel () throws Exception
|
{
|
this.cancel = true;
|
}
|
|
|
|
|
|
// public DIAMOND_File retrieveFileData (Serial serial) throws Exception
|
// {
|
// DIAMOND_File file = new DIAMOND_File(receiveFileData(serial));
|
// return file;
|
// }
|
//
|
//
|
//
|
//
|
//
|
//
|
// public int[] receiveFileData (Serial serial) throws Exception
|
// {
|
//
|
// try
|
// {
|
// descarga_timestampinicio = System.currentTimeMillis();
|
// descarga_totalbytes = 0;
|
// descarga_totalpaquetescorrectos = 0;
|
// descarga_totalpaqueteserroneos = 0;
|
// cancel = false;
|
//
|
// estado = ESTADO_DESCARGANDO;
|
// if (listener != null) listener.nuevoEstado(numero, ESTADO_DESCARGANDO);
|
//
|
// try { serial.read("\n", 100); } catch (Exception e) {};
|
// String comando = "R" + formatter.format(numero) + "\r";
|
// String resultado = DIAMOND.IntToString(serial.read(comando, 50));
|
// if (resultado.indexOf(comando) < 0)
|
// {
|
// throw new Exception("Incorrect answer");
|
// }
|
//
|
// int longitud = Integer.parseInt(resultado.substring(comando.length()+1, comando.length()+7), 16);
|
//
|
// // Recibir datos del fichero XModem
|
//
|
// int[] fichero = new int[longitud];
|
//
|
// int[] datos = serial.read(NACK, 50);
|
//
|
// do
|
// {
|
// if (datos.length == 132)
|
// {
|
// System.arraycopy(datos, 3, fichero, descarga_totalbytes, Math.min(datos.length - 4, fichero.length - descarga_totalbytes));
|
// descarga_totalbytes = descarga_totalbytes + Math.min(datos.length - 4, fichero.length - descarga_totalbytes);
|
// descarga_totalpaquetescorrectos = descarga_totalpaquetescorrectos + 1;
|
// if (descarga_totalbytes < longitud) datos = serial.read(ACK, 50);
|
// if (listener != null) listener.leidos(numero,descarga_totalbytes, descarga_totalpaquetescorrectos);
|
// }
|
// else
|
// {
|
// datos = serial.read(NACK, 50);
|
// descarga_totalpaqueteserroneos = descarga_totalpaqueteserroneos + 1;
|
// if (listener != null) listener.errores(numero,descarga_totalpaqueteserroneos);
|
// }
|
//
|
// if (cancel == true)
|
// {
|
// serial.send(CANCEL);
|
// descarga_totalbytes = 0;
|
// descarga_totalpaquetescorrectos = 0;
|
// descarga_totalpaqueteserroneos = 0;
|
// estado = ESTADO_DESCARGA_INCORRECTO;
|
// if (listener != null) listener.nuevoEstado(numero,ESTADO_DESCARGA_INCORRECTO);
|
// if (listener != null) listener.finalizado(numero);
|
// return new int[0];
|
// }
|
// }
|
// while (descarga_totalbytes < longitud);
|
//
|
// serial.send(END);
|
// descarga_totalbytes = 0;
|
// descarga_totalpaquetescorrectos = 0;
|
// descarga_totalpaqueteserroneos = 0;
|
// estado = ESTADO_DESCARGA_CORRECTO;
|
// if (listener != null) listener.nuevoEstado(numero,ESTADO_DESCARGA_CORRECTO);
|
// if (listener != null) listener.finalizado(numero);
|
// return fichero;
|
//
|
// }
|
// catch (Exception e)
|
// {
|
// serial.send(END);
|
// descarga_totalbytes = 0;
|
// descarga_totalpaquetescorrectos = 0;
|
// descarga_totalpaqueteserroneos = 0;
|
// estado = ESTADO_DESCARGA_INCORRECTO;
|
// if (listener != null) listener.nuevoEstado(numero, ESTADO_DESCARGA_INCORRECTO);
|
// if (listener != null) listener.finalizado(numero);
|
// throw e;
|
// }
|
//
|
//
|
// }
|
|
|
|
|
// Opciones de descarga
|
|
private SimpleDateFormat formato1 = new SimpleDateFormat("dd/MM/yyyy HH:mm");
|
private DecimalFormat formato2 = new DecimalFormat("###,###,###");
|
|
|
|
|
public String getLongitud()
|
{
|
return formato2.format(length);
|
}
|
|
|
public String getTiempoTotalDescarga()
|
{
|
return formato2.format((System.currentTimeMillis() - descarga_timestampinicio)/1000);
|
}
|
|
|
public String getRendimientoDescarga()
|
{
|
long segundos = (System.currentTimeMillis() - descarga_timestampinicio)/1000;
|
if (segundos == 0) return "0";
|
return formato2.format(descarga_totalbytes / segundos);
|
}
|
|
|
|
public String getProgreso()
|
{
|
return formato2.format(descarga_totalbytes) + " de " + formato2.format(length);
|
}
|
|
|
|
|
}
|