hs3000.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. from hub import methods, Global
  2. async def code_3001(**sources):
  3. """
  4. 任务列表数据获取接口(分页)
  5. """
  6. # --- check ---
  7. if not sources.get('page'):
  8. return dict(code=1, detail=f"something is wrong.")
  9. elif not sources.get('size'):
  10. return dict(code=2, detail=f"something is wrong.")
  11. # --- fill d1 ---
  12. d1 = list()
  13. page = sources.get('page')
  14. size = sources.get('size')
  15. for item in Global.mdb.get_all('VehicleTaskList'):
  16. item['uuid'] = str(item.get('_id'))
  17. item.pop('_id')
  18. d1.append(item)
  19. return dict(code=0, data=d1[(page - 1) * size: page * size], total=len(d1), page=page, size=size)
  20. async def code_3002(**sources):
  21. """
  22. 任务暂停接口
  23. """
  24. return dict(code=0, data=sources.get('uuid'))
  25. async def code_3003(**sources):
  26. """
  27. 任务取消接口
  28. """
  29. return dict(code=0, data=sources.get('uuid'))
  30. async def code_3004(**sources):
  31. """
  32. 任务创建并执行
  33. 渣罐位:
  34. X排.X位: 渣罐X排X位
  35. 接渣口:
  36. dump.MN: 接渣口7
  37. dump.KL: 接渣口6
  38. dump.IJ: 接渣口5
  39. dump.GH: 接渣口4
  40. dump.EF: 接渣口3
  41. dump.CD: 接渣口2
  42. dump.AB: 接渣口1
  43. 接渣口:
  44. load.1
  45. load.2
  46. load.3
  47. """
  48. # --- check ---
  49. if not sources.get('uuid'):
  50. return dict(code=1, detail=f"Reason: 参数缺失")
  51. elif not sources.get('task_type'):
  52. return dict(code=2, detail=f"Reason: 参数缺失")
  53. elif not sources.get('target_point_name'):
  54. return dict(code=3, detail=f"Reason: 参数缺失")
  55. # --- check ---
  56. item = Global.mdb.get_one_by_id('VehicleInfo', sources.get('uuid'))
  57. if not item:
  58. return dict(code=4, detail=f"Reason: 查询为空")
  59. # --- check ---
  60. # if not item.get('current_vehicle_direction'):
  61. # return dict(code=5, detail=f"Reason: 参数缺失")
  62. # --- check ---
  63. # if not item.get('current_vehicle_direction') in [3, 9, 6, 12]:
  64. # return dict(code=6, detail=f"Reason: 不具备启动条件")
  65. # --- check ---
  66. if not item.get('state') or item.get('state') != 2:
  67. return dict(code=7, detail=f"Reason: 状态错误")
  68. # --- get navigation ---
  69. from unit.Scheduler_d1 import test
  70. navigation = test(current_direction_type=item.get('current_vehicle_direction'),
  71. start_x=item.get('coordinate_x'),
  72. start_y=item.get('coordinate_y'),
  73. target_point_name=sources.get('target_point_name'))
  74. # --- send --- todo 拼接数据,发送给车端
  75. methods.debug_log('hs3000.code_3004.86:', f"#navigation: {navigation}")
  76. # Global.http_api.cmd1001(address=item.get('address'), navigation=navigation)
  77. # --- save ---
  78. """
  79. VehicleTaskList: 渣包车自动驾驶任务信息表
  80. VehicleTaskList.uuid: 任务id
  81. VehicleTaskList.vehicle_uuid: 车辆id
  82. VehicleTaskList.task_type: 任务类型 101 自动驾驶 102 叉包 103 放包 104 倒渣
  83. VehicleTaskList.target_point_name: 目标点名称
  84. VehicleTaskList.task_state: 任务状态 1 已经下发 2 已完成 3 中止 4 失败
  85. VehicleTaskList.create_at: 创建时间
  86. """
  87. data = {
  88. 'vehicle_uuid': sources.get('uuid'),
  89. 'task_type': sources.get('task_type'),
  90. 'target_point_name': sources.get('target_point_name'),
  91. 'task_state': 1, # 任务状态 1 已经下发 2 已完成 3 中止 4 失败
  92. 'create_at': methods.now_ts(),
  93. }
  94. uuid = Global.mdb.add('VehicleTaskList', data)
  95. return dict(code=0, data=uuid)
  96. async def code_3005(**sources):
  97. """
  98. 获取指定任务信息
  99. """
  100. uuid = sources.get('uuid')
  101. if not uuid:
  102. return dict(code=1, detail=f"Reason: 参数缺失")
  103. item = Global.mdb.get_one_by_id('VehicleTaskList', uuid)
  104. if not item:
  105. return dict(code=2, detail=f"Reason: 查无数据")
  106. # --- check ---
  107. vehicle_uuid = item.get('vehicle_uuid')
  108. vehicle = Global.mdb.get_one_by_id('VehicleInfo', vehicle_uuid)
  109. if not vehicle:
  110. return dict(code=3, detail=f"Reason: 查无数据")
  111. # --- check ---
  112. state = vehicle.get('state')
  113. if not state:
  114. return dict(code=4, detail=f"Reason: 参数缺失")
  115. # --- check --- todo 需要改成socket通信方式,接收车端消息来更新任务状态
  116. """
  117. VehicleTaskList: 渣包车自动驾驶任务信息表
  118. VehicleTaskList.uuid: 任务id
  119. VehicleTaskList.vehicle_uuid: 车辆id
  120. VehicleTaskList.task_type: 任务类型 101 自动驾驶 102 叉包 103 放包 104 倒渣
  121. VehicleTaskList.target_point_name: 目标点名称
  122. VehicleTaskList.task_state: 任务状态 1 已经下发 2 已完成 3 中止 4 失败
  123. VehicleTaskList.create_at: 创建时间
  124. """
  125. if state == 2:
  126. Global.mdb.update_one_by_id('VehicleTaskList', uuid, {'task_state': 2})
  127. # --- fill ---
  128. item.pop('_id')
  129. item['uuid'] = uuid
  130. item['task_state'] = 2
  131. return dict(code=0, data=item)