ACQ400_XRM (xrmIoc)
Loading...
Searching...
No Matches
pvxsWrapper.cpp
1/*
2 * pvxsWrapper.cpp
3 *
4 * Created on: 27 Mar 2026
5 * Author: pgm
6 */
7
8#include <assert.h>
9#include <stdio.h>
10#include <string.h>
11
12#include <iostream>
13
14#include "acq-util.h"
15#include "split2.h"
16#include "xrm_structs.h"
17#include "pvxsWrapper.h"
18
19#include "acq400_asyn_common.h"
20
21extern int G_verbose;
22
23template<class CONTAINER>
24const CONTAINER* PVX_getter<CONTAINER>::parse(CONTAINER* values, char* txt)
25{
26 unsigned nelems;
27 if (G_verbose > 1 ) fprintf(stderr, "parse: \"%s\"\n", txt);
28
29 if (sscanf(txt, "{%u}", &nelems) != 1){
30 fprintf(stderr, "scan fail\n");
31 assert(false);
32 }
33 char* start = strchr(txt, '[');
34 assert(start != 0);
35 char* end = strchr(txt, ']');
36 assert(end != 0);
37 *end = '\0';
38
39 split2(++start, *values, ',');
40 if (G_verbose > 1 )
41 fprintf(stderr, "parse: values.size %u nelems %u\n",
42 (unsigned)(values->size()), nelems);
43
44 assert(values->size() == nelems);
45
46 return values;
47}
48
49template<class CONTAINER>
50const CONTAINER* PVX_getter<CONTAINER>::pvx_get(
51 CONTAINER* values,
52 bool wait_first_change)
53{
54 static char myline[MAXSIZE];
55 int lno = 0;
56 char cmd[128];
57 snprintf(cmd, 128, "unbuffer pvxmonitor -r value %s", pv_name);
58
59 FILE *pp = popen(cmd, "r");
60 while (fgets(myline, MAXSIZE, pp) != 0){
61 if (lno++ == 0 && wait_first_change){
62 fprintf(stderr, "skip initial value and wait_first change\n");
63 continue;
64 }
65
66 if (G_verbose > 2 ) fprintf(stderr, "[%2d] %s\n", lno, myline);
67 char* cursor = strstr(myline, needle);
68 if (cursor){
69 return parse(values, cursor+strlen(needle));
70 }
71 }
72 assert(false);
73 return 0;
74}
75
76template<class CONTAINER>
77const char* PVX_getter<CONTAINER>::make_pv_name(
78 const char* hostname, const char* pv_suffix)
79{
80 char* pvname = new char[strlen(hostname)+strlen(pv_suffix)];
81 strcpy(pvname, hostname);
82 return strcat(pvname, pv_suffix);
83}
84
85
86template<>
87PVX_getter<VIS>::PVX_getter(
88 const char* hostname,
89 const char* pv_suffix,
90 const char* NEEDLE):
91 pv_name(make_pv_name(hostname, pv_suffix)),
92 needle("value int32_t[] = ")
93{
94
95}
96
97template<>
98PVX_getter<VDS>::PVX_getter(
99 const char* hostname,
100 const char* pv_suffix,
101 const char* NEEDLE):
102 pv_name(make_pv_name(hostname, pv_suffix)),
103 needle("value double[] = ")
104{
105
106}
107
108template<class CONTAINER>
109PVX_getter<CONTAINER>::PVX_getter(
110 const char* hostname,
111 const char* pv_suffix,
112 const char* NEEDLE):
113 pv_name(make_pv_name(hostname, pv_suffix)),
114 needle(NEEDLE)
115{
116 assert(NEEDLE != 0);
117}
118
119
120template<class CONTAINER>
121PVX_getter<CONTAINER>::~PVX_getter()
122{
123 delete [] pv_name;
124}
125
Declarations for key XRM structures for internal and wire (external) use.