[Firebug-cvs] firebug/project/java/src/org/firebug XBowLogger.java,NONE,1.1 ListenFB.java,1.20,1.21
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2004-07-01 19:33:17
|
Update of /cvsroot/firebug/firebug/project/java/src/org/firebug In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv326/src/org/firebug Modified Files: ListenFB.java Added Files: XBowLogger.java Log Message: Writing extract code for xbow type messages. --- NEW FILE: XBowLogger.java --- /** * * Handles the XBow data layout packages. * * * * typedef struct { uint16_t battery; uint16_t humidity; uint16_t temp; uint16_t cal_word1; //!< Pressure calibration word 1 uint16_t cal_word2; //!< Pressure calibration word 2 uint16_t cal_word3; //!< Pressure calibration word 3 uint16_t cal_word4; //!< Pressure calibration word 4 uint16_t intersematemp; uint16_t intersemapressure; uint16_t taosch0; uint16_t taosch1; uint16_t accel_x; } XSensorMTS400Data1; typedef struct { uint8_t hours; //Hours uint8_t minutes;//Minutes uint8_t Lat_deg;//Latitude degrees uint8_t Long_deg;//Longitude degrees uint32_t dec_sec;//Decimal seconds uint32_t Lat_dec_min;//Latitude decimal minutes uint32_t Long_dec_min;//Longitude decimal minutes uint8_t NSEWind;//NSEWind uint8_t Fixed; // as to whether the packet is valid(i.e. has the gps Fixed on to the sattelites). }XSensorMTS420GPSData; */ package org.firebug; import org.firebug.database.MysqlDBHandler; import java.io.*; import java.sql.*; import java.util.Random; import net.tinyos.message.*; public class XBowLogger implements ListenFB.PacketPrinter { private MysqlDBHandler dbh; // Move this into some test code later. private Random rand = new Random(); public XBowLogger (String dbname) { dbh = new MysqlDBHandler("localhost","3306","root","",dbname,true); } public void print(InputStream in) { } 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++) { String val = Integer.toHexString((int)packet[i]); if (val.length() == 1) { val = "0" + val; } System.out.print(val + " "); } System.out.println("\n"); } public void parse_packet_1(byte [] packet) { FireMsg fmsg = new FireMsg(packet,5); Connection conn = dbh.getConnection(); int mote_id = packet[7]; System.out.println("Mote id: " + packet[7]); int cnt = fmsg.get_cnt(); //int temp = (0x000000ff&packet[13]); int temp = packet[13]; temp = packet[14] << 8; System.out.println("temp: " + temp); float ftemp = (float)(-38.4) + (float)0.0098*(float)temp; System.out.println("ftemp: " + ftemp); float rel_hum = fmsg.get_rel_hum(); float baro_pres = fmsg.get_baro_pres(); float lux = fmsg.get_lux(); /** 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 updatequery = "UPDATE current " + "SET " //+ "time=" + time + ", " + "cnt=" + cnt + "," + "rel_hum=" + rel_hum + ", " + "baro_pres=" + baro_pres + ", " + "temp=" + temp + "," + "lux=" + lux + " WHERE mote_id=" + mote_id; String insertquery = "INSERT INTO cumulative VALUES (" + mote_id + ", " + "NULL," // NULL lets timestamp do its thing. //time + ", " + cnt + ", " + temp + ", " + rel_hum + ", " + baro_pres + ", " + lux + ")"; try { rs = stmt.executeQuery(insertquery); } catch (SQLException sqle) { System.out.println("Problem with insert statement: " + insertquery); sqle.printStackTrace(); } try { rs = stmt.executeQuery(updatequery); } catch (SQLException sqle) { System.out.println("Problem with update statement: " + updatequery); sqle.printStackTrace(); } stmt.close(); } catch (SQLException sqle) { System.out.println("Problem with statement"); sqle.printStackTrace(); } dbh.return_connection(conn); } public void parse_packet_2(byte [] packet) { } /** Put everything in print for now. */ public void print(byte [] packet) { // Ugh what a kludge. The GPS date/time format // is not compatible with java. The date/time // should probably be stored as a string in the // database, then converted whenever it needs to // be displayed. int time = (int)System.currentTimeMillis(); int packet_id = packet[6]; System.out.println("Packet ID: " + packet_id); if (packet_id == 1) { parse_packet_1(packet); } else { parse_packet_2(packet); } //System.out.println("mote_id: " + mote_id); //System.out.println("cnt: " + cnt); //System.out.println("temp: " + temp); /* if (get_packet_type(packet) != 1){ dbh.return_connection(conn); return; } */ //print_packet_raw(packet); // This needs to throw an exception. /* 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; } */ /* FIXME: Need to be able to return a url as well as a * description. */ //return result; } private static void test() { String database_name = "test"; XBowLogger fl = new XBowLogger(database_name); while (true) { TestXBowLogger.test(fl); 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(); } } /** The TestDBLogger class exists only to construct * example packets to be fed into the DBLogger class. */ class TestXBowLogger { /** "test" is the _only_public_method_ in this * class. */ public static boolean test(XBowLogger fl) { return false; } } Index: ListenFB.java =================================================================== RCS file: /cvsroot/firebug/firebug/project/java/src/org/firebug/ListenFB.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ListenFB.java 2 Apr 2004 17:53:04 -0000 1.20 --- ListenFB.java 1 Jul 2004 19:33:07 -0000 1.21 *************** *** 64,67 **** --- 64,69 ---- private RangeLogger rangelogger; private GPSLogger gpslogger; + private XBowLogger xbowlogger; + /** Use this interface when changing the output *************** *** 114,118 **** return gpslogger; } else { ! return null; } } --- 116,120 ---- return gpslogger; } else { ! return xbowlogger; } } *************** *** 201,205 **** */ int am_type = extract_am_type(packet); ! System.out.println("AM type number: " + am_type); PacketPrinter printer = GetPrinter(am_type); if (printer != null) { --- 203,207 ---- */ int am_type = extract_am_type(packet); ! //System.out.println("AM type number: " + am_type); PacketPrinter printer = GetPrinter(am_type); if (printer != null) { *************** *** 257,263 **** // Instantiating will allow processing statistics // at the base station level. ! listener.firelogger = new FireLogger(dbname); ! listener.rangelogger = new RangeLogger(dbname); ! listener.gpslogger = new GPSLogger(dbname); try { --- 259,268 ---- // Instantiating will allow processing statistics // at the base station level. ! ! //listener.firelogger = new FireLogger(dbname); ! //listener.rangelogger = new RangeLogger(dbname); ! //listener.gpslogger = new GPSLogger(dbname); ! ! listener.xbowlogger = new XBowLogger(dbname); try { |