Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #109 #240

Merged
merged 3 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions rosserial_client/src/ros_lib/ros/msg.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2011, Willow Garage, Inc.
Expand Down Expand Up @@ -36,6 +36,7 @@
#define _ROS_MSG_H_

#include <stdint.h>
#include <stddef.h>

namespace ros {

Expand Down Expand Up @@ -114,14 +115,31 @@ class Msg
if (exp != 0)
{
*val |= ((exp) - 1023 + 127) << 23;
}
}

// Copy negative sign.
*val |= ((uint32_t)(*(inbuffer++)) & 0x80) << 24;

return 8;
}

// Copy data from variable into a byte array
template<typename A, typename V>
static void varToArr(A arr, const V var)
{
for(size_t i = 0; i < sizeof(V); i++)
arr[i] = (var >> (8 * i));
}

// Copy data from a byte array into variable
template<typename V, typename A>
static void arrToVar(V& var, const A arr)
{
var = 0;
for(size_t i = 0; i < sizeof(V); i++)
var |= (arr[i] << (8 * i));
}

};

} // namespace ros
Expand Down
4 changes: 2 additions & 2 deletions rosserial_client/src/rosserial_client/make_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ def make_declaration(self, f):
def serialize(self, f):
cn = self.name.replace("[","").replace("]","")
f.write(' uint32_t length_%s = strlen(this->%s);\n' % (cn,self.name))
f.write(' memcpy(outbuffer + offset, &length_%s, sizeof(uint32_t));\n' % cn)
f.write(' varToArr(outbuffer + offset, length_%s);\n' % cn)
f.write(' offset += 4;\n')
f.write(' memcpy(outbuffer + offset, this->%s, length_%s);\n' % (self.name,cn))
f.write(' offset += length_%s;\n' % cn)

def deserialize(self, f):
cn = self.name.replace("[","").replace("]","")
f.write(' uint32_t length_%s;\n' % cn)
f.write(' memcpy(&length_%s, (inbuffer + offset), sizeof(uint32_t));\n' % cn)
f.write(' arrToVar(length_%s, (inbuffer + offset));\n' % cn)
f.write(' offset += 4;\n')
f.write(' for(unsigned int k= offset; k< offset+length_%s; ++k){\n'%cn) #shift for null character
f.write(' inbuffer[k-1]=inbuffer[k];\n')
Expand Down