Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

TestDir.cc

Go to the documentation of this file.
00001 /*
00002 
00003     Test direction finding
00004     Copyright (C) 1999-2000 Jussi Laako
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 */
00021 
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <math.h>
00027 #include <float.h>
00028 #include <signal.h>
00029 
00030 #include "Config.h"
00031 #include "Messages.hh"
00032 #include "SockClie.hh"
00033 #include "SockOp.hh"
00034 
00035 
00036 bool bRun = true;
00037 
00038 
00039 void SigHandler (int iSigNum)
00040 {
00041     bRun = false;
00042 }
00043 
00044 
00045 int main (int argc, char *argv[])
00046 {
00047     int iSockH;
00048     int iMsgLen;
00049     int iBeamCntr;
00050     char cpReqMsgBuf[GLOBAL_HEADER_LEN];
00051     char *cpMsgBuf;
00052     GDT fpResData[18];
00053     stDirReq sRq;
00054     stDirRes sResHdr;
00055     clSockClie SClient;
00056     clSockOp *SOp;
00057     clDirMsg DirMsg;
00058 
00059     signal(SIGINT, SigHandler);
00060     if (argc < 3)
00061     {
00062         printf("%s <host> <port>\n", argv[0]);
00063         return 1;
00064     }
00065     iSockH = SClient.Connect(argv[1], NULL, atoi(argv[2]));
00066     if (iSockH < 0)
00067     {
00068         printf("Can't connect\n");
00069         return 1;
00070     }
00071     SOp = new clSockOp(iSockH);
00072     strcpy(cpReqMsgBuf, "direction");
00073     if (SOp->WriteN(cpReqMsgBuf, GLOBAL_HEADER_LEN) < GLOBAL_HEADER_LEN)
00074     {
00075         printf("Can't send process name\n");
00076         return 1;
00077     }
00078     sRq.iAlgorithm = MSG_DIR_ALG_BEAM;
00079     sRq.fSoundSpeed = 1430.0F;
00080     sRq.fLowFreqLimit = 60.0F;
00081     sRq.fIntegrationTime = 5.0F;
00082     sRq.iScaling = MSG_DIR_SCAL_LIN;
00083     sRq.fScalingExp = 0.0F;
00084     sRq.bNormalize = false;
00085     sRq.fLeftDir = -(M_PI / 2.0);
00086     sRq.fRightDir = M_PI / 2.0;
00087     sRq.lSectorCount = 18;
00088     DirMsg.SetRequest(cpReqMsgBuf, &sRq);
00089     if (SOp->WriteN(cpReqMsgBuf, GLOBAL_HEADER_LEN) < GLOBAL_HEADER_LEN)
00090     {
00091         printf("Can't send request message\n");
00092         return 1;
00093     }
00094     iMsgLen = GLOBAL_HEADER_LEN + 18 * sizeof(GDT);
00095     cpMsgBuf = (char *) alloca(iMsgLen);
00096     if (cpMsgBuf == NULL)
00097     {
00098         printf("Memory allocation error!\n");
00099         return 2;
00100     }
00101     while (bRun)
00102     {
00103         if (SOp->ReadN(cpMsgBuf, iMsgLen) == iMsgLen)
00104         {
00105             DirMsg.GetResult(cpMsgBuf, &sResHdr, fpResData);
00106             for (iBeamCntr = 0; iBeamCntr < 18; iBeamCntr++)
00107             {
00108                 printf(" %.2f", fpResData[iBeamCntr]);
00109             }
00110             printf("\n\n");
00111         }
00112         else
00113         {
00114             printf("Result read error\n");
00115             break;
00116         }
00117     }
00118     delete SOp;
00119     return 0;
00120 }
00121 

Generated on Sun Oct 26 19:11:23 2003 for HASAS by doxygen 1.3.3