]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - resources/item/tests/test_item.c
Deadline miss notification signals API changed
[frescor/frsh.git] / resources / item / tests / test_item.c
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
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                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
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.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FRSH (FRescor ScHeduler)                         */
26 /*                                                                        */
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.                                              */
37 /*                                                                        */
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 /**************************************************************************/
46
47 /**
48  * @file   test_item.c
49  * @author Michal Sojka <sojkam1@fel.cvut.cz>
50  * @date   Wed Feb 18 16:11:34 2009
51  * 
52  * @brief  Test for ITEM WSN resource
53  * 
54  * 
55  */
56
57
58 #include <frsh.h>
59 #include <error.h>
60 #include <item.h>
61 #include <fres_contract.h>
62
63 //ITEM ADD
64 //#include "FWSN.h"
65
66 #if 1
67 #define N 4
68 int contract_deadline_sec[N] = { 4,4,4,4 };
69 int contract_nodes[N] = { 0x04, 0x05, 0x02 ,0x03};
70 #else
71 #define N 3
72 int contract_deadline_sec[N] = {2,2,2};
73 int contract_nodes[N] = { 0x02,0x03,0x04};
74 #endif
75 int main(int argc, char *argv[])
76 {
77         int ret;
78         frsh_contract_t contract[N];
79         frsh_vres_id_t vres[N];
80         int i;
81         
82         
83         ret = frsh_init();
84         if (ret) PERROR_AND_EXIT(ret, "frsh_init");
85
86         /* Negotiate N contracts */
87         for (i=0; i<N; i++) {
88                 frsh_rel_time_t deadline;
89                 fres_block_item_nodes *nodes;
90                 ret = frsh_contract_init(&contract[i]);
91                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
92
93                 /* Set resource */
94                 ret = frsh_contract_set_resource_and_label(
95                         &contract[i], FRSH_RT_NETWORK, FRSH_NETPF_ITEM, NULL);
96                 if (ret) PERROR_AND_EXIT(ret, "Cannot set resource\n");
97
98                 /* Set nodes we want to receive data from */
99                 nodes = malloc(sizeof(*nodes));
100                 if (!nodes) PERROR_AND_EXIT(errno, "malloc");
101                 //nodes->mask = contract_nodes[i];
102                 
103                 nodes->mask =1;
104                 nodes->mask = nodes->mask << (contract_nodes[i]);
105                         
106                 
107                         ret = fres_contract_add_item_nodes(contract[i], nodes);
108                 if (ret) PERROR_AND_EXIT(ret, "Cannot add item_nodes block\n");
109
110                 /* Set deadline */
111                 deadline = fosa_msec_to_rel_time(contract_deadline_sec[i]*1000);
112                 ret = frsh_contract_set_timing_reqs(&contract[i],
113                                                     false, &deadline);
114                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_timing_reqs");
115
116                 /* Negotiate the contract */
117                 ret = frsh_contract_negotiate(&contract[i], &vres[i]);
118                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
119                 if (ret) printf(" \n frsh_contract_negotiate - NOT ACCEPTED \n");
120         }
121         printf("Contracts negotiated\n");
122
123         for (i=0; i<30; i++) {
124                 //int j;
125                 //printf("Reading data\n");
126                 //for (j=0; j<N; j++) {
127                         unsigned char *data;
128                         int len;
129                 //                      int k;
130                         ret = fra_item_receive(vres[1], &data);
131                         if (ret == -1) PERROR_AND_EXIT(errno, "frs_item_receive");
132                         len = ret;
133                         
134                         /*  Do something with the received data */
135                                 
136                         /*      printf("JOP 89 : %i  - ",len);
137                         for (k = 0; k < len-1; k++)
138                         {
139                                 printf("%02x ", data[k]);
140                                 if (k%4 == 3)
141                                         printf(" | ");
142                         }
143                         putchar('\n');*/
144                         
145                         int l;
146                         int m;
147                         for (l=1; l < len/4; l++)
148                         {
149                                 for(m=1; m < 20; m++)
150                                 {
151                                         if (data[4*l-1] > 6*m) putchar('*');
152                                         else putchar(' ');
153                                 }
154                                 printf(" | ");
155                         }                       
156                         putchar('\n');
157                         
158                         forb_free(data);
159                 //}
160                 sleep(1);
161         } 
162
163         for (i=0; i<N; i++) { 
164                 frsh_contract_cancel(vres[i]); 
165         }
166         return 0;
167 }