12#error This is a C++ include file and cannot be used from plain C
58 int Option(
const char *name,
const char *value) {
59 if (strcmp(name,
"-fd") == 0)
63 else if (strcmp(name,
"-p") == 0)
69 else if (strcmp(name,
"-s") == 0)
77 else if (strcmp(name,
"-b") == 0)
83 else if (strcmp(name,
"-c") == 0)
89 else if (strcmp(name,
"-nl") == 0)
95 else if (strcmp(name,
"-bitpix") == 0)
111 fprintf(fd,
"standard options:\n");
112 fprintf(fd,
" -p <port> - service port\n");
113 fprintf(fd,
" (default: 0)\n");
114 fprintf(fd,
" -s <words> - ADC packet size (32-bit words)\n");
115 fprintf(fd,
" (default: 2)\n");
116 fprintf(fd,
" -b <boards> - number of ADC boards\n");
117 fprintf(fd,
" (default: 1)\n");
118 fprintf(fd,
" -c <channels> - channels per ADC board\n");
119 fprintf(fd,
" (default: 4)\n");
120 fprintf(fd,
" -bitpix <bits> - bits per pixel\n");
121 fprintf(fd,
" (default: 16)\n");
169 if (packetBuffer_ != NULL) free(packetBuffer_);
170 if (linkBuffer_ != NULL) free(linkBuffer_);
203 while (Connected_()) Packet_();
216 virtual unsigned short Sample16(
size_t channel,
size_t cvt) {
218 pix = (
unsigned short)channel;
263 packetBuffer_ = (
char *)malloc(size_);
264 if (packetBuffer_ == NULL)
266 strcpy(erms_,
"cannot allocate packet buffer");
270 linkBuffer_ = (
char *)malloc(size_);
271 if (linkBuffer_ == NULL)
273 strcpy(erms_,
"cannot allocate link buffer");
274 free(packetBuffer_); packetBuffer_ = NULL;
282 sprintf(s,
"%d",
pktCfg.port);
292 strcpy(erms_,
"invalid port");
293 free(linkBuffer_); linkBuffer_ = NULL;
294 free(packetBuffer_); packetBuffer_ = NULL;
300 free(linkBuffer_); linkBuffer_ = NULL;
301 free(packetBuffer_); packetBuffer_ = NULL;
308 int Connected_() {
return (out_ >= 0);}
317 strcpy(erms_,
"service not established");
349 buffer = linkBuffer_;
354 buffer = packetBuffer_;
360 unsigned short *p = (
unsigned short *)buffer;
361 for (b=0;b<
pktCfg.boards;b++)
364 for (n=0;n<nPix/
pktCfg.channels;n++)
366 for (c=0;c<
pktCfg.channels;c++) *p++ =
Sample16(c0 + c, cvt_ + n);
371 else if (
pktCfg.bytes == 4)
373 int *p = (
int *)buffer;
374 for (b=0;b<
pktCfg.boards;b++)
377 for (n=0;n<nPix/
pktCfg.channels;n++)
379 for (c=0;c<
pktCfg.channels;c++) *p++ =
Sample32(c0 + c, cvt_ + n);
386 memset(packetBuffer_, 0, size_);
396 size_t chunk = size_ / links;
397 size_t x = links * 8;
399 for (i=0;i<links;i++)
401 char *b1 = linkBuffer_ + (i * chunk);
402 char *b2 = packetBuffer_ + (i * 8);
403 for (j=0;j<links;j++)
412 if (
ngcbTcpWrite(out_, packetBuffer_, size_, erms_) != 0) Disconnect_();
414 cvt_ += (nPix /
pktCfg.channels);
int Service()
Service loop.
Definition ngcbPIX.hpp:186
ngcbPIX & operator=(const ngcbPIX &other)
Operator =.
Definition ngcbPIX.hpp:133
ngcbPIX(const ngcb_pcfg_t &cfg)
Constructor.
Definition ngcbPIX.hpp:148
virtual unsigned short Sample16(size_t channel, size_t cvt)
16-bit sample
Definition ngcbPIX.hpp:216
int Initialized()
Initialized.
Definition ngcbPIX.hpp:180
ngcb_pcfg_t pktCfg
Packet service configuration.
Definition ngcbPIX.hpp:213
ngcbPIX(const ngcbPIX &other)
Copy constructor.
Definition ngcbPIX.hpp:143
const char * ErrMsg()
Return error message.
Definition ngcbPIX.hpp:174
virtual ~ngcbPIX()
Destructor.
Definition ngcbPIX.hpp:153
void RstCnt()
Reset convert counter.
Definition ngcbPIX.hpp:183
int Port()
Return actual service port.
Definition ngcbPIX.hpp:177
virtual int Sample32(size_t channel, size_t cvt)
32-bit sample
Definition ngcbPIX.hpp:223
int ngcbSocketPort(int fd)
Definition ngcbSocket.c:201
int ngcbTcpClose(int fd)
Definition ngcbTcp.c:401
int ngcbTcpWrite(int fd, const void *buffer, size_t size, char *erms)
Definition ngcbTcp.c:459
int ngcbTcpService(const char *service, char *erms)
Definition ngcbTcp.c:38
int ngcbTcpAccept(int fd, char *erms)
Definition ngcbTcp.c:134
int ngcbSocketWait(int fd, int timeout, char *erms)
Definition ngcbSocket.c:241
#define ngcbLog(...)
Definition ngcb.h:118
int ngcbStr2UInt(const char *s, unsigned int *value)
Definition ngcbString.c:197
int ngcbStr2Int(const char *s, int *value)
Definition ngcbString.c:185
Definition ngcbPIX.hpp:33
int Option(const char *name, const char *value)
Handle command line option.
Definition ngcbPIX.hpp:58
unsigned int links
Number of links.
Definition ngcbPIX.hpp:50
unsigned int bytes
Bytes per pixel.
Definition ngcbPIX.hpp:47
int port
Port number.
Definition ngcbPIX.hpp:35
unsigned int size
Packet size (bytes)
Definition ngcbPIX.hpp:38
unsigned int boards
Number of boards.
Definition ngcbPIX.hpp:41
unsigned int channels
Number of channels per board.
Definition ngcbPIX.hpp:44
void Usage(FILE *fd)
Print option usage.
Definition ngcbPIX.hpp:110
ngcb_pcfg_t()
Constructor.
Definition ngcbPIX.hpp:53