Go to the documentation of this file.00001
00009
00010
00011
00012
00013 #ifndef KOBUKI_GP_INPUT_HPP__
00014 #define KOBUKI_GP_INPUT_HPP__
00015
00016
00017
00018
00019
00020 #include <vector>
00021 #include "../packet_handler/payload_base.hpp"
00022 #include "../packet_handler/payload_headers.hpp"
00023
00024
00025
00026
00027
00028 namespace kobuki
00029 {
00030
00031
00032
00033
00034
00035 class GpInput : public packet_handler::payloadBase
00036 {
00037 public:
00038 struct Data {
00039 Data() : analog_input(4) {}
00040 uint16_t digital_input;
00046 std::vector<uint16_t> analog_input;
00047 } data;
00048
00049 bool serialise(ecl::PushAndPop<unsigned char> & byteStream)
00050 {
00051 if (!(byteStream.size() > 0))
00052 {
00053
00054 return false;
00055 }
00056
00057 unsigned char length = 2 + 2*data.analog_input.size();
00058 buildBytes(Header::GpInput, byteStream);
00059 buildBytes(length, byteStream);
00060 buildBytes(data.digital_input, byteStream);
00061 for (unsigned int i = 0; i < data.analog_input.size(); ++i)
00062 {
00063 buildBytes(data.analog_input[i], byteStream);
00064 }
00065 return true;
00066 }
00067
00068 bool deserialise(ecl::PushAndPop<unsigned char> & byteStream)
00069 {
00070 if (!(byteStream.size() > 0))
00071 {
00072
00073 return false;
00074 }
00075
00076 unsigned char header_id, length;
00077 buildVariable(header_id, byteStream);
00078 buildVariable(length, byteStream);
00079 buildVariable(data.digital_input, byteStream);
00080
00081
00082
00083
00084
00085
00086 for (unsigned int i = 0; i < 4; ++i)
00087 {
00088 buildVariable(data.analog_input[i], byteStream);
00089 }
00090 for (unsigned int i = 0; i < 3; ++i) {
00091 uint16_t dummy;
00092 buildVariable(dummy, byteStream);
00093 }
00094 return true;
00095 }
00096
00097 };
00098
00099 }
00100
00101 #endif
00102