13#error This is a C++ include file and cannot be used from plain C
59 int Option(
const char *name,
const char *value) {
60 if (strcmp(name,
"-fd") == 0)
64 else if (strcmp(name,
"-p") == 0)
70 else if (strcmp(name,
"-s") == 0)
78 else if (strcmp(name,
"-b") == 0)
84 else if (strcmp(name,
"-c") == 0)
90 else if (strcmp(name,
"-nl") == 0)
96 else if (strcmp(name,
"-bitpix") == 0)
112 fprintf(fd,
"standard options:\n");
113 fprintf(fd,
" -p <port> - service port\n");
114 fprintf(fd,
" (default: 0)\n");
115 fprintf(fd,
" -s <words> - ADC packet size (32-bit words)\n");
116 fprintf(fd,
" (default: 2)\n");
117 fprintf(fd,
" -b <boards> - number of ADC boards\n");
118 fprintf(fd,
" (default: 1)\n");
119 fprintf(fd,
" -c <channels> - channels per ADC board\n");
120 fprintf(fd,
" (default: 4)\n");
121 fprintf(fd,
" -bitpix <bits> - bits per pixel\n");
122 fprintf(fd,
" (default: 16)\n");
170 if (packetBuffer_ != NULL) free(packetBuffer_);
171 if (linkBuffer_ != NULL) free(linkBuffer_);
204 while (Connected_()) Packet_();
217 virtual unsigned short Sample16(
size_t channel,
size_t cvt) {
219 pix = (
unsigned short)channel;
264 packetBuffer_ = (
char *)malloc(size_);
265 if (packetBuffer_ == NULL)
267 strcpy(erms_,
"cannot allocate packet buffer");
271 linkBuffer_ = (
char *)malloc(size_);
272 if (linkBuffer_ == NULL)
274 strcpy(erms_,
"cannot allocate link buffer");
275 free(packetBuffer_); packetBuffer_ = NULL;
283 sprintf(s,
"%d",
pktCfg.port);
293 strcpy(erms_,
"invalid port");
294 free(linkBuffer_); linkBuffer_ = NULL;
295 free(packetBuffer_); packetBuffer_ = NULL;
301 free(linkBuffer_); linkBuffer_ = NULL;
302 free(packetBuffer_); packetBuffer_ = NULL;
309 int Connected_() {
return (out_ >= 0);}
318 strcpy(erms_,
"service not established");
350 buffer = linkBuffer_;
355 buffer = packetBuffer_;
361 unsigned short *p = (
unsigned short *)buffer;
362 for (b=0;b<
pktCfg.boards;b++)
365 for (n=0;n<nPix/
pktCfg.channels;n++)
367 for (c=0;c<
pktCfg.channels;c++) *p++ =
Sample16(c0 + c, cvt_ + n);
372 else if (
pktCfg.bytes == 4)
374 int *p = (
int *)buffer;
375 for (b=0;b<
pktCfg.boards;b++)
378 for (n=0;n<nPix/
pktCfg.channels;n++)
380 for (c=0;c<
pktCfg.channels;c++) *p++ =
Sample32(c0 + c, cvt_ + n);
387 memset(packetBuffer_, 0, size_);
397 size_t chunk = size_ / links;
398 size_t x = links * 8;
400 for (i=0;i<links;i++)
402 char *b1 = linkBuffer_ + (i * chunk);
403 char *b2 = packetBuffer_ + (i * 8);
404 for (j=0;j<links;j++)
413 if (
ngcbTcpWrite(out_, packetBuffer_, size_, erms_) != 0) Disconnect_();
415 cvt_ += (nPix /
pktCfg.channels);
int Service()
Service loop.
Definition ngcbPIX.hpp:187
ngcbPIX & operator=(const ngcbPIX &other)
Operator =.
Definition ngcbPIX.hpp:134
ngcbPIX(const ngcb_pcfg_t &cfg)
Constructor.
Definition ngcbPIX.hpp:149
virtual unsigned short Sample16(size_t channel, size_t cvt)
16-bit sample
Definition ngcbPIX.hpp:217
int Initialized()
Initialized.
Definition ngcbPIX.hpp:181
ngcb_pcfg_t pktCfg
Packet service configuration.
Definition ngcbPIX.hpp:214
ngcbPIX(const ngcbPIX &other)
Copy constructor.
Definition ngcbPIX.hpp:144
const char * ErrMsg()
Return error message.
Definition ngcbPIX.hpp:175
virtual ~ngcbPIX()
Destructor.
Definition ngcbPIX.hpp:154
void RstCnt()
Reset convert counter.
Definition ngcbPIX.hpp:184
int Port()
Return actual service port.
Definition ngcbPIX.hpp:178
virtual int Sample32(size_t channel, size_t cvt)
32-bit sample
Definition ngcbPIX.hpp:224
int ngcbSocketPort(int fd)
Definition ngcbSocket.c:202
int ngcbTcpClose(int fd)
Definition ngcbTcp.c:402
int ngcbTcpWrite(int fd, const void *buffer, size_t size, char *erms)
Definition ngcbTcp.c:460
int ngcbTcpService(const char *service, char *erms)
Definition ngcbTcp.c:39
int ngcbTcpAccept(int fd, char *erms)
Definition ngcbTcp.c:135
int ngcbSocketWait(int fd, int timeout, char *erms)
Definition ngcbSocket.c:242
#define ngcbLog(...)
Definition ngcb.h:119
int ngcbStr2UInt(const char *s, unsigned int *value)
Definition ngcbString.c:198
int ngcbStr2Int(const char *s, int *value)
Definition ngcbString.c:186
Definition ngcbPIX.hpp:34
int Option(const char *name, const char *value)
Handle command line option.
Definition ngcbPIX.hpp:59
unsigned int links
Number of links.
Definition ngcbPIX.hpp:51
unsigned int bytes
Bytes per pixel.
Definition ngcbPIX.hpp:48
int port
Port number.
Definition ngcbPIX.hpp:36
unsigned int size
Packet size (bytes)
Definition ngcbPIX.hpp:39
unsigned int boards
Number of boards.
Definition ngcbPIX.hpp:42
unsigned int channels
Number of channels per board.
Definition ngcbPIX.hpp:45
void Usage(FILE *fd)
Print option usage.
Definition ngcbPIX.hpp:111
ngcb_pcfg_t()
Constructor.
Definition ngcbPIX.hpp:54