• 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不是没有好处.

  • 相关阅读:
    java中的变量
    小程序获取设备信息
    小游戏学习1
    live-server
    Babel安装在本地并用webstrom由ES6转Es5
    测试目录
    使用Java模拟一个简单的Dos学生成绩管理系统:
    RabbitMQ——开源稳定的消息队列
    wpf读写app.config中的数据
    C# Arc Gis实例教程——网络链接
  • 原文地址:https://www.cnblogs.com/Montauk/p/7161927.html
Copyright © 2020-2023  润新知