[diablu commit] r314 - in trunk/SMS2OSC/src/pt/citar/diablu/sms2osc: . bluetooth gui osc parser util

0 views
Skip to first unread message

codesite...@google.com

unread,
Dec 2, 2008, 12:18:05 PM12/2/08
to diablu...@googlegroups.com
Author: pedro.r.santos
Date: Tue Dec 2 09:16:27 2008
New Revision: 314

Added:
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/parser/
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/parser/S2OSMSParser.java
Modified:
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/S2O.java
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/bluetooth/S2OBTConnection.java
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/gui/S2OGUI.form
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/gui/S2OGUI.java
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/osc/S2OOscClient.java
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/util/S2OProperties.java

Log:
Parser a funcionar.
Tabela com mensagens recebidas implementada

Modified: trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/S2O.java
==============================================================================
--- trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/S2O.java (original)
+++ trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/S2O.java Tue Dec 2 09:16:27
2008
@@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
-import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
@@ -11,6 +10,7 @@
import pt.citar.diablu.sms2osc.gui.S2OGUI;
import pt.citar.diablu.sms2osc.osc.S2OOscClient;
import pt.citar.diablu.sms2osc.osc.S2OOscServer;
+import pt.citar.diablu.sms2osc.parser.S2OSMSParser;
import pt.citar.diablu.sms2osc.util.S2OCommPortList;
import pt.citar.diablu.sms2osc.util.S2OProperties;
import pt.citar.diablu.sms2osc.util.S2OTextAreaHandler;
@@ -26,15 +26,16 @@

private S2OGUI gui;
private S2OTextAreaHandler textAreaHandler;
- private ConsoleHandler consoleHandler;
private FileHandler fileHandler;
private S2OOscServer oscServer;
private S2OOscClient oscClient;


+ private S2OSMSParser smsParser;
private S2OBTConnection btConnection;
public Thread btConnectionThread;

+
public S2O()
{
logger = Logger.getLogger("pt.citar.diablu.sms2osc");
@@ -47,6 +48,12 @@
oscServer = new S2OOscServer(this);
oscClient = new S2OOscClient(this);

+ smsParser = new S2OSMSParser(this, properties.useParser());
+ if(smsParser.isActive())
+ {
+ System.out.println("lalala");
+ smsParser.getCommands(properties.getCommands());
+ }
btConnection = new S2OBTConnection(this,
properties.getGateway(), "COM6", 57600, "Siemens", "S65");


@@ -75,7 +82,6 @@
logger.setLevel(Level.ALL);

textAreaHandler = new S2OTextAreaHandler(gui.getLogTextArea());
- consoleHandler = new ConsoleHandler();
try {
fileHandler = new FileHandler("logs.txt");
} catch (IOException ex) {
@@ -126,6 +132,12 @@
public Logger getLogger() {
return logger;
}
+
+ public S2OSMSParser getSmsParser() {
+ return smsParser;
+ }
+
+


Modified:
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/bluetooth/S2OBTConnection.java
==============================================================================
---
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/bluetooth/S2OBTConnection.java
(original)
+++
trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/bluetooth/S2OBTConnection.java
Tue Dec 2 09:16:27 2008
@@ -13,7 +13,6 @@
import org.smslib.IOutboundMessageNotification;
import org.smslib.InboundMessage;
import org.smslib.InboundMessage.MessageClasses;
-import org.smslib.Library;
import org.smslib.Message.MessageTypes;
import org.smslib.OutboundMessage;
import org.smslib.SMSLibException;
@@ -21,10 +20,7 @@
import org.smslib.TimeoutException;
import org.smslib.modem.SerialModemGateway;

-/**
- *
- * @author Raspa
- */
+
public class S2OBTConnection implements Runnable {

String id;
@@ -58,7 +54,6 @@
OutboundNotification outboundNotification = new
OutboundNotification();


- System.out.println("Version: " + Library.getLibraryVersion());
srv = new Service();
SerialModemGateway gateway = new SerialModemGateway(id, port,
baud, manufacturer, model);
gateway.setInbound(true);
@@ -81,8 +76,7 @@
System.out.println(msg);
}
this.connected = true;
- this.connecting = false;
-
+
} catch (TimeoutException ex) {

Logger.getLogger(S2OBTConnection.class.getName()).log(Level.SEVERE, null,
ex);
this.connecting = false;
@@ -148,19 +142,25 @@

if (msgType == MessageTypes.INBOUND) {
System.out.println(">>> New Inbound message detected from
Gateway: " + gatewayId);
- s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/sms", new Object[] { msg.getOriginator(),
msg.getText()}));
- System.out.println("Message: " + msg.getText());
-
- } else if (msgType == MessageTypes.STATUSREPORT) {
- System.out.println(">>> New Inbound Status Report message
detected from Gateway: " + gatewayId);
- }
- try {
-
- srv.deleteMessage(msg);
- } catch (Exception e) {
+ s2o.getGui().addMessageRow(msg.getOriginator(), "Inbound",
msg.getText());
+ if(s2o.getSmsParser().isActive())
+ {
+ s2o.getSmsParser().parse(msg.getText());
+ }
+ else
+ {
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/sms", new Object[] { msg.getOriginator(),
msg.getText()}));
+ System.out.println("Message: " + msg.getText());
+ }
+ try {
+ srv.deleteMessage(msg);
+ } catch (Exception e) {
+
System.out.println("Oops!!! Something gone bad...");
e.printStackTrace();
+ }
}
+
}
}


Modified: trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/gui/S2OGUI.form
==============================================================================
--- trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/gui/S2OGUI.form (original)
+++ trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/gui/S2OGUI.form Tue Dec 2
09:16:27 2008
@@ -317,6 +317,81 @@
</Container>
</SubComponents>
</Container>
+ <Container class="javax.swing.JPanel" name="jPanel2">
+ <Constraints>
+ <Constraint
layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"
value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
+ <JTabbedPaneConstraints tabName="tab3">
+ <Property name="tabTitle" type="java.lang.String"
value="tab3"/>
+ </JTabbedPaneConstraints>
+ </Constraint>
+ </Constraints>
+
+ <Layout>
+ <DimensionLayout dim="0">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" alignment="0" attributes="0">
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="jScrollPane2" pref="634" max="32767"
attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ <DimensionLayout dim="1">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" alignment="1" attributes="0">
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="jScrollPane2" pref="190" max="32767"
attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ </DimensionLayout>
+ </Layout>
+ <SubComponents>
+ <Container class="javax.swing.JScrollPane" name="jScrollPane2">
+ <AuxValues>
+ <AuxValue name="autoScrollPane" type="java.lang.Boolean"
value="true"/>
+ </AuxValues>
+
+ <Layout
class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JTable" name="jTable1">
+ <Properties>
+ <Property name="model"
type="javax.swing.table.TableModel"
editor="org.netbeans.modules.form.editors2.TableModelEditor">
+ <Table columnCount="3" rowCount="20">
+ <Column editable="false" title="Number"
type="java.lang.String"/>
+ <Column editable="false" title="Direction"
type="java.lang.String"/>
+ <Column editable="false" title="Title 3"
type="java.lang.String"/>
+ </Table>
+ </Property>
+ <Property name="autoResizeMode" type="int" value="0"/>
+ <Property name="columnModel"
type="javax.swing.table.TableColumnModel"
editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
+ <TableColumnModel selectionModel="0">
+ <Column maxWidth="-1" minWidth="-1"
prefWidth="100" resizable="false">
+ <Title/>
+ <Editor/>
+ <Renderer/>
+ </Column>
+ <Column maxWidth="-1" minWidth="-1"
prefWidth="100" resizable="false">
+ <Title/>
+ <Editor/>
+ <Renderer/>
+ </Column>
+ <Column maxWidth="-1" minWidth="-1"
prefWidth="600" resizable="false">
+ <Title/>
+ <Editor/>
+ <Renderer/>
+ </Column>
+ </TableColumnModel>
+ </Property>
+ <Property name="tableHeader"
type="javax.swing.table.JTableHeader"
editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
+ <TableHeader reorderingAllowed="false"
resizingAllowed="true"/>
+ </Property>
+ </Properties>
+ </Component>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+ </Container>
<Container class="javax.swing.JPanel" name="jPanel1">
<Constraints>
<Constraint
layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"
value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">

Modified: trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/gui/S2OGUI.java
==============================================================================
--- trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/gui/S2OGUI.java (original)
+++ trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/gui/S2OGUI.java Tue Dec 2
09:16:27 2008
@@ -9,6 +9,7 @@
public class S2OGUI extends javax.swing.JFrame {

S2O s2o;
+ int rowNumber = 0;

public S2OGUI(S2O s2o) {
this.s2o = s2o;
@@ -46,6 +47,9 @@
CommPorts = new javax.swing.JComboBox();
Connect = new javax.swing.JButton();
CommPortLabel = new javax.swing.JLabel();
+ jPanel2 = new javax.swing.JPanel();
+ jScrollPane2 = new javax.swing.JScrollPane();
+ jTable1 = new javax.swing.JTable();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
logTextArea = new javax.swing.JTextArea();
@@ -230,6 +234,77 @@

S2OTabbedPane.addTab("Connection", ConnectionPanel);

+ jTable1.setModel(new javax.swing.table.DefaultTableModel(
+ new Object [][] {
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null},
+ {null, null, null}
+ },
+ new String [] {
+ "Number", "Direction", "Title 3"
+ }
+ ) {
+ Class[] types = new Class [] {
+ java.lang.String.class, java.lang.String.class,
java.lang.String.class
+ };
+ boolean[] canEdit = new boolean [] {
+ false, false, false
+ };
+
+ public Class getColumnClass(int columnIndex) {
+ return types [columnIndex];
+ }
+
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return canEdit [columnIndex];
+ }
+ });
+ jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
+ jTable1.getTableHeader().setReorderingAllowed(false);
+ jScrollPane2.setViewportView(jTable1);
+ jTable1.getColumnModel().getColumn(0).setResizable(false);
+ jTable1.getColumnModel().getColumn(0).setPreferredWidth(100);
+ jTable1.getColumnModel().getColumn(1).setResizable(false);
+ jTable1.getColumnModel().getColumn(1).setPreferredWidth(100);
+ jTable1.getColumnModel().getColumn(2).setResizable(false);
+ jTable1.getColumnModel().getColumn(2).setPreferredWidth(600);
+
+ javax.swing.GroupLayout jPanel2Layout = new
javax.swing.GroupLayout(jPanel2);
+ jPanel2.setLayout(jPanel2Layout);
+ jPanel2Layout.setHorizontalGroup(
+
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel2Layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(jScrollPane2,
javax.swing.GroupLayout.DEFAULT_SIZE, 634, Short.MAX_VALUE)
+ .addContainerGap())
+ );
+ jPanel2Layout.setVerticalGroup(
+
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel2Layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(jScrollPane2,
javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
+ .addContainerGap())
+ );
+
+ S2OTabbedPane.addTab("tab3", jPanel2);
+
logTextArea.setColumns(20);
logTextArea.setRows(5);
jScrollPane1.setViewportView(logTextArea);
@@ -330,7 +405,10 @@
private javax.swing.JPanel YourAppPane;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JPanel jPanel1;
+ private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JScrollPane jScrollPane2;
+ private javax.swing.JTable jTable1;
private javax.swing.JTextArea logTextArea;
// End of variables declaration//GEN-END:variables

@@ -356,8 +434,32 @@
public JTextArea getLogTextArea() {
return logTextArea;
}
-

+ public void addMessageRow(String number, String direction, String
message)
+ {
+ if(rowNumber < 20)
+ {
+ jTable1.getModel().setValueAt(number, rowNumber,0);
+ jTable1.getModel().setValueAt(direction, rowNumber,1);
+ jTable1.getModel().setValueAt(message, rowNumber,2);
+ jTable1.changeSelection(rowNumber, 0, false, false);
+ rowNumber++;
+ }
+ else
+ {
+ for(int i = 0; i < 19; i++)
+ {
+
jTable1.getModel().setValueAt(jTable1.getModel().getValueAt(i+1, 0), i,0);
+
jTable1.getModel().setValueAt(jTable1.getModel().getValueAt(i+1, 1), i,1);
+
jTable1.getModel().setValueAt(jTable1.getModel().getValueAt(i+1, 2), i,2);
+ }
+ jTable1.getModel().setValueAt(number, 19,0);
+ jTable1.getModel().setValueAt(direction,19,1);
+ jTable1.getModel().setValueAt(message, 19,2);
+ jTable1.changeSelection(19, 0, false, false);
+ rowNumber++;
+ }
+ }


}

Modified: trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/osc/S2OOscClient.java
==============================================================================
--- trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/osc/S2OOscClient.java
(original)
+++ trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/osc/S2OOscClient.java Tue
Dec 2 09:16:27 2008
@@ -1,26 +1,4 @@
-/*
- * DiABlu Mailman
- * Copyright (C) 2008-2009, CITAR (Research Centre for Science and
Technology in Art)
- *
- * This is part of the DiABlu Project, created by Jorge Cardoso -
http://diablu.jorgecardoso.eu
- *
- *
- * Contributors:
- * - Pedro Santos <psa...@porto.ucp.pt>
- * - Jorge Cardoso <jcca...@porto.ucp.pt>
- *
- * This program is free software; you can redistribute it and/or modify it
under the terms of the
- * GNU General Public License as published by the Free Software
Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
with this program;
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston,
- * MA 02111-1307 USA
- */
+

package pt.citar.diablu.sms2osc.osc;

@@ -42,7 +20,7 @@
{
try {
this.s2o = s2o;
- if
(this.s2o.getProperties().getUseLoopback().equalsIgnoreCase("true") ) {
+ if (s2o.getProperties().useLoopback()) {
oscClient = OSCClient.newUsing(OSCClient.UDP, 12345, true);
} else {
oscClient = OSCClient.newUsing(OSCClient.UDP);

Added: trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/parser/S2OSMSParser.java
==============================================================================
--- (empty file)
+++ trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/parser/S2OSMSParser.java Tue
Dec 2 09:16:27 2008
@@ -0,0 +1,138 @@
+package pt.citar.diablu.sms2osc.parser;
+
+import de.sciss.net.OSCMessage;
+import java.util.HashMap;
+import java.util.StringTokenizer;
+import pt.citar.diablu.sms2osc.S2O;
+
+public class S2OSMSParser {
+
+ S2O s2o;
+ boolean active;
+ HashMap<String, String> commands;
+
+ public S2OSMSParser(S2O s2o, boolean active) {
+
+ this.s2o = s2o;
+ this.active = active;
+ this.commands = new HashMap<String, String>();
+
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void getCommands(String commandString) {
+ StringTokenizer st = new StringTokenizer(commandString, ";");
+ String command;
+ while (st.hasMoreTokens()) {
+ command = st.nextToken();
+
System.out.println(s2o.getProperties().getCommandString(command));
+ commands.put(command,
s2o.getProperties().getCommandString(command));
+ }
+ }
+
+ public void parse(String msg) {
+ StringTokenizer st = new StringTokenizer(msg, "\n ");
+ String command = st.nextToken();
+
+ if (commands.containsKey(command)) {
+ String value = commands.get(command);
+ Object[] arguments = new Object[value.length()];
+ char c;
+ float f;
+ String s;
+ boolean first;
+
+ if (value.length() == 0) {
+ if (!st.hasMoreTokens()) {
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/" + command));
+ } else {
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/commandError1", new Object[]{msg}));
+ }
+ } else {
+ for (int i = 0; i < value.length(); i++) {
+ System.out.println("lsls");
+ if (st.hasMoreTokens()) {
+ c = value.charAt(i);
+ switch (c) {
+ case 'i': {
+ try {
+ arguments[i] =
Integer.parseInt(st.nextToken());
+ System.out.println(arguments[i]);
+ break;
+ } catch (NumberFormatException ex) {
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/commandError2", new Object[]{msg}));
+ return;
+ }
+ }
+ case 'f': {
+ try {
+ StringTokenizer floatSt = new
StringTokenizer(st.nextToken(), ".,");
+ if (floatSt.countTokens() == 2) {
+ f =
Integer.parseInt(floatSt.nextToken());
+ String decimal =
floatSt.nextToken();
+ f += Integer.parseInt(decimal) /
(Math.pow(10.0, decimal.length()));
+ arguments[i] = f;
+ System.out.println(arguments[i]);
+ break;
+ }
+ } catch (NumberFormatException ex) {
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/commandError3", new Object[]{msg}));
+ return;
+ }
+ }
+ case 'w': {
+ if (st.hasMoreTokens()) {
+ arguments[i] = st.nextToken();
+ System.out.println(arguments[i]);
+ break;
+ } else {
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/commandError4", new Object[]{msg}));
+ return;
+ }
+ }
+ case 's': {
+ s = "";
+ first = true;
+ while (st.hasMoreElements()) {
+ if (first) {
+ s = st.nextToken();
+ first = false;
+ } else {
+ s = s + " " + st.nextToken();
+ }
+ }
+ arguments[i] = s;
+ System.out.println(arguments[i]);
+ break;
+ }
+ case 'c': {
+ if (st.hasMoreElements()) {
+ s = st.nextToken();
+ if (s.length() == 1) {
+ String l = "" + s.charAt(0);
+ arguments[i] = l;
+ System.out.println(arguments[i]);
+ break;
+ } else {
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/commandError5", new Object[]{msg}));
+ return;
+ }
+ } else {
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/commandError", new Object[]{msg}));
+ return;
+ }
+ }
+ }
+ }
+ }
+ s2o.getOscClient().send(new OSCMessage("/diablu/sms2osc/"
+ command, arguments));
+ }
+ } else {
+ System.out.println("Command does not exist: " + command);
+ s2o.getOscClient().send(new
OSCMessage("/diablu/sms2osc/commandNotFounf", new Object[] {command, msg}));
+ }
+ }
+}

Modified: trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/util/S2OProperties.java
==============================================================================
--- trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/util/S2OProperties.java
(original)
+++ trunk/SMS2OSC/src/pt/citar/diablu/sms2osc/util/S2OProperties.java Tue
Dec 2 09:16:27 2008
@@ -81,10 +81,33 @@
return properties.getProperty("ComPort",
s2o.getCommPortList().getFirst());
}

- public String getUseLoopback()
+ public boolean useLoopback()
{
- return properties.getProperty("UseLoopback", "true");
+
if(properties.getProperty("UseLoopback", "false").compareToIgnoreCase("true")
== 1)
+ return true;
+ return false;
}
+
+ public boolean useParser()
+ {
+
if(properties.getProperty("UseParser", "false").compareToIgnoreCase("true")
== 0)
+ return true;
+ return false;
+ }
+
+ public String getCommands()
+ {
+ return properties.getProperty("Commands", "");
+ }
+
+ public String getCommandString(String command)
+ {
+ return properties.getProperty(command, "");
+ }
+
+
+
+

}

Reply all
Reply to author
Forward
0 new messages