/* MobileRobots Advanced Robotics Interface for Applications (ARIA) Copyright (C) 2004, 2005 ActivMedia Robotics LLC Copyright (C) 2006, 2007 MobileRobots Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA If you wish to redistribute ARIA under different terms, contact MobileRobots for information about a commercial version of ARIA at robots@mobilerobots.com or MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481 */ #include "Aria.h" #include "ArNetworking.h" ArClientBase client; void jpegHandler(ArNetPacket *packet) { unsigned int width; unsigned int height; unsigned char jpeg[50000]; int jpegSize; FILE *file; width = packet->bufToUByte2(); height = packet->bufToUByte2(); printf("Got jpeg of %d x %d\n", width, height); jpegSize = packet->getDataLength() - packet->getDataReadLength(); printf("Jpeg %d long\n", jpegSize); packet->bufToData((char *)jpeg, jpegSize); if ((file = fopen("client.jpg", "wb+")) != NULL) { fwrite(jpeg, jpegSize, 1, file); fclose(file); } else printf("Could not write file\n"); //client.disconnect(); //client.stopRunning(); } int main(int argc, char **argv) { Aria::init(); ArGlobalFunctor1<ArNetPacket *> jpegHandlerCB(&jpegHandler); ArNetPacket packet; std::string hostname; int port; printf("Usage: %s [hostname>] [port]\n", argv[0]); if (argc >= 2) hostname = argv[1]; else hostname = "localhost"; if (argc >= 3) port = atoi(argv[2]); else port = 7070; if (!client.blockingConnect(hostname.c_str(), port)) { printf("Could not connect to server, exiting\n"); exit(1); } client.addHandler("getPictureCam1", &jpegHandlerCB); client.request("getPictureCam1", -2); // stop request packet.uByteToBuf(90); client.requestOnce("getPictureCam1", &packet); // request one frame with an argument of 90 client.request("getPictureCam1", -1); // request a continuous stream client.run(); Aria::shutdown(); return 0; }