[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/shockfish/tools/java_tc65/src/com/shockfish/tinyos/tools
Tc65Listen.java, NONE, 1.1 tc65listen.jad, NONE,
1.1 MamaBoardManager.java, 1.1, 1.2 Tc65Manager.java, 1.1, 1.2
rogmeier
rogmeier at users.sourceforge.net
Mon Sep 11 06:40:07 PDT 2006
- Previous message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/shockfish/tools/java_tc65/src/com/shockfish/tinyos/packet
CldcNetworkByteSource.java, 1.1, 1.2 CldcPacketizer.java, 1.1, 1.2
- Next message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/shockfish/tools/java_tc65/src/com/shockfish/tinyos/apps/demo
Makefile, NONE, 1.1 OscopeDataCaptureThread.java, NONE,
1.1 MamaBoardDemo.java, 1.1, 1.2 MamaBoardDemoManager.java, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/contrib/shockfish/tools/java_tc65/src/com/shockfish/tinyos/tools
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28926/src/com/shockfish/tinyos/tools
Modified Files:
MamaBoardManager.java Tc65Manager.java
Added Files:
Tc65Listen.java tc65listen.jad
Log Message:
TC65/TinyNode foundations.
--- NEW FILE: Tc65Listen.java ---
package com.shockfish.tinyos.tools;
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.io.*;
import com.siemens.icm.io.*;
import net.tinyos.message.Dump;
import net.tinyos.util.PrintStreamMessenger;
import com.shockfish.tinyos.packet.Tc65SerialByteSource;
import com.shockfish.tinyos.packet.CldcPacketizer;
public class Tc65Listen extends MIDlet {
CommConnection commConn;
InputStream inStream;
OutputStream outStream;
public Tc65Listen() {
System.out.println("Shockfish GPRS module");
System.out.println("Available COM Ports: " + System.getProperty("microedition.commports"));
}
public void startApp() throws MIDletStateChangeException {
try {
Tc65SerialByteSource tsb = new Tc65SerialByteSource("TinyNodeLight", 0);
CldcPacketizer reader = new CldcPacketizer("TinyNodeLight",tsb, 0);
reader.open(PrintStreamMessenger.err);
int packetCnt = 0;
for (;;) {
byte[] packet = reader.readPacket();
System.out.println("Received packets :"+packetCnt++);
Dump.printPacket(System.out, packet);
}
} catch(IOException e) {
System.out.println(e);
}
System.out.println();
destroyApp(true);
}
/**
* pauseApp()
*/
public void pauseApp() {
System.out.println("pauseApp()");
}
/**
* destroyApp()
*
* This is important. It closes the app's RecordStore
* @param cond true if this is an unconditional destroy
* false if it is not
* currently ignored and treated as true
*/
public void destroyApp(boolean cond) {
System.out.println("-- destroyApp(" + cond + ")");
try {
inStream.close();
outStream.close();
commConn.close();
System.out.println("Streams and connection closed");
} catch(IOException e) {
System.out.println(e);
}
notifyDestroyed();
}
}
--- NEW FILE: tc65listen.jad ---
MIDlet-Name: Tc65Listen
MIDlet-Version: 1.0
MIDlet-Vendor: Shockfish SA
MIDlet-Description: TODO
MicroEdition-Profile: IMP-NG
MicroEdition-Configuration: CLDC-1.1
MIDlet-1: TinyListen, , com.shockfish.tinyos.tools.Tc65Listen
MIDlet-Jar-URL: http://www2.shockfish.com/TODO
MIDlet-Jar-Size: 2307
Index: MamaBoardManager.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/shockfish/tools/java_tc65/src/com/shockfish/tinyos/tools/MamaBoardManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MamaBoardManager.java 25 May 2006 19:09:37 -0000 1.1
--- MamaBoardManager.java 11 Sep 2006 13:40:03 -0000 1.2
***************
*** 1,3 ****
--- 1,8 ----
package com.shockfish.tinyos.tools;
+ import com.shockfish.tinyos.packet.CldcPacketizer;
+ import com.shockfish.tinyos.bridge.CldcBridgeThread;
+ import com.shockfish.tinyos.bridge.CldcBridgeMasterThread;
+ import com.shockfish.tinyos.util.ToolBox;
+ import com.shockfish.tinyos.packet.Tc65SerialByteSource;
public abstract class MamaBoardManager extends Tc65Manager {
***************
*** 6,22 ****
public static final int MAMABOARD_GPIO_LED = 0;
! public static final int MAMABOARD_GPIO_RESET = 3;
public MamaBoardManager() {
super();
! init();
}
! private void init() {
// open driver
sendAT("at^spio=1", "OK");
sendAT("at^scpin=1," + MAMABOARD_GPIO_LED + ",1,0", "OK");
! sendAT("at^scpin=1," + MAMABOARD_GPIO_RESET + ",1,0", "OK");
// turn the led off
setPinOut(MAMABOARD_GPIO_LED, 0);
--- 11,38 ----
public static final int MAMABOARD_GPIO_LED = 0;
! public static final int MAMABOARD_GPIO_NRESET = 3;
+
+ public static CldcPacketizer serialAsc0Packetizer;
+ public static Tc65SerialByteSource serialAsc0ByteSource;
+
+
+ public abstract void enterBridgeMode();
+ public abstract void leaveBridgeMode();
+
+ private CldcBridgeMasterThread bridge;
+
public MamaBoardManager() {
super();
! initGpio();
! initSerialAsc0Packetizer();
}
! private void initGpio() {
// open driver
sendAT("at^spio=1", "OK");
sendAT("at^scpin=1," + MAMABOARD_GPIO_LED + ",1,0", "OK");
! sendAT("at^scpin=1," + MAMABOARD_GPIO_NRESET + ",1,0", "OK");
// turn the led off
setPinOut(MAMABOARD_GPIO_LED, 0);
***************
*** 46,51 ****
public void resetTinyNode() {
! setPinOut(MAMABOARD_GPIO_RESET, 1);
}
}
--- 62,136 ----
public void resetTinyNode() {
! setPinOut(MAMABOARD_GPIO_NRESET, 0);
! try {
! Thread.sleep(400);
! } catch (InterruptedException ie) {}
! setPinOut(MAMABOARD_GPIO_NRESET, 1);
}
+ private void initSerialAsc0Packetizer() {
+ this.serialAsc0ByteSource = new Tc65SerialByteSource("SERIAL", 0);
+ this.serialAsc0Packetizer = new CldcPacketizer("SERIAL",this.serialAsc0ByteSource, 0); // 0 is tinynode
+ }
+
+ protected void defaultCommandHandler(String command, String args) {
+ if (command.startsWith("SET")) {
+ String prop = command.substring(3);
+ setProp(prop, args);
+ return;
+ }
+
+ if (command.equals("RESETMODULE")) {
+ resetModule();
+ return;
+ }
+
+ if (command.equals("RESETBASESTATION")) {
+ resetTinyNode();
+ return;
+ }
+
+ if (command.equals("STARTBRIDGE")) {
+ int port;
+ String[] hostport = ToolBox.split(args,';');
+ if (hostport == null) {
+ return;
+ }
+ try {
+ port = Integer.parseInt(hostport[1]);
+ } catch (NumberFormatException nfe) {
+ return;
+ }
+ startBridge(hostport[0], port);
+ return;
+ }
+
+ if (command.equals("STOPBRIDGE")) {
+ stopBridge();
+ return;
+ }
+
+ if (command.equals("SENDSTATUSSMS")) {
+ sendSms(args, getTc65Status());
+ return;
+ }
+ }
+
+ public void startBridge(String host, int port) {
+ // beware : the node needs to be restarted after this operation.
+
+ // if the bridge object exists, check if it is running!
+ // TODO
+
+ enterBridgeMode();
+ bridge = new CldcBridgeMasterThread(this, host, port);
+ bridge.start();
+ }
+
+ public void stopBridge() {
+ if (bridge == null)
+ return;
+ bridge.requestStop();
+ }
+
}
Index: Tc65Manager.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/shockfish/tools/java_tc65/src/com/shockfish/tinyos/tools/Tc65Manager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Tc65Manager.java 25 May 2006 19:04:53 -0000 1.1
--- Tc65Manager.java 11 Sep 2006 13:40:03 -0000 1.2
***************
*** 7,10 ****
--- 7,11 ----
import com.siemens.icm.io.*;
import java.io.*;
+
import com.siemens.icm.io.file.*;
import java.util.Enumeration;
***************
*** 24,28 ****
// TC65-related
- private final static int MT_CAPACITY = 30;
private final static String FILE_CONN_FLASH_FS = "file:///a:/";
--- 25,28 ----
***************
*** 39,46 ****
private final static String OTAP_NL = "\n";
- private final static String OTAP_SECRET = "tc";
-
// Config-related
! private final static String FACTORY_GPRS_OPTS = ";bearer_type=gprs;access_point=internet;dns=213.055.128.001;timeout=40000";
// informe if the timer of the module has been synchronized correctly
--- 39,46 ----
private final static String OTAP_NL = "\n";
// Config-related
! private final static String FACTORY_GPRS_OPTS =
! ";bearer_type=gprs;access_point=internet;"
! + "dns=213.055.128.001;timeout=40";
// informe if the timer of the module has been synchronized correctly
***************
*** 52,55 ****
--- 52,58 ----
private static long offsetCalendar;
+ // time at which the app has been started up, used to maintain the uptime.
+ private static long startTime = 0;
+
private Hashtable propertiesTable;
***************
*** 57,60 ****
--- 60,65 ----
public Tc65Manager() {
+ startTime = System.currentTimeMillis();
+
try {
ata = new ATCommand(false);
***************
*** 68,88 ****
}
- public boolean setDate(Date date) {
- offsetCalendar = date.getTime() - System.currentTimeMillis();
- calendar.setTime(date);
- //TODO improve if possible this mechanism
- return sendAT("at+CCLK=\"" + FormatDate.GetATCCLKformat(date) + "\"",
- "OK");
- }
-
public static Date getDate() {
- //Date date=new Date(System.currentTimeMillis()+offsetCalendar);
return new Date(System.currentTimeMillis() + offsetCalendar);
}
public static long getTime() {
return System.currentTimeMillis() + offsetCalendar;
}
public boolean pinCode(int password) {
return sendAT("at+cpin=" + password, "OK");
--- 73,98 ----
}
public static Date getDate() {
return new Date(System.currentTimeMillis() + offsetCalendar);
}
+ public static long getUptime() {
+ return System.currentTimeMillis() - startTime;
+ }
+
public static long getTime() {
return System.currentTimeMillis() + offsetCalendar;
}
+ private static long lastDateUpdate;
+
+ private static long derivationAveragePerHour = 0;
+
+ private final static long ONE_HOUR_IN_MILLI_SEC = 1000 * 60 * 60;
+
+ public void setOffsetCalendar(long off) {
+ this.offsetCalendar = off;
+ }
+
public boolean pinCode(int password) {
return sendAT("at+cpin=" + password, "OK");
***************
*** 95,127 ****
}
- public boolean ATCommandOTAP(String sms_pwd, String jad_URL,
- String appl_Dir, String http_user, String http_Pwd, String bs,
- String dest, String net_user, String net_pwd, String dns,
- String notifyURL) {
- return sendAT("AT^SJOTAP=\"" + sms_pwd + "\",\"" + jad_URL + "\",\""
- + appl_Dir + "\",\"" + http_user + "\",\"" + http_Pwd + "\",\""
- + bs + "\",\"" + dest + "\",\"" + net_user + "\",\"" + net_pwd
- + "\",\"" + dns + "\",\"" + notifyURL + "\"", "OK");
- }
-
- public boolean ATCommandOTAP() {
- String sms_pwd = "tc";
- String jad_URL = "http://myurl";
- String appl_Dir = "a:/apps";
- String http_user = "";
- String http_Pwd = "";
- String bs = "gprs";
- String dest = "gprs.swisscom.ch";
- String net_user = "";
- String net_pwd = "";
- String dns = "164.128.36.34";
- String notifyURL = "";
- return sendAT("AT^SJOTAP=\"" + sms_pwd + "\",\"" + jad_URL + "\",\""
- + appl_Dir + "\",\"" + http_user + "\",\"" + http_Pwd + "\",\""
- + bs + "\",\"" + dest + "\",\"" + net_user + "\",\"" + net_pwd
- + "\",\"" + dns + "\",\"" + notifyURL + "\"", "OK");
-
- }
-
public void setSyncedTime() {
synced_Time = true;
--- 105,108 ----
***************
*** 141,145 ****
public String getGprsConf() {
! String conf = readProp("GRPSCONF");
if (conf == null) {
conf = FACTORY_GPRS_OPTS;
--- 122,126 ----
public String getGprsConf() {
! String conf = readProp("GPRSCONF");
if (conf == null) {
conf = FACTORY_GPRS_OPTS;
***************
*** 182,186 ****
propertiesTable.put(prop, val);
CldcLogger.info("property (" + prop + "|" + val
! + ") charged in ram memory.");
} else {
CldcLogger.warning("property \"" + prop + "\" is not set.");
--- 163,167 ----
propertiesTable.put(prop, val);
CldcLogger.info("property (" + prop + "|" + val
! + ") loaded.");
} else {
CldcLogger.warning("property \"" + prop + "\" is not set.");
***************
*** 212,222 ****
ioe.printStackTrace();
}
! // and change it in the properties table
if (propertiesTable.containsKey(prop)) {
! // no need to do propretiesTable.remove(prop); because put will replace
! // the value if the key already exist.
! CldcLogger.info("Replace property (" + prop + "=" + val + ")");
} else {
! CldcLogger.info("Set new property (" + prop + "=" + val + ")");
}
propertiesTable.put(prop, val);
--- 193,201 ----
ioe.printStackTrace();
}
!
if (propertiesTable.containsKey(prop)) {
! CldcLogger.info("Replace property (" + prop + "|" + val + ")");
} else {
! CldcLogger.info("Set new property (" + prop + "|" + val + ")");
}
propertiesTable.put(prop, val);
***************
*** 232,240 ****
// received SMS should go to MT memory, set preferred storage
sendAT("AT+CPMS=\"MT\"", "OK");
! // delete all msg, TODO : this is best-effort!
! for (int i = 1; i <= MT_CAPACITY; i++) {
! String atcom = "AT+CMGD=" + i;
! sendAT(atcom, "OK");
}
// init for SMS URC
// AT+CNMI=[<mode>][, <mt>][, <bm>][, <ds>][, <bfr>]
--- 211,220 ----
// received SMS should go to MT memory, set preferred storage
sendAT("AT+CPMS=\"MT\"", "OK");
!
! int i = 1;
! while (sendAT("AT+CMGD=" + i, "OK")) {
! i++;
}
+
// init for SMS URC
// AT+CNMI=[<mode>][, <mt>][, <bm>][, <ds>][, <bfr>]
***************
*** 260,263 ****
--- 240,247 ----
}
+ public boolean pubSendAT(String command, String expect) {
+ return sendAT(command, expect);
+ }
+
protected String getAT(String command, String expect) {
try {
***************
*** 281,285 ****
public String getTc65Status() {
! return "\nFreemem=" + (Runtime.getRuntime()).freeMemory()
+ "\nFreeflash=" + getFreeFlashSpace();
}
--- 265,270 ----
public String getTc65Status() {
! return "\nSerial=" + getDeviceSerial()
! + "\nFreemem=" + (Runtime.getRuntime()).freeMemory()
+ "\nFreeflash=" + getFreeFlashSpace();
}
***************
*** 321,333 ****
/*
! * when some AT event occures, like a sms reception, a call reception.
*/
public void ATEvent(String event) {
CldcLogger.devDebug(CldcLogger.SRC_1, "ATEvent()\tevent = \n" + event
+ "(end)");
- System.out.println("URC ->");
- System.out.println(event);
- System.out.println(event.length());
-
int idx;
idx = event.indexOf(URC_INCOMING_SMS);
--- 306,314 ----
/*
! * when some AT event occurs, like a sms reception, a call reception.
*/
public void ATEvent(String event) {
CldcLogger.devDebug(CldcLogger.SRC_1, "ATEvent()\tevent = \n" + event
+ "(end)");
int idx;
idx = event.indexOf(URC_INCOMING_SMS);
***************
*** 349,360 ****
}
! /**
! *
! * @param event
! * @param idx
! */
boolean once = false;
private void handleSms(String event, int idx) {
CldcLogger.devDebug(CldcLogger.SRC_1, "handleSms()\tevent = " + event
+ " idx = " + idx);
--- 330,341 ----
}
! public void resetModule() {
! sendAT("at+cfun=1,1", "OK");
! }
!
boolean once = false;
private void handleSms(String event, int idx) {
+ //sendAT("AT+CMGF=1", "OK");
CldcLogger.devDebug(CldcLogger.SRC_1, "handleSms()\tevent = " + event
+ " idx = " + idx);
***************
*** 379,383 ****
.GSM2Java(getAT("at+cmgr=" + smsId, "OK"));
! CldcLogger.devDebug(CldcLogger.SRC_1, "handleSms()\tmsg = " + msg);
// TODO : delete message
int otidx = msg.indexOf(OTAP_KEYWORD);
--- 360,367 ----
.GSM2Java(getAT("at+cmgr=" + smsId, "OK"));
! sendAT("AT+CMGD=" + smsId, "OK");
!
! CldcLogger.devDebug(CldcLogger.SRC_1, "handleSms()\tmsg = " + msg
! + " and already erased");
// TODO : delete message
int otidx = msg.indexOf(OTAP_KEYWORD);
***************
*** 394,398 ****
CldcLogger.devDebug(CldcLogger.SRC_1, "handleSms()\tsms pwd = <" + pass
+ ">");
! if (!pass.equals(OTAP_SECRET)) {
System.out.println("Incorrect PWD");
return;
--- 378,382 ----
CldcLogger.devDebug(CldcLogger.SRC_1, "handleSms()\tsms pwd = <" + pass
+ ">");
! if (!pass.equals(getSecret())) {
System.out.println("Incorrect PWD");
return;
***************
*** 401,410 ****
System.out.println("CMD:" + getOtapPropValue(OTAP_COMMAND, msg));
System.out.println("ARGS:" + getOtapPropValue(OTAP_ARGS, msg));
! OtapCommandCalled(getOtapPropValue(OTAP_COMMAND, msg),
! getOtapPropValue(OTAP_ARGS, msg));
}
! abstract protected void OtapCommandCalled(String command, String args);
private String getOtapPropValue(String propName, String msg) {
--- 385,404 ----
System.out.println("CMD:" + getOtapPropValue(OTAP_COMMAND, msg));
System.out.println("ARGS:" + getOtapPropValue(OTAP_ARGS, msg));
!
! boolean handled = customCommandHandler(getOtapPropValue(OTAP_COMMAND,
! msg), getOtapPropValue(OTAP_ARGS, msg));
!
! if (!handled) {
! defaultCommandHandler(getOtapPropValue(OTAP_COMMAND, msg),
! getOtapPropValue(OTAP_ARGS, msg));
! }
}
! protected abstract boolean customCommandHandler(String command, String args);
!
! protected abstract void defaultCommandHandler(String command, String args);
!
! protected abstract String getSecret();
private String getOtapPropValue(String propName, String msg) {
***************
*** 428,430 ****
--- 422,425 ----
return msg.substring(idxa + token.length(), idxb);
}
+
}
\ No newline at end of file
- Previous message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/shockfish/tools/java_tc65/src/com/shockfish/tinyos/packet
CldcNetworkByteSource.java, 1.1, 1.2 CldcPacketizer.java, 1.1, 1.2
- Next message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/shockfish/tools/java_tc65/src/com/shockfish/tinyos/apps/demo
Makefile, NONE, 1.1 OscopeDataCaptureThread.java, NONE,
1.1 MamaBoardDemo.java, 1.1, 1.2 MamaBoardDemoManager.java, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-contrib-commits
mailing list