/** * Return bursts from a hexa frame without time advance * * @param hexaFrame frame in hexadecimal * @param fn the frame number * @param siType the System Information type (5/5ter/6) * @return String[] with all 4 bursts from the frame * @throws IOException if error while executing command */ public static String[] getBursts(String hexaFrame, String fn, String siType) throws IOException { String[] bursts = new String[6]; bursts[4] = fn; bursts[5] = siType; int i = 0; // delete Time Advance StringBuilder hexaFrameNoTA = new StringBuilder(hexaFrame); hexaFrameNoTA.setCharAt(2, '0'); hexaFrameNoTA.setCharAt(3, '0'); ProcessBuilder pb = new ProcessBuilder("./gsmframecoder", hexaFrameNoTA.toString()); pb.redirectErrorStream(true); pb.directory(Configuration.gsmFrameCoder); Process p = pb.start(); p.getOutputStream().flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String ligne = new String(); while ((ligne = reader.readLine()) != null) { if (ligne.length() == 114 && i < 4) { bursts[i] = ligne; i++; } } p.destroy(); p.destroyForcibly(); return bursts; }
@AfterClass public static void dispose() throws InterruptedException { System.out.print("Terminating server..."); System.out.flush(); if (!PROCESS.destroyForcibly().waitFor(10, TimeUnit.SECONDS)) { throw new IllegalStateException("Failed to terminate process"); } System.out.println("done!"); }
@Override public void start(Stage primaryStage) throws Exception { Thread.setDefaultUncaughtExceptionHandler((t, e) -> Issues.create(null, e)); try { Properties properties = new Properties(); try (InputStream in = TRLauncher.class.getResourceAsStream("MANIFEST.MF")) { if (in != null) properties.load(in); else log.warn("Failed to load the jar manifest. Are we running in a development environment?"); } version = properties.getProperty("Implementation-Version", "unknown"); analytics = new TRAnalytics( new SimpleAnalytics( version, "4b2c71837e92e180fcbc0433b57f3a05", "0e0384bf65d2d6c8887f9c4a9294a1fbed83c363")); analytics.sendEvent("OS:" + System.getProperty("os.name")); analytics.sendEvent("Arch:" + System.getProperty("os.arch")); analytics.sendEvent("JavaVersion:" + System.getProperty("java.version").split("_")[0]); analytics.sendEvent("JavaVendor:" + System.getProperty("java.vendor")); } catch (Throwable t) { log.error("Failed to setup analytics."); analytics = new TRAnalytics(null); } ModpackUtils.loadModpacks(modpacks); this.primaryStage = MiscUtils.addIcons(primaryStage); this.primaryStage.setTitle("Temporal Reality"); Runtime.getRuntime() .addShutdownHook( new Thread( () -> { if (minecraft != null) minecraft.destroyForcibly(); })); if (OperatingSystem.getOS() == OperatingSystem.OSX) { // buuuu //What did you expect? It's OSX try { OSUtils.setOSXDockIcon(new URL("http://temporal-reality.com/logo/1024.png")); } catch (MalformedURLException ignored) { } } initRootLayout(); showModpackOverview(); }
@BeforeClass public static void setup() throws IOException, InterruptedException { final String javaHome = System.getProperty("java.home"); final ProcessBuilder pb = new ProcessBuilder("target/instance/server"); pb.environment().put("JAVA_HOME", javaHome); final Map<String, String> additional = new HashMap<>(); makeProcessSystemProperties(pb, additional); pb.inheritIO(); System.out.println("Starting: " + pb); PROCESS = pb.start(); System.out.print("Started ... waiting for port... "); System.out.flush(); int i = 0; while (i < 5) { if (isOpen(JETTY_PORT)) { break; } i++; Thread.sleep(1000); } if (i >= 5) { PROCESS.destroyForcibly(); throw new IllegalStateException("Failed to wait for port"); } else { System.out.println("Port open!"); // sleep a little bit longer to allow OSGi to fire up all services Thread.sleep(1000); } }
/** * @param timestamps This should be a sorted array of timestamps with no gaps * @param series The raw series values * @param seasonality The seasonality in number of buckets * @return The timeseries with seasonality removed */ public static double[] removeSeasonality(long[] timestamps, double[] series, int seasonality) { int numDataPoints = timestamps.length; if (numDataPoints != series.length) { throw new IllegalArgumentException("time series lengths do not match"); } if (seasonality < 0) { throw new IllegalArgumentException("seasonality cannot be negative"); } Process process = null; BufferedReader stdout = null; BufferedWriter stdin = null; try { ProcessBuilder processBuilder = new ProcessBuilder("Rscript", TMP_STL_WRAPPER_R_PATH, "" + seasonality); processBuilder.redirectErrorStream(true); process = processBuilder.start(); // the Rscript's stdout stdout = new BufferedReader(new InputStreamReader(process.getInputStream())); // the Rscript's stdin stdin = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); stdin.write("\"Bucket\",\"Series\"\n"); for (int i = 0; i < numDataPoints; i++) { stdin.write(timestamps[i] + "," + series[i] + "\n"); } stdin.close(); // wait for Rscript to finish process.waitFor(); // read the result line by line double[] result = new double[numDataPoints]; for (int i = 0; i < numDataPoints; i++) { String line = stdout.readLine(); result[i] = Double.valueOf(line); } return result; } catch (Exception e) { LOGGER.info("exception trying to run stl", e); return null; } finally { if (stdin != null) { try { stdin.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (stdout != null) { try { stdout.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (process != null) { process.destroyForcibly(); } } }