|
@@ -14,35 +14,6 @@ import (
|
|
|
|
|
|
func TestWriteRosBag(t *testing.T) {
|
|
|
|
|
|
- // create a node and connect to the master
|
|
|
- n, err := goroslib.NewNode(goroslib.NodeConf{
|
|
|
- Name: "goroslib_sub",
|
|
|
- MasterAddress: "127.0.0.1:11311",
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- defer n.Close()
|
|
|
-
|
|
|
- // create a subscriber
|
|
|
- sub, err := goroslib.NewSubscriber(goroslib.SubscriberConf{
|
|
|
- Node: n,
|
|
|
- Topic: "test_topic",
|
|
|
- Callback: func(msg *pjisuv_msgs.PerceptionLocalization) {
|
|
|
- log.Printf("Incoming: %+v\n", msg)
|
|
|
- },
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- defer sub.Close()
|
|
|
-
|
|
|
- // // wait for CTRL-C
|
|
|
- // c := make(chan os.Signal, 1)
|
|
|
- // signal.Notify(c, os.Interrupt)
|
|
|
- // <-c
|
|
|
- // ------------------------------------------------------------------------------------
|
|
|
-
|
|
|
// 指定文件路径
|
|
|
filePath := "C:\\Users\\mlxengingin\\Desktop\\1118\\my-bag.bag"
|
|
|
|
|
@@ -68,8 +39,8 @@ func TestWriteRosBag(t *testing.T) {
|
|
|
Data: rosbag.ConnectionHeader{
|
|
|
Topic: "/cicv_location",
|
|
|
Type: "perception_msgs/PerceptionLocalization",
|
|
|
- MD5Sum: "abc",
|
|
|
- MessageDefinition: []byte{0x01, 0x02, 0x03},
|
|
|
+ MD5Sum: "b871ae769d4b537baab00d1c75ff3891",
|
|
|
+ MessageDefinition: []byte("定位信息"),
|
|
|
|
|
|
//// optional fields
|
|
|
//CallerID: &callerID,
|
|
@@ -79,20 +50,47 @@ func TestWriteRosBag(t *testing.T) {
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
+ // -------------------------------------------------------------------------------------
|
|
|
|
|
|
- for i := 0; i < 10000; i++ {
|
|
|
- nowInt := time.Now().Unix()
|
|
|
- data := pjisuv_msgs.PerceptionLocalization{}
|
|
|
- err = writer.WriteMessage(&rosbag.Message{
|
|
|
- Conn: 1,
|
|
|
- Time: uint64(nowInt),
|
|
|
- Data: []byte(data),
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- t.Log("当前时间", uint64(nowInt))
|
|
|
- t.Log("保存数据", data)
|
|
|
+ // create a node and connect to the master
|
|
|
+ n, err := goroslib.NewNode(goroslib.NodeConf{
|
|
|
+ Name: "goroslib_sub",
|
|
|
+ MasterAddress: "127.0.0.1:11311",
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
}
|
|
|
+ defer n.Close()
|
|
|
+
|
|
|
+ // create a subscriber
|
|
|
+ sub, err := goroslib.NewSubscriber(goroslib.SubscriberConf{
|
|
|
+ Node: n,
|
|
|
+ Topic: "/cicv_location",
|
|
|
+ Callback: func(msg *pjisuv_msgs.PerceptionLocalization) {
|
|
|
+ log.Printf("Incoming: %+v\n", msg)
|
|
|
+ nowInt := time.Now().Unix()
|
|
|
+ data := pjisuv_msgs.PerceptionLocalization{}
|
|
|
+ err = writer.WriteMessage(&rosbag.Message{
|
|
|
+ Conn: 1,
|
|
|
+ Time: uint64(nowInt),
|
|
|
+ Data: []byte(msg),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ t.Log("当前时间", uint64(nowInt))
|
|
|
+ t.Log("保存数据", data)
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ defer sub.Close()
|
|
|
+
|
|
|
+ // // wait for CTRL-C
|
|
|
+ // c := make(chan os.Signal, 1)
|
|
|
+ // signal.Notify(c, os.Interrupt)
|
|
|
+ // <-c
|
|
|
+ // ------------------------------------------------------------------------------------
|
|
|
|
|
|
}
|