]> rtime.felk.cvut.cz Git - frescor/fna.git/blobdiff - src_frescan/frescan_fna.c
net
[frescor/fna.git] / src_frescan / frescan_fna.c
index f1f4cbcfa842dbf54202e76dd25b642f8565a537..7c4d1570c7dd0d51af1a8521ca04e7eb7d670de5 100644 (file)
@@ -166,7 +166,7 @@ int frescan_fna_contract_negotiate
         frescan_contract_t frescan_contract;
 
         DEBUG(FRESCAN_FNA_ENABLE_DEBUG,
-              "convert frsh contract to frescan contract\n");
+              "frsh contract->frescan contract\n");
 
         // TODO: budget is stored as number of can frames in tv_sec
         frescan_contract.min_values.budget = contract->budget_min.tv_sec;
@@ -646,8 +646,27 @@ int frescan_fna_send_async
                  const void *msg,
                  const size_t size)
 {
-        ERROR("not implemented\n");
-        return -1;
+        int ret;
+        frescan_send_params_t params;
+
+        DEBUG(FRESCAN_FNA_ENABLE_DEBUG,
+              "net:%u dest:%u chan:%u size:%u ss:%u\n",
+              endpoint->resource_id, endpoint->destination,
+              endpoint->stream_id, size, endpoint->vres);
+
+        params.net      = (frescan_network_t)endpoint->resource_id;
+        params.to       = (frescan_node_t)endpoint->destination;
+        params.channel  = (frescan_channel_t)endpoint->stream_id;
+        params.flags    = FRESCAN_SS | FRESCAN_ASYNC;
+        params.ss       = endpoint->vres;
+
+        ret = frescan_send(&params, (uint8_t *)msg, size);
+        if (ret != 0) {
+                ERROR ("could not send message\n");
+                return -1;
+        }
+
+        return 0;
 }
 
 /**
@@ -694,8 +713,34 @@ int frescan_fna_receive_sync
                  size_t *received_bytes,
                  frsh_network_address_t *from)
 {
-        ERROR("not implemented\n");
-        return -1;
+        int ret;
+        frescan_recv_params_t params;
+        frescan_node_t frescan_from;
+        frescan_prio_t prio;
+
+        params.net      = (frescan_network_t)endpoint->resource_id;
+        params.channel  = (frescan_channel_t)endpoint->stream_id;
+        params.flags    = FRESCAN_SYNC;
+
+        DEBUG(FRESCAN_FNA_ENABLE_DEBUG,
+              "net:%u chan:%u size:%u\n",
+              endpoint->resource_id, endpoint->stream_id, buffer_size);
+
+        ret = frescan_recv(&params, (uint8_t *)buffer, buffer_size,
+                           received_bytes, &frescan_from, &prio);
+
+        if (ret != 0) {
+                ERROR ("error while receiving message");
+                return -1;
+        }
+
+        *from = (frsh_network_address_t)frescan_from;
+
+        DEBUG(FRESCAN_FNA_ENABLE_DEBUG,
+              "msg received, from:%u bytes:%u prio:%u\n",
+              *from, *received_bytes, prio);
+
+        return 0;
 }
 
 /**
@@ -785,8 +830,8 @@ int frescan_fna_send_endpoint_get_status
 int frescan_fna_receive_endpoint_created
                 (fna_endpoint_data_t *endpoint)
 {
-        ERROR("not implemented\n");
-        return -1;
+        DEBUG(FRESCAN_FNA_ENABLE_DEBUG, "receive endpoint created\n");
+        return 0;
 }
 
 /**
@@ -885,8 +930,23 @@ int frescan_fna_network_bytes_to_budget
                  const size_t nbytes,
                  struct timespec *budget)
 {
-        ERROR("not implemented\n");
-        return -1;
+        int number_of_packets;
+
+        if (budget == NULL || nbytes < 0) {
+                return -1;
+        }
+
+        // we measure the budget in number of FRESCAN frames (8 bytes)
+        number_of_packets = nbytes / 8 + 1;
+
+        // we store the budget in number of packets instead of in time. We
+        // use a field in the timespec structure.
+        budget->tv_sec = number_of_packets;
+
+        DEBUG(FRESCAN_FNA_ENABLE_DEBUG,
+              "bytes: %d -> budget: %d\n", nbytes, budget->tv_sec);
+
+        return 0;
 }
 
 /**
@@ -914,8 +974,17 @@ int frescan_fna_network_budget_to_bytes
                  const struct timespec *budget,
                  size_t *nbytes)
 {
-        ERROR("not implemented\n");
-        return -1;
+        int number_of_packets;
+
+        if (budget == NULL || nbytes == NULL) {
+                return -1;
+        }
+
+        number_of_packets = budget->tv_sec;
+
+        *nbytes = number_of_packets * 8;
+
+        return 0;
 }
 
 /**
@@ -950,8 +1019,13 @@ int frescan_fna_network_get_min_eff_budget
                 (const frsh_resource_id_t resource_id,
                  struct timespec *budget)
 {
-        ERROR("not implemented\n");
-        return -1;
+        if (budget == NULL) {
+                return -1;
+        }
+
+        budget->tv_sec = 1;
+
+        return 0;
 }
 
 // GLOBAL variable to install the network protocol in FRESCOR