00001 #include <orte.h> 00002 00003 #ifdef CONFIG_ORTE_RTL 00004 #include <linux/module.h> 00005 #include <posix/pthread.h> 00006 #define printf rtl_printf 00007 #elif defined CONFIG_ORTE_RTAI 00008 #include <linux/module.h> 00009 #include <rtai/compat.h> 00010 #define printf rt_printk 00011 #else 00012 #include <stdio.h> 00013 #endif 00014 00015 ORTEDomain *d=NULL; 00016 ORTEPublication *publisherMotor; 00017 00018 uint16_t laserRecv[12]; 00019 int16_t motorSpeedCmd[2]; 00020 00021 void *subscriberLaserCreate(void *arg) { 00022 ORTESubscription *s; 00023 NtpTime deadline,minimumSeparation; 00024 00025 ORTETypeRegisterAdd(d,"LaserMsg",NULL,NULL,NULL,sizeof(laserRecv)); 00026 NTPTIME_BUILD(deadline,10); 00027 NTPTIME_BUILD(minimumSeparation,0); 00028 s=ORTESubscriptionCreate(d, IMMEDIATE, BEST_EFFORTS, "laser", "LaserMsg", &laserRecv, &deadline, &minimumSeparation, recvCallBackMotor, NULL, IPADDRESS_INVALID); 00029 return arg; 00030 } 00031 00032 void *publisherMotorCreate(void *arg) { 00033 ORTEPublication *p; 00034 NtpTime persistence, delay; 00035 00036 ORTETypeRegisterAdd(d,"MotorCmdMsg",NULL,NULL,NULL,sizeof(motorSpeedCmd)); 00037 NTPTIME_BUILD(persistence,3); 00038 NTPTIME_BUILD(delay,1); 00039 publisherMotor=ORTEPublicationCreate(d, "motor", "MotorCmdMsg", &motorSpeedCmd, &persistence, 1, NULL, NULL, &delay); 00040 return arg; 00041 } 00042 00043 void recvCallBackLaser(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) { 00044 uint16_t *instance=(uint16_t *)vinstance; 00045 00046 switch (info->status) { 00047 case NEW_DATA: 00048 break; 00049 case DEADLINE: 00050 printf("deadline occurred\n"); 00051 break; 00052 } 00053 } 00054 00055 void initOrte() { 00056 ORTEInit(); 00057 00058 ORTEVerbositySetOptions("ALL.0"); 00059 d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE); 00060 if (!d) { 00061 printf("ORTEDomainAppCreate failed!\n"); 00062 } 00063 subscriberLaserCreate(NULL); 00064 publisherMotorCreate(NULL); 00065 }