]> rtime.felk.cvut.cz Git - orte/eurobot.git/blob - orte/examples/reliable/r_publisher.c
7f9408f3c8fab26aa2ec43f359c91b1b8af71568
[orte/eurobot.git] / orte / examples / reliable / r_publisher.c
1 /*
2  *  $Id: publisher.c,v 0.0.0.1          2003/12/27 
3  *
4  *  DEBUG:  section                     publisher
5  *
6  *  -------------------------------------------------------------------  
7  *                                ORTE                                 
8  *                      Open Real-Time Ethernet                       
9  *                                                                    
10  *                      Copyright (C) 2001-2006                       
11  *  Department of Control Engineering FEE CTU Prague, Czech Republic  
12  *                      http://dce.felk.cvut.cz                       
13  *                      http://www.ocera.org                          
14  *                                                                    
15  *  Author:              Petr Smolik    petr.smolik@wo.cz             
16  *  Advisor:             Pavel Pisa                                   
17  *  Project Responsible: Zdenek Hanzalek                              
18  *  --------------------------------------------------------------------
19  *
20  *  This program is free software; you can redistribute it and/or modify
21  *  it under the terms of the GNU General Public License as published by
22  *  the Free Software Foundation; either version 2 of the License, or
23  *  (at your option) any later version.
24  *  
25  *  This program is distributed in the hope that it will be useful,
26  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  *  GNU General Public License for more details.
29  *  
30  */ 
31
32 #include <stdio.h>
33 #ifdef __RTL__
34   #include <posix/pthread.h>
35 #endif
36 #include "orte.h"
37
38 #ifdef MAIN_RENAMED
39 #define main orte_r_publisher_main
40 #define exit return
41 #endif
42
43 static ORTEDomain        *d;
44 static char              instance2Send[64];
45 static int               counter=0;
46
47 static void
48 sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam) {
49   char *instance=(char*)vinstance;
50
51   switch (info->status) {
52     case NEED_DATA:
53       printf("Sampling publication, count %d\n", counter);
54       sprintf(instance,"Hello Universe! (%d)",counter++);
55       break;
56     case CQL:  //criticalQueueLevel
57       break;
58   }
59 }
60
61
62 int 
63 main(int argc, char *args[]) {
64   ORTEPublication *p;
65   NtpTime         persistence,repeating;
66
67   ORTEInit();
68   d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
69   ORTETypeRegisterAdd(d,"HelloMsg",NULL,NULL,NULL,sizeof(instance2Send));
70   NTPTIME_BUILD(persistence,3); 
71   NTPTIME_BUILD(repeating,1); 
72   p=ORTEPublicationCreate(
73        d,
74       "Reliable HelloMsg",
75       "HelloMsg",
76       &instance2Send,
77       &persistence,
78       1,
79       sendCallBack,
80       NULL,
81       &repeating);
82   if (p == NULL) {
83     printf("ORTEPublicationCreate failed\n");
84     return 1;
85   }
86   #ifndef CONFIG_ORTE_RT
87   while(1) {
88     ORTESleepMs(1000);
89   }
90   #endif
91   return 0;
92 }
93
94 #ifdef CONFIG_ORTE_RT
95 void 
96 hello_init(void) {
97   main(0,NULL);
98 }
99 void 
100 hello_exit(void) {
101   ORTEDomainAppDestroy(d);
102 }
103 MODULE_LICENSE("GPL");
104 module_init(hello_init);
105 module_exit(hello_exit);
106 #endif
107