[Firebug-cvs] firebug/project/java/src/org/firebug RangeLogger.java,NONE,1.1 RangeMsg.java,NONE,1.1
Brought to you by:
doolin
From: <do...@us...> - 2004-03-12 00:12:42
|
Update of /cvsroot/firebug/firebug/project/java/src/org/firebug In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30708/src/org/firebug Added Files: RangeLogger.java RangeMsg.java Log Message: Added Range message class for investigating rssi, voltage and packet counting. --- NEW FILE: RangeLogger.java --- package org.firebug; import org.firebug.database.MysqlDBHandler; import java.io.*; import java.sql.*; import java.util.Random; import net.tinyos.message.*; public class RangeLogger implements ListenFB.PacketPrinter { private MysqlDBHandler dbh; // Move this into some test code later. private Random rand = new Random(); public RangeLogger (String dbname) { dbh = new MysqlDBHandler("localhost","3306","root","",dbname,true); } public void print(InputStream in) { } /** All of the private methods for extracting * data from packets are deterministic, that is, * these methods should work on any random packet. */ /* private int getMoteID (byte [] packet) { int baseID=packet[5]; return baseID; //id; } */ private int get_packet_type(byte [] packet) { return (int)packet[2]; } public void print_packet_raw(byte [] packet) { for (int i = 0; i < packet.length; i++) { System.out.print(packet[i] + " "); } System.out.println("\n"); } /** Put everything in print for now. */ public void print(byte [] packet) { // Given a packet, we need to get a TOS // message. //System.out.println("dblogger.print(byte [] packet)\n"); // The following line gets an ArrayOutOfBounds exception: //SensorMsg msg = new SensorMsg(packet,5,19); RangeMsg msg = new RangeMsg(packet,5,RangeMsg.DEFAULT_MESSAGE_SIZE); int mote_id = msg.get_mote_id(); int rssi = msg.get_rssi(); int count = msg.get_count(); int raw_voltage = msg.get_voltage(); float voltage = (float)((1.223*1024)/raw_voltage); Connection conn = dbh.getConnection(); /* if (get_packet_type(packet) != 1){ dbh.return_connection(conn); return; } if ( get_packet_type(packet) == 1 && packet[7] == -1) { dbh.return_connection(conn); return; } //base station ID is 1; if (mote_id == 1) { dbh.return_connection(conn); return; } */ print_packet_raw(packet); /** FIXME: Ugly flow control using exception logic to * to track down a bbad statement, needs to be cleaned up. */ try { ResultSet rs; Statement stmt = conn.createStatement(); String range = "insert into range values(" + mote_id + ",NULL," + count + "," + rssi + "," + voltage + ")"; System.out.println(range); try { rs = stmt.executeQuery(range); } catch (SQLException sqle) { System.out.println("Problem with range statement: " + range); sqle.printStackTrace(); } stmt.close(); } catch (SQLException sqle) { System.out.println("Problem with statement"); sqle.printStackTrace(); } dbh.return_connection(conn); /* FIXME: Need to be able to return a url as well as a * description. */ //return result; } private static void test() { String database_name = "test"; RangeLogger dbl = new RangeLogger(database_name); /* while (true) { TestDBLogger.test(dbl); try { Thread.sleep(3000); } catch (Exception e) { System.out.println(e); } } */ // Unreachable /* if (TestDBLogger.test(dbl)) { System.out.println("Passed DBLogger test"); } else { System.out.println("Failed DBLogger test"); } */ } public static void main(String [] args) { test(); } } --- NEW FILE: RangeMsg.java --- /** * This class is automatically generated by mig. DO NOT EDIT THIS FILE. * This class implements a Java interface to the 'RangeMsg' * message type. */ package org.firebug; public class RangeMsg extends net.tinyos.message.Message { /** The default size of this message type in bytes. */ public static final int DEFAULT_MESSAGE_SIZE = 8; /** The Active Message type associated with this message. */ public static final int AM_TYPE = 129; /** Create a new RangeMsg of size 8. */ public RangeMsg() { super(DEFAULT_MESSAGE_SIZE); amTypeSet(AM_TYPE); } /** Create a new RangeMsg of the given data_length. */ public RangeMsg(int data_length) { super(data_length); amTypeSet(AM_TYPE); } /** * Create a new RangeMsg with the given data_length * and base offset. */ public RangeMsg(int data_length, int base_offset) { super(data_length, base_offset); amTypeSet(AM_TYPE); } /** * Create a new RangeMsg using the given byte array * as backing store. */ public RangeMsg(byte[] data) { super(data); amTypeSet(AM_TYPE); } /** * Create a new RangeMsg using the given byte array * as backing store, with the given base offset. */ public RangeMsg(byte[] data, int base_offset) { super(data, base_offset); amTypeSet(AM_TYPE); } /** * Create a new RangeMsg using the given byte array * as backing store, with the given base offset and data length. */ public RangeMsg(byte[] data, int base_offset, int data_length) { super(data, base_offset, data_length); amTypeSet(AM_TYPE); } /** * Create a new RangeMsg embedded in the given message * at the given base offset. */ public RangeMsg(net.tinyos.message.Message msg, int base_offset) { super(msg, base_offset, DEFAULT_MESSAGE_SIZE); amTypeSet(AM_TYPE); } /** * Create a new RangeMsg embedded in the given message * at the given base offset and length. */ public RangeMsg(net.tinyos.message.Message msg, int base_offset, int data_length) { super(msg, base_offset, data_length); amTypeSet(AM_TYPE); } /** /* Return a String representation of this message. Includes the * message type name and the non-indexed field values. */ public String toString() { String s = "Message <RangeMsg> \n"; try { s += " [mote_id=0x"+Long.toHexString(get_mote_id())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [count=0x"+Long.toHexString(get_count())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [rssi=0x"+Long.toHexString(get_rssi())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [voltage=0x"+Long.toHexString(get_voltage())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } return s; } // Message-type-specific access methods appear below. ///////////////////////////////////////////////////////// // Accessor methods for field: mote_id // Field type: int, unsigned // Offset (bits): 0 // Size (bits): 16 ///////////////////////////////////////////////////////// /** * Return whether the field 'mote_id' is signed (false). */ public static boolean isSigned_mote_id() { return false; } /** * Return whether the field 'mote_id' is an array (false). */ public static boolean isArray_mote_id() { return false; } /** * Return the offset (in bytes) of the field 'mote_id' */ public static int offset_mote_id() { return (0 / 8); } /** * Return the offset (in bits) of the field 'mote_id' */ public static int offsetBits_mote_id() { return 0; } /** * Return the value (as a int) of the field 'mote_id' */ public int get_mote_id() { return (int)getUIntElement(offsetBits_mote_id(), 16); } /** * Set the value of the field 'mote_id' */ public void set_mote_id(int value) { setUIntElement(offsetBits_mote_id(), 16, value); } /** * Return the size, in bytes, of the field 'mote_id' */ public static int size_mote_id() { return (16 / 8); } /** * Return the size, in bits, of the field 'mote_id' */ public static int sizeBits_mote_id() { return 16; } ///////////////////////////////////////////////////////// // Accessor methods for field: count // Field type: int, unsigned // Offset (bits): 16 // Size (bits): 16 ///////////////////////////////////////////////////////// /** * Return whether the field 'count' is signed (false). */ public static boolean isSigned_count() { return false; } /** * Return whether the field 'count' is an array (false). */ public static boolean isArray_count() { return false; } /** * Return the offset (in bytes) of the field 'count' */ public static int offset_count() { return (16 / 8); } /** * Return the offset (in bits) of the field 'count' */ public static int offsetBits_count() { return 16; } /** * Return the value (as a int) of the field 'count' */ public int get_count() { return (int)getUIntElement(offsetBits_count(), 16); } /** * Set the value of the field 'count' */ public void set_count(int value) { setUIntElement(offsetBits_count(), 16, value); } /** * Return the size, in bytes, of the field 'count' */ public static int size_count() { return (16 / 8); } /** * Return the size, in bits, of the field 'count' */ public static int sizeBits_count() { return 16; } ///////////////////////////////////////////////////////// // Accessor methods for field: rssi // Field type: int, unsigned // Offset (bits): 32 // Size (bits): 16 ///////////////////////////////////////////////////////// /** * Return whether the field 'rssi' is signed (false). */ public static boolean isSigned_rssi() { return false; } /** * Return whether the field 'rssi' is an array (false). */ public static boolean isArray_rssi() { return false; } /** * Return the offset (in bytes) of the field 'rssi' */ public static int offset_rssi() { return (32 / 8); } /** * Return the offset (in bits) of the field 'rssi' */ public static int offsetBits_rssi() { return 32; } /** * Return the value (as a int) of the field 'rssi' */ public int get_rssi() { return (int)getUIntElement(offsetBits_rssi(), 16); } /** * Set the value of the field 'rssi' */ public void set_rssi(int value) { setUIntElement(offsetBits_rssi(), 16, value); } /** * Return the size, in bytes, of the field 'rssi' */ public static int size_rssi() { return (16 / 8); } /** * Return the size, in bits, of the field 'rssi' */ public static int sizeBits_rssi() { return 16; } ///////////////////////////////////////////////////////// // Accessor methods for field: voltage // Field type: int, unsigned // Offset (bits): 48 // Size (bits): 16 ///////////////////////////////////////////////////////// /** * Return whether the field 'voltage' is signed (false). */ public static boolean isSigned_voltage() { return false; } /** * Return whether the field 'voltage' is an array (false). */ public static boolean isArray_voltage() { return false; } /** * Return the offset (in bytes) of the field 'voltage' */ public static int offset_voltage() { return (48 / 8); } /** * Return the offset (in bits) of the field 'voltage' */ public static int offsetBits_voltage() { return 48; } /** * Return the value (as a int) of the field 'voltage' */ public int get_voltage() { return (int)getUIntElement(offsetBits_voltage(), 16); } /** * Set the value of the field 'voltage' */ public void set_voltage(int value) { setUIntElement(offsetBits_voltage(), 16, value); } /** * Return the size, in bytes, of the field 'voltage' */ public static int size_voltage() { return (16 / 8); } /** * Return the size, in bits, of the field 'voltage' */ public static int sizeBits_voltage() { return 16; } } |