void EventViewer::addData(const VariablesDataVector& data) { const double elapsedTime = (double)startingTime.msecsTo(QTime::currentTime()) / 1000.; if (timeWindowCheckBox->isChecked()) { // remove old data while ( (!timeStamps.empty()) && (elapsedTime - timeStamps[0] > timeWindowLength->value()) ) { timeStamps.pop_front(); for (size_t i = 0; i < values.size(); i++) values[i].pop_front(); } } timeStamps.push_back(elapsedTime); for (size_t i = 0; i < values.size(); i++) { if (i < data.size()) { values[i].push_back(data[i]); } else { values[i].push_back(0); } } plot->replot(); }
void UsageLogger::logUserEvent(unsigned id, const VariablesDataVector& data){ Action * wrapper = getActionWithCurrentState(); DeviceAction *a = new DeviceAction(); a->set_id(id); for(unsigned i=0; i < data.size(); i++){ a->add_variable(data[i]); } wrapper->set_type(Action_ActionType_DEVICE_ACTION); wrapper->set_allocated_deviceaction(a); storeAction(wrapper); }
void UsageLogger::logTabletData(const VariablesDataVector& data){ assert(data.size() == 15); const float cam_x = float(data[0]) * 0.001; const float cam_y = float(data[1]) * 0.001; const float cam_z = float(data[2]) * 0.001; const float cam_ax = float(data[3]) * 0.1; const float cam_ay = float(data[4]) * 0.1; const float cam_az = float(data[5]) * 0.1; const float thymio_x = float(data[6]) * 0.001; const float thymio_z = float(data[7]) * 0.001; const float thymio_ay = float(data[8]) * 0.1; qDebug() << "pos data" << cam_x << cam_y << cam_z << cam_ax << cam_ay << cam_az << thymio_x << thymio_z << thymio_ay; const unsigned recording_duration = data[9]; const float timeline_left = float(data[10]) / 10000.f; const float timeline_right = float(data[11]) / 10000.f; const unsigned selected_set_id = data[12]; const float selected_set_time = float(data[11]) / 10000.f; const bool app_recording = data[14] & (1<<0); const bool board_is_tracked = data[14] & (1<<1); const bool thymio_is_tracked = data[14] & (1<<2); qDebug() << "app state" << recording_duration << timeline_left << timeline_right << selected_set_id << selected_set_time << app_recording << board_is_tracked << thymio_is_tracked; Action * wrapper = getActionWithCurrentState(); TabletAction *a = new TabletAction(); a->set_camerax(cam_x); a->set_cameray(cam_y); a->set_cameraz(cam_z); a->set_cameraanglex(cam_ax); a->set_cameraangley(cam_ay); a->set_cameraanglez(cam_az); a->set_thymiox(thymio_x); a->set_thymioangley(thymio_ay); a->set_thymioz(thymio_z); a->set_recordingduration(recording_duration); a->set_lefttimelinepos(timeline_left); a->set_righttimelinepos(timeline_right); a->set_selectedsetid(selected_set_id); a->set_selectedsettime(selected_set_time); a->set_apprecording(app_recording); a->set_boardistracked(board_is_tracked); a->set_thymioistracked(thymio_is_tracked); wrapper->set_type(Action_ActionType_TABLET); wrapper->set_allocated_tabletaction(a); storeAction(wrapper); }
void Shell::emit(const strings& args) { // check that there are enough arguments if (args.size() < 2) { wcerr << "missing argument, usage: emit EVENT_NAME EVENT_DATA*" << endl; return; } size_t pos; if (!commonDefinitions.events.contains(UTF8ToWString(args[1]), &pos)) { wcerr << "event " << UTF8ToWString(args[1]) << " is unknown" << endl; return; } // build event and emit VariablesDataVector data; for (size_t i=2; i<args.size(); ++i) data.push_back(atoi(args[i].c_str())); UserMessage userMessage(pos, data); userMessage.serialize(targetStream); targetStream->flush(); }
void Shell::setVariable(const strings& args) { // check that there are enough arguments if (args.size() < 4) { wcerr << "missing argument, usage: set NODE_NAME VAR_NAME VAR_DATA+" << endl; return; } // get node id, variable position and length unsigned nodeId, pos; const bool exists(getNodeAndVarPos(args[1], args[2], nodeId, pos)); if (!exists) return; // send the message VariablesDataVector data; for (size_t i=3; i<args.size(); ++i) data.push_back(atoi(args[i].c_str())); SetVariables setVariables(nodeId, pos, data); setVariables.serialize(targetStream); targetStream->flush(); }
//! The content of a variable has changed void ThymioVPLStandalone::variableValueUpdated(const QString& name, const VariablesDataVector& values) { // we do not perform this check if we are forced to use any target if (useAnyTarget) return; if ((name == ASEBA_PID_VAR_NAME) && (values.size() >= 1)) { // make sure that pid is ASEBA_PID_THYMIO2, otherwise print an error and quit if (values[0] != ASEBA_PID_THYMIO2) { QMessageBox::critical(this, tr("Thymio VPL Error"), tr("You need to connect a Thymio II to use this application.") ); close(); } } }