void RFIDMonitorDaemon::start()
{
    if(m_localServer->listen(m_serverName)){
        qDebug() <<  QString("Server name: %1").arg(m_localServer->serverName());

        initMonitor();

        QThread *consoleThread = new QThread(this);
        Console *console = new Console;
        console->moveToThread(consoleThread);

        connect(consoleThread, SIGNAL(destroyed()), console, SLOT(deleteLater()));
        connect(consoleThread, &QThread::started, console, &Console::run);
        connect(console, &Console::exitApp, consoleThread, &QThread::quit);
        connect(console, SIGNAL(exitApp()), qApp, SLOT(quit()));

        // consoleThread->start();

        QTimer::singleShot(100, this, SLOT(tcpConnect()));
    }else{
        qDebug() <<  "Could not start IPC server";
    }
    if(!m_udpSocket->bind(QHostAddress::Any, 9999))
        qDebug() <<  QString("Couldn't listening to broadcast");
}
RFIDMonitorDaemon::RFIDMonitorDaemon(QObject *parent) :
    QObject(parent),
    m_localServer(0),
    m_tcpSocket(0),
    m_tcpAppSocket(0),
    isConnected(false)
{
    m_configManager = new ConfigManager(this);

    m_localServer = new QLocalServer(this);
    m_tcpSocket = new QTcpSocket(this);
    m_tcpSocket->setObjectName("server");

    m_udpSocket = new QUdpSocket(this);
    m_tcpAppSocket = new QTcpSocket(this);
    m_tcpAppSocket->setObjectName("deskApp");

    m_serverName = "RFIDMonitorDaemon";

    m_restoreTimer.setInterval(10000);
    connect(&m_restoreTimer, &QTimer::timeout, [=](){
        m_configManager->restoreConfig();
        initMonitor();
    });

    connect(m_localServer, SIGNAL(newConnection()), SLOT(ipcNewConnection()));

    connect(m_tcpSocket, SIGNAL(connected()), SLOT(tcpConnected()));
    connect(m_tcpSocket, SIGNAL(disconnected()), SLOT(tcpDisconnected()));
    connect(m_tcpSocket, SIGNAL(readyRead()), SLOT(routeTcpMessage()));
    connect(m_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(tcpHandleError(QAbstractSocket::SocketError)));

    connect(m_udpSocket, SIGNAL(readyRead()), SLOT(readDatagrams()));

    connect(m_tcpAppSocket, &QTcpSocket::connected, ([=] () { m_udpSocket->close(); qDebug() <<  "Connected with DeskApp";}));
    connect(m_tcpAppSocket, &QTcpSocket::disconnected,
            ([=] () {
        qDebug() <<  "DeskApp Connection Closed";
        if(!m_udpSocket->bind(QHostAddress::Any, 9999)){
            qDebug() <<  QString("Couldn't listening broadcast");
        };
    }));

    connect(m_tcpAppSocket, SIGNAL(readyRead()), SLOT(routeTcpMessage()));

    QString socketFile = QString("/tmp/%1").arg(m_serverName);

    if(QFile::exists(socketFile)){
        QString rmCommand = QString("rm -f %1").arg(socketFile);
        system(rmCommand.toStdString().c_str());
    }
}
void RFIDMonitorDaemon::initMonitor()
{
    m_process.kill();
    m_process.start(QCoreApplication::applicationDirPath() + "/RFIDMonitor");

    qDebug() << "Process Started, PID: " << m_process.pid();

    connect(this, &RFIDMonitorDaemon::destroyed, &m_process, &QProcess::kill);
    connect(this, &RFIDMonitorDaemon::restartMonitor, [&]()
    {
        // Stop the RFIDMonitor
        ipcSendMessage(buildMessage(QJsonObject(), "STOP").toJson());
        // After 5 seconds try to restart the RFIDMonitor
        QTimer::singleShot(5000, this, SLOT(initMonitor()));
    });
    m_restoreTimer.start();
}
MusicAudioRecorderWidget::MusicAudioRecorderWidget(QWidget *parent)
    : MusicAbstractMoveDialog(parent),
      ui(new Ui::MusicAudioRecorderWidget), m_mBuffer(BufferSize, 0)
{
    ui->setupUi(this);

    ui->topTitleCloseButton->setIcon(QIcon(":/share/searchclosed"));
    ui->topTitleCloseButton->setStyleSheet(MusicUIObject::MToolButtonStyle03);
    ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->topTitleCloseButton->setToolTip(tr("Close"));

    connect(ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
    ui->startButton->setStyleSheet(MusicUIObject::MPushButtonStyle05);
    ui->startButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->startButton->setToolTip(tr("startAudio"));
    ui->stopButton->setStyleSheet(MusicUIObject::MPushButtonStyle05);
    ui->stopButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->stopButton->setToolTip(tr("stopAudio"));
    ui->playButton->setStyleSheet(MusicUIObject::MPushButtonStyle05);
    ui->playButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->playButton->setToolTip(tr("playAudio"));
    ui->saveButton->setStyleSheet(MusicUIObject::MPushButtonStyle05);
    ui->saveButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->saveButton->setToolTip(tr("saveButton"));

    connect(ui->startButton, SIGNAL(clicked()), SLOT(onRecordStart()));
    connect(ui->stopButton, SIGNAL(clicked()), SLOT(onRecordStop()));
    connect(ui->playButton, SIGNAL(clicked()), SLOT(onRecordPlay()));
    connect(ui->saveButton, SIGNAL(clicked()), SLOT(onRecordSave()));

    ui->checkBox->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox_2->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox_3->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox_4->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox_5->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox->setCursor(QCursor(Qt::PointingHandCursor));
    ui->checkBox_2->setCursor(QCursor(Qt::PointingHandCursor));
    ui->checkBox_3->setCursor(QCursor(Qt::PointingHandCursor));
    ui->checkBox_4->setCursor(QCursor(Qt::PointingHandCursor));
    ui->checkBox_5->setCursor(QCursor(Qt::PointingHandCursor));

    connect(&m_timer, SIGNAL(timeout()), SLOT(onTimerout()));
    ui->stopButton->setEnabled(false);
    ui->playButton->setEnabled(false);
    ui->saveButton->setEnabled(false);
    m_movie = nullptr;
    m_time = 0;

    m_miMaxValue = 0;
    ui->horizontalSlider->setValue(100);
    m_miVolume = 100;
    m_mpOutputFile = nullptr;
    m_mpAudioInputFile = nullptr;
    m_mpAudioOutputFile = nullptr;

    m_mpAudioInputSound = nullptr;
    m_mpAudioOutputSound = nullptr;

    m_mpInputDevSound = nullptr;
    m_mpInputDevSound = nullptr;

    m_mpOutputFile = new QFile(this);
    m_mpOutputFile->setFileName("record.raw");

    m_mFormatFile.setSampleSize(16);
    m_mFormatFile.setSampleType(QAudioFormat::SignedInt);
    m_mFormatFile.setByteOrder(QAudioFormat::LittleEndian);
    m_mFormatFile.setCodec("audio/pcm");

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
    if(!info.isFormatSupported(m_mFormatFile))
    {
        M_LOGGERS("input default mFormatFile not supported try to use nearest");
        m_mFormatFile = info.nearestFormat(m_mFormatFile);
    }
    QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
    if(!info1.isFormatSupported(m_mFormatFile))
    {
        M_LOGGERS("output default mFormatFile not supported - trying to use nearest");
        //           mFormatFile = info.nearestFormat(mFormatSound);
        M_LOGGERS("output no support input mFormatFile.");
        return;
    }
    if(m_mFormatFile.sampleSize() != 16)
    {
        M_LOGGER << "audio device doesn't support 16 bit support %d bit samples, example cannot run"
                 << m_mFormatFile.sampleSize() << LOG_END;
        m_mpAudioInputFile = 0;
        return;
    }

    m_mpAudioInputFile = nullptr;
    m_mpAudioOutputFile = nullptr;

    initMonitor();
}
MusicAudioRecorderWidget::MusicAudioRecorderWidget(QWidget *parent)
    : MusicAbstractMoveWidget(parent),
      m_ui(new Ui::MusicAudioRecorderWidget), m_mBuffer(BufferSize, 0)
{
    m_ui->setupUi(this);

    setAttribute(Qt::WA_DeleteOnClose, true);
    setAttribute(Qt::WA_QuitOnClose, true);

    m_ui->topTitleCloseButton->setIcon(QIcon(":/functions/btn_close_hover"));
    m_ui->topTitleCloseButton->setStyleSheet(MusicUIObject::MToolButtonStyle04);
    m_ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->topTitleCloseButton->setToolTip(tr("Close"));

    connect(m_ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
    m_ui->startButton->setStyleSheet(MusicUIObject::MPushButtonStyle04);
    m_ui->startButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->startButton->setToolTip(tr("startAudio"));
    m_ui->stopButton->setStyleSheet(MusicUIObject::MPushButtonStyle04);
    m_ui->stopButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->stopButton->setToolTip(tr("stopAudio"));
    m_ui->playButton->setStyleSheet(MusicUIObject::MPushButtonStyle04);
    m_ui->playButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->playButton->setToolTip(tr("playAudio"));
    m_ui->saveButton->setStyleSheet(MusicUIObject::MPushButtonStyle04);
    m_ui->saveButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->saveButton->setToolTip(tr("saveButton"));

    connect(m_ui->startButton, SIGNAL(clicked()), SLOT(onRecordStart()));
    connect(m_ui->stopButton, SIGNAL(clicked()), SLOT(onRecordStop()));
    connect(m_ui->playButton, SIGNAL(clicked()), SLOT(onRecordPlay()));
    connect(m_ui->saveButton, SIGNAL(clicked()), SLOT(onRecordSave()));

    m_ui->checkBox->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox_2->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox_3->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox_4->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox_5->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->checkBox_2->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->checkBox_3->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->checkBox_4->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->checkBox_5->setCursor(QCursor(Qt::PointingHandCursor));

#ifdef Q_OS_UNIX
    m_ui->startButton->setFocusPolicy(Qt::NoFocus);
    m_ui->stopButton->setFocusPolicy(Qt::NoFocus);
    m_ui->playButton->setFocusPolicy(Qt::NoFocus);
    m_ui->saveButton->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox_2->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox_3->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox_4->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox_5->setFocusPolicy(Qt::NoFocus);
#endif

    m_ui->progress->setStyleSheet(MusicUIObject::MProgressBar02);
    m_ui->horizontalSlider->setStyleSheet(MusicUIObject::MSliderStyle01);

    connect(&m_timer, SIGNAL(timeout()), SLOT(onTimerout()));
    m_ui->stopButton->setEnabled(false);
    m_ui->playButton->setEnabled(false);
    m_ui->saveButton->setEnabled(false);
    m_movie = nullptr;
    m_time = 0;

    m_miMaxValue = 0;
    m_ui->horizontalSlider->setValue(100);
    m_miVolume = 100;

    m_mpAudioInputSound = nullptr;
    m_mpAudioOutputSound = nullptr;

    m_mpInputDevSound = nullptr;
    m_mpOutputDevSound = nullptr;

    m_recordCore = new MusicAudioRecorderCore(this);

    initMonitor();
}
예제 #6
0
void SystemInit(void)
{
    C29ID c29id;
    uint8_t payload[8] = {0};

    HardwareInit();

    //upper light initial
    g_Device.ULight.Intensity = 1;
    g_Device.ULight.Intensity_I = 1;
    g_Device.ULight.status = 0x0a17;
    //lower light initial
    g_Device.LLight.Intensity = 4;
    g_Device.LLight.Intensity_I = 4;
    g_Device.ULight.status = 0x0a17;
    //colibri
    g_Device.Colibri.Settled = false;
    //dazzle protection
#if RELEASE
    g_Device.DazzleProtect = true;
#else
    g_Device.DazzleProtect = false;
#endif
    //HAL100 initial
    g_Device.HAL100.Settled = false;
    //keys initial
    g_Device.Keys.KnobValue = 0;
    g_Device.Keys.RLTLStatus = sts00;
    g_Device.Keys.LmSnap = sts00;
    //RLTL switch initial
    if (g_Device.Serie == Axiolab && g_Device.VarType == VAR_Bio) {
        g_Device.RLTLSw.Sw = LSW_LOWER;
        UGreenOn();  // for indicator board share with vario, only one LED always on, and no rltl button.
    }else if (g_Device.VarType == VAR_Vario) {
        g_Device.RLTLSw.Sw = LSW_UPPER;
        UGreenOn();
    }else {
        g_Device.RLTLSw.Sw = LSW_UPPER;
        UGreenOn();
    }
    g_Device.RLTLSw.Lock.Status = false;
    g_Device.RLTLSw.status = 0x0117;
    //lampled initial
    g_Device.LampLed.LampMode = true;
    g_Device.LampLed.pLed = &g_Device.ULight;
    g_Device.LampLed.Lock.Status = false;
    //lightmanager initial
    g_Device.LM.Enable = true;
    g_Device.LM.LRatio = 0xffff;
    g_Device.LM.URatio = 0xffff;
    //lockmask initial
    g_Device.LockMask = 0;
    //mode
    g_Device.Mode = NORM;
    // dodge
    g_Device.dodge_z= false;
    //motor x,y,z part initial
    g_Device.MotorX.Settled = false;
    g_Device.MotorY.Settled = false;
    g_Device.MotorZ.Settled = false;
    g_Device.MotorX.moving = false;
    g_Device.MotorY.moving = false;
    g_Device.MotorZ.moving = false;
    g_Device.MotorX.Position = 0;
    g_Device.MotorY.Position = 0;
    g_Device.MotorZ.Position = 0;
    g_Device.MotorX.PrevParIndex = Position0;
    g_Device.MotorY.PrevParIndex = Position0;
    g_Device.MotorZ.PrevParIndex = Position0;
    g_Device.MotorX.PosPrevPar = 0;
    g_Device.MotorY.PosPrevPar = 0;
    g_Device.MotorZ.PosPrevPar = 0;
    g_Device.MotorX.Lock.Status = false;
    g_Device.MotorY.Lock.Status = false;
    g_Device.MotorZ.Lock.Status = false;
    g_Device.MotorX.SoftLimit = 0;
    g_Device.MotorY.SoftLimit = 0;
    g_Device.MotorZ.SoftLimit = 0;
//  g_Device.MotorX.Parcenter = -1;
//  g_Device.MotorY.Parcenter = -1;
//  g_Device.MotorZ.Parcenter = -1;
//  g_Device.NosePiece.status = 0x0203; // device exists | device encoded | device initialized
//  g_Device.Reflector.status = 0x0203;
    g_Device.NosePiece.status = 0x0207; // to pretend they're motorized
    g_Device.Reflector.status = 0x0207;

    //indicator initial
    g_Device.Indc.BlinkColour = IND_NONE;
    g_Device.Indc.RequireColour = IND_NONE;
    g_Device.Indc.IndSts = Indsts_Norm;

    //key initial
    g_Device.Keys.StartTime_single_snap = GetSysTick0();    // leilc add for double click

    //descriptor init
    DescInitRead(DESC_RFLM, 0x10, RLMatrix, 42, DESCFMT_USHORT);
    DescInitRead(DESC_TMLM, 0x10, TLMatrix, 6, DESCFMT_USHORT);
    DescInitRead(DESC_XYZ, 0x41, PcTable.Z, 6, DESCFMT_LONG);
    DescInitRead(DESC_XYZ, 0x91, PcTable.X, 6, DESCFMT_LONG);
    DescInitRead(DESC_XYZ, 0xA1, PcTable.Y, 6, DESCFMT_LONG);

    DescInitRead(DESC_ELEMENTS, 0x12, &np_mag[0], 1, DESCFMT_FLOAT);
    DescInitRead(DESC_ELEMENTS, 0x22, &np_mag[1], 1, DESCFMT_FLOAT);
    DescInitRead(DESC_ELEMENTS, 0x32, &np_mag[2], 1, DESCFMT_FLOAT);
    DescInitRead(DESC_ELEMENTS, 0x42, &np_mag[3], 1, DESCFMT_FLOAT);
    DescInitRead(DESC_ELEMENTS, 0x52, &np_mag[4], 1, DESCFMT_FLOAT);
    DescInitRead(DESC_ELEMENTS, 0x62, &np_mag[5], 1, DESCFMT_FLOAT);

    Reset_gDeviceShadow();

    //book event of focus-z stable position
    c29id.all = 0x1B0f195f;
    payload[0] = 0x01; //pid
    payload[1] = 0x1f; //subid
    payload[2] = 0; //devid
    payload[3] = 0x03; //mode
    payload[4] = 0x00; //interval_h
    payload[5] = 0xf0; //interval_l
    payload[6] = CANNODE_MCB; //address
    payload[7] = 0x01; //pid
    StartECanTxTask(c29id, payload, 8, 30);
    //book event of motor-x stable position
    c29id.all = 0x1B26195f;
    payload[0] = 0x01; //pid
    payload[1] = 0x1f; //subid
    payload[2] = 0; //devid
    payload[3] = 0x03; //mode
    payload[4] = 0x00; //interval_h
    payload[5] = 0x00; //interval_l
    payload[6] = CANNODE_MCB; //address
    payload[7] = 0x01; //pid
    StartECanTxTask(c29id, payload, 8, 30);
    //book event of motor-y stable position
    c29id.all = 0x1B27195f;
    payload[0] = 0x01; //pid
    payload[1] = 0x1f; //subid
    payload[2] = 0; //devid
    payload[3] = 0x03; //mode
    payload[4] = 0x00; //interval_h
    payload[5] = 0x00; //interval_l
    payload[6] = CANNODE_MCB; //client address
    payload[7] = 0x01; //pid
    StartECanTxTask(c29id, payload, 8, 30);

    // get Z position
    c29id.all = 0x180f195f;
    payload[0] = 0x01; //pid
    payload[1] = 0x31; //subid
    payload[2] = 0; //devid
    StartECanTxTask(c29id, payload, 3, 30);

    monitorHandwheel(true);
    initMonitor();
}