zoukankan      html  css  js  c++  java
  • rosserial_python serial_node.py分析--补遗

    上位机会每隔2秒左右发送一个帧, 看帧id, 其实是0x0A, 就是时间, 那么问题来了, 后面8个字节怎么表示的时间呢?

        def handleTimeRequest(self, data):
            """ Respond to device with system time. """
            t = Time()
            t.data = rospy.Time.now()
            data_buffer = StringIO.StringIO()
            t.serialize(data_buffer)
            self.send( TopicInfo.ID_TIME, data_buffer.getvalue() )
            self.lastsync = rospy.Time.now()

    查Time.h文件, 发现序列化的方法是:

        virtual int serialize(unsigned char *outbuffer) const
        {
          int offset = 0;
          *(outbuffer + offset + 0) = (this->data.sec >> (8 * 0)) & 0xFF;
          *(outbuffer + offset + 1) = (this->data.sec >> (8 * 1)) & 0xFF;
          *(outbuffer + offset + 2) = (this->data.sec >> (8 * 2)) & 0xFF;
          *(outbuffer + offset + 3) = (this->data.sec >> (8 * 3)) & 0xFF;
          offset += sizeof(this->data.sec);
          *(outbuffer + offset + 0) = (this->data.nsec >> (8 * 0)) & 0xFF;
          *(outbuffer + offset + 1) = (this->data.nsec >> (8 * 1)) & 0xFF;
          *(outbuffer + offset + 2) = (this->data.nsec >> (8 * 2)) & 0xFF;
          *(outbuffer + offset + 3) = (this->data.nsec >> (8 * 3)) & 0xFF;
          offset += sizeof(this->data.nsec);
          return offset;
        }

    这样就明了了, 8个bytes,有4个是小数点之前, 有4个是小数点之后的.

    所以, "xc8x38x67x59x05xb6x2cx37", 其实是:

    0x596738c8   .  xxxx, 放计算器里面一算, 就是1499936968.xxxx不重要了吧...

    这样看来就没有设么问题了吧, 看来学点python不是没有好处.

  • 相关阅读:
    删除查询出以外的数据
    查询头3条
    查询共多少条记录
    Linq查询非泛型集合要指定Student类型(比如List)
    Linq to 泛型集合查询集合包括大写M和年龄小于等于18
    LINQ查询字符串判断是否大写
    LINQ查询数组里面是否包含某值
    Lambda表达式
    构建之法(四)
    构建之法(三)
  • 原文地址:https://www.cnblogs.com/Montauk/p/7161927.html
Copyright © 2011-2022 走看看