milliseconds -> microseconds update

This commit is contained in:
fros4943 2009-05-26 14:31:07 +00:00
parent 62db437c2d
commit c59fc91487
4 changed files with 22 additions and 19 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MicaClock.java,v 1.2 2009/03/11 14:12:19 fros4943 Exp $
* $Id: MicaClock.java,v 1.3 2009/05/26 14:35:52 fros4943 Exp $
*/
package se.sics.cooja.avrmote.interfaces;
@ -63,12 +63,12 @@ public class MicaClock extends Clock {
return time > 0 ? time : 0;
}
public void setDrift(int drift) {
myMote.cycleDrift = MicaZMote.NR_CYCLES_PER_MSEC * drift;
public void setDrift(long drift) {
myMote.cycleDrift = Simulation.MILLISECOND * MicaZMote.NR_CYCLES_PER_MSEC * drift;
}
public int getDrift() {
return (int) (myMote.cycleDrift / MicaZMote.NR_CYCLES_PER_MSEC);
public long getDrift() {
return (long) ((double)myMote.cycleDrift / MicaZMote.NR_CYCLES_PER_MSEC / Simulation.MILLISECOND);
}
public JPanel getInterfaceVisualizer() {

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MspClock.java,v 1.8 2009/03/09 17:14:35 fros4943 Exp $
* $Id: MspClock.java,v 1.9 2009/05/26 14:31:07 fros4943 Exp $
*/
package se.sics.cooja.mspmote.interfaces;
@ -61,16 +61,16 @@ public class MspClock extends Clock {
}
public long getTime() {
int time = (int) ((cpu.cycles + myMote.cycleDrift) / MspMote.NR_CYCLES_PER_MSEC);
long time = (long) ((double)cpu.cycles * Simulation.MILLISECOND / MspMote.NR_CYCLES_PER_MSEC);
return time > 0 ? time : 0;
}
public void setDrift(int drift) {
myMote.cycleDrift = MspMote.NR_CYCLES_PER_MSEC * drift;
public void setDrift(long drift) {
myMote.usDrift = drift;
}
public int getDrift() {
return (int) (myMote.cycleDrift / MspMote.NR_CYCLES_PER_MSEC);
public long getDrift() {
return myMote.usDrift;
}
public JPanel getInterfaceVisualizer() {

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MspMoteID.java,v 1.11 2009/03/09 16:05:11 fros4943 Exp $
* $Id: MspMoteID.java,v 1.12 2009/05/26 14:31:07 fros4943 Exp $
*/
package se.sics.cooja.mspmote.interfaces;
@ -41,6 +41,7 @@ import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.Mote;
import se.sics.cooja.Simulation;
import se.sics.cooja.TimeEvent;
import se.sics.cooja.interfaces.MoteID;
import se.sics.cooja.mspmote.MspMote;
@ -118,7 +119,7 @@ public class MspMoteID extends MoteID {
/*logger.debug("ID location: " + location);*/
if (PERSISTENT_SET_ID) {
mote.getSimulation().scheduleEvent(persistentSetIDEvent, mote.getSimulation().getSimulationTime()+1);
mote.getSimulation().scheduleEvent(persistentSetIDEvent, mote.getSimulation().getSimulationTime());
}
}
@ -128,12 +129,13 @@ public class MspMoteID extends MoteID {
if (persistentSetIDCounter-- > 0)
{
setMoteID(moteID);
/*logger.debug("Persistent set ID: " + moteID);*/
/*logger.info("Setting ID: " + moteID + " at " + t);*/
if (t < -mote.getInterfaces().getClock().getDrift()) {
if (t + mote.getInterfaces().getClock().getDrift() < 0) {
/* Wait until node is booting */
mote.getSimulation().scheduleEvent(this, -mote.getInterfaces().getClock().getDrift());
} else {
mote.getSimulation().scheduleEvent(this, t+1);
mote.getSimulation().scheduleEvent(this, t+Simulation.MILLISECOND);
}
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: SkySerial.java,v 1.14 2009/03/09 17:14:35 fros4943 Exp $
* $Id: SkySerial.java,v 1.15 2009/05/26 14:31:07 fros4943 Exp $
*/
package se.sics.cooja.mspmote.interfaces;
@ -56,6 +56,8 @@ import se.sics.cooja.plugins.SLIP;
*/
@ClassDescription("Serial port")
public class SkySerial extends Log implements SerialPort, USARTListener {
private static final long DELAY_INCOMING_DATA = 69; /* Corresponds to 115200 bit/s */
private static Logger logger = Logger.getLogger(SkySerial.class);
private SkyMote mote;
@ -104,7 +106,6 @@ public class SkySerial extends Log implements SerialPort, USARTListener {
public void writeByte(byte b) {
incomingData.add(b);
tryWriteNextByte();
mote.getSimulation().scheduleEvent(writeDataEvent, mote.getSimulation().getSimulationTime());
}
@ -157,7 +158,7 @@ public class SkySerial extends Log implements SerialPort, USARTListener {
public void execute(long t) {
tryWriteNextByte();
if (!incomingData.isEmpty()) {
mote.getSimulation().scheduleEvent(this, t+1);
mote.getSimulation().scheduleEvent(this, t+DELAY_INCOMING_DATA);
}
}
};