public void messageReceived(int to, Message message) {
    Date date = Calendar.getInstance().getTime();

    if (message instanceof RadioSignalResultsMsg) {
      RadioSignalResultsMsg resultMsg = (RadioSignalResultsMsg) message;
      log(
          date
              + "\t"
              + date.getTime()
              + "\t"
              + "RADIO15.4_RESULT_MSG"
              + "\t"
              + resultMsg.get_idReceiver()
              + "\t"
              + resultMsg.get_idSender()
              + "\t"
              + resultMsg.get_seqno()
              + "\t"
              + resultMsg.get_rssi()
              + "\t"
              + resultMsg.get_lqi()
              + "\t"
              + resultMsg.get_timestamp());
    } else {
      log(date + "\t" + date.getTime() + "\t UNKNOWN_MSG" + "\t" + message.toString());
    }
  }
Esempio n. 2
0
 // Send message to base station
 public void sendMessage(Message m) {
   try {
     os.write(m.toString().getBytes());
     os.flush();
   } catch (IOException e) {
     System.out.println("Failed to send message!");
   }
 }
Esempio n. 3
0
 @Override
 public String toString() {
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < messages.size(); i++) {
     Message m = messages.get(i);
     if (i > 0) sb.append(",");
     sb.append(m.toString());
   }
   return sb.toString();
 }
Esempio n. 4
0
 public void run() {
   while (keeprunning) {
     try {
       Message m = outqueue.take();
       if (!keeprunning) break;
       // synchronized (out) { // shouldn't need to synchronize here, there's only one thread
       // running this
       out.println(m.toString());
       // }
     } catch (InterruptedException e) {
     } catch (Exception e) {
       System.err.println("unexpected exception in OuputHandler");
       e.printStackTrace();
     }
   }
 }
 public void showMessages(boolean isFormatted) {
   try {
     Collections.sort(data);
     if (isFormatted) {
       System.out.println("FORMATTED LIST OF MESSAGES:");
       log("QUERY formatted list");
       for (Message i : data) {
         System.out.println(i.getFormattedMessage());
       }
     } else {
       System.out.println("FULL LIST OF MESSAGES:");
       log("QUERY full list");
       for (Message i : data) {
         System.out.println(i.toString());
       }
     }
   } catch (Exception e) {
     System.out.println(RED + "Failed on your query. Try another one." + END);
     log("QUERY failed");
   }
 }
  public synchronized void receive(Message m) {

    Utils.out(pid, m.toString()); /* The default action. */
  }
Esempio n. 7
0
    public void run() {
      String messageString;
      long lastActivity = System.currentTimeMillis();
      while (keeprunning) {
        try {
          if (in.ready()) {
            messageString = in.readLine();

            if (messageString == null) continue;
            Message m = new Message(messageString);

            if (m.getCommand().matches("\\d+"))
              try {
                int intcommand = Integer.parseInt(m.getCommand());
                if (intcommand == Constants.RPL_ENDOFMOTD) {
                  System.err.println("MOTD SEEN, must be connected.");
                  if (connected) joinChannels();
                  connected = true;
                } else if (intcommand == Constants.ERR_NICKNAMEINUSE) {
                  System.err.println("NICKNAMEINUSE");
                  namecount++;
                  BotStats.getInstance().setBotname(botdefaultname + namecount);
                  new Message("", "NICK", BotStats.getInstance().getBotname(), "").send();
                  new Message(
                          "",
                          "USER",
                          BotStats.getInstance().getBotname()
                              + " nowhere.com "
                              + BotStats.getInstance().getServername(),
                          BotStats.getInstance().getClientName()
                              + " v."
                              + BotStats.getInstance().getVersion())
                      .send();
                  System.err.println("Setting nick to:" + botdefaultname + namecount);
                }
              } catch (NumberFormatException nfe) {
                // we ignore this
                System.err.println("Unknown command:" + m.getCommand());
              }

            if (m.getCommand().equals("PING")) {
              outqueue.add(new Message("", "PONG", "", m.getTrailing()));
              if (debug) System.out.println("PUNG at " + new Date());
            } else if (BotStats.getInstance().containsIgnoreName(m.getSender())) {
              if (debug) System.out.println("Ignored: " + m);
            } else {
              inqueue.add(m); // add to inqueue
              if (debug) System.out.println(m.toString());
              // System.out.println("Inbuffer: prefix: " + m.prefix + " params: " + m.params + "
              // trailing:"
              // + m.trailing + " command:" + m.command + " sender: " + m.sender + "\n    "
              // + "isCTCP:" + m.isCTCP + " isPrivate:" + m.isPrivate + " CTCPCommand:" +
              // m.CTCPCommand
              // + " CTCPMessage:" + m.CTCPMessage);
            }

            lastActivity = System.currentTimeMillis();
          } else {
            if (System.currentTimeMillis() - lastActivity > 400000) {
              System.err.println("400 seconds since last activity! Attempting reconnect");
              in.close();
              oh.disconnect();
              keeprunning = false;
              reconnect();
              return;
            }
            sleep(100);
          }
        } catch (IOException ioe) {
          System.out.println("EOF on connection: " + ioe.getMessage());
        } catch (InterruptedException ie) {
          System.out.println("Interrupted: " + ie.getMessage());
        } catch (Exception e) {
          System.err.println("Unexpected exception in InputHandler :");
          e.printStackTrace();
        }
      }
    }