for_competition.go 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package svc
  2. import (
  3. commonConfig "cicv-data-closedloop/aarch64/pjisuv/common/config"
  4. "cicv-data-closedloop/common/util"
  5. "strings"
  6. "time"
  7. )
  8. /*
  9. 实车比赛临时使用
  10. */
  11. var (
  12. timeInterval = "5"
  13. dir = "/root/competition"
  14. )
  15. func ForCompetition() {
  16. util.CreateDir(dir)
  17. // 1 打包
  18. var commandArgs = []string{"record", "--split", "--duration=" + timeInterval, "/pji_gps", "/data_read"}
  19. _, _ = util.ExecuteWithEnvAndDirAsync(commonConfig.RosbagEnvs, dir, commonConfig.RosbagPath, commandArgs...)
  20. // 2 扫描目录文件
  21. for {
  22. time.Sleep(time.Duration(2) * time.Second)
  23. files, _ := util.ListAbsolutePathAndSort(dir)
  24. if len(files) >= 2 {
  25. for i := range files {
  26. if i == len(files)-1 { // 最后一个包在录制中,不上传
  27. break
  28. }
  29. bagSlice := strings.Split(files[0], "/")
  30. commonConfig.OssMutex.Lock()
  31. _ = commonConfig.OssBucket.PutObjectFromFile("competition/"+bagSlice[len(bagSlice)-1], files[0])
  32. commonConfig.OssMutex.Unlock()
  33. }
  34. }
  35. }
  36. }