public synchronized void send(Message m) { try { intf.send(MoteIF.TOS_BCAST_ADDR, m); } catch (IOException e) { e.printStackTrace(); System.out.println("ERROR: Can't send message"); System.exit(1); } }
private void send(Message m) { try { moteIF.send(MoteIF.TOS_BCAST_ADDR, m); } catch (IOException e) { e.printStackTrace(); System.out.println("ERROR: Can't send message"); System.exit(1); } catch (Exception e) { e.printStackTrace(); } }
/* User pressed the "Update" button. Read the GUI fields and send a SettingsMsg with the requested values. When the requested settings are bad, we silently update them to sane values. */ public void updateSettings() { SettingsMsg smsg = new SettingsMsg(); short alert = 0; short detect = 0; int checkInterval = Constants.DEFAULT_CHECK_INTERVAL; /* Extract current interval value, fixing bad values */ String intervalS = fieldInterval.getText().trim(); try { int newInterval = Integer.parseInt(intervalS); if (newInterval < 10) throw new NumberFormatException(); checkInterval = newInterval; } catch (NumberFormatException e) { /* Reset field when value is bad */ fieldInterval.setText("" + checkInterval); } /* Extract alert settings */ if (repLedCb.isSelected()) alert |= Constants.ALERT_LEDS; if (repSirenCb.isSelected()) alert |= Constants.ALERT_SOUND; if (repNeighboursCb.isSelected()) alert |= Constants.ALERT_RADIO; if (repServerCb.isSelected()) alert |= Constants.ALERT_ROOT; if (alert == 0) { /* If nothing select, force-select LEDs */ alert = Constants.ALERT_LEDS; repLedCb.setSelected(true); } /* Extract detection settings */ if (detDarkCb.isSelected()) detect |= Constants.DETECT_DARK; if (detAccelCb.isSelected()) detect |= Constants.DETECT_ACCEL; if (detect == 0) { /* If no detection selected, force-select dark */ detect = Constants.DETECT_DARK; detDarkCb.setSelected(true); } /* Build and send settings message */ smsg.set_alert(alert); smsg.set_detect(detect); smsg.set_checkInterval(checkInterval); try { mote.send(MoteIF.TOS_BCAST_ADDR, smsg); } catch (IOException e) { error("Cannot send message to mote"); } }
public void sendPackets() { int counter = 0; BlinkToRadioMsg payload = new BlinkToRadioMsg(); try { while (true) { System.out.println("Sending packet " + counter); payload.set_counter(counter); moteIF.send(0, payload); counter++; try { Thread.sleep(1000); } catch (InterruptedException exception) { } } } catch (IOException exception) { System.err.println("Exception thrown when sending packets. Exiting."); System.err.println(exception); } }