Elem & Machine::execute(std::ostream &out) { Instruction *command; std::shared_ptr<Elem> command_ptr; Elem *ADD(new Instruction("ADD")); Elem *MUL(new Instruction("MUL")); Elem *SUB(new Instruction("SUB")); Elem *DIV(new Instruction("DIV")); Elem *REM(new Instruction("REM")); Elem *EQ(new Instruction("EQ")); Elem *LEQ(new Instruction("LEQ")); Elem *SEL(new Instruction("SEL")); Elem *LD(new Instruction("LD")); Elem *LDC(new Instruction("LDC")); Elem *LDF(new Instruction("LDF")); Elem *CAR(new Instruction("CAR")); Elem *CDR(new Instruction("CDR")); Elem *CONS(new Instruction("CONS")); Elem *NIL(new Instruction("NIL")); Elem *DUM(new Instruction("DUM")); Elem *AP(new Instruction("AP")); Elem *RAP(new Instruction("RAP")); Elem *RTN(new Instruction("RTN")); Elem *JOIN(new Instruction("JOIN")); Elem *STOP(new Instruction("STOP")); while (!C->empty()) { if (out != 0x0) { print_S(out); print_E(out); print_C(out); out << std::endl; } command_ptr = C->pop_ret(); command = dynamic_cast<Instruction*>(&*command_ptr); if (command == nullptr) throw Exception("Execute", "FatalError"); if (*command == *ADD) this->ADD(); else if (*command == *MUL) this->MUL(); else if (*command == *SUB) this->SUB(); else if (*command == *DIV) this->DIV(); else if (*command == *REM) this->REM(); else if (*command == *EQ) this->EQ(); else if (*command == *LEQ) this->LEQ(); else if (*command == *SEL) this->SEL(); else if (*command == *LD) this->LD(); else if (*command == *LDC) this->LDC(); else if (*command == *LDF) this->LDF(); else if (*command == *CAR) this->CAR(); else if (*command == *CDR) this->CDR(); else if (*command == *CONS) this->CONS(); else if (*command == *NIL) this->NIL(); else if (*command == *DUM) this->DUM(); else if (*command == *AP) this->AP(); else if (*command == *RAP) this->RAP(); else if (*command == *RTN) this->RTN(); else if (*command == *JOIN) this->JOIN(); else if (*command == *STOP) { return (*(this->STOP()));} else throw Exception("Execute", "Expected 'instruction' but greeted constant."); } throw Exception("Execute", "FatalError"); }
//_______________________________________________________________________________________________________ int main(int argc, char** argv) { parseArgs(argc, argv); printf("\n"); printY("[TEST] Test conditions:\n"); if (m_start_dsp) printG("\tDisplay\n"); else printR("\tDisplay\n"); if (m_start_imu) printG("\tIMU\n"); else printR("\tIMU\n"); if (m_start_imu && m_start_env) printG("\tEnvSens\n"); else if (m_start_imu && !m_start_env) printR("\tEnvSens\n"); else if (!m_start_imu && m_start_env) printR("\tskipping EnvSens (IMU needs to be enabled!)\n"); else printR("\tEnvSens\n"); if (m_start_ldc) printG("\tLDC\n"); else printR("\tLDC\n"); if (m_start_bat) printG("\tBatGauge\n"); else printR("\tBatGauge\n"); printf("\n"); printY("[TEST] Init devices...\n"); printf("\n"); fflush(stdout); // Set up display if (m_start_dsp) m_dsp = new display_edison(m_dsp_resolution, m_dsp_hands); // Set up IMU if (m_start_imu) { m_imu = new imu_edison(m_i2c_bus, m_mpu_address, m_start_env); m_imu->setupIMU(); } // Set up LDC if (m_start_ldc) m_ldc = new ldc_edison(m_i2c_bus); // Start battery gauge if (m_start_bat) { m_bat = new batgauge_edison(m_i2c_bus); m_bat->setAlertThreshold(m_alert_threshold); } printf("\n"); usleep(1000000); // start testing bool success = true; // test display if (m_start_dsp) { printY("[TEST] Drawing clock on display...\n"); printf("\n"); m_dsp->clear(); m_dsp->analogClock(true); m_dsp->flush(); } // test IMU if (m_start_imu) { printY("[TEST] Testing IMU...\n"); printf("IMU "); if (!IDtest(m_imu->getID(), m_imu_ID)) success = false; printf("MAG "); if (!IDtest(m_imu->getMagID(), m_mag_ID)) success = false; if (!m_idonly) { std::vector<float> data = m_imu->toReadable(m_imu->readRawIMU()); float mx, my, mz; m_imu->getCompassData(mx, my, mz); printf("Temperature [DegC]:\n\t%f\n", data[6]); printf("Accelerometer [m/s^2]:\n"); printf("\tX: %f\n", data[0]); printf("\tY: %f\n", data[1]); printf("\tZ: %f\n", data[2]); printf("Gyroscope [deg/s]:\n"); printf("\tX: %f\n", data[3]); printf("\tY: %f\n", data[4]); printf("\tZ: %f\n", data[5]); printf("Compass [mGs]:\n"); printf("\tX: %f\n", mx); printf("\tY: %f\n", my); printf("\tZ: %f\n", mz); } printf("\n"); fflush(stdout); } // test EnvSens if (m_start_imu && m_start_env) { printY("[TEST] Testing environmental sensor...\n"); if (!IDtest(m_imu->getEnvID(), m_env_ID)) success = false; if (!m_idonly) { float T, P, H; m_imu->getEnvData(T, P, H); printf("Temperature [DegC]: %f\n", T); printf("Pressure [hPa]: %f\n", P); printf("Humidity [%%RH]: %f\n", H); } printf("\n"); fflush(stdout); } // test LDC if (m_start_ldc) { printY("[TEST] Testing LDC...\n"); if (!IDtest(m_ldc->getVersion(), m_ldc_ID)) success = false; if (!m_idonly) { std::vector<uint16_t> LDC(2, 0); LDC = m_ldc->getADC(); printf("ADC0 (vis/IR) [raw]: %i\n", LDC[0]); printf("ADC1 (IR) [raw]: %i\n", LDC[1]); } printf("\n"); fflush(stdout); } // test BatGauge if (m_start_bat) { printY("[TEST] Testing battery gauge...\n"); if (!IDtest(m_bat->getVersion(), m_bat_ID)) success = false; if (!m_idonly) { printf("Voltage: %fV\n", m_bat->getVCell()); printf("State of Charge: %i%%\n", m_bat->getSoC()); printf("Alert Threshold: %i%%\n", m_bat->getAlertThreshold()); } printf("\n"); fflush(stdout); } if (success) printG("[TEST] All ID tests successful.\n"); else printR("[TEST] Some ID tests failed!\n"); if (m_start_bat) delete m_bat; if (m_start_ldc) delete m_ldc; if (m_start_imu) delete m_imu; if (m_start_dsp) delete m_dsp; if (success) return 0; else return 1; }