appmodel.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  1. #include "appmodel.h"
  2. #include "Ego.h"
  3. #define WIN23_LEAN_AND_MEAN
  4. #include <Windows.h>
  5. #include <QJsonObject>
  6. //#include "FishEyeWindow.h"
  7. // extern std::array<IRender *, 3> ar;
  8. std::atomic<int> g_iForwordState = 0;
  9. CarData::CarData(QObject *parent) : QObject(parent) {}
  10. CarData::CarData(const CarData &other)
  11. : QObject(nullptr), m_uid(other.m_uid), m_name(other.m_name),
  12. m_type(other.m_type), m_state(other.m_state) {}
  13. int32_t CarData::uid() const { return m_uid; }
  14. QString CarData::name() const { return m_name; }
  15. QString CarData::type() const { return m_type; }
  16. QString CarData::state() const { return m_state; }
  17. void CarData::setUid(const int32_t &value) {
  18. m_uid = value;
  19. emit dataChanged();
  20. }
  21. void CarData::setCarType(const int32_t& value)
  22. {
  23. m_carType = value;
  24. }
  25. void CarData::setName(const QString &value) {
  26. m_name = value;
  27. emit dataChanged();
  28. }
  29. void CarData::setState(const QString &value) {
  30. m_state = value;
  31. emit dataChanged();
  32. }
  33. void CarData::setType(const QString &value) {
  34. m_type = value;
  35. emit dataChanged();
  36. }
  37. /*
  38. car 用于存储实际的数据,而 carProp 则用于将 car 列表属性暴露给 QML 引擎。
  39. 通过这样的方式,可以在 C++ 代码中维护数据,同时在 QML 中直接访问和操作这些数据,而不需要直接暴露内部实现细节
  40. */
  41. class AppModelPrivate {
  42. public:
  43. QList<CarData *> car;
  44. QQmlListProperty<CarData> *carProp = nullptr;
  45. };
  46. //向car列表中添加元素
  47. static void carAppend(QQmlListProperty<CarData> *prop, CarData *val) {
  48. Q_UNUSED(val);
  49. Q_UNUSED(prop);
  50. }
  51. //获取指定索引处的 CarData 对象指针
  52. static CarData *carAt(QQmlListProperty<CarData> *prop, qsizetype index) {
  53. AppModelPrivate *d = static_cast<AppModelPrivate *>(prop->data);
  54. return d->car.at(index);
  55. }
  56. //获取 car 列表中元素的数量
  57. static qsizetype carCount(QQmlListProperty<CarData> *prop) {
  58. AppModelPrivate *d = static_cast<AppModelPrivate *>(prop->data);
  59. return d->car.size();
  60. }
  61. //清空 car 列表中的所有元素
  62. static void carClear(QQmlListProperty<CarData> *prop) {
  63. static_cast<AppModelPrivate *>(prop->data)->car.clear();
  64. }
  65. AppModel::AppModel(IEgoNotify *n, IEgoControl *c, QObject* qmlobj, QObject *parent)
  66. : _notify(n), _control(c), QObject(parent), d(new AppModelPrivate),m_peer(-1),m_qmlObj(qmlobj) {
  67. m_account = QString::fromStdString(_control->GetAccount());
  68. m_password = QString::fromStdString(_control->GetPassword());
  69. m_driveName = QString::fromStdString(_control->GetName());
  70. d->carProp = new QQmlListProperty<CarData>(this, d, carAppend, carCount,
  71. carAt, carClear);
  72. m_ready = false;
  73. // _window = std::make_unique<CFishEyeWindow>();
  74. //_window->Start("192.168.1.64");
  75. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoLoginResult(bool)), this,
  76. SLOT(onLoginRst(bool)));
  77. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoGearChanged(int)), this,
  78. SLOT(egoGearChanged(int))); /** 换挡操作 */
  79. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoGear_DChanged(int)), this,
  80. SLOT(egoGear_DChanged(int))); /** 升降换挡操作 */
  81. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoDirectionLightChanged(int)), this,
  82. SLOT(egoDirectionLightChanged(int))); /** 转向灯 */
  83. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoWiperChanged(bool)), this,
  84. SLOT(egoWiperChanged(bool))); /** 雨刮器 */
  85. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoFrontLightChanged(bool)), this,
  86. SLOT(egoFrontLightChanged(bool))); /** 前车灯 */
  87. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoBackLightChanged(bool)), this,
  88. SLOT(egoBackLightChanged(bool))); /** 后车灯 */
  89. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoBuzzerChanged(bool)), this,
  90. SLOT(egoBuzzerChanged(bool))); /** 喇叭 */
  91. //connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoEmergencyChanged(bool)), this,
  92. // SLOT(egoEmergencyChanged(bool))); /** 急停开关按下 */
  93. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoCautionLightChanged(bool)), this,
  94. SLOT(egoCautionLightChanged(bool)));
  95. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoLightLChanged(bool)), this,
  96. SLOT(egoLightLChanged(bool)));
  97. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoLightRChanged(bool)), this,
  98. SLOT(egoLightRChanged(bool)));
  99. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoGearFChanged(bool)), this,
  100. SLOT(egoGearFChanged(bool)));
  101. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoGearRChanged(bool)), this,
  102. SLOT(egoGearRChanged(bool)));
  103. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoCarParkChanged(bool)), this,
  104. SLOT(egoCarParkChanged(bool)));
  105. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoBuzzerPlayChanged(bool)), this,
  106. SLOT(egoBuzzerPlayChanged(bool)));
  107. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoLightFrontChanged(bool)), this,
  108. SLOT(egoLightFrontChanged(bool)));
  109. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoLightWorkChanged(bool)), this,
  110. SLOT(egoLightWorkChanged(bool)));
  111. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoEmergencyChanged(bool)), this,
  112. SLOT(egoEmergencyChanged(bool)));
  113. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoMqttChanged(cannet_frame)), this,
  114. SLOT(egoMqttChanged(cannet_frame)));
  115. //链接Ego中的egoCarAppend信号和onCarAppend槽,传递参数
  116. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoCarAppend(UserCamera)),
  117. this, SLOT(onCarAppend(UserCamera)));
  118. connect(
  119. dynamic_cast<QObject *>(_notify),
  120. SIGNAL(egoRadar(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)),
  121. this,
  122. SLOT(
  123. onRadarUpadte(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t,int32_t)));
  124. //传递CHANNEL_IMU通道数据到Qt前端
  125. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoImu(float, float)), this,
  126. SLOT(onImuUpdate(float, float)));
  127. connect(
  128. dynamic_cast<QObject*>(_notify),
  129. SIGNAL(egoEncode(int32_t, int32_t)),
  130. this,
  131. SLOT(
  132. onEncodeUpdate(int32_t, int32_t)));
  133. connect(dynamic_cast<QObject*>(_notify),
  134. SIGNAL(egoFeedData(const FeedData&)),
  135. this,
  136. SLOT(onFeedData(const FeedData&)));
  137. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoPing(int32_t,double)), this,
  138. SLOT(onPing(int32_t,double)));
  139. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoPosition(float, float, float)), this,
  140. SLOT(OnPosition(float, float, float)));
  141. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyLeave(int32_t)), this,
  142. SLOT(onNotifyLeave(int32_t)));
  143. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyFail(int32_t)), this,
  144. SLOT(onNotifyFail(int32_t)));
  145. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoNotifyDel(int32_t)), this,
  146. SLOT(onNotifyDel(int32_t)));
  147. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoKickoff()), this,
  148. SLOT(onKickoff()));
  149. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoMoveEnd(int32_t, WorkArea , int32_t)), this,
  150. SLOT(onMoveEnd(int32_t, WorkArea, int32_t)));
  151. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoMoveRet(MoveDesc)), this,
  152. SLOT(onMoveRet(MoveDesc)));
  153. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyState(int32_t, UserState)), this,
  154. SLOT(onNotifyState(int32_t, UserState)));
  155. // connect(dynamic_cast<QObject *>(_notify),SIGNAL(ego)
  156. }
  157. AppModel::~AppModel() {
  158. if (d->carProp)
  159. delete d->carProp;
  160. if (d)
  161. delete d;
  162. }
  163. int AppModel::BrakePressure() const { return m_brake_pressure; }
  164. int AppModel::GearboxOilPressure()const { return m_gearbox_oil_pressure; }
  165. int AppModel::GearboxOilTemp() const { return m_gearbox_oil_temp; }
  166. int AppModel::EnginRpm()const { return m_engine_rpm; }
  167. int AppModel::Speed() const { return m_speed; }
  168. bool AppModel::Visible() const { return m_visible; }
  169. //int AppModel::Gear() const { return m_gear; }
  170. int AppModel::Cold() const { return m_cold_water; }
  171. //int AppModel::ModelX() const { return m_modelx; }
  172. //int AppModel::ModelY() const { return m_modely; }
  173. //int AppModel::ModelZ() const { return m_modelz; }
  174. int32_t AppModel::leftAngle() const { return m_leftAngle; }
  175. int32_t AppModel::rightAngle() const { return m_rightAngle; }
  176. int AppModel::EngineOilPressure() const { return m_engine_oil_pressure; }
  177. bool AppModel::ready() const
  178. {
  179. return m_ready;
  180. }
  181. QString AppModel::Account() const { return m_account; }
  182. QString AppModel::Password() const { return m_password; }
  183. QString AppModel::CarName() const { return m_carName; }
  184. QString AppModel::DriveName() const { return m_driveName; }
  185. int32_t AppModel::WorkPressure() const { return m_work_pressure; }
  186. int AppModel::radar1() const { return m_radar1; }
  187. int AppModel::radar2() const { return m_radar2; }
  188. int AppModel::radar3() const { return m_radar3; }
  189. int AppModel::radar4() const { return m_radar4; }
  190. int AppModel::radar5() const { return m_radar5; }
  191. int AppModel::radar6() const { return m_radar6; }
  192. int AppModel::radar7() const { return m_radar7; }
  193. int AppModel::radar8() const { return m_radar8; }
  194. int32_t AppModel::OilPos() const { return m_oil_pos; }
  195. int AppModel::ping() const { return m_ping; }
  196. double AppModel::temp() const { return m_temp; }
  197. float AppModel::imux() const { return int(m_imux); }
  198. float AppModel::imuy() const { return int(m_imuy); }
  199. int AppModel::alertSound() const { return m_alert; }
  200. bool AppModel::cautionLight() const { return m_cautionLight; }
  201. bool AppModel::lightL() const { return m_lightL; }
  202. bool AppModel::lightR() const { return m_lightR; }
  203. bool AppModel::gearF() const { return m_gearF; }
  204. bool AppModel::gearR() const { return m_gearR; }
  205. bool AppModel::carPark() const { return m_carPark; }
  206. bool AppModel::buzzerPlay() const { return m_buzzerPlay; }
  207. bool AppModel::lightFront() const { return m_lightFront; }
  208. bool AppModel::lightWork() const { return m_lightWork; }
  209. bool AppModel::emergency1() const { return m_emergency; }
  210. int AppModel::engineSpeed() const { return m_engineSpeed; }
  211. int AppModel::travelSpeed() const { return m_travelSpeed; }
  212. int AppModel::fuelLevel() const { return m_fuelLevel; }
  213. int AppModel::engineTemperature() const { return m_engineTemperature; }
  214. int AppModel::hydraulicOilTemperature() const { return m_hydraulicOilTemperature; }
  215. int AppModel::mainPump1Pressure() const { return m_mainPump1Pressure; }
  216. int AppModel::mainPump2Pressure() const { return m_mainPump2Pressure; }
  217. int AppModel::handGear() const { return m_handGear; }
  218. int AppModel::actualGear() const { return m_actualGear; }
  219. float AppModel::gripperHeight() const { return m_gripperHeight; }
  220. float AppModel::amplitude1() const { return m_amplitude; }
  221. int64_t AppModel::boomAngle() const { return m_boomAngle; }
  222. int64_t AppModel::stickAngle() const { return m_stickAngle; }
  223. bool AppModel::idleProtection() const { return m_idleProtection; }
  224. bool AppModel::frontToggle() const { return m_frontToggle; }
  225. bool AppModel::backToggle() const { return m_backToggle; }
  226. int AppModel::interLock() const { return m_interLock; }
  227. int AppModel::safetySwitch() const { return m_safetySwitch; }
  228. int AppModel::armLiftPilot() const { return m_armLiftPilot; }
  229. int AppModel::armLoweringPilot() const { return m_armLoweringPilot; }
  230. int AppModel::leverLiftingLilot() const { return m_leverLiftingLilot; }
  231. int AppModel::rodLoweringPilot() const { return m_rodLoweringPilot; }
  232. int AppModel::leftRotaryPilot() const { return m_leftRotaryPilot; }
  233. int AppModel::rightRotaryPilot() const { return m_rightRotaryPilot; }
  234. int AppModel::grabOpenPilot() const { return m_grabOpenPilot; }
  235. int AppModel::grabClosePilot() const { return m_grabClosePilot; }
  236. int AppModel::safetyValves() const { return m_safetyValves; }
  237. bool AppModel::liftPilotPressureSensor_F() const { return m_liftPilotPressureSensor_F; }
  238. bool AppModel::loweringPilotPressureSensor_F() const { return m_loweringPilotPressureSensor_F; }
  239. bool AppModel::leverLiftPilotPressureSensor_F() const { return m_leverLiftPilotPressureSensor_F; }
  240. bool AppModel::rodLoweringPilotPressurePensor_F() const { return m_rodLoweringPilotPressurePensor_F; }
  241. bool AppModel::leftTurnPilotPressureSensor_F() const { return m_leftTurnPilotPressureSensor_F; }
  242. bool AppModel::rightTurnPilotPressureSensor_F() const { return m_rightTurnPilotPressureSensor_F; }
  243. bool AppModel::legExtensionPilotPressureSensor_F() const { return m_legExtensionPilotPressureSensor_F; }
  244. bool AppModel::legRetractPilotPressureSensor_F() const { return m_legRetractPilotPressureSensor_F; }
  245. bool AppModel::grabOpenPilotPressureSensor_F() const { return m_grabOpenPilotPressureSensor_F; }
  246. bool AppModel::grabClosurePilotPressureSensor_F() const { return m_grabClosurePilotPressureSensor_F; }
  247. bool AppModel::mainPump1PressureSensor_F() const { return m_mainPump1PressureSensor_F; }
  248. bool AppModel::mainPump2PressureSensor_F() const { return m_mainPump2PressureSensor_F; }
  249. bool AppModel::chamberPressureSensor_F() const { return m_chamberPressureSensor_F; }
  250. bool AppModel::bucketRodPressureSensor_F() const { return m_bucketRodPressureSensor_F; }
  251. bool AppModel::parkingPressureSensor_F() const { return m_parkingPressureSensor_F; }
  252. bool AppModel::accumulatorPressureSensor_F() const { return m_accumulatorPressureSensor_F; }
  253. bool AppModel::gasPedal_F() const { return m_gasPedal_F; }
  254. bool AppModel::throttleKnob_F() const { return m_throttleKnob_F; }
  255. bool AppModel::legHandle_F() const { return m_legHandle_F; }
  256. bool AppModel::gripKnob_F() const { return m_gripKnob_F; }
  257. bool AppModel::hydraulicOilTemperatureSensor_F() const { return m_hydraulicOilTemperatureSensor_F; }
  258. bool AppModel::fuelLevelSensor_F() const { return m_fuelLevelSensor_F; }
  259. bool AppModel::boomAngleSensor_F() const { return m_boomAngleSensor_F; }
  260. bool AppModel::bucketLeverTiltSensor_F() const { return m_bucketLeverTiltSensor_F; }
  261. bool AppModel::expansionModule_F() const { return m_expansionModule_F; }
  262. bool AppModel::workingDistanceOverrun_F() const { return m_workingDistanceOverrun_F; }
  263. bool AppModel::lowOilLevel_F() const { return m_lowOilLevel_F; }
  264. bool AppModel::batteryLowVoltage_F() const { return m_batteryLowVoltage_F; }
  265. bool AppModel::batteryHighVoltage_F() const { return m_batteryHighVoltage_F; }
  266. bool AppModel::accumulatorPressure_F() const { return m_accumulatorPressure_F; }
  267. bool AppModel::highHydraulicOilTemperature_F() const { return m_highHydraulicOilTemperature_F; }
  268. bool AppModel::lowOilPressure_F() const { return m_lowOilPressure_F; }
  269. bool AppModel::coolantLevelLow_F() const { return m_coolantLevelLow_F; }
  270. bool AppModel::coolantTemperatureHigh_F() const { return m_coolantTemperatureHigh_F; }
  271. bool AppModel::systemOverload_F() const { return m_systemOverload_F; }
  272. bool AppModel::safebypassPressDown_F() const { return m_safebypassPressDown_F; }
  273. bool AppModel::engineSPN_F() const { return m_engineSPN_F; }
  274. bool AppModel::engineWarmUp_F() const { return m_engineWarmUp_F; }
  275. bool AppModel::engineWarmUpTimeout_F() const { return m_engineWarmUpTimeout_F; }
  276. bool AppModel::emergencyStopPress_F() const { return m_emergencyStopPress_F; }
  277. bool AppModel::leftFrontLegChosed() const { return m_leftFrontLegChosed; }
  278. bool AppModel::rightFrontLegChosed() const { return m_rightFrontLegChosed; }
  279. bool AppModel::leftRearLegChosed() const { return m_leftRearLegChosed; }
  280. bool AppModel::rightRearLegChosed() const { return m_rightRearLegChosed; }
  281. void AppModel::setReady(const bool value) {
  282. m_ready = value;
  283. emit readyChanged();
  284. }
  285. void AppModel::SetSpeed(const int32_t value)
  286. {
  287. m_speed = value;
  288. emit speedChanged();
  289. }
  290. void AppModel::SetVisible(const bool value)
  291. {
  292. m_visible = value;
  293. emit visibleChanged();
  294. }
  295. void AppModel::SetCold(const int32_t value)
  296. {
  297. m_cold_water = value;
  298. emit coldChanged();
  299. }
  300. void AppModel::SetGearBoxOilPressure(const int32_t value)
  301. {
  302. m_gearbox_oil_pressure = value;
  303. emit gearboxOilPressureChanged();
  304. }
  305. void AppModel::setAccount(const QString& value)
  306. {
  307. m_account = value;
  308. emit accountChanged();
  309. }
  310. void AppModel::setLeftAngle(const int32_t value)
  311. {
  312. m_leftAngle = value;
  313. emit leftAngleChanged();
  314. }
  315. void AppModel::setRightAngle(const int32_t value)
  316. {
  317. m_rightAngle = value;
  318. emit rightAngleChanged();
  319. }
  320. /*
  321. void AppModel::setModelX(const int32_t value)
  322. {
  323. m_modelx = value;
  324. emit modelXChanged();
  325. }
  326. void AppModel::setModelZ(const int32_t value)
  327. {
  328. m_modelz = value+200;
  329. emit modelZChanged();
  330. }
  331. void AppModel::setModelY(const int32_t value)
  332. {
  333. m_modely = value;
  334. emit modelYChanged();
  335. }
  336. */
  337. void AppModel::setPassword(const QString& password)
  338. {
  339. m_password = password;
  340. emit passwordChanged();
  341. }
  342. void AppModel::setCarName(const QString& carname)
  343. {
  344. m_carName = carname;
  345. emit carNameChanged();
  346. }
  347. void AppModel::setDriveName(const QString& drivename)
  348. {
  349. m_driveName = drivename;
  350. emit driveNameChanged();
  351. }
  352. void AppModel::setWorkPressure(const int32_t value)
  353. {
  354. m_work_pressure = value;
  355. emit workPressureChanged();
  356. }
  357. /*
  358. void AppModel::SetGear(const int32_t value)
  359. {
  360. m_gear = value;
  361. emit gearChanged();
  362. }
  363. */
  364. void AppModel::SetBrakePressure(int32_t value)
  365. {
  366. m_brake_pressure = value;
  367. emit brakePressureChanged();
  368. }
  369. void AppModel::SetOilPos(int32_t value)
  370. {
  371. m_oil_pos = value;
  372. emit oilPosChanged();
  373. }
  374. void AppModel::SetGearBoxOilTemp(const int32_t value)
  375. {
  376. m_gearbox_oil_temp = value;
  377. emit gearboxOilTempChanged();
  378. }
  379. void AppModel::SetEngingRpm(const int32_t value)
  380. {
  381. m_engine_rpm = value;
  382. emit engineRpmChanged();
  383. }
  384. void AppModel::SetEngineOilPressure(const int32_t value)
  385. {
  386. m_engine_oil_pressure = value;
  387. emit engineoilPressureChanged();
  388. }
  389. void AppModel::setForward(const int32_t& value) {
  390. m_forward = value;
  391. g_iForwordState = value;
  392. //m_pQTimer->start(2000);
  393. emit forwardChanged();
  394. // m_pQTimer->start(2000);
  395. //QThread::msleep(500);
  396. // QGuiApplication::processEvents();
  397. // QThread::msleep(100);
  398. // QGuiApplication::processEvents();
  399. }
  400. void AppModel::setBackward(const int32_t& value) {
  401. m_backward = value;
  402. emit backwardChanged();
  403. }
  404. void AppModel::setGear_D(const int32_t& value) {
  405. m_gear_d = value;
  406. emit gear_dChanged();
  407. }
  408. void AppModel::setDirectionLight(const int32_t& value) {
  409. m_light = value;
  410. emit directionlightChanged();
  411. }
  412. void AppModel::setWiper(const bool& value) {
  413. m_wiper = value;
  414. emit wiperChanged();
  415. }
  416. void AppModel::setFrontLight(const bool& value) {
  417. m_frontlight = value;
  418. emit frontlightChanged();
  419. }
  420. void AppModel::setBackLight(const bool& value) {
  421. m_backlight = value;
  422. emit backlightChanged();
  423. }
  424. void AppModel::setBuzzer(const bool& value) {
  425. m_buzzer = value;
  426. emit buzzerChanged();
  427. }
  428. void AppModel::setRadar1(const int32_t &value) {
  429. m_radar1 = value;
  430. emit radar1Changed();
  431. emit setRadar1Play(value);
  432. }
  433. void AppModel::setRadar2(const int32_t &value) {
  434. m_radar2 = value;
  435. emit radar2Changed();
  436. emit setRadar2Play(value);
  437. }
  438. void AppModel::setRadar3(const int32_t &value) {
  439. m_radar3 = value;
  440. emit radar3Changed();
  441. emit setRadar3Play(value);
  442. }
  443. void AppModel::setRadar4(const int32_t &value) {
  444. m_radar4 = value;
  445. emit radar4Changed();
  446. emit setRadar4Play(value);
  447. }
  448. void AppModel::setRadar5(const int32_t &value) {
  449. m_radar5 = value;
  450. emit radar5Changed();
  451. emit setRadar5Play(value);
  452. }
  453. void AppModel::setRadar6(const int32_t& value)
  454. {
  455. m_radar6 = value;
  456. emit radar6Changed();
  457. emit setRadar6Play(value);
  458. }
  459. void AppModel::setRadar7(const int32_t& value)
  460. {
  461. m_radar7 = value;
  462. emit radar7Changed();
  463. emit setRadar7Play(value);
  464. }
  465. void AppModel::setRadar8(const int32_t &value) {
  466. m_radar8 = value;
  467. emit radar8Changed();
  468. emit setRadar8Play(value);
  469. }
  470. void AppModel::setImuy(const float& value) {
  471. m_imuy = value;
  472. emit imuyChanged();
  473. }
  474. void AppModel::setImux(const float& value) {
  475. m_imux = value;
  476. emit imuxChanged();
  477. }
  478. void AppModel::setEngineSpeed(const int32_t& value) {
  479. m_engineSpeed = value;
  480. emit engineSpeedPlay(int(value));
  481. emit engineSpeedChanged();
  482. }
  483. void AppModel::setTravelSpeed(const int32_t& value) {
  484. m_travelSpeed = value;
  485. emit travelSpeedChanged();
  486. }
  487. void AppModel::setFuelLevel(const int32_t& value) {
  488. m_fuelLevel = value;
  489. emit fuelLevelChanged();
  490. }
  491. void AppModel::setEngineTemperature(const int32_t& value) {
  492. m_engineTemperature = value;
  493. emit engineTemperatureChanged();
  494. }
  495. void AppModel::setHydraulicOilTemperature(const int32_t& value) {
  496. m_hydraulicOilTemperature = value;
  497. emit hydraulicOilTemperatureChanged();
  498. }
  499. void AppModel::setMainPump1Pressure(const int32_t& value) {
  500. m_mainPump1Pressure = value;
  501. emit mainPump1PressureChanged();
  502. }
  503. void AppModel::setMainPump2Pressure(const int32_t& value) {
  504. m_mainPump2Pressure = value;
  505. emit mainPump2PressureChanged();
  506. }
  507. void AppModel::setHandGear(const int32_t& value) {
  508. m_handGear = value;
  509. emit handGearChanged();
  510. }
  511. void AppModel::setActualGear(const int32_t& value) {
  512. m_actualGear = value;
  513. emit actualGearChanged();
  514. }
  515. void AppModel::setGripperHeight(const float& value) {
  516. m_gripperHeight = value;
  517. emit gripperHeightChanged();
  518. }
  519. void AppModel::setAmplitude(const float& value) {
  520. m_amplitude = value;
  521. emit amplitudeChanged();
  522. }
  523. void AppModel::setBoomAngle(const int32_t& value) {
  524. m_boomAngle = value;
  525. emit boomAngleChanged();
  526. }
  527. void AppModel::setStickAngle(const int32_t& value) {
  528. m_stickAngle = value;
  529. emit stickAngleChanged();
  530. }
  531. void AppModel::setIdleProtection(const bool& value) {
  532. m_idleProtection = value;
  533. emit idleProtectionChanged();
  534. }
  535. void AppModel::setFrontToggle(const bool& value) {
  536. m_frontToggle = value;
  537. emit frontToggleChanged();
  538. }
  539. void AppModel::setBackToggle(const bool& value) {
  540. m_backToggle = value;
  541. emit backToggleChanged();
  542. }
  543. void AppModel::setInterLock(const int32_t& value) {
  544. m_interLock = value;
  545. emit interLockChanged();
  546. }
  547. void AppModel::setSafetySwitch(const int32_t& value) {
  548. m_safetySwitch = value;
  549. emit safetySwitchChanged();
  550. }
  551. void AppModel::setArmLiftPilot(const int32_t& value) {
  552. m_armLiftPilot = value;
  553. emit armLiftPilotChanged();
  554. }
  555. void AppModel::setArmLoweringPilot(const int32_t& value) {
  556. m_armLoweringPilot = value;
  557. emit armLoweringPilotChanged();
  558. }
  559. void AppModel::setLeverLiftingLilot(const int32_t& value) {
  560. m_leverLiftingLilot = value;
  561. emit leverLiftingLilotChanged();
  562. }
  563. void AppModel::setRodLoweringPilot(const int32_t& value) {
  564. m_rodLoweringPilot = value;
  565. emit rodLoweringPilotChanged();
  566. }
  567. void AppModel::setLeftRotaryPilot(const int32_t& value) {
  568. m_leftRotaryPilot = value;
  569. emit leftRotaryPilotChanged();
  570. }
  571. void AppModel::setRightRotaryPilot(const int32_t& value) {
  572. m_rightRotaryPilot = value;
  573. emit rightRotaryPilotChanged();
  574. }
  575. void AppModel::setGrabOpenPilot(const int32_t& value) {
  576. m_grabOpenPilot = value;
  577. emit grabOpenPilotChanged();
  578. }
  579. void AppModel::setGrabClosePilot(const int32_t& value) {
  580. m_grabClosePilot = value;
  581. emit grabClosePilotChanged();
  582. }
  583. void AppModel::setSafetyValves(const int32_t& value) {
  584. m_safetyValves = value;
  585. emit safetyValvesChanged();
  586. }
  587. //报警信息
  588. void AppModel::setLiftPilotPressureSensor_F(const bool& value) {
  589. m_liftPilotPressureSensor_F = value;
  590. emit liftPilotPressureSensor_FChanged();
  591. }
  592. void AppModel::setLoweringPilotPressureSensor_F(const bool& value) {
  593. m_loweringPilotPressureSensor_F = value;
  594. emit loweringPilotPressureSensor_FChanged();
  595. }
  596. void AppModel::setLeverLiftPilotPressureSensor_F(const bool& value) {
  597. m_leverLiftPilotPressureSensor_F = value;
  598. emit leverLiftPilotPressureSensor_FChanged();
  599. }
  600. void AppModel::setRodLoweringPilotPressurePensor_F(const bool& value) {
  601. m_rodLoweringPilotPressurePensor_F = value;
  602. emit rodLoweringPilotPressurePensor_FChanged();
  603. }
  604. void AppModel::setLeftTurnPilotPressureSensor_F(const bool& value) {
  605. m_leftTurnPilotPressureSensor_F = value;
  606. emit leftTurnPilotPressureSensor_FChanged();
  607. }
  608. void AppModel::setRightTurnPilotPressureSensor_F(const bool& value) {
  609. m_rightTurnPilotPressureSensor_F = value;
  610. emit rightTurnPilotPressureSensor_FChanged();
  611. }
  612. void AppModel::setLegExtensionPilotPressureSensor_F(const bool& value) {
  613. m_legExtensionPilotPressureSensor_F = value;
  614. emit legExtensionPilotPressureSensor_FChanged();
  615. }
  616. void AppModel::setLegRetractPilotPressureSensor_F(const bool& value) {
  617. m_legRetractPilotPressureSensor_F = value;
  618. emit legRetractPilotPressureSensor_FChanged();
  619. }
  620. void AppModel::setGrabOpenPilotPressureSensor_F(const bool& value) {
  621. m_grabOpenPilotPressureSensor_F = value;
  622. emit grabOpenPilotPressureSensor_FChanged();
  623. }
  624. void AppModel::setGrabClosurePilotPressureSensor_F(const bool& value) {
  625. m_grabClosurePilotPressureSensor_F = value;
  626. emit grabClosurePilotPressureSensor_FChanged();
  627. }
  628. void AppModel::setMainPump1PressureSensor_F(const bool& value) {
  629. m_mainPump1PressureSensor_F = value;
  630. emit mainPump1PressureSensor_FChanged();
  631. }
  632. void AppModel::setMainPump2PressureSensor_F(const bool& value) {
  633. m_mainPump2PressureSensor_F = value;
  634. emit mainPump2PressureSensor_FChanged();
  635. }
  636. void AppModel::setChamberPressureSensor_F(const bool& value) {
  637. m_chamberPressureSensor_F = value;
  638. emit chamberPressureSensor_FChanged();
  639. }
  640. void AppModel::setBucketRodPressureSensor_F(const bool& value) {
  641. m_bucketRodPressureSensor_F = value;
  642. emit bucketRodPressureSensor_FChanged();
  643. }
  644. void AppModel::setParkingPressureSensor_F(const bool& value) {
  645. m_parkingPressureSensor_F = value;
  646. emit parkingPressureSensor_FChanged();
  647. }
  648. void AppModel::setAccumulatorPressureSensor_F(const bool& value) {
  649. m_accumulatorPressureSensor_F = value;
  650. emit accumulatorPressureSensor_FChanged();
  651. }
  652. void AppModel::setGasPedal_F(const bool& value) {
  653. m_gasPedal_F = value;
  654. emit gasPedal_FChanged();
  655. }
  656. void AppModel::setThrottleKnob_F(const bool& value) {
  657. m_throttleKnob_F = value;
  658. emit throttleKnob_FChanged();
  659. }
  660. void AppModel::setLegHandle_F(const bool& value) {
  661. m_legHandle_F = value;
  662. emit legHandle_FChanged();
  663. }
  664. void AppModel::setGripKnob_F(const bool& value) {
  665. m_gripKnob_F = value;
  666. emit gripKnob_FChanged();
  667. }
  668. void AppModel::setHydraulicOilTemperatureSensor_F(const bool& value) {
  669. m_hydraulicOilTemperatureSensor_F = value;
  670. emit hydraulicOilTemperatureSensor_FChanged();
  671. }
  672. void AppModel::setFuelLevelSensor_F(const bool& value) {
  673. m_fuelLevelSensor_F = value;
  674. emit fuelLevelSensor_FChanged();
  675. }
  676. void AppModel::setBoomAngleSensor_F(const bool& value) {
  677. m_boomAngleSensor_F = value;
  678. emit boomAngleSensor_FChanged();
  679. }
  680. void AppModel::setBucketLeverTiltSensor_F(const bool& value) {
  681. m_bucketLeverTiltSensor_F = value;
  682. emit bucketLeverTiltSensor_FChanged();
  683. }
  684. void AppModel::setExpansionModule_F(const bool& value) {
  685. m_expansionModule_F = value;
  686. emit expansionModule_FChanged();
  687. }
  688. void AppModel::setWorkingDistanceOverrun_F(const bool& value) {
  689. m_workingDistanceOverrun_F = value;
  690. emit workingDistanceOverrun_FChanged();
  691. }
  692. void AppModel::setLowOilLevel_F(const bool& value) {
  693. m_lowOilLevel_F = value;
  694. emit lowOilLevel_FChanged();
  695. }
  696. void AppModel::setBatteryLowVoltage_F(const bool& value) {
  697. m_batteryLowVoltage_F = value;
  698. emit batteryLowVoltage_FChanged();
  699. }
  700. void AppModel::setBatteryHighVoltage_F(const bool& value) {
  701. m_batteryHighVoltage_F = value;
  702. emit batteryHighVoltage_FChanged();
  703. }
  704. void AppModel::setAccumulatorPressure_F(const bool& value) {
  705. m_accumulatorPressure_F = value;
  706. emit accumulatorPressure_FChanged();
  707. }
  708. void AppModel::setHighHydraulicOilTemperature_F(const bool& value) {
  709. m_highHydraulicOilTemperature_F = value;
  710. emit highHydraulicOilTemperature_FChanged();
  711. }
  712. void AppModel::setLowOilPressure_F(const bool& value) {
  713. m_lowOilPressure_F = value;
  714. emit lowOilPressure_FChanged();
  715. }
  716. void AppModel::setCoolantLevelLow_F(const bool& value) {
  717. m_coolantLevelLow_F = value;
  718. emit coolantLevelLow_FChanged();
  719. }
  720. void AppModel::setCoolantTemperatureHigh_F(const bool& value) {
  721. m_coolantTemperatureHigh_F = value;
  722. emit coolantTemperatureHigh_FChanged();
  723. }
  724. void AppModel::setSystemOverload_F(const bool& value) {
  725. m_systemOverload_F = value;
  726. emit systemOverload_FChanged();
  727. }
  728. void AppModel::setSafebypassPressDown_F(const bool& value) {
  729. m_safebypassPressDown_F = value;
  730. emit safebypassPressDown_FChanged();
  731. }
  732. void AppModel::setEngineSPN_F(const bool& value) {
  733. m_engineSPN_F = value;
  734. emit engineSPN_FChanged();
  735. }
  736. void AppModel::setEngineWarmUp_F(const bool& value) {
  737. m_engineWarmUp_F = value;
  738. emit engineWarmUp_FChanged();
  739. }
  740. void AppModel::setEngineWarmUpTimeout_F(const bool& value) {
  741. m_engineWarmUpTimeout_F = value;
  742. emit engineWarmUpTimeout_FChanged();
  743. }
  744. void AppModel::setEmergencyStopPress_F(const bool& value) {
  745. m_emergencyStopPress_F = value;
  746. emit emergencyStopPress_FChanged();
  747. }
  748. void AppModel::setLeftFrontLegChosed(const bool& value) {
  749. m_leftFrontLegChosed = value;
  750. emit leftFrontLegChosedChanged();
  751. }
  752. void AppModel::setRightFrontLegChosed(const bool& value) {
  753. m_rightFrontLegChosed = value;
  754. emit rightFrontLegChosedChanged();
  755. }
  756. void AppModel::setLeftRearLegChosed(const bool& value) {
  757. m_leftRearLegChosed = value;
  758. emit leftRearLegChosedChanged();
  759. }
  760. void AppModel::setRightRearLegChosed(const bool& value) {
  761. m_rightRearLegChosed = value;
  762. emit rightRearLegChosedChanged();
  763. }
  764. void AppModel::setCautionLight(const bool& value) {
  765. m_cautionLight = value;
  766. emit cautionLightChanged();
  767. }
  768. void AppModel::setLightL(const bool& value) {
  769. m_lightL = value;
  770. emit lightLPlay(value);
  771. emit lightLChanged();
  772. }
  773. void AppModel::setLightR(const bool& value) {
  774. m_lightR = value;
  775. emit lightRPlay(value);
  776. emit lightRChanged();
  777. }
  778. void AppModel::setGearF(const bool& value) {
  779. m_gearF = value;
  780. emit gearFChanged();
  781. }
  782. void AppModel::setGearR(const bool& value) {
  783. m_gearR = value;
  784. emit gearRPlay(value);
  785. emit gearRChanged();
  786. }
  787. void AppModel::setCarPark(const bool& value) {
  788. m_carPark = value;
  789. emit carParkChanged();
  790. }
  791. void AppModel::setBuzzerPlay(const bool& value) {
  792. m_buzzerPlay = value;
  793. emit buzzerPlayIt(value);
  794. emit buzzerPlayChanged();
  795. }
  796. void AppModel::setLightFront(const bool& value) {
  797. m_lightFront = value;
  798. emit lightFrontChanged();
  799. }
  800. void AppModel::setLightWork(const bool& value) {
  801. m_lightWork = value;
  802. emit lightWorkChanged();
  803. }
  804. void AppModel::setEmergency(const bool& value) {
  805. m_emergency = value;
  806. emit emergencyChanged();
  807. }
  808. /*void AppModel::setMqttToSever(cannet_frame* frames)
  809. {
  810. int keyStatus = ((frames[3].data[2] >> 7) & 0x01) * 2 + ((frames[3].data[3] >> 0) & 0x01) * 1;
  811. int gearControl= ((frames[3].data[0] >> 6) & 0x01) * 2 + ((frames[3].data[0] >> 5) & 0x01) * 1;
  812. int travelLight = ((frames[3].data[0] >> 0) & 0x01) * 2 + ((frames[3].data[0] >> 1) & 0x01) * 1;
  813. QString accPedal = QString::fromStdString(std::to_string(frames[0].data[0]) + " AND " + std::to_string(frames[0].data[1]) +
  814. " || " + std::to_string(frames[0].data[2]) + " AND " + std::to_string(frames[0].data[3]));
  815. QString brakePedal = QString::number(frames[0].data[4]) + " AND " +QString::number(frames[0].data[5]);
  816. QString steeringWheel = QString::number(frames[2].data[2]) + " AND " + QString::number(frames[2].data[3]);
  817. int turnSignal= ((frames[3].data[0] >> 4) & 0x01) * 2 + ((frames[3].data[0] >> 3) & 0x01) * 1;
  818. int turnMode = ((frames[3].data[3] >> 6) & 0x01) * 4 + ((frames[3].data[3] >> 5) & 0x01) * 3 +
  819. ((frames[3].data[3] >> 4) & 0x01) * 2 + ((frames[3].data[3] >> 3) & 0x01) * 1;
  820. int workLight = ((frames[3].data[2] >> 5) & 0x01) * 2 + ((frames[3].data[2] >> 4) & 0x01) * 1;
  821. int baseLegSwitch = ((frames[3].data[1] >> 5) & 0x01) * 8 + ((frames[3].data[1] >> 4) & 0x01) * 4 +
  822. ((frames[3].data[1] >> 3) & 0x01) * 2 + ((frames[3].data[1] >> 2) & 0x01) * 1;
  823. QString baseLegControl = QString::number(frames[0].data[6]) + " AND " + QString::number(frames[0].data[7]);
  824. QString taskJoint_1 = QString::number(frames[1].data[0]) + " AND " + QString::number(frames[1].data[1]);
  825. QString taskJoint_2 = QString::number(frames[1].data[6]) + " AND " + QString::number(frames[1].data[7]);
  826. QString taskJoint_3 = QString::number(frames[1].data[2]) + " AND " + QString::number(frames[1].data[3]);
  827. QString endJoint = QString::number(frames[2].data[0]) + " AND " + QString::number(frames[2].data[1]);
  828. QString toolControl = QString::number(frames[1].data[4]) + " AND " + QString::number(frames[1].data[5]);
  829. int cabLift = ((frames[3].data[1] >> 7) & 0x01) * 2 + ((frames[3].data[1] >> 6) & 0x01) * 1;
  830. int coopSignal = ((frames[3].data[4] >> 4) & 0x01) * 2 + ((frames[3].data[4] >> 3) & 0x01) * 1;
  831. int errAccPedal = ((frames[3].data[5] >> 7) & 0x01) * 2 + ((frames[3].data[5] >> 6) & 0x01) * 1;
  832. int errHandle = ((frames[3].data[5] >> 4) & 0x01) * 16+((frames[3].data[5] >> 3) & 0x01) * 8 + ((frames[3].data[5] >> 2) & 0x01) * 4 +
  833. ((frames[3].data[5] >> 1) & 0x01) * 2 + ((frames[3].data[5] >> 0) & 0x01) * 1;
  834. QJsonObject pcanObject;
  835. pcanObject.insert("cockpitID", "Cop001");
  836. pcanObject.insert("userID", "Ego");
  837. pcanObject.insert("vehicleID", "0538");
  838. pcanObject.insert("timeStamp", "11111111111");
  839. QJsonObject basObject;
  840. basObject.insert("keyStatus", keyStatus);
  841. basObject.insert("parkControl", frames[3].data[1] >> 0 & 0x01);
  842. basObject.insert("travelMode", frames[3].data[3] >> 2 & 0x01);
  843. basObject.insert("eStop", frames[3].data[3] >> 1 & 0x01);
  844. basObject.insert("directSwitch", frames[3].data[4] >> 2 & 0x01);
  845. basObject.insert("gearControl", gearControl);
  846. basObject.insert("hazardLight", frames[3].data[0] >> 2 & 0x01);
  847. basObject.insert("travelLight", travelLight);
  848. basObject.insert("vehicleHorn", frames[3].data[1] >> 1 & 0x01);
  849. basObject.insert("silencedAlarm", frames[3].data[2] >> 6 & 0x01);
  850. pcanObject.insert("basControl", basObject);
  851. QJsonObject driveObject;
  852. driveObject.insert("accPedal", accPedal);
  853. driveObject.insert("brakePedal", brakePedal);
  854. driveObject.insert("steeringWheel", steeringWheel);
  855. driveObject.insert("turnSignal", turnSignal);
  856. driveObject.insert("turnMode", turnMode);
  857. pcanObject.insert("driverControl", driveObject);
  858. QJsonObject taskObject;
  859. taskObject.insert("enableHydraulic", frames[3].data[2] >> 0 & 0x01);
  860. taskObject.insert("workLight", workLight);
  861. taskObject.insert("bypassSwitch", frames[3].data[2] >> 1 & 0x01);
  862. taskObject.insert("baseLegSwitch", baseLegSwitch);
  863. taskObject.insert("baseLegControl", baseLegControl);
  864. taskObject.insert("taskJoint_1", taskJoint_1);
  865. taskObject.insert("taskJoint_2", taskJoint_2);
  866. taskObject.insert("taskJoint_3", taskJoint_3);
  867. taskObject.insert("endJoint", endJoint);
  868. taskObject.insert("toolControl", toolControl);
  869. taskObject.insert("suckerSelect", frames[3].data[2] >> 2 & 0x01);
  870. taskObject.insert("cabLift", cabLift);
  871. taskObject.insert("esCabLift", frames[3].data[2] >> 3 & 0x01);
  872. taskObject.insert("coopSignal", coopSignal);
  873. pcanObject.insert("taskControl", taskObject);
  874. QJsonObject errObject;
  875. errObject.insert("errBasOperation", "");
  876. errObject.insert("errAccPedal", errAccPedal);
  877. errObject.insert("errBrakePedal", frames[3].data[6] >> 0 & 0x01);
  878. errObject.insert("errSteeringWheel", frames[3].data[6] >> 1 & 0x01);
  879. errObject.insert("errHandle", errHandle);
  880. errObject.insert("errEndTool", frames[3].data[5] >> 5 & 0x01);
  881. errObject.insert("errOther", "");
  882. pcanObject.insert("errCode", errObject);
  883. }*/
  884. void AppModel::setSteerAngle(const float& value)
  885. {
  886. m_steerAngle = value;
  887. emit steerAngleChanged();
  888. }
  889. float AppModel::Steer() const
  890. {
  891. return m_steerAngle;
  892. }
  893. void AppModel::setPing(const int32_t &value) {
  894. m_ping = value;
  895. emit pingChanged();
  896. }
  897. void AppModel::setTemp(const double& value)
  898. {
  899. m_temp = value;
  900. emit tempChanged();
  901. }
  902. void AppModel::onKickoff() { emit closeWin(); }
  903. /** 换挡 */
  904. void AppModel::egoGearChanged(int gear)
  905. {
  906. //qDebug() << this << "gear states " << gear << "changed!!";
  907. //gear == 1 是N挡
  908. if (gear == 1) {
  909. //setForward(1);
  910. setForward(-1);
  911. }
  912. //gear ==2 是D挡
  913. else if (gear == 2) {
  914. setForward(0);
  915. //setForward(1);
  916. }
  917. //gear==3 是R挡
  918. else if (gear == 3) {
  919. //setForward(0);
  920. setForward(1);
  921. }
  922. }
  923. /** 升降换挡 */
  924. void AppModel::egoGear_DChanged(int gear_d)
  925. {
  926. //qDebug() << this << "gear_d states " << gear << "changed!!";
  927. if (gear_d == 0) {
  928. setGear_D(gear_d);
  929. }
  930. else if (gear_d == 1) {
  931. setGear_D(gear_d);
  932. }
  933. else if (gear_d == 2) {
  934. setGear_D(gear_d);
  935. }
  936. else if (gear_d == 3) {
  937. setGear_D(gear_d);
  938. }
  939. else if (gear_d == 4) {
  940. setGear_D(gear_d);
  941. }
  942. }
  943. /**转向灯*/
  944. void AppModel::egoDirectionLightChanged(int light)
  945. {
  946. if (light == 0)
  947. {
  948. setDirectionLight(0);
  949. }
  950. else if (light == 1)
  951. {
  952. setDirectionLight(1);
  953. }
  954. else if (light == 2)
  955. {
  956. setDirectionLight(2);
  957. }
  958. }
  959. void AppModel::egoWiperChanged(bool wiper)
  960. {
  961. if (wiper == 0)
  962. {
  963. setWiper(1);
  964. }
  965. else if (wiper == 1)
  966. {
  967. setWiper(0);
  968. }
  969. }
  970. void AppModel::egoFrontLightChanged(bool frontlight)
  971. {
  972. if (frontlight == 0)
  973. {
  974. setFrontLight(1);
  975. }
  976. else if (frontlight == 1)
  977. {
  978. setFrontLight(0);
  979. }
  980. }
  981. void AppModel::egoBackLightChanged(bool backlight)
  982. {
  983. if (backlight == 0)
  984. {
  985. setBackLight(1);
  986. }
  987. else if (backlight == 1)
  988. {
  989. setBackLight(0);
  990. }
  991. }
  992. //add-wfg
  993. void AppModel::egoBuzzerChanged(bool buzzer)
  994. {
  995. if (buzzer == 0)
  996. {
  997. setBuzzer(1);
  998. }
  999. else if (buzzer == 1)
  1000. {
  1001. setBuzzer(0);
  1002. }
  1003. }
  1004. void AppModel::egoCautionLightChanged(bool cautionLight)
  1005. {
  1006. setCautionLight(cautionLight);
  1007. }
  1008. void AppModel::egoLightLChanged(bool lightL)
  1009. {
  1010. setLightL(lightL);
  1011. }
  1012. void AppModel::egoLightRChanged(bool lightR)
  1013. {
  1014. setLightR(lightR);
  1015. }
  1016. void AppModel::egoGearFChanged(bool gearF)
  1017. {
  1018. setGearF(gearF);
  1019. }
  1020. void AppModel::egoGearRChanged(bool gearR)
  1021. {
  1022. setGearR(gearR);
  1023. }
  1024. void AppModel::egoCarParkChanged(bool carPark)
  1025. {
  1026. setCarPark(carPark);
  1027. }
  1028. void AppModel::egoBuzzerPlayChanged(bool buzzerPlay)
  1029. {
  1030. setBuzzerPlay(buzzerPlay);
  1031. }
  1032. void AppModel::egoLightFrontChanged(bool lightFront)
  1033. {
  1034. setLightFront(lightFront);
  1035. }
  1036. void AppModel::egoLightWorkChanged(bool lightWork)
  1037. {
  1038. setLightWork(lightWork);
  1039. }
  1040. void AppModel::egoEmergencyChanged(bool emergency)
  1041. {
  1042. setEmergency(emergency);
  1043. }
  1044. void AppModel::egoMqttChanged(cannet_frame* frames)
  1045. {
  1046. //setMqttToSever(frames);
  1047. }
  1048. void AppModel::onNotifyLeave(int32_t peer) { m_peer = -1; }
  1049. void AppModel::onNotifyFail(int32_t peer)
  1050. {
  1051. m_peer = -1;
  1052. }
  1053. QQmlListProperty<CarData> AppModel::car() const { return *(d->carProp); }
  1054. void AppModel::userLogin(QString useName, QString password) {
  1055. _control->Login(useName.toStdString(), password.toStdString());
  1056. }
  1057. void AppModel::leaveCar(int carID) {
  1058. if (m_ready == false) return;
  1059. m_ready = false;
  1060. m_peer = -1;
  1061. _control->SetReady(false);
  1062. _control->OnCarLeave();
  1063. //_control->ChangeState(UserState::Idle);
  1064. _control->ChangeState(carID,UserState::Idle);
  1065. }
  1066. bool AppModel::idle(int id)
  1067. {
  1068. for (auto& node : _users)
  1069. {
  1070. if (node.uid == id &&((id==m_peer)|| node.state == UserState::Idle))
  1071. return true;
  1072. }
  1073. return false;
  1074. }
  1075. void AppModel::connectCar(int id)
  1076. {
  1077. for (auto& node : _users)
  1078. {
  1079. if (node.uid == id&&node.state==UserState::Idle)
  1080. {
  1081. if (m_ready == true) return;
  1082. //_control->ChangeState(UserState::Remote);
  1083. _control->ChangeState(id,UserState::Remote);
  1084. _control->OnCarConnect(id);
  1085. _control->SetReady(true);
  1086. m_peer = id;
  1087. SetVisible(node.carType == CarType::ZJ);
  1088. setReady(true);
  1089. this->setCarName(QString::fromStdString(node.name));
  1090. break;
  1091. }
  1092. }
  1093. }
  1094. void AppModel::controlCar(int id)
  1095. {
  1096. connectCar(id);
  1097. }
  1098. void AppModel::cancelControl()
  1099. {
  1100. //_control->ChangeState(UserState::Idle);
  1101. }
  1102. void AppModel::showBackDlg(QString content, WorkArea area, int32_t no, int32_t uid)
  1103. {
  1104. QVariant arg_1 = content;
  1105. QVariant arg_2 = (int32_t)area;
  1106. QVariant arg_3 = no;
  1107. QVariant arg_4 = uid;
  1108. QMetaObject::invokeMethod(m_qmlObj, "popDialog",
  1109. Q_ARG(QVariant, arg_1),
  1110. Q_ARG(QVariant, arg_2),
  1111. Q_ARG(QVariant, arg_3),
  1112. Q_ARG(QVariant, arg_4));
  1113. }
  1114. void AppModel::showMoveDlg(MoveDesc desc)
  1115. {
  1116. QVariant arg_1 = (int32_t)desc;
  1117. QMetaObject::invokeMethod(m_qmlObj, "moveErrorDialog", Q_ARG(QVariant, arg_1));
  1118. }
  1119. /*
  1120. void AppModel::showTrackDlg()
  1121. {
  1122. }
  1123. void AppModel::unTrack()
  1124. {
  1125. m_ready = false;
  1126. _control->SetReady(false);
  1127. _control->OnCarLeave();
  1128. }
  1129. bool AppModel::autoClose()
  1130. {
  1131. return _control->IsAutoClose();
  1132. }
  1133. */
  1134. void AppModel::onLoginRst(bool rst) {
  1135. qDebug() << "AppModel::loginResult >>";
  1136. // if (rst) {
  1137. // delete previous carList
  1138. // foreach (CarData *inf, d->car)
  1139. // delete inf;
  1140. // d->car.clear();
  1141. // req new list
  1142. //_control->ReqCarList();
  1143. // } else {
  1144. // qDebug() << "AppModel::loginResult >>" << rst;
  1145. // }
  1146. }
  1147. void AppModel::onNotifyDel(int32_t peer) {
  1148. for (int32_t i = 0; i < d->car.count(); i++)
  1149. {
  1150. if (d->car.at(i)->uid() == peer)
  1151. {
  1152. delete d->car.at(i);
  1153. d->car.removeAt(i);
  1154. break;
  1155. }
  1156. }
  1157. emit carChanged();
  1158. for (auto it = _users.begin(); it != _users.end(); ++it)
  1159. {
  1160. if ((*it).uid == peer)
  1161. {
  1162. _users.erase(it);
  1163. break;
  1164. }
  1165. }
  1166. // d->car.clear();
  1167. }
  1168. //车辆增加管理
  1169. void AppModel::onCarAppend(const UserCamera &info) {
  1170. bool bFind = false;
  1171. for (auto& node : d->car)
  1172. {
  1173. if (node->uid() == info.uid)
  1174. {
  1175. node->setType(QString::number(info.type));
  1176. node->setName(QString::fromStdString(info.name));
  1177. node->setState(QString::number(info.state));
  1178. node->setCarType(info.carType);
  1179. bFind = true;
  1180. return;
  1181. }
  1182. }
  1183. if (!bFind)
  1184. {
  1185. CarData* users = new CarData;// = (CarData*)malloc;
  1186. users->setUid(info.uid);
  1187. users->setType(QString::number(info.type));
  1188. users->setName(QString::fromStdString(info.name));
  1189. users->setState(QString::number(info.state));
  1190. users->setCarType(info.carType);
  1191. d->car.append(users);
  1192. }
  1193. bFind = false;
  1194. for (auto& node : _users)
  1195. {
  1196. if (node.uid == info.uid)
  1197. {
  1198. bFind = true;
  1199. }
  1200. }
  1201. if(!bFind)
  1202. _users.push_back(info); //在 _users 中添加新的 UserCamera 对象
  1203. emit carChanged();
  1204. }
  1205. void AppModel::onNotifyState(int32_t uid, UserState state)
  1206. {
  1207. for (auto& node : d->car)
  1208. {
  1209. if (node->uid() == uid)
  1210. {
  1211. node->setState(QString::number(state));
  1212. break;
  1213. }
  1214. }
  1215. emit carChanged();
  1216. for (auto& node : _users)
  1217. {
  1218. if (node.uid == uid)
  1219. {
  1220. node.state = state;
  1221. break;
  1222. }
  1223. }
  1224. }
  1225. void AppModel::onRadarUpadte(int32_t r0, int32_t r1, int32_t r2, int32_t r3,
  1226. int32_t r4, int32_t r5,int32_t r6, int32_t r7) {
  1227. if (r0 > 0)
  1228. this->setRadar1(r0);
  1229. if (r1 > 0)
  1230. this->setRadar2(r1);
  1231. if (r2 > 0)
  1232. this->setRadar3(r2);
  1233. if (r3 > 0)
  1234. this->setRadar4(r3);
  1235. if (r4 > 0)
  1236. this->setRadar5(r4);
  1237. if (r5 > 0)
  1238. this->setRadar6(r5);
  1239. if (r6 > 0)
  1240. this->setRadar7(r6);
  1241. if (r7 > 0)
  1242. this->setRadar8(r7);
  1243. //断点
  1244. int32_t distance = 2000;
  1245. if ((r0 > 0 && r0 < distance) || (r1 > 0 && r1 < distance) ||
  1246. (r2 > 0 && r2 < distance) || (r3 > 0 && r3 < distance) ||
  1247. (r4 > 0 && r4 < distance) || (r5 > 0 && r5 < distance) ||
  1248. (r6 > 0 && r6 < distance) || (r7 > 0 && r7 < distance)) {
  1249. emit playAlertSound();
  1250. }
  1251. }
  1252. void AppModel::onFeedData(const FeedData& data)
  1253. {
  1254. this->setEngineSpeed(data.engine_speed);
  1255. this->setTravelSpeed(data.travel_speed);
  1256. this->setFuelLevel(data.fuel_level);
  1257. this->setEngineTemperature(data.engine_temperature);
  1258. this->setHydraulicOilTemperature(data.hydraulic_oil_temperature);
  1259. this->setMainPump1Pressure(data.main_pump_1_pressure);
  1260. this->setMainPump2Pressure(data.main_pump_2_pressure);
  1261. this->setHandGear(data.hand_gear);
  1262. this->setActualGear(data.actual_gear);
  1263. this->setGripperHeight(data.gripper_height);
  1264. this->setAmplitude(data.amplitude);
  1265. this->setBoomAngle(data.boom_angle);
  1266. this->setStickAngle(data.stick_angle);
  1267. this->setIdleProtection(data.idle_protection);
  1268. this->setFrontToggle(data.front_toggle);
  1269. this->setBackToggle(data.back_toggle);
  1270. this->setInterLock(data.interlock);
  1271. this->setSafetySwitch(data.safety_switch);
  1272. this->setArmLiftPilot(data.arm_lift_pilot);
  1273. this->setArmLoweringPilot(data.arm_lowering_pilot);
  1274. this->setLeverLiftingLilot(data.lever_lifting_pilot);
  1275. this->setRodLoweringPilot(data.rod_lowering_pilot);
  1276. this->setLeftRotaryPilot(data.left_rotary_pilot);
  1277. this->setRightRotaryPilot(data.right_rotary_pilot);
  1278. this->setGrabOpenPilot(data.grab_open_pilot);
  1279. this->setGrabClosePilot(data.grab_close_pilot);
  1280. this->setSafetyValves(data.safety_valves);
  1281. this->setLiftPilotPressureSensor_F(data.liftpilotpressuresensor_f);
  1282. this->setLoweringPilotPressureSensor_F(data.loweringpilotpressuresensor_f);
  1283. this->setLeverLiftPilotPressureSensor_F(data.leverliftpilotpressuresensor_f);
  1284. this->setRodLoweringPilotPressurePensor_F(data.rodloweringpilotpressurepensor_f);
  1285. this->setLeftTurnPilotPressureSensor_F(data.leftturnpilotpressuresensor_f);
  1286. this->setRightTurnPilotPressureSensor_F(data.rightturnpilotpressuresensor_f);
  1287. this->setLegExtensionPilotPressureSensor_F(data.legextensionpilotpressuresensor_f);
  1288. this->setLegRetractPilotPressureSensor_F(data.legretractpilotpressuresensor_f);
  1289. this->setGrabOpenPilotPressureSensor_F(data.grabopenpilotpressuresensor_f);
  1290. this->setGrabClosurePilotPressureSensor_F(data.grabclosurepilotpressuresensor_f);
  1291. this->setMainPump1PressureSensor_F(data.mainpump1pressuresensor_f);
  1292. this->setMainPump2PressureSensor_F(data.mainpump2pressuresensor_f);
  1293. this->setChamberPressureSensor_F(data.chamberpressuresensor_f);
  1294. this->setBucketRodPressureSensor_F(data.bucketrodpressuresensor_f);
  1295. this->setParkingPressureSensor_F(data.parkingpressuresensor_f);
  1296. this->setAccumulatorPressureSensor_F(data.accumulatorpressuresensor_f);
  1297. this->setGasPedal_F(data.gaspedal_f);
  1298. this->setThrottleKnob_F(data.throttleknob_f);
  1299. this->setLegHandle_F(data.leghandle_f);
  1300. this->setGripKnob_F(data.gripknob_f);
  1301. this->setHydraulicOilTemperatureSensor_F(data.hydraulicoiltemperaturesensor_f);
  1302. this->setFuelLevelSensor_F(data.fuellevelsensor_f);
  1303. this->setBoomAngleSensor_F(data.boomanglesensor_f);
  1304. this->setBucketLeverTiltSensor_F(data.bucketlevertiltsensor_f);
  1305. this->setExpansionModule_F(data.expansionmodule_f);
  1306. this->setWorkingDistanceOverrun_F(data.workingdistanceoverrun_f);
  1307. this->setLowOilLevel_F(data.lowoillevel_f);
  1308. this->setBatteryLowVoltage_F(data.batterylowvoltage_f);
  1309. this->setBatteryHighVoltage_F(data.batteryhighvoltage_f);
  1310. this->setAccumulatorPressure_F(data.accumulatorpressure_f);
  1311. this->setHighHydraulicOilTemperature_F(data.highhydraulicoiltemperature_f);
  1312. this->setLowOilPressure_F(data.lowoilpressure_f);
  1313. this->setCoolantLevelLow_F(data.coolantlevellow_f);
  1314. this->setCoolantTemperatureHigh_F(data.coolanttemperaturehigh_f);
  1315. this->setSystemOverload_F(data.systemoverload_f);
  1316. this->setSafebypassPressDown_F(data.safebypasspressdown_f);
  1317. this->setEngineSPN_F(data.enginespn_f);
  1318. this->setEngineWarmUp_F(data.enginewarmup_f);
  1319. this->setEngineWarmUpTimeout_F(data.enginewarmuptimeout_f);
  1320. this->setEmergencyStopPress_F(data.emergencystoppress_f);
  1321. this->setLeftFrontLegChosed(data.leftfrontlegchosed);
  1322. this->setRightFrontLegChosed(data.rightfrontlegchosed);
  1323. this->setLeftRearLegChosed(data.leftrearlegchosed);
  1324. this->setRightRearLegChosed(data.rightrearlegchosed);
  1325. this->SetBrakePressure(data.brake_pressure);
  1326. this->SetEngineOilPressure(data.engine_pressure);
  1327. this->SetEngingRpm(data.engine_rpm);
  1328. //this->SetGear(data.gear);
  1329. this->SetGearBoxOilPressure(data.gearbox_oil_pressure);
  1330. this->SetGearBoxOilTemp(data.gearbox_oil_temp);
  1331. this->SetSpeed(data.speed);
  1332. this->setWorkPressure(data.work_pressure);
  1333. this->SetCold(data.cold_water);
  1334. this->setSteerAngle(data.steer_angle/4096.f*360.f);
  1335. }
  1336. void AppModel::onPing(int32_t value, double temp) { this->setPing(value); this->setTemp(temp); }
  1337. void AppModel::onImuUpdate(float x, float y) {
  1338. //断点
  1339. this->setImux(x);
  1340. this->setImuy(y);
  1341. }
  1342. void AppModel::logout() {
  1343. d->car.clear();
  1344. m_ready = false;
  1345. }
  1346. void AppModel::moveBegin(int32_t area,int32_t no)
  1347. {
  1348. if (m_peer == -1) return;
  1349. no -= 1;
  1350. // _control->OnCarLeave();
  1351. _control->OnMoveBegin(m_peer, static_cast<WorkArea>(area), no);
  1352. }
  1353. /*
  1354. void AppModel::switchDriver()
  1355. {
  1356. if (m_peer == -1) return;
  1357. _control->SwitchDriver(m_peer);
  1358. }
  1359. */
  1360. void AppModel::onMoveEnd(int32_t rid, WorkArea area, int32_t no)
  1361. {
  1362. for (auto& user:_users)
  1363. {
  1364. if (user.uid == rid)
  1365. {
  1366. //sr text[128];
  1367. //sprintf(text,"%s �Ѿ�����Ŀ��ص�\n \t ����Զ�̲ٿ�", data->name().toStdString().c_str());
  1368. QString str = QString::fromStdString(user.name);
  1369. showBackDlg(str, area,no,rid);
  1370. //_control->ChangeState(UserState::AskRemote);
  1371. _control->ChangeState(rid,UserState::AskRemote);
  1372. // sprintf(text, "321321312" );
  1373. }
  1374. }
  1375. }
  1376. void AppModel::onMoveRet(MoveDesc desc)
  1377. {
  1378. if (desc != MoveDesc::Move_OK)
  1379. {
  1380. showMoveDlg(desc);
  1381. }
  1382. }
  1383. /*
  1384. void AppModel::areaChanged(int32_t area)
  1385. {
  1386. m_area = static_cast<WorkArea>(area);
  1387. }
  1388. */
  1389. void AppModel::OnClose()
  1390. {
  1391. if (m_ready)
  1392. {
  1393. leaveCar(100);
  1394. Sleep(5000);
  1395. }
  1396. //调用直接终止当前进程
  1397. ::ExitProcess(0);
  1398. }
  1399. void AppModel::onEncodeUpdate(int32_t left, int32_t right)
  1400. {
  1401. setLeftAngle(left);
  1402. setRightAngle(right);
  1403. }
  1404. /*
  1405. void AppModel::OnPosition(float x, float y, float z)
  1406. {
  1407. setModelX(x * 100);
  1408. setModelY(y * 100);
  1409. setModelZ(z * 100);
  1410. }
  1411. */