123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- #include "appmodel.h"
- #include "Ego.h"
- #define WIN23_LEAN_AND_MEAN
- #include <Windows.h>
- #include <mmsystem.h>
- #pragma comment (lib,"winmm.lib")
- //#include "FishEyeWindow.h"
- // extern std::array<IRender *, 3> ar;
- CarData::CarData(QObject *parent) : QObject(parent) {}
- CarData::CarData(const CarData &other)
- : QObject(nullptr), m_uid(other.m_uid), m_name(other.m_name),
- m_type(other.m_type), m_state(other.m_state) {}
- int32_t CarData::uid() const { return m_uid; }
- QString CarData::name() const { return m_name; }
- QString CarData::type() const { return m_type; }
- QString CarData::state() const { return m_state; }
- void CarData::setUid(const int32_t &value) {
- m_uid = value;
- emit dataChanged();
- }
- void CarData::setCarType(const int32_t& value)
- {
- m_carType = value;
- }
- void CarData::setName(const QString &value) {
- m_name = value;
- emit dataChanged();
- }
- void CarData::setState(const QString &value) {
- m_state = value;
- emit dataChanged();
- }
- void CarData::setType(const QString &value) {
- m_type = value;
- emit dataChanged();
- }
- class AppModelPrivate {
- public:
- QList<CarData *> car;
- QQmlListProperty<CarData> *carProp = nullptr;
- };
- static void carAppend(QQmlListProperty<CarData> *prop, CarData *val) {
- Q_UNUSED(val);
- Q_UNUSED(prop);
- }
- static CarData *carAt(QQmlListProperty<CarData> *prop, qsizetype index) {
- AppModelPrivate *d = static_cast<AppModelPrivate *>(prop->data);
- return d->car.at(index);
- }
- static qsizetype carCount(QQmlListProperty<CarData> *prop) {
- AppModelPrivate *d = static_cast<AppModelPrivate *>(prop->data);
- return d->car.size();
- }
- static void carClear(QQmlListProperty<CarData> *prop) {
- static_cast<AppModelPrivate *>(prop->data)->car.clear();
- }
- AppModel::AppModel(IEgoNotify *n, IEgoControl *c, QObject* qmlobj, QObject *parent)
- : _notify(n), _control(c), QObject(parent), d(new AppModelPrivate),m_peer(-1),m_qmlObj(qmlobj) {
- m_account = QString::fromStdString(_control->GetAccount());
- m_password = QString::fromStdString(_control->GetPassword());
- m_driveName = QString::fromStdString(_control->GetName());
- d->carProp = new QQmlListProperty<CarData>(this, d, carAppend, carCount,
- carAt, carClear);
- m_ready = false;
- // _window = std::make_unique<CFishEyeWindow>();
- //_window->Start("192.168.1.64");
- connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoLoginResult(bool)), this,
- SLOT(onLoginRst(bool)));
- connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoCarAppend(UserCamera)),
- this, SLOT(onCarAppend(UserCamera)));
- connect(
- dynamic_cast<QObject *>(_notify),
- SIGNAL(egoRadar(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)),
- this,
- SLOT(
- onRadarUpadte(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)));
- connect(
- dynamic_cast<QObject*>(_notify),
- SIGNAL(egoEncode(int32_t, int32_t)),
- this,
- SLOT(
- onEncodeUpdate(int32_t, int32_t)));
- connect(dynamic_cast<QObject*>(_notify),
- SIGNAL(egoFeedData(const FeedData&)),
- this,
- SLOT(onFeedData(const FeedData&)));
- connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoPing(int32_t,double)), this,
- SLOT(onPing(int32_t,double)));
- connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoPosition(float, float, float)), this,
- SLOT(OnPosition(float, float, float)));
- connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyLeave(int32_t)), this,
- SLOT(onNotifyLeave(int32_t)));
- connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyFail(int32_t)), this,
- SLOT(onNotifyFail(int32_t)));
- connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoNotifyDel(int32_t)), this,
- SLOT(onNotifyDel(int32_t)));
- connect(dynamic_cast<QObject *>(_notify), SIGNAL(egoKickoff()), this,
- SLOT(onKickoff()));
- connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoMoveEnd(int32_t, WorkArea , int32_t)), this,
- SLOT(onMoveEnd(int32_t, WorkArea, int32_t)));
- connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoMoveRet(MoveDesc)), this,
- SLOT(onMoveRet(MoveDesc)));
-
- connect(dynamic_cast<QObject*>(_notify), SIGNAL(egoNotifyState(int32_t, UserState)), this,
- SLOT(onNotifyState(int32_t, UserState)));
- // connect(dynamic_cast<QObject *>(_notify),SIGNAL(ego)
- }
- AppModel::~AppModel() {
- if (d->carProp)
- delete d->carProp;
- if (d)
- delete d;
- }
- int AppModel::BrakePressure() const { return m_brake_pressure; }
- int AppModel::GearboxOilPressure()const { return m_gearbox_oil_pressure; }
- int AppModel::GearboxOilTemp() const { return m_gearbox_oil_temp; }
- int AppModel::EnginRpm()const { return m_engine_rpm; }
- int AppModel::Speed() const { return m_speed; }
- bool AppModel::Visible() const { return m_visible; }
- //int AppModel::Gear() const { return m_gear; }
- int AppModel::Cold() const { return m_cold_water; }
- //int AppModel::ModelX() const { return m_modelx; }
- //int AppModel::ModelY() const { return m_modely; }
- //int AppModel::ModelZ() const { return m_modelz; }
- int32_t AppModel::leftAngle() const { return m_leftAngle; }
- int32_t AppModel::rightAngle() const { return m_rightAngle; }
- int AppModel::EngineOilPressure() const { return m_engine_oil_pressure; }
- bool AppModel::ready() const
- {
- return m_ready;
- }
- QString AppModel::Account() const { return m_account; }
- QString AppModel::Password() const { return m_password; }
- QString AppModel::CarName() const { return m_carName; }
- QString AppModel::DriveName() const { return m_driveName; }
- int AppModel::radar1() const { return m_radar1; }
- int32_t AppModel::WorkPressure() const { return m_work_pressure; }
- int AppModel::radar2() const { return m_radar2; }
- int AppModel::radar3() const { return m_radar3; }
- int AppModel::radar4() const { return m_radar4; }
- int AppModel::radar5() const { return m_radar5; }
- //int AppModel::radar6() const { return m_radar6; }
- //int AppModel::radar7() const { return m_radar7; }
- int32_t AppModel::OilPos() const { return m_oil_pos; }
- //int AppModel::radar6() const { return m_radar6; }
- int AppModel::ping() const { return m_ping; }
- double AppModel::temp() const { return m_temp; }
- int AppModel::alertSound() const { return m_alert; }
- void AppModel::setReady(const bool value) {
- m_ready = value;
- emit readyChanged();
- }
- void AppModel::SetSpeed(const int32_t value)
- {
- m_speed = value;
- emit speedChanged();
- }
- void AppModel::SetVisible(const bool value)
- {
- m_visible = value;
- emit visibleChanged();
- }
- void AppModel::SetCold(const int32_t value)
- {
- m_cold_water = value;
- emit coldChanged();
- }
- void AppModel::SetGearBoxOilPressure(const int32_t value)
- {
- m_gearbox_oil_pressure = value;
- emit gearboxOilPressureChanged();
- }
- void AppModel::setAccount(const QString& value)
- {
- m_account = value;
- emit accountChanged();
- }
- void AppModel::setLeftAngle(const int32_t value)
- {
- m_leftAngle = value;
- emit leftAngleChanged();
- }
- void AppModel::setRightAngle(const int32_t value)
- {
- m_rightAngle = value;
- emit rightAngleChanged();
- }
- /*
- void AppModel::setModelX(const int32_t value)
- {
- m_modelx = value;
- emit modelXChanged();
- }
- void AppModel::setModelZ(const int32_t value)
- {
- m_modelz = value+200;
- emit modelZChanged();
- }
- void AppModel::setModelY(const int32_t value)
- {
- m_modely = value;
- emit modelYChanged();
- }
- */
- void AppModel::setPassword(const QString& password)
- {
- m_password = password;
- emit passwordChanged();
- }
- void AppModel::setCarName(const QString& carname)
- {
- m_carName = carname;
- emit carNameChanged();
- }
- void AppModel::setDriveName(const QString& drivename)
- {
- m_driveName = drivename;
- emit driveNameChanged();
- }
- void AppModel::setWorkPressure(const int32_t value)
- {
- m_work_pressure = value;
- emit workPressureChanged();
- }
- /*
- void AppModel::SetGear(const int32_t value)
- {
- m_gear = value;
- emit gearChanged();
- }
- */
- void AppModel::SetBrakePressure(int32_t value)
- {
- m_brake_pressure = value;
- emit brakePressureChanged();
- }
- void AppModel::SetOilPos(int32_t value)
- {
- m_oil_pos = value;
- emit oilPosChanged();
- }
-
- void AppModel::SetGearBoxOilTemp(const int32_t value)
- {
- m_gearbox_oil_temp = value;
- emit gearboxOilTempChanged();
- }
- void AppModel::SetEngingRpm(const int32_t value)
- {
- m_engine_rpm = value;
- emit engineRpmChanged();
- }
- void AppModel::SetEngineOilPressure(const int32_t value)
- {
- m_engine_oil_pressure = value;
- emit engineoilPressureChanged();
- }
- void AppModel::setRadar1(const int32_t &value) {
- m_radar1 = value;
- emit radar1Changed();
- }
- void AppModel::setRadar2(const int32_t &value) {
- m_radar2 = value;
- emit radar2Changed();
- }
- void AppModel::setRadar3(const int32_t &value) {
- m_radar3 = value;
- emit radar3Changed();
- }
- void AppModel::setSteerAngle(const float& value)
- {
-
- m_steerAngle = value;
- emit steerAngleChanged();
- }
- float AppModel::Steer() const
- {
- return m_steerAngle;
- }
- void AppModel::setRadar4(const int32_t &value) {
- m_radar4 = value;
- emit radar4Changed();
- }
- void AppModel::setRadar5(const int32_t &value) {
- m_radar5 = value;
- emit radar5Changed();
- }
- /*
- void AppModel::setRadar6(const int32_t& value)
- {
- m_radar6 = value;
- emit radar6Changed();
- }
- void AppModel::setRadar7(const int32_t& value)
- {
- m_radar7 = value;
- emit radar7Changed();
- }
- */
- /*
- void AppModel::setRadar6(const int32_t &value) {
- m_radar6 = value;
- emit radar6Changed();
- }
- */
- void AppModel::setPing(const int32_t &value) {
- m_ping = value;
- emit pingChanged();
- }
- void AppModel::setTemp(const double& value)
- {
- m_temp = value;
- emit tempChanged();
- }
- void AppModel::onKickoff() { emit closeWin(); }
- void AppModel::onNotifyLeave(int32_t peer) { m_peer = -1; }
- void AppModel::onNotifyFail(int32_t peer)
- {
- m_peer = -1;
- }
- QQmlListProperty<CarData> AppModel::car() const { return *(d->carProp); }
- void AppModel::userLogin(QString useName, QString password) {
- _control->Login(useName.toStdString(), password.toStdString());
- }
- void AppModel::leaveCar() {
- if (m_ready == false) return;
- m_ready = false;
- m_peer = -1;
- _control->SetReady(false);
- _control->OnCarLeave();
- _control->ChangeState(UserState::Idle);
- }
- bool AppModel::idle(int id)
- {
- for (auto& node : _users)
- {
- if (node.uid == id &&((id==m_peer)|| node.state == UserState::Idle))
- return true;
- }
- return false;
- }
- void AppModel::connectCar(int id) {
- for (auto& node : _users)
- {
- if (node.uid == id&&node.state==UserState::Idle)
- {
- if (m_ready == true) return;
- _control->ChangeState(UserState::Remote);
- _control->OnCarConnect(id);
- _control->SetReady(true);
- m_peer = id;
- SetVisible(node.carType == CarType::ZJ);
- setReady(true);
-
- this->setCarName(QString::fromStdString(node.name));
- break;
- }
- }
-
- }
- void AppModel::controlCar(int id)
- {
- connectCar(id);
- }
- void AppModel::cancelControl()
- {
- _control->ChangeState(UserState::Idle);
- }
- void AppModel::showBackDlg(QString content, WorkArea area, int32_t no, int32_t uid)
- {
-
- QVariant arg_1 = content;
- QVariant arg_2 = (int32_t)area;
- QVariant arg_3 = no;
- QVariant arg_4 = uid;
- QMetaObject::invokeMethod(m_qmlObj, "popDialog",
-
- Q_ARG(QVariant, arg_1),
- Q_ARG(QVariant, arg_2),
- Q_ARG(QVariant, arg_3),
- Q_ARG(QVariant, arg_4));
- }
- void AppModel::showMoveDlg(MoveDesc desc)
- {
- QVariant arg_1 = (int32_t)desc;
- QMetaObject::invokeMethod(m_qmlObj, "moveErrorDialog", Q_ARG(QVariant, arg_1));
- }
- /*
- void AppModel::showTrackDlg()
- {
- }
- void AppModel::unTrack()
- {
- m_ready = false;
- _control->SetReady(false);
- _control->OnCarLeave();
- }
- bool AppModel::autoClose()
- {
- return _control->IsAutoClose();
- }
- */
- void AppModel::onLoginRst(bool rst) {
- qDebug() << "AppModel::loginResult >>";
- // if (rst) {
- // delete previous carList
- // foreach (CarData *inf, d->car)
- // delete inf;
- // d->car.clear();
- // req new list
- //_control->ReqCarList();
- // } else {
- // qDebug() << "AppModel::loginResult >>" << rst;
- // }
-
- }
- void AppModel::onNotifyDel(int32_t peer) {
- for (int32_t i = 0; i < d->car.count(); i++)
- {
- if (d->car.at(i)->uid() == peer)
- {
- delete d->car.at(i);
- d->car.removeAt(i);
- break;
- }
- }
- emit carChanged();
- for (auto it = _users.begin(); it != _users.end(); ++it)
- {
- if ((*it).uid == peer)
- {
- _users.erase(it);
- break;
- }
- }
- // d->car.clear();
- }
- void AppModel::onCarAppend(const UserCamera &info) {
- bool bFind = false;
- for (auto& node : d->car)
- {
- if (node->uid() == info.uid)
- {
- node->setType(QString::number(info.type));
- node->setName(QString::fromStdString(info.name));
- node->setState(QString::number(info.state));
- node->setCarType(info.carType);
- bFind = true;
- return;
- }
- }
- if (!bFind)
- {
- CarData* users = new CarData;// = (CarData*)malloc;
- users->setUid(info.uid);
- users->setType(QString::number(info.type));
- users->setName(QString::fromStdString(info.name));
- users->setState(QString::number(info.state));
- users->setCarType(info.carType);
- d->car.append(users);
- }
- bFind = false;
- for (auto& node : _users)
- {
- if (node.uid == info.uid)
- {
- bFind = true;
- }
- }
- if(!bFind)
- _users.push_back(info);
- emit carChanged();
- }
- void AppModel::onNotifyState(int32_t uid, UserState state)
- {
- for (auto& node : d->car)
- {
- if (node->uid() == uid)
- {
- node->setState(QString::number(state));
- break;
- }
- }
- emit carChanged();
- for (auto& node : _users)
- {
- if (node.uid == uid)
- {
- node.state = state;
- break;
- }
- }
-
-
- }
- void AppModel::onRadarUpadte(int32_t r0, int32_t r1, int32_t r2, int32_t r3,
- int32_t r4, int32_t ,int32_t ) {
- if (r0 > 0)
- this->setRadar1(r0);
- if (r1 > 0)
- this->setRadar2(r1);
- if (r2 > 0)
- this->setRadar3(r2);
- if (r3 > 0)
- this->setRadar4(r3);
- if (r4 > 0)
- this->setRadar5(r4);
- /*
- if (r5 > 0)
- this->setRadar6(r5);
- if (r6 > 0)
- this->setRadar7(r6);
- */
- int32_t distance = 200;
- /*if ((r0 > 0 && r0 < distance)) {
- PlaySound(TEXT("beep-1.wav"), NULL, SND_FILENAME | SND_ASYNC);
- }*/
- }
- void AppModel::onFeedData(const FeedData& data)
- {
- this->SetBrakePressure(data.brake_pressure);
- this->SetEngineOilPressure(data.engine_pressure);
- this->SetEngingRpm(data.engine_rpm);
- //this->SetGear(data.gear);
- this->SetGearBoxOilPressure(data.gearbox_oil_pressure);
- this->SetGearBoxOilTemp(data.gearbox_oil_temp);
- this->SetSpeed(data.speed);
- this->setWorkPressure(data.work_pressure);
- this->SetCold(data.cold_water);
- this->setSteerAngle(data.steer_angle/4096.f*360.f);
- }
- void AppModel::onPing(int32_t value, double temp) { this->setPing(value); this->setTemp(temp); }
-
- void AppModel::logout() {
- d->car.clear();
- m_ready = false;
- }
- void AppModel::moveBegin(int32_t area,int32_t no)
- {
-
- if (m_peer == -1) return;
- no -= 1;
- // _control->OnCarLeave();
- _control->OnMoveBegin(m_peer, static_cast<WorkArea>(area), no);
- }
- /*
- void AppModel::switchDriver()
- {
- if (m_peer == -1) return;
- _control->SwitchDriver(m_peer);
- }
- */
- void AppModel::onMoveEnd(int32_t rid, WorkArea area, int32_t no)
- {
- for (auto& user:_users)
- {
-
- if (user.uid == rid)
- {
- //sr text[128];
-
- //sprintf(text,"%s �Ѿ�����Ŀ��ص�\n \t ����Զ�̲ٿ�", data->name().toStdString().c_str());
- QString str = QString::fromStdString(user.name);
- showBackDlg(str, area,no,rid);
- _control->ChangeState(UserState::AskRemote);
- // sprintf(text, "321321312" );
- }
- }
-
- }
- void AppModel::onMoveRet(MoveDesc desc)
- {
- if (desc != MoveDesc::Move_OK)
- {
- showMoveDlg(desc);
- }
- }
- /*
- void AppModel::areaChanged(int32_t area)
- {
- m_area = static_cast<WorkArea>(area);
-
-
- }
- */
- void AppModel::OnClose()
- {
- if (m_ready)
- {
- leaveCar();
- Sleep(5000);
-
- }
- ::ExitProcess(0);
- }
- void AppModel::onEncodeUpdate(int32_t left, int32_t right)
- {
- setLeftAngle(left);
- setRightAngle(right);
- }
- /*
- void AppModel::OnPosition(float x, float y, float z)
- {
- setModelX(x * 100);
- setModelY(y * 100);
- setModelZ(z * 100);
- }
- */
|