View Javadoc
1   package gov.usgs.volcanoes.winston.legacyServer.cmd;
2   
3   import java.nio.ByteBuffer;
4   import java.nio.channels.SocketChannel;
5   
6   import org.slf4j.Logger;
7   import org.slf4j.LoggerFactory;
8   
9   import gov.usgs.math.DownsamplingType;
10  import gov.usgs.net.NetTools;
11  import gov.usgs.plot.data.RSAMData;
12  import gov.usgs.volcanoes.core.time.J2kSec;
13  import gov.usgs.volcanoes.core.util.UtilException;
14  import gov.usgs.volcanoes.winston.db.WinstonDatabase;
15  import gov.usgs.volcanoes.winston.legacyServer.WWS;
16  import gov.usgs.volcanoes.winston.legacyServer.WWSCommandString;
17  
18  /**
19   *
20   * @author Dan Cervelli
21   */
22  public class GetSCNLRSAMRawCommand extends BaseCommand {
23    private static final Logger LOGGER = LoggerFactory.getLogger(GetSCNLRSAMRawCommand.class);
24  
25    public GetSCNLRSAMRawCommand(final NetTools nt, final WinstonDatabase db, final WWS wws) {
26      super(nt, db, wws);
27    }
28  
29    public void doCommand(final Object info, final SocketChannel channel) {
30      final WWSCommandString cmd = new WWSCommandString((String) info);
31      if (!cmd.isLegalSCNLTT(10) || Double.isNaN(cmd.getDouble(8))
32          || cmd.getInt(9) == Integer.MIN_VALUE)
33        return; // malformed command
34  
35      RSAMData rsam = null;
36      double t1 = Double.NaN;
37      double t2 = Double.NaN;
38  
39      try {
40        t1 = cmd.getT1(true);
41        t1 = timeOrMaxDays(t1);
42  
43        t2 = cmd.getT2(true);
44        t2 = timeOrMaxDays(t2);
45  
46        final int ds = (int) cmd.getDouble(8);
47        DownsamplingType dst = DownsamplingType.MEAN;
48        if (ds < 2)
49          dst = DownsamplingType.NONE;
50  
51        rsam = data.getRSAMData(cmd.getWinstonSCNL(), t1, t2, 0, dst, ds);
52      } catch (final UtilException e) {
53        // can I do anything here?
54      }
55      ByteBuffer bb = null;
56      if (rsam != null && rsam.rows() > 0)
57        bb = (ByteBuffer) rsam.toBinary().flip();
58      final int bytes = writeByteBuffer(cmd.getID(), bb, cmd.getInt(9) == 1, channel);
59  
60      final String time = J2kSec.toDateString(t1) + " - " + J2kSec.toDateString(t2);
61      LOGGER.debug("GETSCNLRSAMRAW {}: {},{} bytes.", cmd.getWinstonSCNL(), time, bytes);
62    }
63  }