35 #ifndef ROS_NODE_HANDLE_H_
36 #define ROS_NODE_HANDLE_H_
45 #define SYNC_SECONDS 5
47 #define MODE_FIRST_FF 0
56 #define MODE_PROTOCOL_VER 1
57 #define PROTOCOL_VER1 0xff // through groovy
58 #define PROTOCOL_VER2 0xfe // in hydro
59 #define PROTOCOL_VER PROTOCOL_VER2
62 #define MODE_SIZE_CHECKSUM 4 // checksum for msg size received from size L and H
63 #define MODE_TOPIC_L 5 // waiting for topic id
64 #define MODE_TOPIC_H 6
65 #define MODE_MESSAGE 7
66 #define MODE_MSG_CHECKSUM 8 // checksum for msg and topic id
69 #define MSG_TIMEOUT 20 //20 milliseconds to recieve all of message data
93 template<
class Hardware,
94 int MAX_SUBSCRIBERS=25,
95 int MAX_PUBLISHERS=25,
121 for(
unsigned int i=0; i< MAX_PUBLISHERS; i++)
124 for(
unsigned int i=0; i< MAX_SUBSCRIBERS; i++)
127 for(
unsigned int i=0; i< INPUT_SIZE; i++)
130 for(
unsigned int i=0; i< OUTPUT_SIZE; i++)
308 t.
data.
nsec += (offset%1000)*1000000UL;
339 for(
int i = 0; i < MAX_PUBLISHERS; i++){
342 p.
id_ = i+100+MAX_SUBSCRIBERS;
351 template<
typename MsgT>
353 for(
int i = 0; i < MAX_SUBSCRIBERS; i++){
364 template<
typename MReq,
typename MRes>
367 for(
int i = 0; i < MAX_SUBSCRIBERS; i++){
378 template<
typename MReq,
typename MRes>
381 for(
int i = 0; i < MAX_SUBSCRIBERS; i++){
395 for(i = 0; i < MAX_PUBLISHERS; i++)
407 for(i = 0; i < MAX_SUBSCRIBERS; i++)
441 for(
int i =5; i<l+7; i++)
446 if( l <= OUTPUT_SIZE ){
450 logerror(
"Message from device dropped: message larger than buffer.");
460 void log(
char byte,
const char * msg){
495 req.
name = (
char*)name;
497 uint16_t end_time =
hardware_.time() + time_out;
500 if (
hardware_.time() > end_time)
return false;
506 bool getParam(
const char* name,
int* param,
int length =1){
510 for(
int i=0; i<length; i++)
517 bool getParam(
const char* name,
float* param,
int length=1){
521 for(
int i=0; i<length; i++)
528 bool getParam(
const char* name,
char** param,
int length=1){
532 for(
int i=0; i<length; i++)
int id_
Definition: publisher.h:58
Definition: TopicInfo.h:24
uint8_t message_out[OUTPUT_SIZE]
Definition: node_handle.h:110
Definition: subscriber.h:60
void logdebug(const char *msg)
Definition: node_handle.h:468
void logwarn(const char *msg)
Definition: node_handle.h:474
bool configured_
Definition: node_handle.h:171
void initNode()
Definition: node_handle.h:146
uint32_t nsec
Definition: time.h:50
#define MODE_PROTOCOL_VER
Definition: node_handle.h:56
uint32_t sec
Definition: time.h:50
Definition: TopicInfo.h:12
Definition: subscriber.h:43
const char * topic_name
Definition: TopicInfo.h:16
int mode_
Definition: node_handle.h:161
Definition: TopicInfo.h:25
ros::Time data
Definition: Time.h:16
void syncTime(uint8_t *data)
Definition: node_handle.h:301
void log(char byte, const char *msg)
Definition: node_handle.h:460
bool param_recieved
Definition: node_handle.h:489
const char * md5sum
Definition: TopicInfo.h:18
Time now()
Definition: node_handle.h:314
Definition: node_handle.h:98
Definition: node_handle.h:75
virtual bool connected()=0
bool subscribe(Subscriber< MsgT > &s)
Definition: node_handle.h:352
void logerror(const char *msg)
Definition: node_handle.h:477
Publisher pub
Definition: service_server.h:69
uint32_t last_msg_timeout_time
Definition: node_handle.h:176
uint32_t last_sync_time
Definition: node_handle.h:174
uint32_t rt_time
Definition: node_handle.h:104
void logfatal(const char *msg)
Definition: node_handle.h:480
void negotiateTopics()
Definition: node_handle.h:391
virtual void callback(unsigned char *data)=0
virtual int publish(int id, const Msg *msg)
Definition: node_handle.h:422
virtual int deserialize(unsigned char *inbuffer)
Definition: Time.h:39
Definition: TopicInfo.h:20
uint32_t nsec_offset
Definition: node_handle.h:107
NodeHandleBase_ * nh_
Definition: publisher.h:59
#define MODE_SIZE_CHECKSUM
Definition: node_handle.h:62
uint8_t level
Definition: Log.h:15
void loginfo(const char *msg)
Definition: node_handle.h:471
#define SYNC_SECONDS
Definition: node_handle.h:45
int32_t buffer_size
Definition: TopicInfo.h:19
uint8_t strings_length
Definition: RequestParam.h:63
Publisher * publishers[MAX_PUBLISHERS]
Definition: node_handle.h:112
NodeHandle_()
Definition: node_handle.h:119
char ** strings
Definition: RequestParam.h:65
#define MODE_TOPIC_H
Definition: node_handle.h:64
virtual int deserialize(unsigned char *inbuffer)
Definition: RequestParam.h:123
bool requestParam(const char *name, int time_out=1000)
Definition: node_handle.h:492
uint32_t last_sync_receive_time
Definition: node_handle.h:175
uint8_t message_in[INPUT_SIZE]
Definition: node_handle.h:109
Definition: TopicInfo.h:27
#define MODE_MESSAGE
Definition: node_handle.h:65
void setNow(Time &new_now)
Definition: node_handle.h:324
int32_t * ints
Definition: RequestParam.h:59
int id_
Definition: subscriber.h:50
virtual int publish(int id, const Msg *msg)=0
void normalizeSecNSec(uint32_t &sec, uint32_t &nsec)
Definition: time.cpp:39
Hardware hardware_
Definition: node_handle.h:101
Publisher pub
Definition: service_client.h:78
#define MODE_SIZE_H
Definition: node_handle.h:61
int topic_
Definition: node_handle.h:167
virtual bool connected()
Definition: node_handle.h:286
bool getParam(const char *name, int *param, int length=1)
Definition: node_handle.h:506
#define MODE_MSG_CHECKSUM
Definition: node_handle.h:66
Definition: publisher.h:44
int bytes_
Definition: node_handle.h:166
const char * message_type
Definition: TopicInfo.h:17
bool getParam(const char *name, float *param, int length=1)
Definition: node_handle.h:517
bool getParam(const char *name, char **param, int length=1)
Definition: node_handle.h:528
float * floats
Definition: RequestParam.h:62
#define MSG_TIMEOUT
Definition: node_handle.h:69
int index_
Definition: node_handle.h:168
bool advertise(Publisher &p)
Definition: node_handle.h:337
void initNode(char *portName)
Definition: node_handle.h:155
int checksum_
Definition: node_handle.h:169
Definition: RequestParam.h:13
Definition: service_server.h:46
#define MODE_FIRST_FF
Definition: node_handle.h:47
Hardware * getHardware()
Definition: node_handle.h:141
const char * name
Definition: RequestParam.h:16
virtual int serialize(unsigned char *outbuffer) const =0
Subscriber_ * subscribers[MAX_SUBSCRIBERS]
Definition: node_handle.h:113
uint8_t floats_length
Definition: RequestParam.h:60
void requestSyncTime()
Definition: node_handle.h:294
Definition: service_client.h:46
#define PROTOCOL_VER
Definition: node_handle.h:59
rosserial_msgs::RequestParamResponse req_param_resp
Definition: node_handle.h:490
#define MODE_TOPIC_L
Definition: node_handle.h:63
bool advertiseService(ServiceServer< MReq, MRes > &srv)
Definition: node_handle.h:365
Definition: RequestParam.h:54
uint8_t ints_length
Definition: RequestParam.h:57
uint32_t sec_offset
Definition: node_handle.h:107
bool serviceClient(ServiceClient< MReq, MRes > &srv)
Definition: node_handle.h:379
Definition: TopicInfo.h:26
#define MODE_SIZE_L
Definition: node_handle.h:60
uint16_t topic_id
Definition: TopicInfo.h:15
virtual int spinOnce()
Definition: node_handle.h:184
const char * msg
Definition: Log.h:16