Skip to content

Commit

Permalink
adds state counter update
Browse files Browse the repository at this point in the history
  • Loading branch information
bytecod3 committed Jun 24, 2024
1 parent 1a334f8 commit 52f8f44
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/NaFCSE/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->cmbBaudRates->addItem(baudRates[i]);
}


// set the possible timesteps in milliseconds
this->numTimeSteps = 8;
QString time_steps[numTimeSteps] = {"200", "400", "600", "800", "1000", "1500", "2000", "5000"};
Expand Down Expand Up @@ -202,6 +203,5 @@ void MainWindow::updateSerialMonitor(const QString data) {
*/
void MainWindow::readData(const QString data) {
parser.parseAll(data);

}

8 changes: 2 additions & 6 deletions app/NaFCSE/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ color: black;</string>
<item>
<widget class="QLabel" name="label_13">
<property name="styleSheet">
<string notr="true">border: 0px solid black;
border-bottom: 2px solid black;
border-top: 2px solid #a0a0a0;
border-right: 2px solid black;
border-left: 2px solid #a0a0a0;
<string notr="true">border-radius: 4px;
color: black;</string>
</property>
<property name="text">
Expand Down Expand Up @@ -625,7 +621,7 @@ border-left: 2px solid #a0a0a0;</string>
<x>0</x>
<y>0</y>
<width>1242</width>
<height>21</height>
<height>22</height>
</rect>
</property>
</widget>
Expand Down
58 changes: 56 additions & 2 deletions app/NaFCSE/serialparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,66 @@ void SerialParser::parseAll(const QString data) {
QString clean_data = data.trimmed();

QStringList telemetry_packet = clean_data.split(',');

QString recordNumber = telemetry_packet.at(0);

qDebug() << clean_data;
QString state = telemetry_packet.at(1);
this->decodeStates(state);

}

void decodeStates() {
/**
* @brief decodeStates
* @param s
*
* Handle the states received from the serial monitor
*
*/
void SerialParser::decodeStates(const QString s) {
qint8 state = s.toInt();
qDebug() << state;


switch (state) {
case 0:
qDebug() << "PREFLIGHT";
break;

case 1:
qDebug() << "POWERED FLIGHT";
break;

case 2:
qDebug() << "COASTING";
break;

case 3:
qDebug() << "APOGEE";
break;

case 4:
qDebug() << "DROGUE-CHUTE-DEPLOY";
break;

case 5:
qDebug() << "DROGUE-CHUTE-DESCENT";
break;

case 6:
qDebug() << "MAIN-CHUTE-DEPLOY";
break;

case 7:
qDebug() << "MAIN-CHUTE-DESCENT";
break;

case 8:
qDebug() << "POST-FLIGHT";
break;

default:
break;
}


}
2 changes: 1 addition & 1 deletion app/NaFCSE/serialparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SerialParser : public QObject
QVector<QString> packet_vector; // store parsed csv packet

void parseAll(const QString data);
void decodeStates();
void decodeStates(const QString s);
void testParse();


Expand Down
4 changes: 4 additions & 0 deletions app/NaFCSE/serialport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ bool SerialPort::connectToSerial(QString portName, QString baudRate) {

}

/**
* @brief SerialPort::dataReady
* process data received from serial port
*/
void SerialPort::dataReady() {
QString serial_buffer;

Expand Down
16 changes: 10 additions & 6 deletions code-playground/send-states-arduino/send-states-arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ void loop() {
current_time = millis();

if(current_time - previous_time >= burst_interval){
previous_time = current_time;
state_counter++;
counter++;

// record number
uint8_t record_number = counter;
Expand Down Expand Up @@ -123,12 +120,19 @@ void loop() {
velocity
);



Serial.println(telemetry_packet);

state_counter++;

// reset counter
if(state_counter > NUM_OF_STATES-1) {
if(state_counter > NUM_OF_STATES - 1) {
state_counter = 0;
}

Serial.println(telemetry_packet);

counter++;
previous_time = current_time;
}

}
Expand Down

0 comments on commit 52f8f44

Please sign in to comment.