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
2014-08-07 16:31:27 +02:00

86 lines
1.6 KiB
C

/*
* 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.
*/
/**
* @ingroup examples
* @{
*
* @file
* @brief CCN Lite relay example application
*
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
*
* @}
*/
// system
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
// riot
#include "thread.h"
#include "rtc.h"
// ccn
#include "ccn_lite/ccnl-riot.h"
kernel_pid_t relay_pid = KERNEL_PID_UNDEF;
char t2_stack[KERNEL_CONF_STACKSIZE_MAIN];
void set_address_handler(uint16_t a)
{
msg_t mesg;
transceiver_command_t tcmd;
tcmd.transceivers = TRANSCEIVER;
tcmd.data = &a;
mesg.content.ptr = (char *) &tcmd;
printf("trying to set address %" PRIu16 "\n", a);
mesg.type = SET_ADDRESS;
printf("transceiver_pid=%" PRIkernel_pid"\n", transceiver_pid);
msg_send_receive(&mesg, &mesg, transceiver_pid);
printf("got address: %" PRIu16 "\n", a);
}
void populate_cache(void)
{
msg_t m;
m.content.value = 0;
m.type = CCNL_RIOT_POPULATE;
msg_send(&m, relay_pid, 1);
}
void *second_thread(void *arg)
{
(void) arg;
set_address_handler(42);
populate_cache();
return NULL;
}
int main(void)
{
printf("CCN!\n");
relay_pid = thread_getpid();
thread_create(t2_stack, sizeof(t2_stack), PRIORITY_MAIN + 1,
CREATE_STACKTEST, second_thread, NULL, "helper thread");
printf("starting ccn-lite relay...\n");
ccnl_riot_relay_start(NULL);
return 0;
}