00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package sensix;
00036
00037
00038 public class SenseUtil
00039 {
00040 public static String capabilityToString(byte capability) {
00041 switch (capability) {
00042 case Sensix.LIGHT:
00043 return "Light";
00044 case Sensix.TEMP:
00045 return "Temperature";
00046 case Sensix.ACCEL:
00047 return "Accelerometer";
00048 case Sensix.MAG:
00049 return "Magnetometer";
00050 case Sensix.MIC:
00051 return "Microphone";
00052 case Sensix.HUMID:
00053 return "Humidity";
00054 case Sensix.PRESS:
00055 return "Pressure";
00056 case Sensix.GPS:
00057 return "GPS";
00058 case Sensix.BATTERY:
00059 return "Battery";
00060 }
00061 return "Unknown";
00062 }
00063
00064 public static boolean isIntegerData(char discrim) {
00065 switch (discrim) {
00066 case 'd':
00067 case 'i':
00068 case 'u':
00069 case 'x':
00070 return true;
00071 default:
00072 return false;
00073 }
00074 }
00075
00076 public static boolean isFloatingPointData(char discrim) {
00077 switch (discrim) {
00078 case 'f':
00079 case 'e':
00080 case 'g':
00081 case 'a':
00082 return true;
00083 default:
00084 return false;
00085 }
00086 }
00087
00088
00089 public static void appUsage(String appname, String jarname) {
00090 System.err.println(appname + " usage: java -jar " + jarname +
00091 " [--level h_level] [--id node_id] " +
00092 "[--sim host] <-debug> <-info> <-help>");
00093 System.err.println(" where:");
00094 System.err.println(" 'h_level' (required) represents " +
00095 "this node's position in the network hierarchy " +
00096 "in [0 - 255]");
00097 System.err.println(" node_id (required) is a unique " +
00098 "unsigned integer identifier for this node " +
00099 "in [0 - 4294967295]");
00100 System.err.println(" host (optional) specifies the sim forwarder");
00101 System.err.println(" debug increases the verbosity of output");
00102 System.err.println(" info slightly increases the output");
00103 System.err.println(" help produces this output and exits");
00104 }
00105
00106
00108
00109
00110 public int service_port, id;
00111 public boolean simulate;
00112 public String simulator;
00113 public byte level, debug_level;
00114
00115 public SenseUtil(String appname, String jarname, String args[]) {
00116 boolean level_set = false;
00117 boolean id_set = false;
00118 String[] temp_args = new String[args.length];
00119
00120 service_port = 0;
00121 level = 0;
00122 id = 0;
00123 debug_level = 0;
00124
00125 for (int i = 0, j = 0; i < args.length; i++) {
00126 String argument = args[i];
00127 int idx = args[i].lastIndexOf("-");
00128 if (idx > 0 && idx < 2)
00129 argument = args[i].substring(idx);
00130
00131 if (argument.equalsIgnoreCase("debug"))
00132 debug_level = 2;
00133 else if (argument.equalsIgnoreCase("info"))
00134 debug_level = 1;
00135 else if (argument.equalsIgnoreCase("level")) {
00136 i++;
00137 if (i < args.length) {
00138 try {
00139 level = (new Integer(args[i])).byteValue();
00140 level_set = true;
00141 } catch (NumberFormatException e) {
00142 System.err.println(appname + ": Bad level argument: " +
00143 args[i]);
00144 level_set = false;
00145 }
00146 }
00147 }
00148 else if (argument.equalsIgnoreCase("sim")) {
00149 i++;
00150 if (i < args.length) {
00151 simulator = args[i];
00152 simulate = true;
00153 }
00154 }
00155 else if (argument.equalsIgnoreCase("id")) {
00156 i++;
00157 if (i < args.length) {
00158 try {
00159 id = Integer.parseInt(args[i]);
00160 id_set = true;
00161 } catch (NumberFormatException e) {
00162 System.err.println(appname + ": Bad id argument: " +
00163 args[i]);
00164 id_set = false;
00165 }
00166 }
00167 }
00168 else if (argument.equalsIgnoreCase("help")) {
00169 appUsage(appname, jarname);
00170 System.exit(0);
00171 }
00172 }
00173 if (level_set == false || id_set == false) {
00174 appUsage(appname, jarname);
00175 System.exit(1);
00176 }
00177 }
00178 }