Added button for sending route to server.
[speedfreak] / Client / carmainwindow.cpp
index e854ab1..5da33b7 100644 (file)
@@ -7,6 +7,7 @@
  * @author     Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
  * @author     Rikhard Kuutti <rikhard.kuutti@fudeco.com>
  * @author     Kai Rasilainen <kai.rasilainen@fudeco.com>
+ * @author     Jukka Kurttila <jukka.kurttila@fudeco.com>
  * @copyright  (c) 2010 Speed Freak team
  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  */
@@ -14,8 +15,8 @@
 #include "carmainwindow.h"
 #include "math.h"
 
-#define kAccelerometerSampleRate    50
-#define kFilteringFactor            0.2
+#define kAccelerometerSampleRate    40
+#define kFilteringFactor            0.1
 #define kSecondsInHour              3600
 
 /**
@@ -26,6 +27,11 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
 {
     ui->setupUi(this);
     ui->tabWidget->setCurrentWidget(this->ui->StartTab);
+
+    //Disable start buttons before calibration
+    ui->autoStartButton->setEnabled(false);
+    ui->manualStartButton->setEnabled(false);
+
     result = new ResultDialog();
     //measure = new MeasureDialog();
     welcomeDialog = new WelcomeDialog();
@@ -35,11 +41,13 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
     initListViewStartTabAccelerationCategories();
 
     myLogin = new LoginWindow(this);
-    categorylist = new CategoryList();
+    myCategorylist = new CategoryList();
     myHttpClient = new HttpClient(this);
     myRegistration = new Registration(this);
     connect(myRegistration,SIGNAL(sendregistration()),this,SLOT(regUserToServer()));
     connect(myLogin,SIGNAL(userNameChanged()),this,SLOT(userLogin()));
+    connect(myHttpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
+    connect(myHttpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
     myRoute = new RouteDialog( this);
 
     //GPS
@@ -47,6 +55,13 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
     gpsData = new GPSData(location);
     connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
     gpsTime = new QDateTime();
+    gpsTimer = new QTimer();
+    connect(gpsTimer, SIGNAL(timeout()),this, SLOT(gpsTimerTimeout()));
+    gpsSpeedNow = 0.0;
+    gpsSpeedPrevious = 0.0;
+    gpsAcceleration = 0.0;
+    timeFromGps = 0.0; //Measure-tab view.
+    gpsSpeed = 0.0;
 
     this->time = 0;
     this->speed = 0;
@@ -55,13 +70,14 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
 
     // Accelerometer
     accelerometer = new Accelerometer();
+    movingAverageZ = new MovingAverage(10);
 
     reverseAccelerationFlag = false;
     vehicleStartedMoving = false;
     isNewRun = true;
     isSetup = false;
     stopTime = 0;
-    accelerationStartThreshold = 0.02;
+    accelerationStartThreshold = 0.1;
 
     accelerometerTimer = new QTimer(this);
     connect(accelerometerTimer, SIGNAL(timeout()), this, SLOT(readAccelerometerData()));
@@ -74,18 +90,18 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
     resetAccelerometerMeasurements();
 
     measures = new Measures();
-    this->initializeMeasures();
+    measures->initializeMembers();
 
-    this->timer->setInterval(300);
+    this->timer->setInterval(100);
 
     connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout()));
     connect(myLogin, SIGNAL( userNameChanged()), this, SLOT(updateUserName()));
 
     ui->labelMeasureTabResult->hide();
     ui->pushButtonShowResultDialog->setEnabled(false);
+    ui->pushButtonShowResultDialog->setEnabled(false);
 
     this->setWindowTitle("Speed Freak");
-
 }
 
 /**
@@ -97,8 +113,8 @@ CarMainWindow::~CarMainWindow()
     ui = NULL;
     //delete result;
     //delete measure;
-    delete categorylist;
-    categorylist = NULL;
+    delete myCategorylist;
+    myCategorylist = NULL;
     delete welcomeDialog;
     welcomeDialog = NULL;
     delete myRoute;
@@ -107,6 +123,14 @@ CarMainWindow::~CarMainWindow()
     gpsData = NULL;
     delete gpsTime;
     gpsTime = NULL;
+
+    //Route-tab view
+    gpsSpeedNow = 0.0;
+    gpsSpeedPrevious = 0.0;
+    gpsAcceleration = 0.0;
+    timeFromGps = 0.0;
+    gpsSpeed = 0.0;
+    gpsUpdateTime = 0;
 }
 
 /**
@@ -132,37 +156,42 @@ void CarMainWindow::on_listViewStartTabAccelerationCategories_clicked(QModelInde
 {
     QString str = index.data().toString();
     QStringList list = str.split("-");
-    QStringList list2 = list[1].split(" ");
+    QStringList list3 = list[1].split(" ");
+    QStringList list2 = list[0].split(" ");
 
-    ui->lineEditStartTabMin->setText(list[0]);
-    ui->lineEditStartTabMax->setText(list2[0]);
-    updateComboBoxStartTabUnits(list2[1]);
+    ui->lineEditStartTabMin->setText(list2[1]);
+    ui->lineEditStartTabMax->setText(list3[0]);
+    updateComboBoxStartTabUnits(list3[1]);
 }
 
 /**
   *This slot function is called when ever auto start button clicked. Start-tab view.
+  *@todo Check setDiagramGapStem(100) <- (choiceInt == 2)
   */
 void CarMainWindow::on_autoStartButton_clicked()
 {
-    initializeMeasures();
+    measures->initializeMembers();
     resetAccelerometerMeasurements();
     ui->pushButtonSendResult->setEnabled(false);
     ui->pushButtonShowResultDialog->setEnabled(false);
     choice = ui->listViewStartTabAccelerationCategories->currentIndex();
     choiceInt = choice.row();
-    qDebug() << choiceInt;
+    //qDebug() << "choiceInt" << choiceInt << " " << catList.at(choiceInt);
     if (choiceInt == 0)
     {
         ui->labelMeasureTabHeader->setText("Accelerate to 40 km/h");
         result->setDiagramGapStem(75);
     }
-
     else if (choiceInt == 1)
     {
         ui->labelMeasureTabHeader->setText("Accelerate to 100 km/h");
         result->setDiagramGapStem(30);
+    }   
+    else if (choiceInt == 2)
+    {
+        ui->labelMeasureTabHeader->setText("Accelerate to 10 km/h");
+        result->setDiagramGapStem(100);
     }
-
     else
     {
         ui->labelMeasureTabHeader->setText("Accelerate to 80 km/h");
@@ -206,10 +235,19 @@ void CarMainWindow::setComboBoxStartTabUnits(QStringList units)
 
 /**
   *This function is used to init listViewStartTabAccelerationCategories. Start-tab view.
+  *@todo During development categories index values that are used for measuring are hardcoded
+  *@todo and accelerationCategoriesStartTab and catList are used instead of using
+  *@todo CategoryList::categoryList and CategoryList::cats.
   */
 void CarMainWindow::initListViewStartTabAccelerationCategories()
 {
-    accelerationCategoriesStartTab << "0-40 km/h" << "0-100 km/h"; //<< "0-1/4 Mile" << "0-1/8 Mile" << "0-50 km" << "50-100 Mile" << "0-60 Mph" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
+    //Connect the user`s choice fron GUI to a correct variable name
+    catList.insert(0,"acceleration-0-40");
+    catList.insert(1,"acceleration-0-100");
+    catList.insert(2,"acceleration-0-10");
+
+    accelerationCategoriesStartTab << "Acceleration 0-40 km/h" << "Acceleration 0-100 km/h" << "Acceleration 0-10 km/h";
+    //<< "0-1/4 Mile" << "0-1/8 Mile" << "50-100 Mile" << "0-60 Mph" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
     QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab);
     ui->listViewStartTabAccelerationCategories->setModel(model);
 }
@@ -224,23 +262,41 @@ void CarMainWindow::setListViewStartTabAccelerationCategories(QStringList accele
     ui->listViewStartTabAccelerationCategories->setModel(model);
 }
 
+void CarMainWindow::setLabelInfoToUser(QString infoText)
+{
+    ui->labelInfoToUser->setText(infoText);
+}
+
 /**
   *This function is used to set items to category combobox. Top-tab view.
   *@param
   */
 void CarMainWindow::setCategoryCompoBox()
 {
-    ui->comboBoxTopCategory->addItems(categorylist->getCategoryList());
+    qDebug() << "_setCategoryCompoBox";
+    ui->comboBoxTopCategory->addItems(myHttpClient->myXmlreader->myCategoryList->getCategoryList());
+}
+
+/**
+  *This function prcesses UI updating after a new top10List has been received.
+  *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
+  */
+void CarMainWindow::showTop10()
+{
+    int limitNr = 5;
+    setListViewTopList(recentCategory, limitNr);
 }
 
 /**
   *This function is used to set items to labelTopList. Top-tab view.
-  *@param QString category
+  *@param Category
+  *@param Size, number of results.
   */
 void CarMainWindow::setListViewTopList(QString category, int size)
 {
+    qDebug() << "_setListViewTopList";
     QString topList;
-    topList.append( categorylist->getTopList(category, size));
+    topList.append(myHttpClient->myXmlreader->myCategoryList->getTopList(category, size));
     ui->labelTopList->setText(topList);
 }
 
@@ -266,30 +322,20 @@ void CarMainWindow::on_registratePushButton_clicked()
 void CarMainWindow::on_buttonTopRefresh_clicked()
 {
     myHttpClient->requestCategories();
-    setCategoryCompoBox();
 }
 
 /**
   *This slot function is called when ever category combobox current index changed. Top-tab view.
-  *@param QString category
-  *@todo Check where limitNr is taken.
+  *@param QString category.
+  *@todo Check where limitNr is taken, fixed or user input, see showTop10.
   */
 void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
 {
-    int limitNr = 5;                    //replace with real value?
+    qDebug() << "_on_comboBoxTopCategory_currentIndexChanged: " << category;
+    recentCategory = category;      //for showTop10()
+    int limitNr = 5;
     QString limit = QString::number(limitNr);
-    category = "acceleration-0-100";    //replace with real value from category list/top window
     myHttpClient->requestTopList(category, limit);
-    setListViewTopList(category,10);
-}
-
-/**
-  *This slot function is called when ever category combobox activated. Top-tab view.
-  *@param QString category
-  */
-void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
-{
-    setListViewTopList(category,10);
 }
 
 /**
@@ -316,32 +362,20 @@ void CarMainWindow::on_manualStartButton_clicked()
   */
 void CarMainWindow::after_timeout()
 {
-    QString timeString, speedString;
-    //time++;
-    //speed = speed +10;
-    timeString.setNum(time);
-    speedString.setNum(speed);
-    ui->labelMeasureTabTime->setText(timeString);
-    ui->labelMeasureTabSpeed->setText(speedString);
-
-    //handleCheckPoint(time, speed);
-}
+    //IF GPS checkbox is ON
+    if (ui->gpsOnCheckBox->isChecked())
+    {
+        if ( gpsSpeed > 1.0 )
+        {
+            timeFromGps += 0.1;
+        }
+    }
 
-/**
-  * Initializes measures class's member variables.
-  */
-void CarMainWindow::initializeMeasures()
-{
-    measures->setTime10kmh(0);
-    measures->setTime20kmh(0);
-    measures->setTime30kmh(0);
-    measures->setTime40kmh(0);
-    measures->setTime50kmh(0);
-    measures->setTime60kmh(0);
-    measures->setTime70kmh(0);
-    measures->setTime80kmh(0);
-    measures->setTime90kmh(0);
-    measures->setTime100kmh(0);
+    else
+    {
+        ui->labelMeasureTabSpeed->setText(QString::number(this->speed)); //Set speed. //Measure-tab view.
+        ui->labelMeasureTabTime->setText(QString::number(this->time)); //Set time. //Measure-tab view.
+    }
 }
 
 /**
@@ -354,27 +388,27 @@ void CarMainWindow::on_pushButtonMeasureTabAbort_clicked()
     ui->labelMeasureTabResult->hide();
     ui->labelMeasureTabTime->setText("");
     ui->labelMeasureTabSpeed->setText("");
-    measures->setTime10kmh(0);
-    measures->setTime20kmh(0);
-    measures->setTime30kmh(0);
-    measures->setTime40kmh(0);
-    measures->setTime50kmh(0);
-    measures->setTime60kmh(0);
-    measures->setTime70kmh(0);
-    measures->setTime80kmh(0);
-    measures->setTime90kmh(0);
-    measures->setTime100kmh(0);
+    measures->initializeMembers();
     this->accelerometerTimer->stop();
     this->timer->stop();
     this->time = 0;
     this->speed = 0;
     ui->tabWidget->setCurrentWidget(this->ui->StartTab);
     //this->close();
+
+    //GPS
+    gpsSpeed = 0.0;
+    timeFromGps = 0.0;
 }
 
+/**
+  *This slot function is called when pushButtonSendResult is clicked.
+  *@todo Use real category value.
+  */
 void CarMainWindow::on_pushButtonSendResult_clicked()
 {
-    myHttpClient->sendResultXml();
+    //Pick up relevant category name and pass it to the server
+    myHttpClient->sendResultXml(catList.at(choiceInt));
     ui->pushButtonSendResult->setEnabled(false);
 }
 
@@ -388,12 +422,12 @@ void CarMainWindow::updateUserName()
     if (newUserName.length())
     {
        ui->setUserPushButton->setText( "Change User");
-       this->setWindowTitle("Speed freak - " + newUserName);
+       this->setWindowTitle("Speed Freak - " + newUserName);
     }
     else
     {
         ui->setUserPushButton->setText( "Set User");
-        this->setWindowTitle("Speed freak");
+        this->setWindowTitle("Speed Freak");
     }
 }
 
@@ -405,7 +439,16 @@ void CarMainWindow::regUserToServer()
 
 void CarMainWindow::on_drawRoutePushButton_clicked()
 {
-    myRoute->show();
+    QString routeFile = QString("route.txt");
+    if (myRoute->readRouteFromFile( routeFile) == true)
+    {
+        myRoute->show();
+    }
+}
+
+void CarMainWindow::on_sendRoutePushButton_clicked()
+{
+    myHttpClient->sendRouteXml();
 }
 
 /**
@@ -433,13 +476,13 @@ void CarMainWindow::resetAccelerometerMeasurements()
     currentSpeed = "";
     currentTime = 0;
     distanceTraveled = "";
-    firstAcceleration = 0;
+    //firstAcceleration = 0;
     //horsepower = null;
     isNewRun = true;
     //lastScreenUpdateInSeconds = 0;
     previousTime = 0;
     reverseAccelerationFlag = false;
-    stopWatch.setHMS(0, 0, 0, 0);
+    stopWatch.start();
     //accelerometer->stop();
     totalTime = "";
     vehicleStartedMoving = false;
@@ -509,7 +552,6 @@ void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
         this->speed = 0;
         counterForSaveResults = 0;
     }
-
     else if (choiceInt == 1 && measures->getTime100kmh() != 0)
     {
         setTimeAxisGapAndShowResult(measures->getTime100kmh());
@@ -518,9 +560,16 @@ void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
         this->time = 0;
         this->speed = 0;
         counterForSaveResults = 0;
-
     }
-
+    else if (choiceInt == 2 && measures->getTime10kmh() != 0)
+    {
+        setTimeAxisGapAndShowResult(measures->getTime10kmh());
+        this->timer->stop();
+        this->accelerometerTimer->stop();
+        this->time = 0;
+        this->speed = 0;
+        counterForSaveResults = 0;
+    }
     else if (choiceInt != 1 && choiceInt != 0 && measures->getTime80kmh() != 0)
     {
         setTimeAxisGapAndShowResult(measures->getTime80kmh());
@@ -530,10 +579,9 @@ void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
         this->speed = 0;
         counterForSaveResults = 0;
     }
-
     else
     {
-
+        qDebug() << "something wrong in handleCheckPoint()";
     }
 }
 
@@ -547,7 +595,15 @@ void CarMainWindow::readAccelerometerData()
     qreal x, y, z;
 
     accelerometer->getAcceleration(x, y, z);
-    accelerometer->smoothData(x, y, z);
+
+    //  keep the following line as close to the SetKinematicsProperties method as possible
+    currentTime = stopWatch.elapsed();
+
+    //accelerometer->smoothData(x, y, z);
+
+    //Calculate average
+    movingAverageZ->Enqueue(z);
+    z = movingAverageZ->Average();
 
     // Apply calibration
     x -= accelerometer->getCalibrationX();
@@ -558,54 +614,22 @@ void CarMainWindow::readAccelerometerData()
                           "acc y: " + QString::number(y) + "\n" +
                           "acc z: " + QString::number(z) + "\n");
 
-    if (!vehicleStartedMoving)
-    {
-        if (isNewRun)
-        {
-            firstAcceleration = sqrt(x*x + y*y + z*z);
-            //firstAcceleration = y; // first read
-            isNewRun = false;
-        }
-    }
-
-    currentAcceleration = sqrt(x*x + y*y + z*z);
-    changeInAcceleration = (currentAcceleration - firstAcceleration); // firstAcceleration only gets set once
+    currentAcceleration = z;//sqrt(x*x + y*y + z*z);
+    changeInAcceleration = currentAcceleration;
 
     if (((fabs(changeInAcceleration) <= accelerationStartThreshold)
                 && !vehicleStartedMoving))
     {
         return;
     }
-
-    if (reverseAccelerationFlag)
+    else if(!vehicleStartedMoving)
     {
-        // will be false until after 1st calculation
-        if ((changeInAcceleration <= 0))
-        {
-            // actually increasing here...
-            changeInAcceleration = fabs(changeInAcceleration);
-        }
-        else
-        {
-            // actually decreasing here...
-            changeInAcceleration = (changeInAcceleration * -1);
-        }
-    }
-    if (!vehicleStartedMoving)
-    {
-        if ((changeInAcceleration < 0))
-        {
-            // we started to move backwards first time through
-            reverseAccelerationFlag = true;
-            changeInAcceleration = fabs(changeInAcceleration);
-        }
         vehicleStartedMoving = true;
-
-        stopWatch.setHMS(0, 0, 0, 0);
         stopWatch.start();
+        previousTime = 0;
+        currentTime = 0;
     }
-    //  keep the following line as close to the SetKinematicsProperties method as possible
-    currentTime = stopWatch.elapsed();
+
     calculate->calculateParameters(changeInAcceleration, (currentTime - previousTime)/1000);
     previousTime = currentTime;
 
@@ -614,8 +638,8 @@ void CarMainWindow::readAccelerometerData()
 
     speed = 0.0;
     speed = calculate->getCurrentSpeed();
-    speed = ((speed*1000)/kSecondsInHour);
-    s.sprintf("%.2f", speed);
+    speed = speed*3.6;//((speed*1000)/kSecondsInHour);
+    s.sprintf("%.1f", speed);
     currentSpeed = s;
 
     s.sprintf("%.2f", calculate->getDistanceTraveled());
@@ -653,48 +677,134 @@ void CarMainWindow::calibrateAccelerometer()
 }
 
 /**
-  *This slot function is called when GPS on checkbox state changed.  Route-tab view.
+  *This slot function is called when GPS on checkbox state changed. Route-tab view.
   *@param int GPSState
   */
 void CarMainWindow::on_gpsOnCheckBox_stateChanged(int GPSState)
 {
+    //Stop polling GPS. Route-tab view.
     if (GPSState == 0)
     {
-        ui->labelRouteTabGPSStatus->setText("GPS off");//testing
+        ui->labelRouteTabGPSStatus->setText("GPS status: GPS off");
         location->stopPollingGPS();
+        gpsUpdateTime = 0;
+        gpsTimer->stop();
     }
+    //Start polling GPS. Route-tab view.
     else
     {
-        ui->labelRouteTabGPSStatus->setText("GPS on");//testing
+        ui->labelRouteTabGPSStatus->setText("GPS status: GPS on");
         location->startPollingGPS();
     }
 }
 
 /**
-  *This slot function is called when GPS status changed.  Route-tab view.
+  *This slot function is called when GPS status changed. Route- and measure-tab view.
   */
 void CarMainWindow::gpsStatus()
 {
+    //IF GPS checkbox is ON
     if (ui->gpsOnCheckBox->isChecked())
     {
+        //If GPS find 4 satellite.
         if (location->getSatellitesInUse() >= 4)
         {
-            //Set status
+            //Set gps status. Route-tab view.
             ui->labelRouteTabGPSStatus->setText("GPS ready");
 
-            //Set time
+            //Set time. Route-tab view.
             gpsTime->setTime_t(location->getTime());
-            ui->labelRouteTabGPSTime->setText(gpsTime->toString());
-
-            //Set latitude & longitude
-            ui->labelRouteTabLatitude->setText("Lat: " + QString::number(location->getLatitude()));
-            ui->labelRouteTabLongitude->setText("Lon: " + QString::number(location->getLongitude()));
+            QString gpsDateNow = gpsTime->toString("dd.MM.yyyy hh:mm:ss");
+            ui->labelRouteTabGPSTime->setText("GPS time: " + gpsDateNow);
+
+            //Set latitude & longitude. Route-tab view.
+            ui->labelRouteTabLatitude->setText("Latitude: " + QString::number(location->getLatitude()));
+            ui->labelRouteTabLongitude->setText("Longitude: " + QString::number(location->getLongitude()));
+
+            //Set rec status. Route-tab view.
+            if (ui->startRecPushButton->text() == "Stop recording")
+            {
+                ui->labelRouteTabRecStatus->setText("Recorded " + QString::number(gpsData->roundCounter) + " point");
+            }
+
+            //Get speed. Route- and Measure-tab view.
+            gpsSpeed = location->getSpeed();
+
+            //Set speed. Route-tab view.
+            ui->labelRouteTabSpeed->setText("Speed:" + QString::number(gpsSpeed) + "km/h +/-" + QString::number(location->getEps()) + "km/h");
+
+            //Measure-tab view.
+            if (gpsSpeed < 40.0)
+            {              
+                ui->labelMeasureTabSpeed->setText(QString::number(gpsSpeed)); //Set speed. //Measure-tab view.
+                ui->labelMeasureTabTime->setText(QString::number(timeFromGps)); //Set time. //Measure-tab view.
+            }
+            //Measure-tab view.
+            else
+            {
+                timer->stop(); //Measure timer
+                ui->labelMeasureTabResult->setText(QString::number(timeFromGps));
+                ui->labelMeasureTabResult->show();
+                ui->pushButtonShowResultDialog->setEnabled(true);
+                ui->pushButtonShowResultDialog->setEnabled(true);
+            }
         }
 
+        //If GPS find less than 4 satellite.
         else
         {
-            ui->labelRouteTabGPSStatus->setText("Waiting for GPS");
+            ui->labelRouteTabGPSStatus->setText("GPS status: Waiting for GPS");
+            gpsTimer->stop();
         }
+
+        gpsUpdateTime = 0;
+        gpsTimer->start(10);
+    }
+}
+
+/**
+  *This slot function is called when gps timer timeout(10ms).
+  */
+void CarMainWindow::gpsTimerTimeout()
+{
+    int time1000ms = 0;
+    time1000ms += 10;
+
+    //IF time is 1 second
+    if (time1000ms == 1000)
+    {
+        //Calculate acceleration 1/s
+        gpsSpeedPrevious = gpsSpeedNow; //Previous speed
+        gpsSpeedNow = (location->getSpeed())/3.6; //Speed now (m/s)
+        gpsAcceleration = (gpsSpeedNow - gpsSpeedPrevious)/1; //Calculate acceleration: speed now - previous speed / 1s.
+        //Set acceleration. Route-tab view.
+        ui->labelRouteTabAcceleration->setText("Acceleration: " + QString::number( gpsAcceleration ) + " m/s2");
+    }
+
+    gpsUpdateTime++;
+    //Set GPS update time. Route-tab view.
+    ui->labelRouteTabGPSUpdateTime->setText("GPS update time: " + QString::number(gpsUpdateTime) + " ms");
+}
+
+/**
+  *This slot function is called when start rec push button clicked. Route-tab view.
+  */
+void CarMainWindow::on_startRecPushButton_clicked()
+{
+    //Start route recording.
+    if (ui->startRecPushButton->text() == "Start recording")
+    {
+        ui->startRecPushButton->setText("Stop recording");
+        ui->labelRouteTabRecStatus->setText("Recording started");
+        gpsData->startRouteRecording(ui->labelRouteTabGPSTime->text());
+    }
+
+    //Stop route recording.
+    else if (ui->startRecPushButton->text() == "Stop recording")
+    {
+        ui->startRecPushButton->setText("Start recording");
+        ui->labelRouteTabRecStatus->setText("Recording stopped");
+        gpsData->stopRouteRecording(ui->labelRouteTabGPSTime->text());
     }
 }
 
@@ -726,3 +836,12 @@ void CarMainWindow::setTimeAxisGapAndShowResult(double pTime)
         result->setDiagramGapHorizontal(20);
     }
 }
+
+void CarMainWindow::on_calibrateButton_clicked()
+{
+    ui->autoStartButton->setEnabled(true);
+    ui->manualStartButton->setEnabled(true);
+
+    this->accelerometer->calibrate();
+}
+