Refactored the example to broadcast a message to the zoul-demo example

This commit is contained in:
Antonio Lignan 2015-12-22 15:16:55 +01:00
parent 5e14c22c98
commit 36ddb737e1
5 changed files with 39 additions and 19 deletions

View File

@ -1,5 +1,5 @@
DEFINES+=PROJECT_CONF_H=\"project-conf.h\" DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = zoul-demo test-tsl2563 test-sht25 test-pwm CONTIKI_PROJECT = zoul-demo test-tsl2563 test-sht25 test-pwm test-power-mgmt
CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c
all: $(CONTIKI_PROJECT) all: $(CONTIKI_PROJECT)

View File

@ -1,8 +0,0 @@
CONTIKI_PROJECT = test-power-mgmt
TARGET = zoul
all: $(CONTIKI_PROJECT)
CONTIKI = ../../../..
include $(CONTIKI)/Makefile.include

View File

@ -38,7 +38,7 @@
#ifndef PROJECT_CONF_H_ #ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_ #define PROJECT_CONF_H_
#define NETSTACK_CONF_RDC nullrdc_driver #define BROADCAST_CHANNEL 129
#endif /* PROJECT_CONF_H_ */ #endif /* PROJECT_CONF_H_ */

View File

@ -29,11 +29,9 @@
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* \addtogroup remote-examples * \addtogroup remote-power-management-test
* @{ * @{
* *
* \defgroup remote-power-management-test RE-Mote power management example
*
* Test the RE-Mote's power management features, shutdown mode and battery * Test the RE-Mote's power management features, shutdown mode and battery
* management * management
* *
@ -53,6 +51,8 @@
#include "dev/gpio.h" #include "dev/gpio.h"
#include "lib/list.h" #include "lib/list.h"
#include "power-mgmt.h" #include "power-mgmt.h"
#include "net/rime/broadcast.h"
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -65,6 +65,17 @@ AUTOSTART_PROCESSES(&test_remote_pm);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static struct etimer et; static struct etimer et;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void
broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)
{
leds_toggle(LEDS_BLUE);
printf("*** Received %u bytes from %u:%u: '0x%04x'\n", packetbuf_datalen(),
from->u8[0], from->u8[1], *(uint16_t *)packetbuf_dataptr());
}
/*---------------------------------------------------------------------------*/
static const struct broadcast_callbacks bc_rx = { broadcast_recv };
static struct broadcast_conn bc;
/*---------------------------------------------------------------------------*/
static char * static char *
print_pm(uint8_t state) print_pm(uint8_t state)
{ {
@ -173,23 +184,37 @@ PROCESS_THREAD(test_remote_pm, ev, data)
* disconnect the USB cable and power only with the external battery. If * disconnect the USB cable and power only with the external battery. If
* something fails, then you should not see the red LED blinking * something fails, then you should not see the red LED blinking
*/ */
aux = 0; aux = ENTER_SHUTDOWN_COUNT;
/* Open the broadcast channel */
broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
/* Send a message */
packetbuf_copyfrom(&aux, sizeof(aux));
broadcast_send(&bc);
/* And wait a few seconds before going to sleep */
while(1){ while(1){
etimer_set(&et, CLOCK_SECOND); etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();
aux++;
/* Enter shutdown mode before the shutdown period (1 min) expires */ /* Enter shutdown mode before the shutdown period (1 min default) expires */
if((aux % ENTER_SHUTDOWN_COUNT) == 0) { if(!aux) {
/* Say goodnight */ /* Say goodnight */
PM_SHUTDOWN_NOW; PM_SHUTDOWN_NOW;
printf("Goodnight!\n"); printf("Goodnight!\n");
PROCESS_EXIT();
} }
aux--;
leds_toggle(LEDS_RED); leds_toggle(LEDS_RED);
} }
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -73,6 +73,7 @@
#include "dev/watchdog.h" #include "dev/watchdog.h"
#include "dev/serial-line.h" #include "dev/serial-line.h"
#include "dev/sys-ctrl.h" #include "dev/sys-ctrl.h"
#include "net/netstack.h"
#include "net/rime/broadcast.h" #include "net/rime/broadcast.h"
#include <stdio.h> #include <stdio.h>
@ -86,8 +87,6 @@
#define LEDS_SERIAL_IN LEDS_GREEN #define LEDS_SERIAL_IN LEDS_GREEN
#define LEDS_REBOOT LEDS_ALL #define LEDS_REBOOT LEDS_ALL
#define LEDS_RF_RX (LEDS_YELLOW | LEDS_RED) #define LEDS_RF_RX (LEDS_YELLOW | LEDS_RED)
#define BROADCAST_CHANNEL 129
#define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND) #define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static struct etimer et; static struct etimer et;
@ -121,6 +120,10 @@ PROCESS_THREAD(zoul_demo_process, ev, data)
PROCESS_BEGIN(); PROCESS_BEGIN();
counter = 0; counter = 0;
/* Disable the radio duty cycle and keep the radio on */
NETSTACK_MAC.off(1);
broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx); broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
/* Configure the user button */ /* Configure the user button */