mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 03:52:11 +08:00
0c141e45aa
* kind of works now * QR code is now on screen * testing is needed * works, waiting for server update * reduce diff * refactoring part1 * refactor part2 * refactor part3 * works on PC * fix build, annoying bug though... * git is annoying * more classes, still crashes after a while * better style * clearer qr code * less code and test new ssh key * no more AA * rename and collect garbage * no pairing widget without the internet connection * No network connection * more logs * refactor the network calls * no more leaking * works * cleanup * spaces * works on device * fix merge * don't run if screen is off * always initialized * stats updating, not running without scrren * formatting * nicer QR code * ensure the registration * no qr code if no IMEI or no HWSerial * all works * refactor * better networking * all functionality seems to work * small cleanup * get serial once * Small cleanup * No internet text * Don't crash if private key not found * no network should say so * new qr code every 30 minutes * 20FPS sidebar * more responsive networking and QR * more logs * no log spam * fix merge * no running onroad Co-authored-by: Comma Device <device@comma.ai> Co-authored-by: Willem Melching <willem.melching@gmail.com> old-commit-hash: 10bd761cd6fb59f8113f88cc4dc764fbc4f5abf2
47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <QCryptographicHash>
|
|
#include <QJsonValue>
|
|
#include <QNetworkReply>
|
|
#include <QNetworkRequest>
|
|
#include <QPair>
|
|
#include <QString>
|
|
#include <QVector>
|
|
#include <QWidget>
|
|
#include <atomic>
|
|
#include <openssl/bio.h>
|
|
#include <openssl/pem.h>
|
|
#include <openssl/rsa.h>
|
|
class CommaApi : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
static QByteArray rsa_sign(QByteArray data);
|
|
static QString create_jwt(QVector<QPair<QString, QJsonValue>> payloads, int expiry = 60);
|
|
static QString create_jwt();
|
|
private:
|
|
QNetworkAccessManager* networkAccessManager;
|
|
};
|
|
|
|
/**
|
|
* Makes repeated requests to the request endpoint.
|
|
*/
|
|
class RequestRepeater : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
explicit RequestRepeater(QWidget* parent, QString requestURL, int period = 10, QVector<QPair<QString, QJsonValue>> payloads = *(new QVector<QPair<QString, QJsonValue>>()), bool disableWithScreen = true);
|
|
bool active = true;
|
|
private:
|
|
bool disableWithScreen;
|
|
int callId;
|
|
QNetworkReply* reply;
|
|
QNetworkAccessManager* networkAccessManager;
|
|
QTimer* networkTimer;
|
|
std::atomic<bool> aborted = false; // Not 100% sure we need atomic
|
|
void sendRequest(QString requestURL, QVector<QPair<QString, QJsonValue>> payloads);
|
|
private slots:
|
|
void requestTimeout();
|
|
void requestFinished();
|
|
signals:
|
|
void receivedResponse(QString response);
|
|
void failedResponse(QString errorString);
|
|
}; |