1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners: */
5 /* Universidad de Cantabria, SPAIN */
6 /* University of York, UK */
7 /* Scuola Superiore Sant'Anna, ITALY */
8 /* Kaiserslautern University, GERMANY */
9 /* Univ. Politécnica Valencia, SPAIN */
10 /* Czech Technical University in Prague, CZECH REPUBLIC */
12 /* Thales Communication S.A. FRANCE */
13 /* Visual Tools S.A. SPAIN */
14 /* Rapita Systems Ltd UK */
17 /* See http://www.frescor.org for a link to partners' websites */
19 /* FRESCOR project (FP6/2005/IST/5-034026) is funded */
20 /* in part by the European Union Sixth Framework Programme */
21 /* The European Union is not liable of any use that may be */
22 /* made of this code. */
25 /* This file is part of FRSH (FRescor ScHeduler) */
27 /* FRSH is free software; you can redistribute it and/or modify it */
28 /* under terms of the GNU General Public License as published by the */
29 /* Free Software Foundation; either version 2, or (at your option) any */
30 /* later version. FRSH is distributed in the hope that it will be */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
33 /* General Public License for more details. You should have received a */
34 /* copy of the GNU General Public License along with FRSH; see file */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */
36 /* Cambridge, MA 02139, USA. */
38 /* As a special exception, including FRSH header files in a file, */
39 /* instantiating FRSH generics or templates, or linking other files */
40 /* with FRSH objects to produce an executable application, does not */
41 /* by itself cause the resulting executable application to be covered */
42 /* by the GNU General Public License. This exception does not */
43 /* however invalidate any other reasons why the executable file might be */
44 /* covered by the GNU Public License. */
45 /**************************************************************************/
49 * @author Michal Sojka <sojkam1@fel.cvut.cz>
50 * @date Wed Feb 18 16:11:34 2009
52 * @brief Test for ITEM WSN resource
61 #include <fres_contract.h>
68 int contract_deadline_sec[N] = { 4,4,4,4 };
69 int contract_nodes[N] = { 0x04, 0x05, 0x02 ,0x03};
72 int contract_deadline_sec[N] = {2,2,2};
73 int contract_nodes[N] = { 0x02,0x03,0x04};
75 int main(int argc, char *argv[])
78 frsh_contract_t contract[N];
79 frsh_vres_id_t vres[N];
84 if (ret) PERROR_AND_EXIT(ret, "frsh_init");
86 /* Negotiate N contracts */
88 frsh_rel_time_t deadline;
89 frsh_signal_info_t si;
90 fres_block_item_nodes *nodes;
91 ret = frsh_contract_init(&contract[i]);
92 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
95 ret = frsh_contract_set_resource_and_label(
96 &contract[i], FRSH_RT_NETWORK, FRSH_NETPF_ITEM, NULL);
97 if (ret) PERROR_AND_EXIT(ret, "Cannot set resource\n");
99 /* Set nodes we want to receive data from */
100 nodes = malloc(sizeof(*nodes));
101 if (!nodes) PERROR_AND_EXIT(errno, "malloc");
102 //nodes->mask = contract_nodes[i];
105 nodes->mask = nodes->mask << (contract_nodes[i]);
108 ret = fres_contract_add_item_nodes(contract[i], nodes);
109 if (ret) PERROR_AND_EXIT(ret, "Cannot add item_nodes block\n");
112 deadline = fosa_msec_to_rel_time(contract_deadline_sec[i]*1000);
113 ret = frsh_contract_set_timing_reqs(&contract[i],
116 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_timing_reqs");
118 /* Negotiate the contract */
119 ret = frsh_contract_negotiate(&contract[i], &vres[i]);
120 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
121 if (ret) printf(" \n frsh_contract_negotiate - NOT ACCEPTED \n");
123 printf("Contracts negotiated\n");
125 for (i=0; i<30; i++) {
127 //printf("Reading data\n");
128 //for (j=0; j<N; j++) {
132 ret = fra_item_receive(vres[1], &data);
133 if (ret == -1) PERROR_AND_EXIT(errno, "frs_item_receive");
136 /* Do something with the received data */
138 /* printf("JOP 89 : %i - ",len);
139 for (k = 0; k < len-1; k++)
141 printf("%02x ", data[k]);
149 for (l=1; l < len/4; l++)
151 for(m=1; m < 20; m++)
153 if (data[4*l-1] > 6*m) putchar('*');
165 for (i=0; i<N; i++) {
166 frsh_contract_cancel(vres[i]);