appmodel.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. #include "appmodel.h"
  2. #include "Ego.h"
  3. #define WIN23_LEAN_AND_MEAN
  4. #include <Windows.h>
  5. //#include "FishEyeWindow.h"
  6. // extern std::array<IRender *, 3> ar;
  7. CarData::CarData(QObject *parent) : QObject(parent) {}
  8. CarData::CarData(const CarData &other)
  9. : QObject(nullptr), m_uid(other.m_uid), m_name(other.m_name),
  10. m_type(other.m_type), m_state(other.m_state) {}
  11. int32_t CarData::uid() const { return m_uid; }
  12. QString CarData::name() const { return m_name; }
  13. QString CarData::type() const { return m_type; }
  14. QString CarData::state() const { return m_state; }
  15. void CarData::setUid(const int32_t &value) {
  16. m_uid = value;
  17. emit dataChanged();
  18. }
  19. void CarData::setCarType(const int32_t& value)
  20. {
  21. m_carType = value;
  22. }
  23. void CarData::setName(const QString &value) {
  24. m_name = value;
  25. emit dataChanged();
  26. }
  27. void CarData::setState(const QString &value) {
  28. m_state = value;
  29. emit dataChanged();
  30. }
  31. void CarData::setType(const QString &value) {
  32. m_type = value;
  33. emit dataChanged();
  34. }
  35. class AppModelPrivate {
  36. public:
  37. QList<CarData *> car;
  38. QQmlListProperty<CarData> *carProp = nullptr;
  39. };
  40. static void carAppend(QQmlListProperty<CarData> *prop, CarData *val) {
  41. Q_UNUSED(val);
  42. Q_UNUSED(prop);
  43. }
  44. static CarData *carAt(QQmlListProperty<CarData> *prop, qsizetype index) {
  45. AppModelPrivate *d = static_cast<AppModelPrivate *>(prop->data);
  46. return d->car.at(index);
  47. }
  48. static qsizetype carCount(QQmlListProperty<CarData> *prop) {
  49. AppModelPrivate *d = static_cast<AppModelPrivate *>(prop->data);
  50. return d->car.size();
  51. }
  52. static void carClear(QQmlListProperty<CarData> *prop) {
  53. static_cast<AppModelPrivate *>(prop->data)->car.clear();
  54. }
  55. AppModel::AppModel(IEgoNotify *n, IEgoControl *c, QObject* qmlobj, QObject *parent)
  56. : _notify(n), _control(c), QObject(parent), d(new AppModelPrivate),m_peer(-1),m_qmlObj(qmlobj) {
  57. m_account = QString::fromStdString(_control->GetAccount());
  58. m_password = QString::fromStdString(_control->GetPassword());
  59. m_driveName = QString::fromStdString(_control->GetName());
  60. d->carProp = new QQmlListProperty<CarData>(this, d, carAppend, carCount,
  61. carAt, carClear);
  62. m_ready = false;
  63. // _window = std::make_unique<CFishEyeWindow>();
  64. //_window->Start("192.168.1.64");
  65. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoLoginResult(bool)), this,
  66. SLOT(onLoginRst(bool)));
  67. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoCarAppend(UserCamera)),
  68. this, SLOT(onCarAppend(UserCamera)));
  69. connect(
  70. dynamic_cast<QObject *>(_notify),
  71. SIGNAL(egoRadar(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t,int32_t,int32_t)),
  72. this,
  73. SLOT(
  74. onRadarUpadte(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t,int32_t,int32_t)));
  75. connect(
  76. dynamic_cast<QObject*>(_notify),
  77. SIGNAL(egoEncode(int32_t, int32_t)),
  78. this,
  79. SLOT(onEncodeUpdate(int32_t, int32_t)));
  80. connect(dynamic_cast<QObject*>(_notify),
  81. SIGNAL(egoFeedData(const FeedData&)),
  82. this,
  83. SLOT(onFeedData(const FeedData&)));
  84. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoPing(int32_t,double)), this,
  85. SLOT(onPing(int32_t,double)));
  86. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoPosition(float, float, float)), this,
  87. SLOT(OnPosition(float, float, float)));
  88. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyLeave(int32_t)), this,
  89. SLOT(onNotifyLeave(int32_t)));
  90. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyFail(int32_t)), this,
  91. SLOT(onNotifyFail(int32_t)));
  92. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoNotifyDel(int32_t)), this,
  93. SLOT(onNotifyDel(int32_t)));
  94. connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoKickoff()), this,
  95. SLOT(onKickoff()));
  96. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoMoveEnd(int32_t, WorkArea , int32_t)), this,
  97. SLOT(onMoveEnd(int32_t, WorkArea, int32_t)));
  98. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoMoveRet(MoveDesc)), this,
  99. SLOT(onMoveRet(MoveDesc)));
  100. connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyState(int32_t, UserState)), this,
  101. SLOT(onNotifyState(int32_t, UserState)));
  102. // connect(dynamic_cast<QObject *>(_notify),SIGNAL(ego)
  103. }
  104. AppModel::~AppModel() {
  105. if (d->carProp)
  106. delete d->carProp;
  107. if (d)
  108. delete d;
  109. }
  110. int AppModel::BrakePressure() const { return m_brake_pressure; }
  111. int AppModel::GearboxOilPressure()const { return m_gearbox_oil_pressure; }
  112. int AppModel::GearboxOilTemp() const { return m_gearbox_oil_temp; }
  113. int AppModel::EnginRpm()const { return m_engine_rpm; }
  114. float AppModel::Steer() const { return m_steer; }
  115. int AppModel::Speed() const { return m_speed; }
  116. bool AppModel::Visible() const { return m_visible; }
  117. //int AppModel::Gear() const { return m_gear; }
  118. int AppModel::Cold() const { return m_cold_water; }
  119. //int AppModel::ModelX() const { return m_modelx; }
  120. //int AppModel::ModelY() const { return m_modely; }
  121. //int AppModel::ModelZ() const { return m_modelz; }
  122. int32_t AppModel::leftAngle() const { return m_leftAngle; }
  123. int32_t AppModel::rightAngle() const { return m_rightAngle; }
  124. int AppModel::EngineOilPressure() const { return m_engine_oil_pressure; }
  125. bool AppModel::ready() const
  126. {
  127. return m_ready;
  128. }
  129. QString AppModel::Account() const { return m_account; }
  130. QString AppModel::Password() const { return m_password; }
  131. QString AppModel::CarName() const { return m_carName; }
  132. QString AppModel::DriveName() const { return m_driveName; }
  133. int AppModel::radar1() const { return m_radar1; }
  134. int32_t AppModel::WorkPressure() const { return m_work_pressure; }
  135. int AppModel::radar2() const { return m_radar2; }
  136. int AppModel::radar3() const { return m_radar3; }
  137. int AppModel::radar4() const { return m_radar4; }
  138. int AppModel::radar5() const { return m_radar5; }
  139. int AppModel::radar6() const { return m_radar6; }
  140. int AppModel::radar7() const { return m_radar7; }
  141. int AppModel::radar8() const { return m_radar8; }
  142. int AppModel::radar9() const { return m_radar9; }
  143. int32_t AppModel::OilPos() const { return m_oil_pos; }
  144. //大冶新增
  145. int32_t AppModel::engineTime() const { return m_engineTime; }
  146. int32_t AppModel::wireSensorL() const { return m_wireSensorL; }
  147. int32_t AppModel::wireSensorR() const { return m_wireSensorR; }
  148. int32_t AppModel::fuelLevel() const { return m_fuelLevel; }
  149. int32_t AppModel::lockSwitchL() const { return m_lockSwitchL; }
  150. int32_t AppModel::lockSwitchR() const { return m_lockSwitchR; }
  151. int32_t AppModel::tipLimit() const { return m_tipLimit; }
  152. int32_t AppModel::turnLeft() const { return m_turnLeft; }
  153. int32_t AppModel::turnRight() const { return m_turnRight; }
  154. int32_t AppModel::hightBeam() const { return m_hightBeam; }
  155. int32_t AppModel::lowBeam() const { return m_lowBeam; }
  156. int32_t AppModel::parking() const { return m_parking; }
  157. int32_t AppModel::brake() const { return m_brake; }
  158. int32_t AppModel::backCar() const { return m_backCar; }
  159. int32_t AppModel::frontWorkLamp() const { return m_frontWorkLamp; }
  160. int32_t AppModel::rearWorkLamp() const { return m_rearWorkLamp; }
  161. int32_t AppModel::cargoWeight() const { return m_cargoWeight; }
  162. int32_t AppModel::systemVol() const { return m_systemVol; }
  163. int32_t AppModel::fGear() const { return m_fGear; }
  164. int32_t AppModel::gear1() const { return m_gear1; }
  165. int32_t AppModel::lowOilPressureAlarm() const { return m_lowOilPressureAlarm; }
  166. int32_t AppModel::engineWaterTemperatureAlarm() const { return m_engineWaterTemperatureAlarm; }
  167. int32_t AppModel::highEngineOilTemperatureAlarm() const { return m_highEngineOilTemperatureAlarm; }
  168. int32_t AppModel::engineWaterLevelLowAlarm() const { return m_engineWaterLevelLowAlarm; }
  169. int32_t AppModel::lowFuelOilAlarm() const { return m_lowFuelOilAlarm; }
  170. int32_t AppModel::returnOilFilterBlockedAlarm() const { return m_returnOilFilterBlockedAlarm; }
  171. int32_t AppModel::oilFilterBlockedAlarm() const { return m_oilFilterBlockedAlarm; }
  172. int32_t AppModel::controlScreenBlockageAlarm() const { return m_controlScreenBlockageAlarm; }
  173. int32_t AppModel::emergencyFilterBlockingAlarm() const { return m_emergencyFilterBlockingAlarm; }
  174. int32_t AppModel::coolingFilterBlockedAlarm() const { return m_coolingFilterBlockedAlarm; }
  175. int32_t AppModel::electricPumpScreenBlockedAlarm() const { return m_electricPumpScreenBlockedAlarm; }
  176. int32_t AppModel::brakeFilterBlockedAlarm() const { return m_brakeFilterBlockedAlarm; }
  177. int32_t AppModel::variableSpeedFilterBlockedAlarm() const { return m_variableSpeedFilterBlockedAlarm; }
  178. int32_t AppModel::lowVoltageAlarm() const { return m_lowVoltageAlarm; }
  179. int32_t AppModel::highTransmissionOilTemperature() const { return m_highTransmissionOilTemperature; }
  180. int32_t AppModel::transmissionOilPressureIsLow() const { return m_transmissionOilPressureIsLow; }
  181. int32_t AppModel::oilTemperatureSensor1IsFaulty() const { return m_oilTemperatureSensor1IsFaulty; }
  182. int32_t AppModel::oilTemperatureSensor2IsFaulty() const { return m_oilTemperatureSensor2IsFaulty; }
  183. int32_t AppModel::oilLevelSensorIsFaulty() const { return m_oilLevelSensorIsFaulty; }
  184. int32_t AppModel::frontThrottleFault() const { return m_frontThrottleFault; }
  185. int32_t AppModel::rearThrottleFault() const { return m_rearThrottleFault; }
  186. int32_t AppModel::handleOfTheUpperArmIsFaulty() const { return m_handleOfTheUpperArmIsFaulty; }
  187. int32_t AppModel::leftLegHandleIsFaulty() const { return m_leftLegHandleIsFaulty; }
  188. int32_t AppModel::rightLegHandleIsFaulty() const { return m_rightLegHandleIsFaulty; }
  189. int32_t AppModel::engineBusFault() const { return m_engineBusFault; }
  190. int32_t AppModel::transmissionBusFault() const { return m_transmissionBusFault; }
  191. int32_t AppModel::remoteControlBusFault() const { return m_remoteControlBusFault; }
  192. int32_t AppModel::rodChamberPressureSensorIsFaulty() const { return m_rodChamberPressureSensorIsFaulty; }
  193. int32_t AppModel::noRodChamberPressureSensorIsFaulty() const { return m_noRodChamberPressureSensorIsFaulty; }
  194. int32_t AppModel::brakePressureSensorIsFaulty() const { return m_brakePressureSensorIsFaulty; }
  195. int32_t AppModel::systemPressureSensorIsFaulty() const { return m_systemPressureSensorIsFaulty; }
  196. int32_t AppModel::controlPressureSensorIsFaulty() const { return m_controlPressureSensorIsFaulty; }
  197. int32_t AppModel::steeringPressureSensorIsFaulty() const { return m_steeringPressureSensorIsFaulty; }
  198. int32_t AppModel::pressureSensorOfTheLowerArmIsFaulty() const { return m_pressureSensorOfTheLowerArmIsFaulty; }
  199. int32_t AppModel::lockingPinDisplacementSensorLIsFaulty() const { return m_lockingPinDisplacementSensorLIsFaulty; }
  200. int32_t AppModel::lockingPinDisplacementSensorRIsFaulty() const { return m_lockingPinDisplacementSensorRIsFaulty; }
  201. int32_t AppModel::legDisplacementSensorLIsFaulty() const { return m_legDisplacementSensorLIsFaulty; }
  202. int32_t AppModel::legDisplacementSensorRIsFaulty() const { return m_legDisplacementSensorRIsFaulty; }
  203. int32_t AppModel::steeringEncoderFailure() const { return m_steeringEncoderFailure; }
  204. int AppModel::ping() const { return m_ping; }
  205. double AppModel::temp() const { return m_temp; }
  206. int AppModel::alertSound() const { return m_alert; }
  207. void AppModel::setReady(const bool value) {
  208. m_ready = value;
  209. emit readyChanged();
  210. }
  211. void AppModel::SetSpeed(const int32_t value)
  212. {
  213. m_speed = value;
  214. emit speedChanged();
  215. }
  216. void AppModel::SetVisible(const bool value)
  217. {
  218. m_visible = value;
  219. emit visibleChanged();
  220. }
  221. void AppModel::SetCold(const int32_t value)
  222. {
  223. m_cold_water = value;
  224. emit coldChanged();
  225. }
  226. void AppModel::SetGearBoxOilPressure(const int32_t value)
  227. {
  228. m_gearbox_oil_pressure = value;
  229. emit gearboxOilPressureChanged();
  230. }
  231. void AppModel::setAccount(const QString& value)
  232. {
  233. m_account = value;
  234. emit accountChanged();
  235. }
  236. void AppModel::setLeftAngle(const int32_t value)
  237. {
  238. m_leftAngle = value;
  239. emit leftAngleChanged();
  240. }
  241. void AppModel::setRightAngle(const int32_t value)
  242. {
  243. m_rightAngle = value;
  244. emit rightAngleChanged();
  245. }
  246. /*
  247. void AppModel::setModelX(const int32_t value)
  248. {
  249. m_modelx = value;
  250. emit modelXChanged();
  251. }
  252. void AppModel::setModelZ(const int32_t value)
  253. {
  254. m_modelz = value+200;
  255. emit modelZChanged();
  256. }
  257. void AppModel::setModelY(const int32_t value)
  258. {
  259. m_modely = value;
  260. emit modelYChanged();
  261. }
  262. */
  263. void AppModel::setPassword(const QString& password)
  264. {
  265. m_password = password;
  266. emit passwordChanged();
  267. }
  268. void AppModel::setCarName(const QString& carname)
  269. {
  270. m_carName = carname;
  271. emit carNameChanged();
  272. }
  273. void AppModel::setDriveName(const QString& drivename)
  274. {
  275. m_driveName = drivename;
  276. emit driveNameChanged();
  277. }
  278. void AppModel::setWorkPressure(const int32_t value)
  279. {
  280. m_work_pressure = value;
  281. emit workPressureChanged();
  282. }
  283. /*
  284. void AppModel::SetGear(const int32_t value)
  285. {
  286. m_gear = value;
  287. emit gearChanged();
  288. }
  289. */
  290. void AppModel::SetBrakePressure(int32_t value)
  291. {
  292. m_brake_pressure = value;
  293. emit brakePressureChanged();
  294. }
  295. void AppModel::SetOilPos(int32_t value)
  296. {
  297. m_oil_pos = value;
  298. emit oilPosChanged();
  299. }
  300. void AppModel::SetGearBoxOilTemp(const int32_t value)
  301. {
  302. m_gearbox_oil_temp = value;
  303. emit gearboxOilTempChanged();
  304. }
  305. void AppModel::SetEngingRpm(const int32_t value)
  306. {
  307. m_engine_rpm = value;
  308. emit engineRpmChanged();
  309. }
  310. void AppModel::SetEngineOilPressure(const int32_t value)
  311. {
  312. m_engine_oil_pressure = value;
  313. emit engineoilPressureChanged();
  314. }
  315. void AppModel::setRadar1(const int32_t &value) {
  316. m_radar1 = value;
  317. emit radar1Changed();
  318. }
  319. void AppModel::setRadar2(const int32_t &value) {
  320. m_radar2 = value;
  321. emit radar2Changed();
  322. }
  323. void AppModel::setRadar3(const int32_t &value) {
  324. m_radar3 = value;
  325. emit radar3Changed();
  326. }
  327. void AppModel::setSteerAngle(const float& value)
  328. {
  329. if (value > 1)
  330. {
  331. m_steer = (value - 1.0) * (-10);
  332. }
  333. else if(value==1)
  334. {
  335. m_steer = 0.0;
  336. }
  337. else
  338. {
  339. m_steer = value * 10;
  340. }
  341. emit steerAngleChanged();
  342. //qDebug() << "角度值=============" << m_steer;
  343. }
  344. //大冶新增
  345. void AppModel::setEngineTime(const int32_t value){
  346. m_engineTime = value;
  347. emit engineTimeChanged();
  348. }
  349. void AppModel::setWireSensorL(const int32_t value) {
  350. m_wireSensorL = value;
  351. emit wireSensorLChanged();
  352. }
  353. void AppModel::setWireSensorR(const int32_t value) {
  354. m_wireSensorR = value;
  355. emit wireSensorRChanged();
  356. }
  357. void AppModel::setFuelLevel(const int32_t value) {
  358. m_fuelLevel = value;
  359. emit fuelLevelChanged();
  360. }
  361. void AppModel::setLockSwitchL(const int32_t value) {
  362. m_lockSwitchL = value;
  363. emit lockSwitchLChanged();
  364. }
  365. void AppModel::setLockSwitchR(const int32_t value) {
  366. m_lockSwitchR = value;
  367. emit lockSwitchRChanged();
  368. }
  369. void AppModel::setTipLimit(const int32_t value) {
  370. m_tipLimit = value;
  371. //qDebug() << "倾翻压力开关*************" << m_tipLimit;
  372. emit tipLimitChanged();
  373. }
  374. void AppModel::setTurnLeft(const int32_t value) {
  375. m_turnLeft = value;
  376. emit turnLeftChanged();
  377. }
  378. void AppModel::setTurnRight(const int32_t value) {
  379. m_turnRight = value;
  380. emit turnRightChanged();
  381. }
  382. void AppModel::setHightBeam(const int32_t value) {
  383. m_hightBeam = value;
  384. emit hightBeamChanged();
  385. }
  386. void AppModel::setLowBeam(const int32_t value) {
  387. m_lowBeam = value;
  388. emit lowBeamChanged();
  389. }
  390. void AppModel::setParking(const int32_t value) {
  391. m_parking = value;
  392. emit parkingChanged();
  393. }
  394. void AppModel::setBrake(const int32_t value) {
  395. m_brake = value;
  396. emit brakeChanged();
  397. }
  398. void AppModel::setBackCar(const int32_t value) {
  399. m_backCar = value;
  400. emit backCarChanged();
  401. }
  402. void AppModel::setFrontWorkLamp(const int32_t value) {
  403. m_frontWorkLamp = value;
  404. emit frontWorkLampChanged();
  405. }
  406. void AppModel::setRearWorkLamp(const int32_t value) {
  407. m_rearWorkLamp = value;
  408. emit rearWorkLampChanged();
  409. }
  410. void AppModel::setCargoWeight(const int32_t value) {
  411. m_cargoWeight = value;
  412. emit cargoWeightChanged();
  413. }
  414. void AppModel::setSystemVol(const int32_t value) {
  415. m_systemVol = value;
  416. emit systemVolChanged();
  417. }
  418. void AppModel::setFGear(const int32_t value) {
  419. m_fGear = value;
  420. emit fGearChanged();
  421. }
  422. void AppModel::setGear1(const int32_t value) {
  423. m_gear1 = value;
  424. emit gear1Changed();
  425. }
  426. void AppModel::setLowOilPressureAlarm(const int32_t value) {
  427. m_lowOilPressureAlarm = value;
  428. emit lowOilPressureAlarmChanged();
  429. }
  430. void AppModel::setEngineWaterTemperatureAlarm(const int32_t value) {
  431. m_engineWaterTemperatureAlarm = value;
  432. emit engineWaterTemperatureAlarmChanged();
  433. }
  434. void AppModel::setHighEngineOilTemperatureAlarm(const int32_t value) {
  435. m_highEngineOilTemperatureAlarm = value;
  436. emit highEngineOilTemperatureAlarmChanged();
  437. }
  438. void AppModel::setEngineWaterLevelLowAlarm(const int32_t value) {
  439. m_engineWaterLevelLowAlarm = value;
  440. emit engineWaterLevelLowAlarmChanged();
  441. }
  442. void AppModel::setLowFuelOilAlarm(const int32_t value) {
  443. m_lowFuelOilAlarm = value;
  444. emit lowFuelOilAlarmChanged();
  445. }
  446. void AppModel::setReturnOilFilterBlockedAlarm(const int32_t value) {
  447. m_returnOilFilterBlockedAlarm = value;
  448. emit returnOilFilterBlockedAlarmChanged();
  449. }
  450. void AppModel::setOilFilterBlockedAlarm(const int32_t value) {
  451. m_oilFilterBlockedAlarm = value;
  452. emit oilFilterBlockedAlarmChanged();
  453. }
  454. void AppModel::setControlScreenBlockageAlarm(const int32_t value) {
  455. m_controlScreenBlockageAlarm = value;
  456. emit controlScreenBlockageAlarmChanged();
  457. }
  458. void AppModel::setEmergencyFilterBlockingAlarm(const int32_t value) {
  459. m_emergencyFilterBlockingAlarm = value;
  460. emit emergencyFilterBlockingAlarmChanged();
  461. }
  462. void AppModel::setCoolingFilterBlockedAlarm(const int32_t value) {
  463. m_coolingFilterBlockedAlarm = value;
  464. emit coolingFilterBlockedAlarmChanged();
  465. }
  466. void AppModel::setElectricPumpScreenBlockedAlarm(const int32_t value) {
  467. m_electricPumpScreenBlockedAlarm = value;
  468. emit electricPumpScreenBlockedAlarmChanged();
  469. }
  470. void AppModel::setBrakeFilterBlockedAlarm(const int32_t value) {
  471. m_brakeFilterBlockedAlarm = value;
  472. emit brakeFilterBlockedAlarmChanged();
  473. }
  474. void AppModel::setVariableSpeedFilterBlockedAlarm(const int32_t value) {
  475. m_variableSpeedFilterBlockedAlarm = value;
  476. emit variableSpeedFilterBlockedAlarmChanged();
  477. }
  478. void AppModel::setLowVoltageAlarm(const int32_t value) {
  479. m_lowVoltageAlarm = value;
  480. emit lowVoltageAlarmChanged();
  481. }
  482. void AppModel::setHighTransmissionOilTemperature(const int32_t value) {
  483. m_highTransmissionOilTemperature = value;
  484. emit highTransmissionOilTemperatureChanged();
  485. }
  486. void AppModel::setTransmissionOilPressureIsLow(const int32_t value) {
  487. m_transmissionOilPressureIsLow = value;
  488. emit transmissionOilPressureIsLowChanged();
  489. }
  490. void AppModel::setOilTemperatureSensor1IsFaulty(const int32_t value) {
  491. m_oilTemperatureSensor1IsFaulty = value;
  492. emit oilTemperatureSensor1IsFaultyChanged();
  493. }
  494. void AppModel::setOilTemperatureSensor2IsFaulty(const int32_t value) {
  495. m_oilTemperatureSensor2IsFaulty = value;
  496. emit oilTemperatureSensor2IsFaultyChanged();
  497. }
  498. void AppModel::setOilLevelSensorIsFaulty(const int32_t value) {
  499. m_oilLevelSensorIsFaulty = value;
  500. qDebug() << "报警信息===========" << m_oilLevelSensorIsFaulty;
  501. emit oilLevelSensorIsFaultyChanged();
  502. }
  503. void AppModel::setFrontThrottleFault(const int32_t value) {
  504. m_frontThrottleFault = value;
  505. emit frontThrottleFaultChanged();
  506. }
  507. void AppModel::setRearThrottleFault(const int32_t value) {
  508. m_rearThrottleFault = value;
  509. emit rearThrottleFaultChanged();
  510. }
  511. void AppModel::setHandleOfTheUpperArmIsFaulty(const int32_t value) {
  512. m_handleOfTheUpperArmIsFaulty = value;
  513. emit handleOfTheUpperArmIsFaultyChanged();
  514. }
  515. void AppModel::setLeftLegHandleIsFaulty(const int32_t value) {
  516. m_leftLegHandleIsFaulty = value;
  517. emit leftLegHandleIsFaultyChanged();
  518. }
  519. void AppModel::setRightLegHandleIsFaulty(const int32_t value) {
  520. m_rightLegHandleIsFaulty = value;
  521. emit rightLegHandleIsFaultyChanged();
  522. }
  523. void AppModel::setEngineBusFault(const int32_t value) {
  524. m_engineBusFault = value;
  525. emit engineBusFaultChanged();
  526. }
  527. void AppModel::setTransmissionBusFault(const int32_t value) {
  528. m_transmissionBusFault = value;
  529. emit transmissionBusFaultChanged();
  530. }
  531. void AppModel::setRemoteControlBusFault(const int32_t value) {
  532. m_remoteControlBusFault = value;
  533. emit remoteControlBusFaultChanged();
  534. }
  535. void AppModel::setRodChamberPressureSensorIsFaulty(const int32_t value) {
  536. m_rodChamberPressureSensorIsFaulty = value;
  537. emit rodChamberPressureSensorIsFaultyChanged();
  538. }
  539. void AppModel::setNoRodChamberPressureSensorIsFaulty(const int32_t value) {
  540. m_noRodChamberPressureSensorIsFaulty = value;
  541. emit noRodChamberPressureSensorIsFaultyChanged();
  542. }
  543. void AppModel::setBrakePressureSensorIsFaulty(const int32_t value) {
  544. m_brakePressureSensorIsFaulty = value;
  545. emit brakePressureSensorIsFaultyChanged();
  546. }
  547. void AppModel::setSystemPressureSensorIsFaulty(const int32_t value) {
  548. m_systemPressureSensorIsFaulty = value;
  549. emit systemPressureSensorIsFaultyChanged();
  550. }
  551. void AppModel::setControlPressureSensorIsFaulty(const int32_t value) {
  552. m_controlPressureSensorIsFaulty = value;
  553. emit controlPressureSensorIsFaultyChanged();
  554. }
  555. void AppModel::setSteeringPressureSensorIsFaulty(const int32_t value) {
  556. m_steeringPressureSensorIsFaulty = value;
  557. emit steeringPressureSensorIsFaultyChanged();
  558. }
  559. void AppModel::setPressureSensorOfTheLowerArmIsFaulty(const int32_t value) {
  560. m_pressureSensorOfTheLowerArmIsFaulty = value;
  561. emit pressureSensorOfTheLowerArmIsFaultyChanged();
  562. }
  563. void AppModel::setLockingPinDisplacementSensorLIsFaulty(const int32_t value) {
  564. m_lockingPinDisplacementSensorLIsFaulty = value;
  565. emit lockingPinDisplacementSensorLIsFaultyChanged();
  566. }
  567. void AppModel::setLockingPinDisplacementSensorRIsFaulty(const int32_t value) {
  568. m_lockingPinDisplacementSensorRIsFaulty = value;
  569. emit lockingPinDisplacementSensorRIsFaultyChanged();
  570. }
  571. void AppModel::setLegDisplacementSensorLIsFaulty(const int32_t value) {
  572. m_legDisplacementSensorLIsFaulty = value;
  573. emit legDisplacementSensorLIsFaultyChanged();
  574. }
  575. void AppModel::setLegDisplacementSensorRIsFaulty(const int32_t value) {
  576. m_legDisplacementSensorRIsFaulty = value;
  577. emit legDisplacementSensorRIsFaultyChanged();
  578. }
  579. void AppModel::setSteeringEncoderFailure(const int32_t value) {
  580. m_steeringEncoderFailure = value;
  581. emit steeringEncoderFailureChanged();
  582. }
  583. void AppModel::setRadar4(const int32_t &value) {
  584. m_radar4 = value;
  585. emit radar4Changed();
  586. }
  587. void AppModel::setRadar5(const int32_t &value) {
  588. m_radar5 = value;
  589. emit radar5Changed();
  590. }
  591. void AppModel::setRadar6(const int32_t& value)
  592. {
  593. m_radar6 = value;
  594. emit radar6Changed();
  595. }
  596. void AppModel::setRadar7(const int32_t& value)
  597. {
  598. m_radar7 = value;
  599. emit radar7Changed();
  600. }
  601. void AppModel::setRadar8(const int32_t& value)
  602. {
  603. m_radar8 = value;
  604. emit radar8Changed();
  605. }
  606. void AppModel::setRadar9(const int32_t& value)
  607. {
  608. m_radar9 = value;
  609. emit radar9Changed();
  610. }
  611. void AppModel::setPing(const int32_t &value)
  612. {
  613. m_ping = value;
  614. emit pingChanged();
  615. }
  616. void AppModel::setTemp(const double& value)
  617. {
  618. m_temp = value;
  619. emit tempChanged();
  620. }
  621. void AppModel::onKickoff() { emit closeWin(); }
  622. void AppModel::onNotifyLeave(int32_t peer) { m_peer = -1; }
  623. void AppModel::onNotifyFail(int32_t peer)
  624. {
  625. m_peer = -1;
  626. }
  627. QQmlListProperty<CarData> AppModel::car() const { return *(d->carProp); }
  628. void AppModel::userLogin(QString useName, QString password) {
  629. _control->Login(useName.toStdString(), password.toStdString());
  630. }
  631. void AppModel::leaveCar() {
  632. if (m_ready == false) return;
  633. m_ready = false;
  634. m_peer = -1;
  635. _control->SetReady(false);
  636. _control->OnCarLeave();
  637. _control->ChangeState(UserState::Idle);
  638. }
  639. bool AppModel::idle(int id)
  640. {
  641. for (auto& node : _users)
  642. {
  643. if (node.uid == id &&((id==m_peer)|| node.state == UserState::Idle))
  644. return true;
  645. }
  646. return false;
  647. }
  648. void AppModel::connectCar(int id) {
  649. for (auto& node : _users)
  650. {
  651. if (node.uid == id&&node.state==UserState::Idle)
  652. {
  653. if (m_ready == true) return;
  654. _control->ChangeState(UserState::Remote);
  655. _control->OnCarConnect(id);
  656. _control->SetReady(true);
  657. m_peer = id;
  658. SetVisible(node.carType == CarType::ZJ);
  659. setReady(true);
  660. this->setCarName(QString::fromStdString(node.name));
  661. break;
  662. }
  663. }
  664. }
  665. void AppModel::controlCar(int id)
  666. {
  667. connectCar(id);
  668. }
  669. void AppModel::cancelControl()
  670. {
  671. _control->ChangeState(UserState::Idle);
  672. }
  673. void AppModel::showBackDlg(QString content, WorkArea area, int32_t no, int32_t uid)
  674. {
  675. QVariant arg_1 = content;
  676. QVariant arg_2 = (int32_t)area;
  677. QVariant arg_3 = no;
  678. QVariant arg_4 = uid;
  679. QMetaObject::invokeMethod(m_qmlObj, "popDialog",
  680. Q_ARG(QVariant, arg_1),
  681. Q_ARG(QVariant, arg_2),
  682. Q_ARG(QVariant, arg_3),
  683. Q_ARG(QVariant, arg_4));
  684. }
  685. void AppModel::showMoveDlg(MoveDesc desc)
  686. {
  687. QVariant arg_1 = (int32_t)desc;
  688. QMetaObject::invokeMethod(m_qmlObj, "moveErrorDialog", Q_ARG(QVariant, arg_1));
  689. }
  690. /*
  691. void AppModel::showTrackDlg()
  692. {
  693. }
  694. void AppModel::unTrack()
  695. {
  696. m_ready = false;
  697. _control->SetReady(false);
  698. _control->OnCarLeave();
  699. }
  700. bool AppModel::autoClose()
  701. {
  702. return _control->IsAutoClose();
  703. }
  704. */
  705. void AppModel::onLoginRst(bool rst) {
  706. //qDebug() << "AppModel::loginResult >>";
  707. // if (rst) {
  708. // delete previous carList
  709. // foreach (CarData *inf, d->car)
  710. // delete inf;
  711. // d->car.clear();
  712. // req new list
  713. //_control->ReqCarList();
  714. // } else {
  715. // qDebug() << "AppModel::loginResult >>" << rst;
  716. // }
  717. }
  718. void AppModel::onNotifyDel(int32_t peer) {
  719. for (int32_t i = 0; i < d->car.count(); i++)
  720. {
  721. if (d->car.at(i)->uid() == peer)
  722. {
  723. delete d->car.at(i);
  724. d->car.removeAt(i);
  725. break;
  726. }
  727. }
  728. emit carChanged();
  729. for (auto it = _users.begin(); it != _users.end(); ++it)
  730. {
  731. if ((*it).uid == peer)
  732. {
  733. _users.erase(it);
  734. break;
  735. }
  736. }
  737. // d->car.clear();
  738. }
  739. void AppModel::onCarAppend(const UserCamera &info) {
  740. bool bFind = false;
  741. for (auto& node : d->car)
  742. {
  743. if (node->uid() == info.uid)
  744. {
  745. node->setType(QString::number(info.type));
  746. node->setName(QString::fromStdString(info.name));
  747. node->setState(QString::number(info.state));
  748. node->setCarType(info.carType);
  749. bFind = true;
  750. return;
  751. }
  752. }
  753. if (!bFind)
  754. {
  755. CarData* users = new CarData;// = (CarData*)malloc;
  756. users->setUid(info.uid);
  757. users->setType(QString::number(info.type));
  758. users->setName(QString::fromStdString(info.name));
  759. users->setState(QString::number(info.state));
  760. users->setCarType(info.carType);
  761. d->car.append(users);
  762. }
  763. bFind = false;
  764. for (auto& node : _users)
  765. {
  766. if (node.uid == info.uid)
  767. {
  768. bFind = true;
  769. }
  770. }
  771. if(!bFind)
  772. _users.push_back(info);
  773. emit carChanged();
  774. }
  775. void AppModel::onNotifyState(int32_t uid, UserState state)
  776. {
  777. for (auto& node : d->car)
  778. {
  779. if (node->uid() == uid)
  780. {
  781. node->setState(QString::number(state));
  782. break;
  783. }
  784. }
  785. emit carChanged();
  786. for (auto& node : _users)
  787. {
  788. if (node.uid == uid)
  789. {
  790. node.state = state;
  791. break;
  792. }
  793. }
  794. }
  795. void AppModel::onRadarUpadte(int32_t r0, int32_t r1, int32_t r2, int32_t r3,
  796. int32_t r4, int32_t r5,int32_t r6,int32_t r7,int32_t r8) {
  797. if (r0 > 0)
  798. this->setRadar1(r0);
  799. if (r1 > 0)
  800. this->setRadar2(r1);
  801. if (r2 > 0)
  802. this->setRadar3(r2);
  803. if (r3 > 0)
  804. this->setRadar4(r3);
  805. if (r4 > 0)
  806. this->setRadar5(r4);
  807. if (r5 > 0)
  808. this->setRadar6(r5);
  809. if (r6 > 0)
  810. this->setRadar7(r6);
  811. if (r7 > 0)
  812. this->setRadar8(r7);
  813. if (r8 > 0)
  814. this->setRadar9(r8);
  815. int32_t distance = 2000;
  816. if ((r0 > 0 && r0 < distance) || (r1 > 0 && r1 < distance) ||
  817. (r2 > 0 && r2 < distance) || (r3 > 0 && r3 < distance) ||
  818. (r4 > 0 && r4 < distance) /*|| (r5 > 0 && r5 < distance)*/) {
  819. emit playAlertSound();
  820. }
  821. }
  822. void AppModel::onFeedData(const FeedData& data)
  823. {
  824. this->SetBrakePressure(data.brake_pressure);
  825. this->SetEngineOilPressure(data.engine_pressure);
  826. this->SetEngingRpm(data.engine_rpm);
  827. //this->SetGear(data.gear);
  828. this->SetGearBoxOilPressure(data.gearbox_oil_pressure);
  829. this->SetGearBoxOilTemp(data.gearbox_oil_temp);
  830. this->SetSpeed(data.speed);
  831. this->setWorkPressure(data.work_pressure);
  832. this->SetCold(data.cold_water);
  833. //此处计算不确定(小数点前面0为正数,1为负数)
  834. this->setSteerAngle(data.steer_angle);
  835. //this->setSteerAngle(data.steer_angle/4096.f*360.f);
  836. //大冶新增的
  837. this->setEngineTime(data.engine_time);
  838. this->setWireSensorL(data.wire_sensor_l);
  839. this->setWireSensorR(data.wire_sensor_r);
  840. this->setFuelLevel(data.fuel_level);
  841. this->setLockSwitchL(data.lock_switch_l);
  842. this->setLockSwitchR(data.lock_switch_r);
  843. this->setTipLimit(data.tip_limit);
  844. this->setTurnLeft(data.turn_left);
  845. this->setTurnRight(data.turn_right);
  846. this->setHightBeam(data.hight_beam);
  847. this->setLowBeam(data.low_beam);
  848. this->setParking(data.parking);
  849. this->setBrake(data.brake);
  850. this->setBackCar(data.back_car);
  851. this->setFrontWorkLamp(data.front_work_lamp);
  852. this->setRearWorkLamp(data.rear_work_lamp);
  853. this->setCargoWeight(data.cargo_weight);
  854. this->setSystemVol(data.system_vol);
  855. this->setFGear(data.f_gear);
  856. this->setGear1(data.gear_1);
  857. //报警信息
  858. this->setLowOilPressureAlarm(data.low_oil_pressure_alarm);
  859. this->setEngineWaterTemperatureAlarm(data.engine_water_temperature_alarm);
  860. this->setHighEngineOilTemperatureAlarm(data.high_engine_oil_temperature_alarm);
  861. this->setEngineWaterLevelLowAlarm(data.engine_water_level_low_alarm);
  862. this->setLowFuelOilAlarm(data.low_fuel_oil_alarm);
  863. this->setReturnOilFilterBlockedAlarm(data.return_oil_filter_blocked_alarm);
  864. this->setOilFilterBlockedAlarm(data.oil_filter_blocked_alarm);
  865. this->setControlScreenBlockageAlarm(data.control_screen_blockage_alarm);
  866. this->setEmergencyFilterBlockingAlarm(data.emergency_filter_blocking_alarm);
  867. this->setCoolingFilterBlockedAlarm(data.cooling_filter_blocked_alarm);
  868. this->setElectricPumpScreenBlockedAlarm(data.electric_pump_screen_blocked_alarm);
  869. this->setBrakeFilterBlockedAlarm(data.brake_filter_blocked_alarm);
  870. this->setVariableSpeedFilterBlockedAlarm(data.variable_speed_filter_blocked_alarm);
  871. this->setLowVoltageAlarm(data.low_voltage_alarm);
  872. this->setHighTransmissionOilTemperature(data.high_transmission_oil_temperature);
  873. this->setTransmissionOilPressureIsLow(data.transmission_oil_pressure_is_low);
  874. this->setOilTemperatureSensor1IsFaulty(data.oil_temperature_sensor_1_is_faulty);
  875. this->setOilTemperatureSensor2IsFaulty(data.oil_temperature_sensor_2_is_faulty);
  876. this->setOilLevelSensorIsFaulty(data.oil_level_sensor_is_faulty);
  877. this->setFrontThrottleFault(data.front_throttle_fault);
  878. this->setRearThrottleFault(data.rear_throttle_fault);
  879. this->setHandleOfTheUpperArmIsFaulty(data.handle_of_the_upper_arm_is_faulty);
  880. this->setLeftLegHandleIsFaulty(data.left_leg_handle_is_faulty);
  881. this->setRightLegHandleIsFaulty(data.right_leg_handle_is_faulty);
  882. this->setEngineBusFault(data.engine_bus_fault);
  883. this->setTransmissionBusFault(data.transmission_bus_fault);
  884. this->setRemoteControlBusFault(data.remote_control_bus_fault);
  885. this->setRodChamberPressureSensorIsFaulty(data.rod_chamber_pressure_sensor_is_faulty);
  886. this->setNoRodChamberPressureSensorIsFaulty(data.no_rod_chamber_pressure_sensor_is_faulty);
  887. this->setBrakePressureSensorIsFaulty(data.brake_pressure_sensor_is_faulty);
  888. this->setSystemPressureSensorIsFaulty(data.system_pressure_sensor_is_faulty);
  889. this->setControlPressureSensorIsFaulty(data.control_pressure_sensor_is_faulty);
  890. this->setSteeringPressureSensorIsFaulty(data.steering_pressure_sensor_is_faulty);
  891. this->setPressureSensorOfTheLowerArmIsFaulty(data.pressure_sensor_of_the_lower_arm_is_faulty);
  892. this->setLockingPinDisplacementSensorLIsFaulty(data.locking_pin_displacement_sensor_L_is_faulty);
  893. this->setLockingPinDisplacementSensorRIsFaulty(data.locking_pin_displacement_sensor_R_is_faulty);
  894. this->setLegDisplacementSensorLIsFaulty(data.leg_displacement_sensor_L_is_faulty);
  895. this->setLegDisplacementSensorRIsFaulty(data.leg_displacement_sensor_R_is_faulty);
  896. this->setSteeringEncoderFailure(data.steering_encoder_failure);
  897. }
  898. void AppModel::onPing(int32_t value, double temp) { this->setPing(value); this->setTemp(temp); }
  899. void AppModel::logout() {
  900. d->car.clear();
  901. m_ready = false;
  902. }
  903. void AppModel::moveBegin(int32_t area,int32_t no)
  904. {
  905. if (m_peer == -1) return;
  906. no -= 1;
  907. // _control->OnCarLeave();
  908. _control->OnMoveBegin(m_peer, static_cast<WorkArea>(area), no);
  909. }
  910. /*
  911. void AppModel::switchDriver()
  912. {
  913. if (m_peer == -1) return;
  914. _control->SwitchDriver(m_peer);
  915. }
  916. */
  917. void AppModel::onMoveEnd(int32_t rid, WorkArea area, int32_t no)
  918. {
  919. for (auto& user:_users)
  920. {
  921. if (user.uid == rid)
  922. {
  923. //sr text[128];
  924. //sprintf(text,"%s �Ѿ�����Ŀ��ص�\n \t ����Զ�̲ٿ�", data->name().toStdString().c_str());
  925. QString str = QString::fromStdString(user.name);
  926. showBackDlg(str, area,no,rid);
  927. _control->ChangeState(UserState::AskRemote);
  928. // sprintf(text, "321321312" );
  929. }
  930. }
  931. }
  932. void AppModel::onMoveRet(MoveDesc desc)
  933. {
  934. if (desc != MoveDesc::Move_OK)
  935. {
  936. showMoveDlg(desc);
  937. }
  938. }
  939. /*
  940. void AppModel::areaChanged(int32_t area)
  941. {
  942. m_area = static_cast<WorkArea>(area);
  943. }
  944. */
  945. void AppModel::OnClose()
  946. {
  947. if (m_ready)
  948. {
  949. leaveCar();
  950. Sleep(5000);
  951. }
  952. ::ExitProcess(0);
  953. }
  954. void AppModel::onEncodeUpdate(int32_t left, int32_t right)
  955. {
  956. setLeftAngle(left);
  957. setRightAngle(right);
  958. }
  959. /*
  960. void AppModel::OnPosition(float x, float y, float z)
  961. {
  962. setModelX(x * 100);
  963. setModelY(y * 100);
  964. setModelZ(z * 100);
  965. }
  966. */