-#include <pthread.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <misc/error_checks.h>
-#include <unistd.h>
-#include "rtep.h"
-
-static uint16_t channel = 3;
-
-
-/* receiver_task */
-static void *receiver_task (void *arg)
-{
- const int MAX_SIZE = 1500;
- uint8_t buffer[MAX_SIZE+1];
- size_t received_bytes;
- frsh_endpoint_queueing_info_t queueing_info;
- frsh_protocol_info_t protocol_info;
- frsh_receive_endpoint_t endpoint;
-// uint16_t station;
-// uint8_t prio;
-
- printf ("receiver_task\n");
-
- /* create the receive endpoint (TODO: should be done using FRSH api) */
- endpoint.network_id = 0;
- endpoint.stream_id = (frsh_stream_id_t)channel;
- endpoint.queueing_info = queueing_info;
- endpoint.protocol_info = protocol_info;
- CHKE_FATAL (rtep_fna_receive_endpoint_create_callback(&endpoint));
-
- while (1) {
- CHKE_FATAL (rtep_fna_receive_sync (&endpoint, (void *)buffer, MAX_SIZE,
- &received_bytes));
-
- buffer[received_bytes] = 0;
-// printf ("received data from: %u with prio: %u last: %d data: ",
-// station, prio, last);
-// printf ("received %s\n",buffer);
- fputs ((char *)buffer, stdout);
- }
-}
-
-int main ()
-{
- uint16_t me;
- uint16_t dest_station;
- char dest_station_name[] = "broadcast";
- char msg_broadcast[] = "Hi All!\n";
- frsh_contract_t contract;
- uint16_t budget_min = 3;
- struct timespec period_max = {10, 0};
- struct timespec deadline = period_max;
- fna_vres_id_t vres;
- fna_send_endpoint_t send_endpoint;
- uint8_t prio = 8;
- int accepted;
- pthread_t th;
- pthread_attr_t attr;
-
- /* initialization */
- rtep_adainit();
- CHKE_FATAL (rtep_fna_init(0));
-
- me = rtep_get_station_id();
- printf ("I am: %u\n", me);
-
- /* create a thread that receives messages */
- CHKE_FATAL( pthread_attr_init (&attr) );
- CHKE_FATAL( pthread_create (&th, &attr, receiver_task, NULL) );
-
- /* set contract params (TODO: should be done using FRSH api) */
- contract.budget_min = budget_min;
- contract.period_max = period_max;
- contract.deadline = deadline;
- contract.prio = prio;
-
- /* negotiate the contract */
- accepted = rtep_fna_contract_negotiate (0, &contract, &vres);
-
- if (accepted != 0) {
- printf ("contract not accepted\n");
- return -1;
- }
- printf ("contract accepted\n");
-
- /* create the send endpoint (TODO: should be done using FRSH api) */
- dest_station = rtep_get_station_id_by_name
- ((uint8_t *)dest_station_name, sizeof(dest_station_name)-1);
-
- send_endpoint.network_id = 0;
- send_endpoint.destination = (frsh_network_address_t)dest_station;
- send_endpoint.stream_id = (frsh_stream_id_t)channel;
- send_endpoint.vres = vres;
-
- /* send messages */
- while (1) {
- printf ("sending a message\n");
- rtep_fna_send_async(&send_endpoint, msg_broadcast, sizeof(msg_broadcast));
- sleep (2);
- }
-
- // finalization
- rtep_adafinal();
- return 0;
-}