main.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. package main
  2. import (
  3. "fmt"
  4. )
  5. type Rule struct {
  6. Name string
  7. DataType string
  8. TopicName string
  9. }
  10. func generateRuleCode(rules []Rule) string {
  11. code := ""
  12. for i, rule := range rules {
  13. ifPart := "if"
  14. if i > 0 {
  15. ifPart = "} else if"
  16. }
  17. code += fmt.Sprintf(`
  18. %s %s == topic2 { // %d
  19. if f, ok1 := rule.(func(data *%s) string); ok1 {
  20. %s = append(%s, f)
  21. goto JudgeDone
  22. }
  23. log(triggerLocalPath)
  24. continue
  25. `, ifPart, rule.TopicName, i+1, rule.DataType, rule.Name, rule.Name)
  26. }
  27. code += "}"
  28. return code
  29. }
  30. func main() {
  31. rules := []Rule{
  32. {"Rule1", "std_msgs.Int16MultiArray", "Topic1"},
  33. {"Rule2", "geometry_msgs.PoseStamped", "Topic2"},
  34. {"Rule3", "dynamic_reconfigure.ConfigDescription", "Topic3"},
  35. {"Rule4", "dynamic_reconfigure.Config", "Topic4"},
  36. {"Rule5", "std_msgs.String", "Topic5"},
  37. {"Rule6", "geometry_msgs.PoseWithCovarianceStamped", "Topic6"},
  38. {"Rule7", "std_msgs.String", "Topic7"},
  39. {"Rule8", "std_msgs.String", "Topic8"},
  40. {"Rule9", "std_msgs.Bool", "Topic9"},
  41. {"Rule10", "std_msgs.Int8", "Topic10"},
  42. {"Rule11", "std_msgs.Int8", "Topic11"},
  43. {"Rule12", "sensor_msgs.PointCloud2", "Topic12"},
  44. {"Rule13", "sensor_msgs.BatteryState", "Topic13"},
  45. {"Rule14", "std_msgs.Int16", "Topic14"},
  46. {"Rule15", "visualization_msgs.Marker", "Topic15"},
  47. {"Rule16", "std_msgs.String", "Topic16"},
  48. {"Rule17", "sensor_msgs.CameraInfo", "Topic17"},
  49. {"Rule18", "sensor_msgs.Image", "Topic18"},
  50. {"Rule19", "sensor_msgs.CompressedImage", "Topic19"},
  51. {"Rule20", "dynamic_reconfigure.ConfigDescription", "Topic20"},
  52. {"Rule21", "dynamic_reconfigure.Config", "Topic21"},
  53. {"Rule22", "sensor_msgs.CompressedImage", "Topic22"},
  54. {"Rule23", "dynamic_reconfigure.ConfigDescription", "Topic23"},
  55. {"Rule24", "dynamic_reconfigure.Config", "Topic24"},
  56. {"Rule25", "theora_image_transport.Packet", "Topic25"},
  57. {"Rule26", "dynamic_reconfigure.ConfigDescription", "Topic26"},
  58. {"Rule27", "dynamic_reconfigure.Config", "Topic27"},
  59. {"Rule28", "sensor_msgs.PointCloud2", "Topic28"},
  60. {"Rule29", "sensor_msgs.CameraInfo", "Topic29"},
  61. {"Rule30", "sensor_msgs.Image", "Topic30"},
  62. {"Rule31", "sensor_msgs.CompressedImage", "Topic31"},
  63. {"Rule32", "dynamic_reconfigure.ConfigDescription", "Topic32"},
  64. {"Rule33", "dynamic_reconfigure.Config", "Topic33"},
  65. {"Rule34", "sensor_msgs.CompressedImage", "Topic34"},
  66. {"Rule35", "dynamic_reconfigure.ConfigDescription", "Topic35"},
  67. {"Rule36", "dynamic_reconfigure.Config", "Topic36"},
  68. {"Rule37", "theora_image_transport.Packet", "Topic37"},
  69. {"Rule38", "dynamic_reconfigure.ConfigDescription", "Topic38"},
  70. {"Rule39", "dynamic_reconfigure.Config", "Topic39"},
  71. {"Rule40", "geometry_msgs.PoseStamped", "Topic40"},
  72. {"Rule41", "geometry_msgs.PoseStamped", "Topic41"},
  73. {"Rule42", "nav_msgs.Path", "Topic42"},
  74. {"Rule43", "std_msgs.Int8", "Topic43"},
  75. {"Rule44", "std_msgs.Bool", "Topic44"},
  76. {"Rule45", "nav_msgs.Path", "Topic45"},
  77. {"Rule46", "geometry_msgs.PoseStamped", "Topic46"},
  78. {"Rule47", "geometry_msgs.PoseStamped", "Topic47"},
  79. {"Rule48", "geometry_msgs.PoseStamped", "Topic48"},
  80. {"Rule49", "std_msgs.String", "Topic49"},
  81. {"Rule50", "visualization_msgs.MarkerArray", "Topic50"},
  82. {"Rule51", "geometry_msgs.PolygonStamped", "Topic51"},
  83. {"Rule52", "nav_msgs.OccupancyGrid", "Topic52"},
  84. {"Rule53", "nav_msgs.OccupancyGrid", "Topic53"},
  85. {"Rule54", "nav_msgs.OccupancyGrid", "Topic54"},
  86. {"Rule55", "std_msgs.Float32", "Topic55"},
  87. {"Rule56", "std_msgs.Int32", "Topic56"},
  88. {"Rule57", "nav_msgs.Path", "Topic57"},
  89. {"Rule58", "clean_msg.ErrorInfo", "Topic58"},
  90. {"Rule59", "nav_msgs.OccupancyGrid", "Topic59"},
  91. {"Rule60", "nav_msgs.OccupancyGrid", "Topic60"},
  92. {"Rule61", "nav_msgs.OccupancyGrid", "Topic61"},
  93. {"Rule62", "nav_msgs.OccupancyGrid", "Topic62"},
  94. {"Rule63", "nav_msgs.OccupancyGrid", "Topic63"},
  95. {"Rule64", "nav_msgs.OccupancyGrid", "Topic64"},
  96. {"Rule65", "std_msgs.String", "Topic65"},
  97. {"Rule66", "std_msgs.Bool", "Topic66"},
  98. {"Rule67", "std_msgs.Bool", "Topic67"},
  99. {"Rule68", "geometry_msgs.PolygonStamped", "Topic68"},
  100. {"Rule69", "geometry_msgs.PointStamped", "Topic69"},
  101. {"Rule70", "std_msgs.String", "Topic70"},
  102. {"Rule71", "geometry_msgs.Twist", "Topic71"},
  103. {"Rule72", "geometry_msgs.Twist", "Topic72"},
  104. {"Rule73", "nav_msgs.Path", "Topic73"},
  105. {"Rule74", "common_msgs.CreateMapInfo", "Topic74"},
  106. {"Rule75", "geometry_msgs.Twist", "Topic75"},
  107. {"Rule76", "common_msgs.SensorStatus", "Topic76"},
  108. {"Rule77", "geometry_msgs.PoseArray", "Topic77"},
  109. {"Rule78", "nav_msgs.Path", "Topic78"},
  110. {"Rule79", "common_msgs.IdentifierObjsInfo", "Topic79"},
  111. {"Rule80", "common_msgs.McuDiagnostic", "Topic80"},
  112. {"Rule81", "diagnostic_msgs.DiagnosticArray", "Topic81"},
  113. {"Rule82", "std_msgs.Int8", "Topic82"},
  114. {"Rule83", "std_msgs.Int16", "Topic83"},
  115. {"Rule84", "geometry_msgs.Vector3Stamped", "Topic84"},
  116. {"Rule85", "sensor_msgs.LaserScan", "Topic85"},
  117. {"Rule86", "sensor_msgs.PointCloud2", "Topic86"},
  118. {"Rule87", "std_msgs.String", "Topic87"},
  119. {"Rule88", "std_msgs.String", "Topic88"},
  120. {"Rule89", "std_msgs.String", "Topic89"},
  121. {"Rule90", "std_msgs.Int32", "Topic90"},
  122. {"Rule91", "common_msgs.TaskInfo", "Topic91"},
  123. {"Rule92", "common_msgs.MapInfo", "Topic92"},
  124. {"Rule93", "nav_msgs.Path", "Topic93"},
  125. {"Rule94", "common_msgs.VideoStream", "Topic94"},
  126. {"Rule95", "sensor_msgs.PointCloud2", "Topic95"},
  127. {"Rule96", "nav_msgs.Path", "Topic96"},
  128. {"Rule97", "sensor_msgs.PointCloud2", "Topic97"},
  129. {"Rule98", "sensor_msgs.PointCloud2", "Topic98"},
  130. {"Rule99", "sensor_msgs.PointCloud2", "Topic99"},
  131. {"Rule100", "geometry_msgs.PointStamped", "Topic100"},
  132. {"Rule101", "nav_msgs.Path", "Topic101"},
  133. {"Rule102", "geometry_msgs.PoseStamped", "Topic102"},
  134. {"Rule103", "geometry_msgs.PoseWithCovarianceStamped", "Topic103"},
  135. {"Rule104", "geometry_msgs.Pose", "Topic104"},
  136. {"Rule105", "std_msgs.String", "Topic105"},
  137. {"Rule106", "std_msgs.String", "Topic106"},
  138. {"Rule107", "std_msgs.String", "Topic107"},
  139. {"Rule108", "std_msgs.String", "Topic108"},
  140. {"Rule109", "std_msgs.Float64", "Topic109"},
  141. {"Rule110", "std_msgs.String", "Topic110"},
  142. {"Rule111", "std_msgs.String", "Topic111"},
  143. {"Rule112", "sensor_msgs.Imu", "Topic112"},
  144. {"Rule113", "std_msgs.String", "Topic113"},
  145. {"Rule114", "std_msgs.Int8", "Topic114"},
  146. {"Rule115", "std_msgs.Int16", "Topic115"},
  147. {"Rule116", "std_msgs.String", "Topic116"},
  148. {"Rule117", "std_msgs.String", "Topic117"},
  149. {"Rule118", "geometry_msgs.PoseWithCovarianceStamped", "Topic118"},
  150. {"Rule119", "sensor_msgs.JointState", "Topic119"},
  151. {"Rule120", "std_msgs.String", "Topic120"},
  152. {"Rule121", "cartographer_ros_msgs.LandmarkList", "Topic121"},
  153. {"Rule122", "nav_msgs.Odometry", "Topic122"},
  154. {"Rule123", "sensor_msgs.LaserScan", "Topic123"},
  155. {"Rule124", "std_msgs.String", "Topic124"},
  156. {"Rule125", "nav_msgs.Path", "Topic125"},
  157. {"Rule126", "std_msgs.String", "Topic126"},
  158. {"Rule127", "std_msgs.String", "Topic127"},
  159. {"Rule128", "std_msgs.String", "Topic128"},
  160. {"Rule129", "std_msgs.String", "Topic129"},
  161. {"Rule130", "geometry_msgs.PoseWithCovarianceStamped", "Topic130"},
  162. {"Rule131", "std_msgs.String", "Topic131"},
  163. {"Rule132", "std_msgs.String", "Topic132"},
  164. {"Rule133", "common_msgs.LocateInfo", "Topic133"},
  165. {"Rule134", "std_msgs.Bool", "Topic134"},
  166. {"Rule135", "std_msgs.Float64MultiArray", "Topic135"},
  167. {"Rule136", "std_msgs.String", "Topic136"},
  168. {"Rule137", "std_msgs.String", "Topic137"},
  169. {"Rule138", "nav_msgs.OccupancyGrid", "Topic138"},
  170. {"Rule139", "std_msgs.String", "Topic139"},
  171. {"Rule140", "nav_msgs.Path", "Topic140"},
  172. {"Rule141", "std_msgs.String", "Topic141"},
  173. {"Rule142", "std_msgs.String", "Topic142"},
  174. {"Rule143", "nav_msgs.MapMetaData", "Topic143"},
  175. {"Rule144", "nav_msgs.Path", "Topic144"},
  176. {"Rule145", "geometry_msgs.PoseStamped", "Topic145"},
  177. {"Rule146", "nav_msgs.OccupancyGrid", "Topic146"},
  178. {"Rule147", "nav_msgs.OccupancyGrid", "Topic147"},
  179. {"Rule148", "std_msgs.String", "Topic148"},
  180. {"Rule149", "std_msgs.String", "Topic149"},
  181. {"Rule150", "std_msgs.String", "Topic150"},
  182. {"Rule151", "std_msgs.String", "Topic151"},
  183. {"Rule152", "std_msgs.Bool", "Topic152"},
  184. {"Rule153", "sensor_msgs.CameraInfo", "Topic153"},
  185. {"Rule154", "sensor_msgs.Image", "Topic154"},
  186. {"Rule155", "sensor_msgs.CompressedImage", "Topic155"},
  187. {"Rule156", "dynamic_reconfigure.ConfigDescription", "Topic156"},
  188. {"Rule157", "dynamic_reconfigure.Config", "Topic157"},
  189. {"Rule158", "sensor_msgs.CompressedImage", "Topic158"},
  190. {"Rule159", "dynamic_reconfigure.ConfigDescription", "Topic159"},
  191. {"Rule160", "dynamic_reconfigure.Config", "Topic160"},
  192. {"Rule161", "theora_image_transport.Packet", "Topic161"},
  193. {"Rule162", "dynamic_reconfigure.ConfigDescription", "Topic162"},
  194. {"Rule163", "dynamic_reconfigure.Config", "Topic163"},
  195. {"Rule164", "sensor_msgs.CameraInfo", "Topic164"},
  196. {"Rule165", "sensor_msgs.Image", "Topic165"},
  197. {"Rule166", "sensor_msgs.CompressedImage", "Topic166"},
  198. {"Rule167", "dynamic_reconfigure.ConfigDescription", "Topic167"},
  199. {"Rule168", "dynamic_reconfigure.Config", "Topic168"},
  200. {"Rule169", "sensor_msgs.CompressedImage", "Topic169"},
  201. {"Rule170", "dynamic_reconfigure.ConfigDescription", "Topic170"},
  202. {"Rule171", "dynamic_reconfigure.Config", "Topic171"},
  203. {"Rule172", "theora_image_transport.Packet", "Topic172"},
  204. {"Rule173", "dynamic_reconfigure.ConfigDescription", "Topic173"},
  205. {"Rule174", "dynamic_reconfigure.Config", "Topic174"},
  206. {"Rule175", "sensor_msgs.PointCloud2", "Topic175"},
  207. {"Rule176", "sensor_msgs.CameraInfo", "Topic176"},
  208. {"Rule177", "sensor_msgs.Image", "Topic177"},
  209. {"Rule178", "sensor_msgs.CompressedImage", "Topic178"},
  210. {"Rule179", "dynamic_reconfigure.ConfigDescription", "Topic179"},
  211. {"Rule180", "dynamic_reconfigure.Config", "Topic180"},
  212. {"Rule181", "sensor_msgs.CompressedImage", "Topic181"},
  213. {"Rule182", "dynamic_reconfigure.ConfigDescription", "Topic182"},
  214. {"Rule183", "dynamic_reconfigure.Config", "Topic183"},
  215. {"Rule184", "theora_image_transport.Packet", "Topic184"},
  216. {"Rule185", "dynamic_reconfigure.ConfigDescription", "Topic185"},
  217. {"Rule186", "dynamic_reconfigure.Config", "Topic186"},
  218. {"Rule187", "sensor_msgs.CameraInfo", "Topic187"},
  219. {"Rule188", "sensor_msgs.Image", "Topic188"},
  220. {"Rule189", "sensor_msgs.CompressedImage", "Topic189"},
  221. {"Rule190", "dynamic_reconfigure.ConfigDescription", "Topic190"},
  222. {"Rule191", "dynamic_reconfigure.Config", "Topic191"},
  223. {"Rule192", "sensor_msgs.CompressedImage", "Topic192"},
  224. {"Rule193", "dynamic_reconfigure.ConfigDescription", "Topic193"},
  225. {"Rule194", "dynamic_reconfigure.Config", "Topic194"},
  226. {"Rule195", "theora_image_transport.Packet", "Topic195"},
  227. {"Rule196", "dynamic_reconfigure.ConfigDescription", "Topic196"},
  228. {"Rule197", "dynamic_reconfigure.Config", "Topic197"},
  229. {"Rule198", "sensor_msgs.PointCloud2", "Topic198"},
  230. {"Rule199", "geometry_msgs.PoseStamped", "Topic199"},
  231. {"Rule200", "geometry_msgs.PoseStamped", "Topic200"},
  232. {"Rule201", "std_msgs.UInt8", "Topic201"},
  233. {"Rule202", "nav_msgs.Odometry", "Topic202"},
  234. {"Rule203", "std_msgs.String", "Topic203"},
  235. {"Rule204", "std_msgs.String", "Topic204"},
  236. {"Rule205", "nav_msgs.Odometry", "Topic205"},
  237. {"Rule206", "sensor_msgs.Imu", "Topic206"},
  238. {"Rule207", "sensor_msgs.PointCloud2", "Topic207"},
  239. {"Rule208", "geometry_msgs.PoseArray", "Topic208"},
  240. {"Rule209", "sensor_msgs.PointCloud2", "Topic209"},
  241. {"Rule210", "sensor_msgs.LaserScan", "Topic210"},
  242. {"Rule211", "geometry_msgs.PoseWithCovarianceStamped", "Topic211"},
  243. {"Rule212", "geometry_msgs.Vector3Stamped", "Topic212"},
  244. {"Rule213", "std_msgs.String", "Topic213"},
  245. {"Rule214", "common_msgs.FunctionAreas", "Topic214"},
  246. {"Rule215", "std_msgs.Bool", "Topic215"},
  247. {"Rule216", "nav_msgs.Path", "Topic216"},
  248. {"Rule217", "std_msgs.Float64MultiArray", "Topic217"},
  249. {"Rule218", "std_msgs.String", "Topic218"},
  250. {"Rule219", "std_msgs.String", "Topic219"},
  251. {"Rule220", "std_msgs.String", "Topic220"},
  252. {"Rule221", "geometry_msgs.PoseStamped", "Topic221"},
  253. {"Rule222", "geometry_msgs.PoseWithCovarianceStamped", "Topic222"},
  254. {"Rule223", "std_msgs.String", "Topic223"},
  255. {"Rule224", "std_msgs.String", "Topic224"},
  256. {"Rule225", "localization_monitor.RobotStatus", "Topic225"},
  257. {"Rule226", "std_msgs.Float64MultiArray", "Topic226"},
  258. {"Rule227", "std_msgs.String", "Topic227"},
  259. {"Rule228", "actionlib_msgs.GoalID", "Topic228"},
  260. {"Rule229", "ipa_building_msgs.MapSegmentationActionFeedback", "Topic229"},
  261. {"Rule230", "ipa_building_msgs.MapSegmentationActionGoal", "Topic230"},
  262. {"Rule231", "dynamic_reconfigure.ConfigDescription", "Topic231"},
  263. {"Rule232", "dynamic_reconfigure.Config", "Topic232"},
  264. {"Rule233", "ipa_building_msgs.MapSegmentationActionResult", "Topic233"},
  265. {"Rule234", "nav_msgs.OccupancyGrid", "Topic234"},
  266. {"Rule235", "actionlib_msgs.GoalStatusArray", "Topic235"},
  267. {"Rule236", "rosgraph_msgs.Log", "Topic236"},
  268. {"Rule237", "rosgraph_msgs.Log", "Topic237"},
  269. {"Rule238", "nav_msgs.Path", "Topic238"},
  270. {"Rule239", "geometry_msgs.Vector3Stamped", "Topic239"},
  271. {"Rule240", "sensor_msgs.LaserScan", "Topic240"},
  272. {"Rule241", "sensor_msgs.LaserScan", "Topic241"},
  273. {"Rule242", "sensor_msgs.LaserScan", "Topic242"},
  274. {"Rule243", "sensor_msgs.LaserScan", "Topic243"},
  275. {"Rule244", "sensor_msgs.LaserScan", "Topic244"},
  276. {"Rule245", "sensor_msgs.PointCloud2", "Topic245"},
  277. {"Rule246", "sensor_msgs.PointCloud2", "Topic246"},
  278. {"Rule247", "visualization_msgs.MarkerArray", "Topic247"},
  279. {"Rule248", "common_msgs.SensorTask", "Topic248"},
  280. {"Rule249", "std_msgs.String", "Topic249"},
  281. {"Rule250", "geometry_msgs.Vector3Stamped", "Topic250"},
  282. {"Rule251", "common_msgs.SonarList", "Topic251"},
  283. {"Rule252", "nav_msgs.Odometry", "Topic252"},
  284. {"Rule253", "sensor_msgs.LaserScan", "Topic253"},
  285. {"Rule254", "std_msgs.Bool", "Topic254"},
  286. {"Rule255", "sensor_msgs.LaserScan", "Topic255"},
  287. {"Rule256", "std_msgs.String", "Topic256"},
  288. {"Rule257", "std_msgs.Bool", "Topic257"},
  289. {"Rule258", "sensor_msgs.CameraInfo", "Topic258"},
  290. {"Rule259", "common_msgs.SysInfo", "Topic259"},
  291. {"Rule260", "sensor_msgs.Image", "Topic260"},
  292. {"Rule261", "sensor_msgs.CompressedImage", "Topic261"},
  293. {"Rule262", "dynamic_reconfigure.ConfigDescription", "Topic262"},
  294. {"Rule263", "dynamic_reconfigure.Config", "Topic263"},
  295. {"Rule264", "sensor_msgs.CompressedImage", "Topic264"},
  296. {"Rule265", "dynamic_reconfigure.ConfigDescription", "Topic265"},
  297. {"Rule266", "dynamic_reconfigure.Config", "Topic266"},
  298. {"Rule267", "theora_image_transport.Packet", "Topic267"},
  299. {"Rule268", "dynamic_reconfigure.ConfigDescription", "Topic268"},
  300. {"Rule269", "dynamic_reconfigure.Config", "Topic269"},
  301. {"Rule270", "std_msgs.Bool", "Topic270"},
  302. {"Rule271", "geometry_msgs.PoseStamped", "Topic271"},
  303. {"Rule272", "geometry_msgs.Vector3Stamped", "Topic272"},
  304. {"Rule273", "common_msgs.TaskFeedbackInfo", "Topic273"},
  305. {"Rule274", "common_msgs.Points", "Topic274"},
  306. {"Rule275", "tf2_msgs.TFMessage", "Topic275"},
  307. {"Rule276", "std_msgs.String", "Topic276"},
  308. {"Rule277", "tf2_msgs.TFMessage", "Topic277"},
  309. {"Rule278", "nav_msgs.Path", "Topic278"},
  310. {"Rule279", "common_msgs.UpLoadFileList", "Topic279"},
  311. {"Rule280", "sensor_msgs.Range", "Topic280"},
  312. {"Rule281", "sensor_msgs.LaserScan", "Topic281"},
  313. {"Rule282", "sensor_msgs.LaserScan", "Topic282"},
  314. {"Rule283", "sensor_msgs.LaserScan", "Topic283"},
  315. {"Rule284", "sensor_msgs.LaserScan", "Topic284"},
  316. }
  317. code := generateRuleCode(rules)
  318. fmt.Println(code)
  319. }