void OsgManager::doBeforeStop() { #ifdef OSS_DEBUG dumpDebugInfo(); #endif // Delete the viewer so that the graphics context will be released in the manager's thread m_viewer = nullptr; }
static void PacketReceived (PACKET_Instance_t *inst, PACKET_Packet_t *packet, PACKET_Error_t err) { if (err == PACKET_ERROR_NONE) { // we really only care about packets for us... if (packet->m_id == 0x01) { switch (packet->m_cmd) { case PACKET_CMD_SET_ID: { //printf ("got SET_ID command\n"); break; } case PACKET_CMD_START_ASYNC: { //printf ("got START_ASYNC command\n"); turnOnAsyncCapture(); break; } case PACKET_CMD_STOP_ASYNC: { //printf ("got STOP_ASYNC command\n"); sendingSamples = 0; break; } case PACKET_CMD_TURN_OFF_BATTERY: { //printf ("got TURN_OFF_BATTERY command\n"); Battery_EnableLow(); break; } case PACKET_CMD_TURN_ON_BATTERY: { //printf ("got TURN_ON_BATTERY command\n"); Battery_EnableHigh(); break; } case PACKET_CMD_SEND_SAMPLE: { //printf ("got PACKET_CMD_SEND_SAMPLE command\n"); //turnOnFlag(); currentSample = 0; CreateSample(SAMPLE_NORMAL); SendSamples(1, PACKET_CMD_SAMPLE); break; } case PACKET_CMD_SET_CALIBRATION: { //printf ("got PACKET_CMD_SET_CALIBRATION command\n"); calibrationFloor = *(float *)&packet->m_param[0]; calibrationScale = *(float *)&packet->m_param[4]; eeprom_write_float((float*)(CALIBRATION_EEPROM_BASE + CALIBRATION_FLOOR_LOCATION), calibrationFloor); eeprom_write_float((float*)(CALIBRATION_EEPROM_BASE + CALIBRATION_SCALE_LOCATION), calibrationScale); eeprom_write_byte((uint8_t*)(CALIBRATION_EEPROM_BASE + CALIBRATION_SIGNATURE_LOCATION), CALIBRATION_SIGNATURE); //printf("Calibration parameters saved to EEPROM\n"); //char output[16]; //dtostrf(calibrationFloor, 7, 4, output); //printf("FLOOR: %s\n", output); //dtostrf(calibrationScale, 7, 4, output); //printf("SCALE: %s\n", output); break; } case PACKET_CMD_GET_CALIBRATION: { if (debugMode) { printf ("got PACKET_CMD_GET_CALIBRATION command\n"); } RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0x01); // ammeter id uint8_t checksum = 0x01; uint8_t floatSize = sizeof(calibrationFloor); uint8_t packetLength = (floatSize * 2) + 2; RingBuffer_Insert(&Send_USB_Buffer, packetLength); // packet length, including all framing checksum += packetLength; RingBuffer_Insert(&Send_USB_Buffer, PACKET_CMD_CALIBRATION); // command checksum += PACKET_CMD_CALIBRATION; for (int index=0; index < floatSize; index++) { uint8_t value = ((uint8_t *)&calibrationFloor)[index]; RingBuffer_Insert(&Send_USB_Buffer, value); checksum += value; } for (int index=0; index < floatSize; index++) { uint8_t value = ((uint8_t *)&calibrationScale)[index]; RingBuffer_Insert(&Send_USB_Buffer, value); checksum += value; } RingBuffer_Insert(&Send_USB_Buffer, ~checksum); break; } case PACKET_CMD_GET_COMPENSATION: { if (debugMode) { printf ("got PACKET_CMD_GET_COMPENSATION command\n"); } RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0x01); // ammeter id uint8_t checksum = 0x01; uint8_t floatSize = sizeof(calibrationFloor); uint8_t packetLength = 1 + floatSize + 2; RingBuffer_Insert(&Send_USB_Buffer, packetLength); // packet length, including all framing checksum += packetLength; RingBuffer_Insert(&Send_USB_Buffer, PACKET_CMD_COMPENSATION); // command checksum += PACKET_CMD_COMPENSATION; RingBuffer_Insert(&Send_USB_Buffer, compensation); checksum += compensation; for (int index=0; index < floatSize; index++) { uint8_t value = ((uint8_t *)&baselineVoltage)[index]; RingBuffer_Insert(&Send_USB_Buffer, value); checksum += value; } RingBuffer_Insert(&Send_USB_Buffer, ~checksum); break; } case PACKET_CMD_GET_RAW_SAMPLE: { //printf ("got PACKET_CMD_GET_RAW_SAMPLE command\n"); currentSample = 0; CreateSample(SAMPLE_RAW); SendSamples(1, PACKET_CMD_GET_RAW_SAMPLE); break; } case PACKET_CMD_GET_VERSION: { //printf ("got PACKET_CMD_GET_VERSION command\n"); RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0x01); // ammeter id uint8_t checksum = 0x01; uint8_t packetLength = 1 + 2; RingBuffer_Insert(&Send_USB_Buffer, packetLength); // packet length, including all framing checksum += packetLength; RingBuffer_Insert(&Send_USB_Buffer, PACKET_CMD_VERSION); // command checksum += PACKET_CMD_VERSION; RingBuffer_Insert(&Send_USB_Buffer, AMMETER_VERSION); checksum += AMMETER_VERSION; RingBuffer_Insert(&Send_USB_Buffer, ~checksum); break; } case PACKET_CMD_GET_SERIAL: { if (debugMode) { printf ("got PACKET_CMD_GET_SERIAL command\n"); } RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0x01); // ammeter id uint8_t checksum = 0x01; uint8_t packetLength = 2 + 2; RingBuffer_Insert(&Send_USB_Buffer, packetLength); // packet length, including all framing checksum += packetLength; RingBuffer_Insert(&Send_USB_Buffer, PACKET_CMD_SERIAL); // command checksum += PACKET_CMD_SERIAL; RingBuffer_Insert(&Send_USB_Buffer, serialNumber & 0xFF); checksum += serialNumber & 0xFF; RingBuffer_Insert(&Send_USB_Buffer, serialNumber >> 8); checksum += serialNumber >> 8; RingBuffer_Insert(&Send_USB_Buffer, ~checksum); break; } case PACKET_CMD_SET_SERIAL: { //printf ("got PACKET_CMD_SET_SERIAL command\n"); serialNumber = *(uint16_t *)&packet->m_param[0]; eeprom_write_word((float*)(CALIBRATION_EEPROM_BASE + SERIAL_NUMBER_LOCATION), serialNumber); //printf("Serial number saved to EEPROM\n"); //printf("Serial Number: %d\n", serialNumber); break; } case PACKET_CMD_DUMP_DEBUG_INFO: { dumpDebugInfo(); break; } case PACKET_CMD_TURN_ON_COMPENSATION: { float value = *(float *)&packet->m_param[0]; if ((value >= 3.7) && (value <= 4.2)) { compensation = 1; eeprom_write_byte((float*)(CALIBRATION_EEPROM_BASE + COMPENSATION_FLAG_LOCATION), compensation); baselineVoltage = value; eeprom_write_float((float*)(CALIBRATION_EEPROM_BASE + BASELINE_VOLTAGE_LOCATION), baselineVoltage); } break; } case PACKET_CMD_TURN_OFF_COMPENSATION: { compensation = 0; eeprom_write_byte((float*)(CALIBRATION_EEPROM_BASE + COMPENSATION_FLAG_LOCATION), compensation); break; } case PACKET_CMD_START_LOGGING: { loggingFlag = 1; if (debugMode) { debugMode = 0; } else { InitUART (); fdevopen (UART1_PutCharStdio, UART1_GetCharStdio); } eeprom_write_byte((float*)(CALIBRATION_EEPROM_BASE + LOGGING_FLAG_LOCATION), loggingFlag); turnOnAsyncCapture(); break; } case PACKET_CMD_STOP_LOGGING: { sendingSamples = 0; loggingFlag = 0; eeprom_write_byte((float*)(CALIBRATION_EEPROM_BASE + LOGGING_FLAG_LOCATION), loggingFlag); break; } case PACKET_CMD_CHECK_AUX_BATTERY: { loggingFlag = 0; if (debugMode) { debugMode = 0; } else { InitUART (); fdevopen (UART1_PutCharStdio, UART1_GetCharStdio); } printf("I2C Test\n"); float voltage = readAuxBatteryVoltage(); char output[16]; dtostrf(voltage, 4, 2, output); printf("Battery Voltage: %s volts\n", output); break; } case PACKET_CMD_TURN_OFF_AUX_USB: { //printf ("got TURN_OFF_BATTERY command\n"); AuxUSB_Disable(); break; } case PACKET_CMD_TURN_ON_AUX_USB: { //printf ("got TURN_ON_BATTERY command\n"); AuxUSB_Enable(); break; } case PACKET_CMD_GET_TEMPERATURE: { if (debugMode) { printf ("got PACKET_CMD_GET_TEMPERATURE command\n"); } float temperature = ReadTemperatureProbe(); RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0xFF); RingBuffer_Insert(&Send_USB_Buffer, 0x01); // ammeter id uint8_t checksum = 0x01; uint8_t floatSize = sizeof(temperature); uint8_t packetLength = floatSize + 2; RingBuffer_Insert(&Send_USB_Buffer, packetLength); // packet length, including all framing checksum += packetLength; RingBuffer_Insert(&Send_USB_Buffer, PACKET_CMD_TEMPERATURE); // command checksum += PACKET_CMD_TEMPERATURE; for (int index=0; index < floatSize; index++) { uint8_t value = ((uint8_t *)&temperature)[index]; RingBuffer_Insert(&Send_USB_Buffer, value); checksum += value; } RingBuffer_Insert(&Send_USB_Buffer, ~checksum); break; } case PACKET_CMD_SOFT_RESET: { if (debugMode) { printf ("got PACKET_CMD_SOFT_RESET command\n"); } wdt_enable(WDTO_60MS); while(1) {}; break; } default: { // there are other commands that we don't care about.... //printf ("ID:0x%02x Cmd: 0x%02x *** Unknown ***\n", packet->m_id, packet->m_cmd); break; } } } else { //printf ("Got packet for ID: %3d\n", packet->m_id); } }
boost::any CsvRecordParser::next() { if(!configured_) { throw std::runtime_error("not configured"); } //if we already have a line, consume that if((uint64_t)rowIndex_ < row_.size()) { if (schema_.find(rowIndex_) == schema_.end() ) { dumpDebugInfo(); std::ostringstream os; os << "Invalid schema. Unable to find type for column " << rowIndex_ << "."; throw std::runtime_error(os.str()); } boost::any myany; bool isNull = false; if (row_[rowIndex_] == "") { isNull = true; myany = CsvRecord(isNull); } else if (schema_[rowIndex_].second == "logical") { bool boolCell; std::string stringCell = row_[rowIndex_]; std::transform(stringCell.begin(), stringCell.end(), stringCell.begin(), ::tolower); if (stringCell == "true") { boolCell = true; } else if (stringCell == "false") { boolCell = false; } else { boolCell = static_cast<bool>(atoll(row_[rowIndex_].c_str())); } myany = CsvRecord(isNull, boolCell); } else if (schema_[rowIndex_].second == "integer") { myany = CsvRecord(isNull, (int32_t)atoi(row_[rowIndex_].c_str())); } else if (schema_[rowIndex_].second == "int64") { myany = CsvRecord(isNull, (double)atof(row_[rowIndex_].c_str())); } else if (schema_[rowIndex_].second == "numeric") { myany = CsvRecord(isNull, (double)atof(row_[rowIndex_].c_str())); } else if (schema_[rowIndex_].second == "character") { myany = CsvRecord(isNull, row_[rowIndex_]); } else { std::ostringstream os; os << "Unsupported type "; os << schema_[rowIndex_].second; os << ". Supported types are int64, double and string"; throw std::runtime_error(os.str()); } DLOG_IF(INFO, recordsProduced_ < 10) << "returning record: " << row_[rowIndex_]; ++recordsProduced_; rowIndex_++; return myany; } else if((uint64_t)rowIndex_ == row_.size()) { if(rowIndex_ != 0) { //notify we're done with line if(!observer_) { throw std::runtime_error("observer not set"); } observer_->update(0); } if(splitProducer_->hasNext()) { //load new line and reset rowIndex_ boost::shared_ptr<splitproducer::Split> s; std::string line; bool isCommentLineFlag = false; bool isEmptyLineFlag = false; do { try { s = splitProducer_->next(); line = std::string(const_cast<const char*>(reinterpret_cast<char *>(s->buffer)), s->used); } catch(const splitproducer::EmptySplitException& e) { DLOG(INFO) << "Split producer returned an empty split"; throw; } /** * Discard comment lines */ isCommentLineFlag = isCommentLine(line, commentCharacter_); if (isCommentLineFlag) { ++commentLinesDiscarded_; } /** * Discard blank lines */ isEmptyLineFlag = line == ""; if (isEmptyLineFlag) { ++blankLinesDiscarded_; } } while (isCommentLineFlag || isEmptyLineFlag); std::istringstream ss(line); text::csv::csv_istream is(ss, delimiter_); is >> row_; rowIndex_ = 0; return next(); } else { throw std::runtime_error("no more records");