diff --git a/src/part2/examples/local/apps/monitor/mon_AP.c b/src/part2/examples/local/apps/monitor/mon_AP.c
index be2b97f..a4dde1d 100644
--- a/src/part2/examples/local/apps/monitor/mon_AP.c
+++ b/src/part2/examples/local/apps/monitor/mon_AP.c
@@ -31,6 +31,8 @@
#define HELP 0x01
void createRandomAddress(void);
+int getDelta(void);
+uint16_t getTime(void);
Radio_Rssi getRssi(void);
void mcuInit(void);
void printMessage(int addr, signed char rssi, char msg[MESSAGE_LENGTH]);
@@ -65,6 +67,7 @@
static uint8_t sPeerFrameSem;
static uint8_t sJoinSem;
static uint8_t sSelfMeasureSem;
+static uint16_t sTime = 0;
/* mode data */
char degCMode = 0; /* use deg F by default */
@@ -118,8 +121,9 @@
for (i = 0; i < 0xFFFF; i++){}
/* initialize the radio network */
+ getDelta();
Radio_start(sCB, &lAddr);
- System_printf("Network initialization done\n");
+ System_printf("Network initialization done (%d)\n", getDelta());
/* main work loop */
while (1) {
@@ -351,6 +355,7 @@
if (!degCMode) {
temp = (((float)temp) * 1.8) + 320;
+ format = "Node:%0.2d, Temp: %d.%dF, Battery: %d.%dV, Strength: %d\n";
}
t1 = temp / 10;
@@ -359,10 +364,7 @@
t2 = -1 * t2;
}
- if (!degCMode) {
- format = "Node:%0.2d, Temp: %d.%dF, Battery: %d.%dV, Strength: %d\n";
- }
-
+ System_printf("time: 0x%x\n", getTime());
System_printf(format, node, t1, t2, volt / 10, volt % 10, rssi_pct);
}
@@ -376,11 +378,54 @@
BCSCTL3 |= LFXT1S_2; /* LFXT1 = VLO */
TBCCTL0 = CCIE; /* Timer_B interrupt enabled */
- TBCCR0 = 12000; /* ~1 second */
+ TBCCR0 = 12000; /* ~1 second @ 8 MHz */
TBCTL = TASSEL_1 + MC_1; /* ACLK, upmode */
}
/*
+ * ======== getTime ========
+ */
+uint16_t getTime(void)
+{
+ uint16_t time;
+
+ int intState = Gate_enterSystem();
+
+ time = TBR;
+ if (time == 0 && (TBCCTL0 & CCIFG)) {
+ time += (sTime + 1) * 12001;
+ }
+ else {
+ time += sTime * 12001;
+ }
+
+ Gate_leaveSystem(intState);
+
+ return (time);
+}
+
+/*
+ * ======== getDelta ========
+ */
+int getDelta(void)
+{
+ static int t0 = 0;
+ int t1, delta;
+
+ t1 = TBR; /* read the current timer counter */
+
+ if (t0 <= t1) {
+ delta = t1 - t0;
+ }
+ else {
+ delta = 12001 - (t1 - t0); /* handle wrap situation */
+ }
+ t0 = t1;
+
+ return (delta);
+}
+
+/*
* ======== getRssi ========
* Compute a measure of the signal strength on the current channel. This
* gives a measure of interference from other wireless devices and can be
@@ -469,6 +514,7 @@
__interrupt void TIMER_B0_ISR (void)
{
sSelfMeasureSem = 1;
+ sTime++;
}
/*