+++ /dev/null
-#include <pthread.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <misc/error_checks.h>
-#include <misc/load.h>
-#include "../rtep.h"
-#include "../frsh/fna/include/fna.h"
-
-int main ()
-{
- uint16_t me;
- int ret;
-
- adjust ();
- rtep_adainit();
-
- // ret = pthread_setschedprio (pthread_self(),5);
-
- // FRSH_Distributed.Init;
- rtep_fna_init();
-
- // Ada.Text_Io.Put_Line ("I am "&RTEP.Station_ID'Image (RP.Get_Station_ID));
- me = rtep_get_station_id();
- printf ("I am: %u\n", me);
-
- // FRSH_Distributed.Set_Basic_Parameters
- // (Contract, Budget_Min, Period_Max, Deadline);
- ret = frsh_contract_set_basic_parameters
- (&contract, b_min, per_max_sec, per_max_nsec, deadline);
-
- // FRSH_Distributed.Set_Priority (Contract, Prio);
- ret = rtep_frsh_contract_set_priority (&contract, prio);
-
- // FRSH_Distributed.Negotiate_Contract
- // (Contract, Vres, Accepted);
- ret = rtep_fna_vres_create (&contract, &vres, &acccepted);
-
- // if not Accepted then
- // Ada.Text_Io.Put_Line ("Contract Not Accepted");
- // return;
- // end if;
- if (!accepted) {
- printf ("contract not accepted\n");
- return -1;
- }
-
- // Ada.Text_Io.Put_Line ("Contract Accepted");
- printf ("contract accepted\n");
-
- // S_Id := FRSH_Distributed.Get_Server_Id (Vres);
- // loop
- // RP.Send_Info
- // (Destination_Station_ID => Dest_Id,
- // Channel_ID => Chan,
- // Data => RTEP_Streams.To_Stream_Element_Array ("Hello World"),
- // Id => S_Id,
- // Blocking => True);
- // Next_Time := Ada.Real_Time."+" (Next_Time, Period_Max);
- // delay until Next_Time;
- // end loop;
- ret = rtep_frsh_create_send_endpoint (&endpoint, dest, chan, vres);
-
- while (1) {
- ret = rtep_fna_send_async (&endpoint, msg, size);
- ret = rtep_fna_receive_sync (&endpoint, msg, size, &received_bytes);
- }
- // finalization
- rtep_adafinal();
- return 0;
-}
+++ /dev/null
-#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;
-}