Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

getVideoExample.cpp

Go to the documentation of this file.
00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "Aria.h"
00027 #include "ArNetworking.h"
00028 
00035 ArClientBase client;
00036 
00037 void jpegHandler(ArNetPacket *packet)
00038 {
00039   unsigned int width;
00040   unsigned int height;
00041   unsigned char jpeg[50000];
00042   int jpegSize;
00043   FILE *file;
00044 
00045   width = packet->bufToUByte2();
00046   height = packet->bufToUByte2();
00047   printf("Got jpeg of %d x %d\n", width, height);
00048   jpegSize = packet->getDataLength() - packet->getDataReadLength();
00049   printf("Jpeg %d long\n", jpegSize);
00050   packet->bufToData((char *)jpeg, jpegSize);
00051   if ((file = fopen("client.jpg", "wb+")) != NULL)
00052   {
00053     fwrite(jpeg, jpegSize, 1, file);
00054     fclose(file);
00055   }
00056   else
00057     printf("Could not write file\n");
00058   
00059   //client.disconnect();
00060   //client.stopRunning();
00061 }
00062 
00063 int main(int argc, char **argv)
00064 {
00065   Aria::init();
00066   ArGlobalFunctor1<ArNetPacket *> jpegHandlerCB(&jpegHandler);
00067   ArNetPacket packet;
00068   
00069   std::string hostname;
00070   int port;
00071 
00072   printf("Usage: %s [hostname>] [port]\n", argv[0]);
00073   
00074   if (argc >= 2)
00075     hostname = argv[1];
00076   else
00077     hostname = "localhost";
00078   
00079   if (argc >= 3)
00080     port = atoi(argv[2]);
00081   else
00082     port = 7070;
00083 
00084   if (!client.blockingConnect(hostname.c_str(), port))
00085   {
00086     printf("Could not connect to server, exiting\n");
00087     exit(1);
00088   }    
00089 
00090   client.addHandler("getPictureCam1", &jpegHandlerCB);
00091 
00092   client.request("getPictureCam1", -2); // stop request
00093 
00094   packet.uByteToBuf(90);
00095   client.requestOnce("getPictureCam1", &packet); // request one frame with an argument of 90
00096 
00097   client.request("getPictureCam1", -1); // request a continuous stream
00098 
00099   client.run();
00100   Aria::shutdown();
00101   return 0;
00102 }
00103 
00104 
00105 

Generated on Tue Feb 20 10:51:50 2007 for ArNetworking by  doxygen 1.4.0