int main() { using std::cout; Tv s42; cout << "Początkowe ustawienia telewizora 42\":\n"; s42.settings(); s42.onoff(); s42.chanup(); cout << "\nNowe ustawienia telewizora 42\":\n"; s42.settings(); Remote grey; grey.set_chan(s42, 10); grey.volup(s42); grey.volup(s42); cout << "\nUstawienia telewizora 42\" po użyciu pilota:\n"; s42.settings(); Tv s58(Tv::On); s58.set_mode(); grey.set_chan(s58, 28); cout << "\nUstawienia telewizora 58\"\n"; s58.settings(); return 0; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); Remote w; QFile st(QDir::currentPath()+ "/remote.ini"); if(!st.open(QIODevice::ReadOnly | QIODevice::Text)) { cout<<"Need remote.ini to start"; QString settingsFile = (QDir::currentPath()+ "/remote.ini"); QSettings *settings =new QSettings(settingsFile,QSettings::IniFormat); settings->setValue("sshServer", "192.168.1.1"); settings->setValue("sshUser", "user"); settings->setValue("sshPwd", "123"); settings->setValue("sshCommand", "free_port.sh"); settings->sync(); delete (settings); } st.close(); w.setStyleSheet("background-image: url(:/suspects.png)"); w.show(); return a.exec(); }
void StateRoom::accessRoom() { INetworkRelay *network = this->_world->getSharedObject<INetworkRelay>("NetworkRelay"); if (network) { Remote *remote = NULL; if (this->_textboxRoom->getString() != "") this->_textboxRoom->setString("defaulte"); if (!(remote = network->getRemote(0))) throw RTException("Invalid remote"); IBuffer *buffer = network->getTCPBuffer(); *buffer << static_cast<char>(INetworkRelay::CHANGE_ROOM_QUERY); *buffer << this->_textboxRoom->getString(); remote->sendTCP(buffer); Thread<INetworkRelay> *thread = new Thread<INetworkRelay>(); thread->start(network, &INetworkRelay::start, Any()); while (42) { LockVector<IBuffer *> &recv_buffer = remote->getRecvBufferTCP(); auto guard = create_lock(recv_buffer); for (auto it = recv_buffer.begin(); it != recv_buffer.end();) { if (this->parsePacket(recv_buffer, it)) return ; } } } else { throw RTException("Invalid network"); } }
int main() { using std::cout; Tv s27; cout << "Initial settings for 27\" TV:\n"; s27.settings(); s27.onoff(); s27.chanup(); cout << "\nAdjusted settings for 27\" TV:\n"; s27.settings(); Remote grey; grey.set_chan(s27, 10); grey.volup(s27); grey.volup(s27); cout << "\n27\" settings after using remote:\n"; s27.settings(); Tv s32(Tv::On); s32.set_mode(); grey.set_chan(s32,28); cout << "\n32\" settings:\n"; s32.settings(); return 0; }
int main() { using std::cout; Tv s42; cout << "Initial setting for 42\" TV:\n"; s42.settings(); s42.onoff(); s42.chanup(); cout << "\nAdjusted settings for 42\" TV:\n"; s42.settings(); Remote grey; grey.set_chan(s42, 10); grey.volup(s42); grey.volup(s42); cout << "\n42\" settings after using remote:\n"; s42.settings(); Tv s58(Tv::On); s58.set_mode(); grey.set_chan(s58,28); cout << "\n58\" settings:\n"; s58.settings(); return 0; }
volatile char timerRemoteStart(char key, char first) { menu.message(TEXT("Started Remote")); remote.set(REMOTE_PROGRAM); remote.set(REMOTE_START); menu.spawn((void*)timerStatusRemote); return FN_JUMP; }
ListView::Row Manager::makeRow(const Remote &remote) const { const auto_string &name = make_autostring(remote.name()); const auto_string &url = make_autostring(remote.url()); return {name, url, isRemoteEnabled(remote) ? AUTO_STR("Enabled") : AUTO_STR("Disabled")}; }
bool Manager::apply() { if(!m_changes) return true; Transaction *tx = m_reapack->setupTransaction(); if(!tx) return false; bool syncAll = false; if(m_autoInstall) { m_config->install.autoInstall = m_autoInstall.value(); syncAll = m_autoInstall.value(); } if(m_bleedingEdge) m_config->install.bleedingEdge = m_bleedingEdge.value(); if(m_promptObsolete) m_config->install.promptObsolete = m_promptObsolete.value(); for(const auto &pair : m_mods) { Remote remote = pair.first; const RemoteMods &mods = pair.second; if(m_uninstall.find(remote) != m_uninstall.end()) continue; if(mods.enable) { m_reapack->setRemoteEnabled(*mods.enable, remote); if(*mods.enable && !syncAll) tx->synchronize(remote); } if(mods.autoInstall) { remote.setAutoInstall(*mods.autoInstall); m_config->remotes.add(remote); const bool isEnabled = mods.enable.value_or(remote.isEnabled()); if(isEnabled && *mods.autoInstall && !syncAll) tx->synchronize(remote); } } for(const Remote &remote : m_uninstall) m_reapack->uninstall(remote); if(syncAll) m_reapack->synchronizeAll(); tx->runTasks(); m_config->write(); reset(); return true; }
bool Manager::isRemoteEnabled(const Remote &remote) const { const auto it = m_mods.find(remote); if(it == m_mods.end()) return remote.isEnabled(); else return it->second.enable.value_or(remote.isEnabled()); }
tribool Manager::remoteAutoInstall(const Remote &remote) const { const auto it = m_mods.find(remote); if(it == m_mods.end()) return remote.autoInstall(); else return it->second.autoInstall.value_or(remote.autoInstall()); }
void RemoteServer::loadRemotes() { QStringList theFiles = KGlobal::dirs()->findAllResources("data", "remotes/*.remote.xml"); for(QStringList::iterator i = theFiles.begin(); i != theFiles.end(); ++i) { kdDebug() << "Found data file: " << *i << endl; Remote *p = new Remote(); p->loadFromFile(*i); theRemotes.insert(p->id(), p); } }
virtual void onConsoleCommand(ConsoleWindow* con, const std::string& str) { if (_remote.getHostPeer() == NULL) { String cmd = str.c_str(); if (StringUtil::startsWith(cmd, "connect")) { String addr = cmd.substr(8); if (_remote.connect(addr)) { DataValue params = DataValue::fromJson("{ client:'nit-rsh', version:'1.0', log:true }"); _remote.request(_remote.getHostPeer(), _channelID, RQ_ATTACH, params); _lastAddr = addr; } return; } else { if (!_lastAddr.empty()) { if (_remote.connect(_lastAddr)) { DataValue params = DataValue::fromJson("{ client:'nit-rsh', version:'1.0', log:true }"); _remote.request(_remote.getHostPeer(), _channelID, RQ_ATTACH, params); } } if (_remote.getHostPeer() == NULL) LOG(0, "*** not connected\n"); } } if (!str.empty()) { Ref<RemotePeer> peer = _remote.getHostPeer(); if (peer) { if (str == "bye") peer->disconnect(); else _remote.notify(peer, _channelID, NT_COMMAND, DataValue(str.c_str(), (int) str.length())); } } }
ConsoleApp(ConsoleWindow* cw) { _console = cw; cw->setListener(this); _channelID = 0xdeb6; EventChannel* ch = _remote.getChannel(0); ch->bind(EVT::REMOTE_CONNECT, this, &ConsoleApp::onRemoteConnect); ch->bind(EVT::REMOTE_DISCONNECT, this, &ConsoleApp::onRemoteDisconnect); ch = _remote.openChannel(_channelID, "nit.RemoteDebugClient"); ch->bind(EVT::REMOTE_NOTIFY, this, &ConsoleApp::onRemoteNotify); ch->bind(EVT::REMOTE_RESPONSE, this, &ConsoleApp::onRemoteResponse); }
bool Manager::isRemoteEnabled(const Remote &remote) const { const auto it = m_enableOverrides.find(remote); if(it == m_enableOverrides.end()) return remote.isEnabled(); else return it->second; }
bool RemoteModel::refresh(const QString &workingDirectory, QString *errorMessage) { // Run branch command with verbose. QStringList remoteArgs; remoteArgs << QLatin1String("-v"); QString output; if (!m_client->synchronousRemoteCmd(workingDirectory, remoteArgs, &output, errorMessage)) return false; // Parse output m_workingDirectory = workingDirectory; m_remotes.clear(); const QStringList lines = output.split(QLatin1Char('\n')); for (int r = 0; r < lines.count(); ++r) { Remote newRemote; if (newRemote.parse(lines.at(r))) m_remotes.push_back(newRemote); } reset(); return true; }
inline std::string metadata_action(const Remote &remote, Delegate func) { try { return func(remote.media_info()); } catch(const std::exception &e) { std::cerr << e.what() << std::endl; return ""; } }
int main(int argc, char *argv[]) { qInstallMessageHandler(myMessageHandler); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication a(argc, argv); qsrand(QTime(0,0,0).msecsTo(QTime::currentTime())); qApp->setStyle(QStyleFactory::create("fusion")); QFont font = qApp->font(); font.setPixelSize(13); qApp->setFont(font); QPalette palette; qApp->setPalette(palette); Remote u; if(u.Start(a.arguments())) return a.exec(); else return 0; }
volatile char timerStatusRemote(char key, char first) { static uint32_t startTime = 0; static uint8_t toggle = 0; if(first) { startTime = 0; } if(clock.Ms() > startTime + 100) { startTime = clock.Ms(); lcd.cls(); if(toggle == 0) remote.request(REMOTE_BATTERY); else if(toggle == 1) remote.send(REMOTE_BATTERY, REMOTE_TYPE_NOTIFY_SET); else if(toggle == 2) remote.request(REMOTE_START); else remote.request(REMOTE_STATUS); if(++toggle >= 10) toggle = 2; displayTimerStatus(1); menu.setTitle(TEXT("Remote")); if(remote.running) menu.setBar(TEXT("RETURN"), TEXT("STOP")); else menu.setBar(TEXT("RETURN"), BLANK_STR); lcd.update(); } if(!remote.connected) return FN_CANCEL; switch(key) { case FR_KEY: remote.set(REMOTE_STOP); break; case FL_KEY: case LEFT_KEY: remote.send(REMOTE_BATTERY, REMOTE_TYPE_NOTIFY_UNSET); toggle = 0; return FN_CANCEL; } return FN_CONTINUE; }
volatile char cableReleaseRemote(char key, char first) { static char status; //, cable; if(first) { status = 0; lcd.cls(); menu.setTitle(TEXT("BT Cable Remote")); menu.setBar(TEXT("Bulb"), TEXT("Photo")); lcd.update(); remote.set(REMOTE_BULB_END); } if(key == FL_KEY) { if(status != 1) { status = 1; lcd.eraseBox(8, 18, 8 + 6 * 11, 26); lcd.writeString(8, 18, TEXT("(BULB OPEN)")); remote.set(REMOTE_BULB_START); lcd.update(); } else { status = 0; lcd.eraseBox(8, 18, 8 + 6 * 11, 26); remote.set(REMOTE_BULB_END); lcd.update(); } } else if(key == FR_KEY && status != 1) { status = 0; lcd.eraseBox(8, 18, 8 + 6 * 11, 26); remote.set(REMOTE_CAPTURE); lcd.update(); } else if(key != 0) { status = 0; lcd.eraseBox(8, 18, 8 + 6 * 11, 26); remote.set(REMOTE_BULB_END); lcd.update(); } if(key == LEFT_KEY || !remote.connected) { remote.set(REMOTE_BULB_END); return FN_CANCEL; } return FN_CONTINUE; }
virtual void onConsoleShow(ConsoleWindow* con) { _logger = new ConsoleWindowLogger(con); LogManager::getSingleton().attach(_logger); LOG(0, "[nit-rsh] usage: connect [<ip_address>]\n"); con->setPrompt("idle> "); SocketBase::initialize(); bool sendWhere = false; if (sendWhere) { char hostname[40]; if (gethostname(hostname, sizeof(hostname)) != SOCKET_ERROR) { _remote.serverWhere(hostname); } } }
static void got_packet(u_char *args, const pcap_pkthdr *header, const u_char *packet) { Remote *r = reinterpret_cast<Remote *>(args); r->onPacket(packet, *header); }
virtual void onConsoleUpdate(ConsoleWindow* con) { _remote.update(); }
Remote<T> read_variable(const char *name) const { Remote<T> res; read_variable(name, res.getBuffer(), sizeof(T)); return res; }
int main(int argc, char *argv[]) { // we need to set stdout and stderr non-buffered // so that messages are actually displayed in the // DARwIn-OP console of the robot window setvbuf(stdout,NULL,_IONBF,0); setvbuf(stderr,NULL,_IONBF,0); int cameraWidthZoomFactor = 1; int cameraHeightZoomFactor = 1; if (argc >= 3) { sscanf(argv[1], "%d", &cameraWidthZoomFactor); sscanf(argv[2], "%d", &cameraHeightZoomFactor); } // Server socket SOCKADDR_IN sin; SOCKET sock; socklen_t recsize = sizeof(sin); // Client socket SOCKADDR_IN csin; SOCKET csock = NULL; socklen_t crecsize; int sock_err; // Creation of the socket sock = socket(AF_INET, SOCK_STREAM, 0); // If socket is valid if (sock != INVALID_SOCKET) { // Configuration sin.sin_addr.s_addr = htonl(INADDR_ANY); // Adresse IP automatic sin.sin_family = AF_INET; // Protocole familial (IP) sin.sin_port = htons(PORT); // Listening of the port bzero(&sin.sin_zero, sizeof(sin.sin_zero)); // make sure the zero are correctly initialized int opt = 1; setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *) &opt, sizeof(int)); sock_err = bind(sock, (SOCKADDR*) &sin, recsize); // If socket works if (sock_err != SOCKET_ERROR) { // Starting port Listening (server mode) sock_err = listen(sock, 1); // only one connexion // If socket works if (sock_err != SOCKET_ERROR) { // Wait until a client connect cout << "Waiting for client connection on port " << PORT << "..." << endl; csock = accept(sock, (SOCKADDR*)&csin, &crecsize); cout << "Client connected." << endl; } else perror("listen"); } else perror("bind"); Remote *remote = new Remote(); remote->remoteStep(); const double *acc; const double *gyro; const unsigned char *image; char *receiveBuffer = (char *)malloc(1024); char *sendBuffer = (char *)malloc(350000); receiveBuffer[0]='\0'; sendBuffer[0]='\0'; Image rgbImage((320/cameraWidthZoomFactor), (240/cameraHeightZoomFactor), Image::RGB_PIXEL_SIZE); unsigned char jpeg_buffer[rgbImage.m_ImageSize]; int c = 0; int n; while(1) { // Wait for message n=0; do n += recv(csock, &receiveBuffer[n], 1024-n, 0); while(n<3); if (receiveBuffer[0]!='W') { cerr << "Error: wrong TCP message received" << endl; continue; } int total = (unsigned char)receiveBuffer[1]+(unsigned char)receiveBuffer[2]*256; while(n<total) n += recv(csock, &receiveBuffer[n], 1024-n, 0); receiveBuffer[total]=0; // set the final 0 int receivePos = 3, sendPos = 5; // Accelerometer if (receiveBuffer[receivePos] == 'A') { acc = remote->getRemoteAccelerometer(); for (c = 0; c < 3; c++) writeINT2Buffer(sendBuffer + 4 * c + sendPos, (int)acc[c]); sendPos += 12; receivePos++; } // Gyro if (receiveBuffer[receivePos] == 'G') { gyro = remote->getRemoteGyro(); for (c = 0; c < 3; c++) writeINT2Buffer(sendBuffer + 4 * c + sendPos, (int)gyro[c]); sendPos += 12; receivePos++; } // Camera if (receiveBuffer[receivePos] == 'C') { image = remote->getRemoteImage(); int image_buffer_position = 0; for (int height = 120 - (120 / cameraHeightZoomFactor) ; height < 120 + (120 / cameraHeightZoomFactor); height++) { for (int width = 160 - (160 / cameraWidthZoomFactor) ; width < 160 + (160 / cameraWidthZoomFactor); width++) { rgbImage.m_ImageData[image_buffer_position + 2] = image[height * 320 * 4 + width * 4 + 0]; rgbImage.m_ImageData[image_buffer_position + 1] = image[height * 320 * 4 + width * 4 + 1]; rgbImage.m_ImageData[image_buffer_position + 0] = image[height * 320 * 4 + width * 4 + 2]; image_buffer_position += 3; } } // Compress image to jpeg int buffer_length = 0; if (cameraHeightZoomFactor *cameraWidthZoomFactor < 2) // -> resolution 320x240 -> put quality at 65% buffer_length = jpeg_utils::compress_rgb_to_jpeg(&rgbImage, jpeg_buffer, rgbImage.m_ImageSize, 65); else // image smaller, put quality at 80% buffer_length = jpeg_utils::compress_rgb_to_jpeg(&rgbImage, jpeg_buffer, rgbImage.m_ImageSize, 80); writeINT2Buffer(sendBuffer + sendPos, buffer_length); // write image_buffer length sendPos += 4; memcpy(sendBuffer + sendPos, jpeg_buffer, buffer_length); // write image sendPos += buffer_length; receivePos++; } // LEDs for (c = 0; c < 5; c++) { if (receiveBuffer[receivePos] == 'L') { unsigned char c1 = static_cast <unsigned char> (receiveBuffer[receivePos+4]); unsigned char c2 = static_cast <unsigned char> (receiveBuffer[receivePos+3]); unsigned char c3 = static_cast <unsigned char> (receiveBuffer[receivePos+2]); int value = c1 + (c2 << 8) + (c3 << 16); remote->setRemoteLED(receiveBuffer[receivePos+1], value); receivePos += 5; } } // Motors Actuator for (c = 0; c < 20; c++) { if (receiveBuffer[receivePos] == 'S') { int motorNumber = (int)receiveBuffer[receivePos+1]; receivePos+= 2; if (receiveBuffer[receivePos] == 'p') { // Position int value = readINTFromBuffer(receiveBuffer + receivePos + 1); remote->setRemoteMotorPosition(motorNumber, value); receivePos += 5; } if (receiveBuffer[receivePos] == 'v') { // Velocity int value = readINTFromBuffer(receiveBuffer + receivePos + 1); remote->setRemoteMotorVelocity(motorNumber, value); receivePos += 5; } if (receiveBuffer[receivePos] == 'a') { // Acceleration int value = readINTFromBuffer(receiveBuffer + receivePos + 1); remote->setRemoteMotorAcceleration(motorNumber, value); receivePos += 5; } if (receiveBuffer[receivePos] == 'm') { // AvailableTorque int value = readINTFromBuffer(receiveBuffer + receivePos + 1); remote->setRemoteMotorAvailableTorque(motorNumber, value); receivePos += 5; } if (receiveBuffer[receivePos] == 'c') { // ControlPID int p = readINTFromBuffer(receiveBuffer + receivePos + 1); int i = readINTFromBuffer(receiveBuffer + receivePos + 1 + 4); int d = readINTFromBuffer(receiveBuffer + receivePos + 1 + 2 * 4); remote->setRemoteMotorControlPID(motorNumber, p, i, d); receivePos += 1 + 3 * 4; // TODO (fabien): why not use sizeof(int) ? } if (receiveBuffer[receivePos] == 'f') { // Torque int value = readINTFromBuffer(receiveBuffer + receivePos + 1); remote->setRemoteMotorTorque(motorNumber, value); receivePos += 5; } } } // Position Sensors for (c = 0; c < 20; c++) { if (receiveBuffer[receivePos] == 'P') { if ((int)receiveBuffer[receivePos+1] < 20) { double motorPosition = remote->getRemotePositionSensor((int)receiveBuffer[receivePos+1]); writeINT2Buffer(sendBuffer + sendPos, (int)motorPosition); } else writeINT2Buffer(sendBuffer + sendPos, 0); sendPos += 4; receivePos += 2; } } // Motors sensors torque for (c = 0; c < 20; c++) { if (receiveBuffer[receivePos] == 'F') { if ((int)receiveBuffer[receivePos+1] < 20) { double motorTorque = remote->getRemoteMotorTorque((int)receiveBuffer[receivePos+1]); writeINT2Buffer(sendBuffer + sendPos, (int)motorTorque); } else writeINT2Buffer(sendBuffer + sendPos, 0); sendPos += 4; receivePos += 2; } } if (receiveBuffer[receivePos]!=0) cerr << "Error: received unknown message: " << receiveBuffer[receivePos] << endl; // Terminate the buffer and send it sendBuffer[0] = 'W'; writeINT2Buffer(sendBuffer+1, sendPos); // Write size of buffer at the beginning sendBuffer[sendPos++] = '\0'; n=0; do n += send(csock, &sendBuffer[n], sendPos-n, 0); while (n!=sendPos); remote->remoteStep(); } // Close client socket and server socket cout << "Closing client socket" << endl; closesocket(csock); cout << "Closing server socket" << endl; closesocket(sock); free(receiveBuffer); free(sendBuffer); } else perror("socket"); return EXIT_SUCCESS; }
template<class T> inline void read(Remote<T>& buffer, RemotePtr<T> ptr, int process_index = ProcessIndexAny) const { this->read_bytes(buffer.getBuffer(), sizeof(T), ptr, process_index); }