1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/examples/ccn-lite-relay/main.c

86 lines
1.6 KiB
C
Raw Normal View History

2014-02-03 22:47:31 +01:00
/*
2014-01-06 10:10:47 +01:00
* Copyright (C) 2013 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
2014-02-03 22:47:31 +01:00
*/
/**
* @ingroup examples
* @{
*
* @file
* @brief CCN Lite relay example application
*
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
2014-01-06 10:10:47 +01:00
*
2014-02-03 22:47:31 +01:00
* @}
2014-01-06 10:10:47 +01:00
*/
// system
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
// riot
#include "thread.h"
#include "periph/rtc.h"
2014-01-06 10:10:47 +01:00
// ccn
#include "ccn_lite/ccnl-riot.h"
static kernel_pid_t _relay_pid = KERNEL_PID_UNDEF;
2014-01-06 10:10:47 +01:00
char t2_stack[KERNEL_CONF_STACKSIZE_MAIN];
2014-01-06 10:10:47 +01:00
void set_address_handler(uint16_t a)
{
msg_t mesg;
transceiver_command_t tcmd;
2014-04-10 22:36:58 +02:00
tcmd.transceivers = TRANSCEIVER;
2014-01-06 10:10:47 +01:00
tcmd.data = &a;
mesg.content.ptr = (char *) &tcmd;
printf("trying to set address %" PRIu16 "\n", a);
2014-01-06 10:10:47 +01:00
mesg.type = SET_ADDRESS;
printf("transceiver_pid=%" PRIkernel_pid"\n", transceiver_pid);
2014-01-06 10:10:47 +01:00
msg_send_receive(&mesg, &mesg, transceiver_pid);
printf("got address: %" PRIu16 "\n", a);
2014-01-06 10:10:47 +01:00
}
void populate_cache(void)
{
msg_t m;
m.content.value = 0;
m.type = CCNL_RIOT_POPULATE;
2014-10-20 16:49:40 +02:00
msg_send(&m, _relay_pid);
2014-01-06 10:10:47 +01:00
}
void *second_thread(void *arg)
2014-01-06 10:10:47 +01:00
{
(void) arg;
2014-01-06 10:10:47 +01:00
set_address_handler(42);
populate_cache();
return NULL;
2014-01-06 10:10:47 +01:00
}
int main(void)
{
printf("CCN!\n");
_relay_pid = thread_getpid();
2014-01-06 10:10:47 +01:00
2014-07-18 20:35:32 +02:00
thread_create(t2_stack, sizeof(t2_stack), PRIORITY_MAIN + 1,
CREATE_STACKTEST, second_thread, NULL, "helper thread");
2014-01-06 10:10:47 +01:00
printf("starting ccn-lite relay...\n");
2014-07-18 20:35:32 +02:00
ccnl_riot_relay_start(NULL);
2014-01-06 10:10:47 +01:00
return 0;
}