mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-11 19:29:50 +00:00
Refactored the example to broadcast a message to the zoul-demo example
This commit is contained in:
parent
5e14c22c98
commit
36ddb737e1
examples/zolertia/zoul
@ -1,5 +1,5 @@
|
||||
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
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
@ -1,8 +0,0 @@
|
||||
CONTIKI_PROJECT = test-power-mgmt
|
||||
|
||||
TARGET = zoul
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../../../..
|
||||
include $(CONTIKI)/Makefile.include
|
@ -38,7 +38,7 @@
|
||||
#ifndef PROJECT_CONF_H_
|
||||
#define PROJECT_CONF_H_
|
||||
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
#define BROADCAST_CHANNEL 129
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
|
||||
|
@ -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
|
||||
* management
|
||||
*
|
||||
@ -53,6 +51,8 @@
|
||||
#include "dev/gpio.h"
|
||||
#include "lib/list.h"
|
||||
#include "power-mgmt.h"
|
||||
#include "net/rime/broadcast.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -65,6 +65,17 @@ AUTOSTART_PROCESSES(&test_remote_pm);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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 *
|
||||
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
|
||||
* 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){
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
PROCESS_WAIT_EVENT();
|
||||
aux++;
|
||||
|
||||
/* Enter shutdown mode before the shutdown period (1 min) expires */
|
||||
if((aux % ENTER_SHUTDOWN_COUNT) == 0) {
|
||||
/* Enter shutdown mode before the shutdown period (1 min default) expires */
|
||||
if(!aux) {
|
||||
/* Say goodnight */
|
||||
PM_SHUTDOWN_NOW;
|
||||
printf("Goodnight!\n");
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
aux--;
|
||||
leds_toggle(LEDS_RED);
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
@ -73,6 +73,7 @@
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/sys-ctrl.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/rime/broadcast.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -86,8 +87,6 @@
|
||||
#define LEDS_SERIAL_IN LEDS_GREEN
|
||||
#define LEDS_REBOOT LEDS_ALL
|
||||
#define LEDS_RF_RX (LEDS_YELLOW | LEDS_RED)
|
||||
#define BROADCAST_CHANNEL 129
|
||||
|
||||
#define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
@ -121,6 +120,10 @@ PROCESS_THREAD(zoul_demo_process, ev, data)
|
||||
PROCESS_BEGIN();
|
||||
|
||||
counter = 0;
|
||||
|
||||
/* Disable the radio duty cycle and keep the radio on */
|
||||
NETSTACK_MAC.off(1);
|
||||
|
||||
broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
|
||||
|
||||
/* Configure the user button */
|
||||
|
Loading…
x
Reference in New Issue
Block a user