00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <iostream>
00035
00036
00037 #include <cstdio>
00038 #include <cstring>
00039
00040
00041 #include <unistd.h>
00042 #include <fcntl.h>
00043 #include <sys/ioctl.h>
00044 #include <sys/socket.h>
00045 #include <netinet/in.h>
00046 #include <arpa/inet.h>
00047 #include <netdb.h>
00048 #include <poll.h>
00049
00050
00051 #include "glbvars.h"
00052
00053 #include "LAN_rhk_hwi.h"
00054
00055
00056
00057 #define INTERNET_DEBUG(S) XSM_DEBUG (DBG_L4, S)
00058
00059
00060
00061
00062
00063
00064
00065 LAN_rhk_hwi_dev::LAN_rhk_hwi_dev(){
00066 char host_name[40];
00067 char *tport;
00068 int port;
00069 struct sockaddr_in pin;
00070 struct hostent *server_host_name;
00071
00072 strcpy(host_name, xsmres.DSPDev);
00073 tport=strstr(host_name,":");
00074 if (tport==NULL)
00075 {
00076 INTERNET_DEBUG("No : in remote address name, assuming 5027");
00077 port=5027;
00078 }
00079 else
00080 {
00081 tport[0]=0;
00082 tport++;
00083 port=atoi(tport);
00084 }
00085
00086 INTERNET_DEBUG("open socket to " << host_name << ", port " << port);
00087 max_points_per_line = 262145;
00088
00089 if ((server_host_name = gethostbyname(host_name)) == 0) {
00090 INTERNET_DEBUG("Error resolving local host");
00091 exit(1);
00092 }
00093
00094 bzero(&pin, sizeof(pin));
00095 pin.sin_family = AF_INET;
00096 pin.sin_addr.s_addr = htonl(INADDR_ANY);
00097 pin.sin_addr.s_addr = ((struct in_addr *)(server_host_name->h_addr))->s_addr;
00098 pin.sin_port = htons(port);
00099
00100 if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
00101 INTERNET_DEBUG("Error opening socket\n");
00102 exit(1);
00103 }
00104
00105
00106 if (connect(socket_descriptor, (struct sockaddr *)&pin, sizeof(pin)) == -1) {
00107 INTERNET_DEBUG("Error connecting to socket\n");
00108 exit(1);
00109 }
00110
00111 }
00112
00113
00114
00115
00116 LAN_rhk_hwi_dev::~LAN_rhk_hwi_dev(){
00117 INTERNET_DEBUG("close remote connection");
00118
00119 close(socket_descriptor);
00120
00121 }
00122
00123 int LAN_rhk_hwi_dev::SendCommand(char *Cmd){
00124 int n;
00125 n=strlen(Cmd);
00126 return(write(socket_descriptor, Cmd, n));
00127 }
00128
00129 size_t LAN_rhk_hwi_dev::ReadData(void *Data, size_t count) {
00130 struct pollfd list[1];
00131
00132 list[0].fd=socket_descriptor;
00133 list[0].events=POLLIN;
00134 while (!poll(list,1,0)) {
00135 gapp->check_events();
00136 }
00137 return(recv(socket_descriptor, Data, count,MSG_WAITALL ));
00138 }
00139
00140 void LAN_rhk_hwi_dev::ExecCmd(int Cmd){
00141
00142 INTERNET_DEBUG("Exec Cmd 0x" << std::hex << Cmd);
00143
00144
00145
00146
00147 }
00148
00149 int LAN_rhk_hwi_dev::WaitExec(int data){
00150 return 0;
00151 }
00152
00153
00154 void LAN_rhk_hwi_dev::SetParameter(PARAMETER_SET &hps, int scanflg){
00155 }
00156
00157 void LAN_rhk_hwi_dev::GetParameter(PARAMETER_SET &hps){
00158 }
00159
00160 int LAN_rhk_hwi_dev::ReadScanData(int y_index, int num_srcs, Mem2d *m[MAX_SRCS_CHANNELS]){
00161 static time_t t0 = 0;
00162 int len = m[0]->GetNx();
00163 int count;
00164 SHT *linebuffer = new SHT[len];
00165 char txt[20];
00166
00167
00168
00169
00170
00171
00172
00173 if (t0 == 0) t0 = time (NULL);
00174 int drift = (int) (time (NULL) - t0);
00175 if (y_index < 0)
00176 for (int k=0; k<m[0]->GetNy (); ++k)
00177 for (int i=0; i<num_srcs; ++i){
00178 count=sprintf(txt, "read %d\n", len);
00179 write(socket_descriptor, txt, count);
00180 ReadData(linebuffer, len*sizeof(short));
00181 write(socket_descriptor, txt, count);
00182 ReadData(linebuffer, len*sizeof(short));
00183 if (m[i])
00184 m[i]->PutDataLine (k, linebuffer);
00185 }
00186 else
00187 for (int i=0; i<num_srcs; ++i){
00188 count=sprintf(txt, "read %d\n", len);
00189 write(socket_descriptor, txt, count);
00190 ReadData(linebuffer, len*sizeof(short));
00191 write(socket_descriptor, txt, count);
00192 count=ReadData(linebuffer, len*sizeof(short));
00193 if (m[i])
00194 m[i]->PutDataLine (y_index, linebuffer);
00195 }
00196 delete[] linebuffer;
00197 return 0;
00198 }
00199
00200 int LAN_rhk_hwi_dev::ReadProbeData(int nsrcs, int nprobe, int kx, int ky, Mem2d *m, double scale){
00201
00202 return 1;
00203 }
00204
00205
00206
00207
00208
00209 gchar* LAN_rhk_hwi_dev::get_info(){
00210 return g_strdup("*--GXSM LAN/Internet HwI base class--*\n"
00211 "Internet device: do not know\n"
00212 "*--Features--*\n"
00213 "SCAN: Yes\n"
00214 "PROBE: No\n"
00215 "ACPROBE: No\n"
00216 "*--EOF--*\n"
00217 );
00218 }