00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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