16 #include <epicsGetopt.h> 36 void usage (
bool details=
false)
39 "Usage: pvput [options] <PV name> <value>\n" 40 " pvput [options] <PV name> <size/ignored> <value> [<value> ...]\n" 41 " pvput [options] <PV name> <field>=<value> ...\n" 42 " pvput [options] <PV name> <json_array>\n" 43 " pvput [options] <PV name> <json_map>\n" 46 " Deprecated options:\n" 47 " default: Auto - try value as enum string, then as index number\n" 48 " -n, -s, -F, -t: ignored\n" 49 " -f <input file>: error" 53 "\n JSON support is present\n" 56 " pvput double01 1.234 # shorthand\n" 57 " pvput double01 value=1.234\n" 59 " pvput arr:pv X 1.0 2.0 # shorthand (X is arbitrary and ignored)\n" 60 " pvput arr:pv \"[1.0, 2.0]\" # shorthand\n" 61 " pvput arr:pv value=\"[1.0, 2.0]\"\n" 63 "Field values may be given with JSON syntax.\n" 65 "Complete structure\n" 67 " pvput double01 '{\"value\":1.234}'\n" 71 " pvput group:pv some='{\"value\":1.234}' other='{\"value\":\"a string\"}'\n" 77 void printValue(std::string
const & channelName, pvd::PVStructure::const_shared_pointer
const &
pv)
79 std::cout<<pv->stream().format(
outmode);
91 Putter() :done(
false) {}
96 typedef std::pair<std::string, std::string> KV_t;
97 typedef std::vector<KV_t> pairs_t;
104 if(
debugFlag) std::cerr<<
"Server defined structure\n"<<build;
107 if(bare.size()==1 && bare[0][0]==
'{') {
109 std::istringstream strm(bare[0]);
112 }
else if(pairs.empty()) {
117 throw std::runtime_error(
"Structure has no .value");
118 pvd::Type ftype = fld->getField()->getType();
122 throw std::runtime_error(
"Can't assign multiple values to scalar");
125 sfld->putFrom(bare[0]);
126 args.tosend.set(sfld->getFieldOffset());
134 sfld->putFrom(freeze(bare));
135 args.tosend.set(sfld->getFieldOffset());
137 }
else if(ftype==
pvd::structure && fld->getField()->getID()==
"enum_t") {
139 throw std::runtime_error(
"Can't assign multiple values to enum");
148 for(
size_t i=0;
i<choices.size();
i++) {
149 if(bare[0]==choices[
i]) {
158 idxfld->putFrom(bare[0]);
161 args.tosend.set(idxfld->getFieldOffset());
163 throw std::runtime_error(
"Don't know how to set field .value");
169 for(pairs_t::const_iterator it=pairs.begin(), end=pairs.end(); it!=end; ++it)
173 fprintf(
stderr,
"%s : Warning: no such field\n", it->first.c_str());
176 }
else if(it->second[0]==
'[') {
178 jarray(arr, it->second.c_str());
182 fprintf(
stderr,
"%s : Error not a scalar array field\n", it->first.c_str());
183 throw std::runtime_error(
"Not a scalar array field");
185 afld->putFrom(freeze(arr));
186 args.tosend.set(afld->getFieldOffset());
188 }
else if(it->second[0]==
'{' || it->second[0]==
'[') {
189 std::istringstream strm(it->second);
195 fprintf(
stderr,
"%s : Error: need a scalar field\n", it->first.c_str());
197 sfld->putFrom(it->second);
198 args.tosend.set(sfld->getFieldOffset());
206 std::cout<<
"To be sent: "<<args.tosend<<
"\n"<<args.root;
224 int main (
int argc,
char *argv[])
231 putenv(const_cast<char*>(
"POSIXLY_CORRECT="));
233 while ((opt =
getopt(argc, argv,
":hvVM:r:w:tp:qdF:f:ns")) != -1) {
239 outmode = pvd::PVStructure::Formatter::Raw;
243 fprintf(
stdout,
"pvAccess %u.%u.%u%s\n",
244 EPICS_PVA_MAJOR_VERSION,
245 EPICS_PVA_MINOR_VERSION,
246 EPICS_PVA_MAINTENANCE_VERSION,
247 (EPICS_PVA_DEVELOPMENT_FLAG)?
"-SNAPSHOT":
"");
248 fprintf(
stdout,
"pvData %u.%u.%u%s\n",
249 EPICS_PVD_MAJOR_VERSION,
250 EPICS_PVD_MINOR_VERSION,
251 EPICS_PVD_MAINTENANCE_VERSION,
252 (EPICS_PVD_DEVELOPMENT_FLAG)?
"-SNAPSHOT":
"");
253 fprintf(
stdout,
"Base %s\n", EPICS_VERSION_FULL);
257 if(strcmp(
optarg,
"raw")==0) {
258 outmode = pvd::PVStructure::Formatter::Raw;
259 }
else if(strcmp(
optarg,
"nt")==0) {
260 outmode = pvd::PVStructure::Formatter::NT;
261 }
else if(strcmp(
optarg,
"json")==0) {
262 outmode = pvd::PVStructure::Formatter::JSON;
265 outmode = pvd::PVStructure::Formatter::Raw;
273 fprintf(
stderr,
"'%s' is not a valid timeout value " 274 "- ignored. ('pvput -h' for help.)\n",
optarg);
298 fprintf(
stderr,
"Unsupported option -f\n");
306 "Unrecognized option: '-%c'. ('pvput -h' for help.)\n",
311 "Option '-%c' requires an argument. ('pvput -h' for help.)\n",
322 fprintf(
stderr,
"No pv name specified. ('pvput -h' for help.)\n");
325 std::string pv = argv[
optind++];
328 std::string pvName(pv);
330 int nVals = argc -
optind;
333 fprintf(
stderr,
"No value(s) specified. ('pvput -h' for help.)\n");
337 std::vector<std::string> values;
339 for (
int n = 0; optind < argc; n++, optind++)
340 values.push_back(argv[optind]);
344 for(
size_t i=0, N=values.size();
i<N;
i++)
346 size_t sep = values[
i].find_first_of(
'=');
347 if(sep==std::string::npos) {
348 thework.bare.push_back(values[
i]);
350 thework.pairs.push_back(std::make_pair(values[
i].substr(0, sep),
351 values[
i].substr(sep+1)));
355 if(!thework.bare.empty() && !thework.pairs.empty()) {
357 fprintf(
stderr,
"\nCan't mix bare values and field=value pairs\n");
360 }
else if(thework.bare.size()==1 && thework.bare[0][0]==
'[') {
362 thework.pairs.push_back(std::make_pair(
"value", thework.bare[0]));
363 thework.bare.clear();
366 pvd::PVStructure::shared_pointer pvRequest;
369 }
catch(std::exception& e){
370 fprintf(
stderr,
"failed to parse request string: %s\n", e.what());
376 std::cout << std::boolalpha;
385 std::cout <<
"Old : ";
386 printValue(pvName, chan.get(
timeout, pvRequest));
393 while(!thework.done) {
395 if(!thework.wait.wait(
timeout)) {
396 fprintf(
stderr,
"Put timeout\n");
403 fprintf(
stderr,
"Error: %s\n", thework.message.c_str());
407 std::cout <<
"New : ";
409 printValue(pvName, chan.get(
timeout, pvRequest));
412 }
catch(std::exception& e) {
413 std::cerr<<
"Error: "<<e.what()<<
"\n";
int getopt(int nargc, char *const *nargv, const char *ostr)
virtual const_svector view() const OVERRIDE FINAL
Fetch a read-only view of the current array data.
PVScalar is the base class for each scalar field.
#define assert(exp)
Declare that a condition should be true.
#define SET_LOG_LEVEL(level)
std::tr1::shared_ptr< const Structure > StructureConstPtr
#define epicsScanDouble(str, to)
PVStructure::shared_pointer createRequest(std::string const &request)
Handle for in-progress get/put/rpc operation.
std::string message
Check when event==Fail.
int main(int argc, char *argv[])
Information on put completion.
void jarray(pvd::shared_vector< std::string > &out, const char *inp)
template class for all extensions of PVArray.
enum pvac::PutEvent::event_t event
Base class for a scalarArray.
std::tr1::shared_ptr< PVScalar > PVScalarPtr
Extended replacement for the Posix exit and atexit routines.
epics::pvData::PVStructure::shared_pointer parseJSON(std::istream &strm)
Data interface for a structure,.
std::tr1::shared_ptr< PVStructure > PVStructurePtr
ClientChannel connect(const std::string &name, const ClientChannel::Options &conf=ClientChannel::Options())
request ends in failure. Check message
std::tr1::shared_ptr< PVField > PVFieldPtr
ChannelPut::shared_pointer op
C++ and C descriptions for a thread.
static void start()
start provider ca
std::string defaultProvider
pvd::PVStructure::Formatter::format_t outmode
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
::epics::pvData::shared_vector< const T > const_svector