20 #ifndef __can_string_generic__
21 #define __can_string_generic__
25 #include <yarp/dev/CanBusInterface.h>
27 #include <yarp/os/LogStream.h>
28 #include <yarp/os/Log.h>
36 char text_buffer [256];
71 inline char*
print(
int buffer_num,
const char* canDevName,
int netNum);
94 for (
int i = 0; i < 256; i++) data[buffer_num].text_buffer[i]=0;
95 data[buffer_num].complete=
false;
96 data[buffer_num].maybe_last_part=
false;
97 data[buffer_num].expected_length = 0;
98 data[buffer_num].board_id=0;
99 data[buffer_num].current_length = 0;
108 yarp::dev::CanMessage* t;
112 t = (yarp::dev::CanMessage*) (can_packet);
115 unsigned char *candata=t->getData();
116 string_id = (candata[1]>>4);
117 offset = (candata[1]&0x0F);
118 data[string_id].board_id = char(
id>>4&0xf);
122 yError(
"msg from board %d contains an ERROR! (>MAX_STRINGS)\n",data[string_id ].board_id);
126 for (j=0 ; j<len-2; j++)
127 data[string_id].text_buffer[j+
offset*6]=candata[j+2];
129 if (candata[0]==ICUBCANPROTO_PER_MC_MSG__PRINT + 128)
131 data[string_id].maybe_last_part =
true;
132 data[string_id].expected_length=
offset*6+len-2;
135 if (data[string_id].maybe_last_part)
137 data[string_id].current_length=strlen(data[string_id].text_buffer);
139 if (data[string_id].expected_length==data[string_id].current_length)
140 data[string_id].complete =
true;
163 if (data[string_id].complete)
return string_id;
171 yDebug(
"%s [%d] msg from board %d: %s \n", canDevName, netNum, data[buffer_num].board_id , data[buffer_num].text_buffer);
173 return data[buffer_num].text_buffer;
void clear_string(int buffer_num)
Resets the string buffer.
can_string_generic()
Default constructor.
char * print(int buffer_num, const char *canDevName, int netNum)
Prints a string buffer.
int add_string(void *can_packet)
Process a string can packet.
~can_string_generic()
Destructor.