Commit 6f2aeec8 authored by Leon Hiemstra's avatar Leon Hiemstra

can read (almost) all registers via OPCua, changed P to pn

parent 40c5626c
......@@ -74,8 +74,6 @@ CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Server
req_ret = Info(argc,argv,termout,sd);
} else if(cmd == CAT) {
req_ret = Cat(argc,argv,termout,sd);
} else if(cmd == VERBOSE) {
req_ret = Verbose(argc,argv,termout,sd);
} else if(cmd == MREAD) {
req_ret = Mread(argc,argv,termout,sd);
} else if(cmd == MWRITE) {
......@@ -87,12 +85,12 @@ CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Server
*/
} else if(cmd == HELP) {
req_ret.status=CMD_STATUS_OK;
termout.strhuman << "Available commands:" << endl;
termout.strout << "Available commands:" << endl;
for(uint i=0;i<supported_cmds.size();i++) {
termout.strhuman << i << ". " << supported_cmds[i] << " [options]" << endl;
termout.strout << i << ". " << supported_cmds[i] << " [options]" << endl;
}
termout.strhuman << endl << "Server also supports '>' and '>>' and '|' operators like the Bash shell" << endl;
termout.strhuman << endl << "Syntax help: use option -h for each command" << endl;
termout.strout << endl << "Server also supports '>' and '>>' and '|' operators like the Bash shell" << endl;
termout.strout << endl << "Syntax help: use option -h for each command" << endl;
} else if(cmd == QUIT) {
req_ret.status=CMD_REQUEST_QUIT;
}
......@@ -150,9 +148,8 @@ CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Server
}
}
if(fname != "" && !fd.fail()) { // in case of a given: >file or >>file
// write streams strout and strhuman to this file fd
// write streams strout to this file fd
fd << termout.strout.str();
fd << termout.strhuman.str();
fd.close();
} else if(pipecmd != "") { // in case of a given: |shell command
ostringstream strs_filter;
......@@ -161,12 +158,6 @@ CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Server
termout.strout.str(""); termout.strout.clear();
termout.strout << strs_filter.str();
// pass stream strhuman to system command and replace strhuman with output of system command:
strs_filter.str(""); strs_filter.clear();
strs_filter << exec_system_cmd_rw(termout.strhuman.str(),pipecmd.c_str(),pipeargv);
termout.strhuman.str(""); termout.strhuman.clear();
termout.strhuman << strs_filter.str();
for(int i=0;(pipeargv[i]!=(char *)0);i++) delete[] pipeargv[i];
delete[] pipeargv;
}
......@@ -195,7 +186,6 @@ CMDstatus CMD::Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
("help,h", "shows this help text")
("version", "shows version")
("all,a", "select all nodes")
("allpn", "select all nodes")
("gn", po::value<std::string>(),
"Node global number. Example: [3,4:7] for PN 3 on UniBoard 0 and PN0:3 on UniBoard 1")
("pn", po::value<std::string>(),
......@@ -211,7 +201,7 @@ CMDstatus CMD::Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
po::notify(vm);
if (vm.count("help")) {
termout.strhuman << "Usage: " << INFO << " [options]" << endl << "Options: " << desc;
termout.strout << "Usage: " << INFO << " [options]" << endl << "Options: " << desc;
return {CMD_STATUS_OK,0,0};
}
if (vm.count("version")) {
......@@ -234,7 +224,7 @@ CMDstatus CMD::Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
string gn=vm["gn"].as<string>();
istringstream vecstr(gn);
nodes=parse_int_vector_range(vecstr);
} else if (vm.count("all") || vm.count("allpn")) {
} else if (vm.count("all")) {
nodes=sd->unb->get_nodes();
}
......@@ -260,28 +250,6 @@ CMDstatus CMD::Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
return ret;
}
CMDstatus CMD::Verbose(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
{
po::options_description desc("set verbose level");
desc.add_options()
("help,h", "shows this help text")
("on", "enable")
("off", "disable")
;
po::variables_map vm;
po::store(po::parse_command_line(argc,argv,desc), vm);
po::notify(vm);
if (vm.count("help")) {
termout.strhuman << "usage: " << VERBOSE << endl << desc;
}
if (vm.count("on")) {
termout.Verbose=1;
} else if (vm.count("off")) {
termout.Verbose=0;
} else termout.strout << "verbose=" << termout.Verbose << endl;
return {CMD_STATUS_OK,0,0};
}
CMDstatus CMD::Mread(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
{
CMDstatus ret={CMD_STATUS_ERROR,0,0};
......@@ -291,7 +259,6 @@ CMDstatus CMD::Mread(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
desc.add_options()
("help,h", "shows this help text")
("all,a", "select all nodes")
("allpn", "select all frontnodes")
("gn", po::value<std::string>(),
"Node global number. Example: [3,4:7] for PN 3 on UniBoard 0 and PN0:3 on UniBoard 1")
("pn", po::value<std::string>(),
......@@ -308,7 +275,7 @@ CMDstatus CMD::Mread(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
po::store(po::parse_command_line(argc,argv,desc), vm);
po::notify(vm);
if (vm.count("help")) {
termout.strhuman << "usage: " << MREAD << " [options]" << endl << "Options: " << desc;
termout.strout << "usage: " << MREAD << " [options]" << endl << "Options: " << desc;
return {CMD_STATUS_OK,0,0};
}
if (vm.count("unb") && vm.count("pn")) {
......@@ -327,7 +294,7 @@ CMDstatus CMD::Mread(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
string gn=vm["gn"].as<string>();
istringstream vecstr(gn);
nodes=parse_int_vector_range(vecstr);
} else if (vm.count("all") || vm.count("allpn")) {
} else if (vm.count("all")) {
nodes=sd->unb->get_nodes();
}
if(nodes.size()==0) throw runtime_error("missing argument(s), add options: --gn or --unb,--pn");
......@@ -357,7 +324,6 @@ CMDstatus CMD::Mwrite(int argc, char* argv[], TermOutput& termout, Serverdat *sd
desc.add_options()
("help,h", "shows this help text")
("all,a", "select all nodes")
("allpn", "select all frontnodes")
("gn", po::value<std::string>(),
"Node global number. Example: [3,4:7] for PN 3 on UniBoard 0 and PN0:3 on UniBoard 1")
("pn", po::value<std::string>(),
......@@ -374,7 +340,7 @@ CMDstatus CMD::Mwrite(int argc, char* argv[], TermOutput& termout, Serverdat *sd
po::store(po::parse_command_line(argc,argv,desc), vm);
po::notify(vm);
if (vm.count("help")) {
termout.strhuman << "usage: " << MWRITE << " [options]" << endl << "Options: " << desc;
termout.strout << "usage: " << MWRITE << " [options]" << endl << "Options: " << desc;
return {CMD_STATUS_OK,0,0};
}
if (vm.count("unb") && vm.count("pn")) {
......@@ -393,7 +359,7 @@ CMDstatus CMD::Mwrite(int argc, char* argv[], TermOutput& termout, Serverdat *sd
string gn=vm["gn"].as<string>();
istringstream vecstr(gn);
nodes=parse_int_vector_range(vecstr);
} else if (vm.count("all") || vm.count("allpn") ) {
} else if (vm.count("all")) {
nodes=sd->unb->get_nodes();
}
if(nodes.size()==0) throw runtime_error("missing argument(s), add options: --gn or --unb,--pb");
......@@ -441,7 +407,7 @@ CMDstatus CMD::Cat(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
po::store(po::parse_command_line(argc,argv,desc), vm);
po::notify(vm);
if (vm.count("help")) {
termout.strhuman << "usage: " << CAT << " [options]" << endl << "Options: " << desc;
termout.strout << "usage: " << CAT << " [options]" << endl << "Options: " << desc;
return {CMD_STATUS_OK,0,0};
} else if (vm.count("file")) {
string filename=vm["file"].as<string>();
......
......@@ -31,7 +31,6 @@ private:
// (1)
const std::string HELP="help";
const std::string VERBOSE="verbose";
const std::string QUIT="quit";
const std::string INFO="ls";
const std::string CAT="cat";
......@@ -46,14 +45,12 @@ private:
// (3)
CMDstatus Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus Cat(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus Verbose(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus Mread(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus Mwrite(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
public:
CMD() {
// (2)
supported_cmds.push_back(VERBOSE);
supported_cmds.push_back(HELP);
supported_cmds.push_back(QUIT);
supported_cmds.push_back(INFO);
......
......@@ -94,14 +94,14 @@ bool Common::mread(TermOutput& termout, std::vector<int> nodes, const string add
for(uint idx=0;idx<nodes.size();idx++) {
auto node = select_node(nodes[idx]);
print_node_id(termout.strhuman,node);
print_node_id(termout.strout,node);
if(idx>0) termout.strout << ",";
termout.strout << "[" << node->GetGlobalNr() << "],";
termout.strout << "[";
std::vector<int> datavec;
if(node->mread(termout.strhuman,addr,offs,datavec,len)) {
if(node->mread(termout.strout,addr,offs,datavec,len)) {
retcnt++;
for(uint i=0;i<datavec.size();i++) {
if(i>0) termout.strout << ",";
......@@ -126,13 +126,15 @@ bool Common::read(TermOutput& termout, const string addr)
termout.strout << addr << "=[";
if(type == "mm") {
RegisterMap *regmap = node->get_RegisterMap(termout.strout);
uint32_t nvalues = regmap->getSpan(relative_addr) / 4;
std::vector<int> datavec;
if(node->mread(termout.strhuman,relative_addr,0,datavec,1)) {
if(node->mread(termout.strout,relative_addr,0,datavec,nvalues)) {
retcnt++;
for(uint i=0;i<datavec.size();i++) {
if(i>0) termout.strout << ",";
termout.strout << datavec[i];
}
//for(uint i=0;i<datavec.size();i++) {
// if(i>0) termout.strout << ",";
// termout.strout << datavec[i];
//}
}
} else if(type == "dev") {
if(node->get_system_info(termout.strout,peripheral)) retcnt++;
......@@ -151,7 +153,7 @@ bool Common::mwrite(TermOutput& termout, std::vector<int> nodes, const string ad
for(uint idx=0;idx<nodes.size();idx++) {
auto node = select_node(nodes[idx]);
print_node_id(termout.strhuman,node);
print_node_id(termout.strout,node);
if(idx>0) termout.strout << ",";
termout.strout << "[" << node->GetGlobalNr() << "],";
......@@ -163,7 +165,7 @@ bool Common::mwrite(TermOutput& termout, std::vector<int> nodes, const string ad
}
termout.strout << "]";
if(node->mwrite(termout.strhuman,addr,offs,data)) retcnt++;
if(node->mwrite(termout.strout,addr,offs,data)) retcnt++;
}
retval = (retcnt==nodes.size());
return retval;
......@@ -227,7 +229,6 @@ int Common::unb_name_to_number(const std::string unb_name)
number = atoi(s_ptr);
}
delete[] s;
//cout << "unb_name_to_number(" << unb_name << ")=" << number << endl;
return number;
}
......@@ -235,10 +236,9 @@ int Common::pn_name_to_number(const std::string pn_name)
{
int number = -1;
if(pn_name.c_str()[0] == 'P' && isdigit(pn_name.c_str()[1])) {
number = pn_name.c_str()[1] - '0';
if(pn_name.c_str()[0] == 'p' && pn_name.c_str()[1] == 'n' && isdigit(pn_name.c_str()[2])) {
number = pn_name.c_str()[2] - '0';
}
//cout << "pn_name_to_number(" << pn_name << ")=" << number << endl;
return number;
}
......@@ -271,7 +271,7 @@ std::string Common::addr_to_relative_addr(std::string addr)
tokens.push_back(token);
}
// "/unb0/P3/mm/addr"
// "/unb0/pn3/mm/addr"
// 0 1 2 3 4
for(uint i=3;i<tokens.size();i++) {
......@@ -292,7 +292,7 @@ std::string Common::addr_to_type(std::string addr)
tokens.push_back(token);
}
// "/unb0/P3/dev/peripheral"
// "/unb0/pn3/dev/peripheral"
// 0 1 2 3 4
if(tokens.size() >= 4) {
......@@ -312,7 +312,7 @@ std::string Common::addr_to_peripheral(std::string addr)
tokens.push_back(token);
}
// "/unb0/P3/dev/peripheral"
// "/unb0/pn3/dev/peripheral"
// 0 1 2 3 4
if(tokens.size() >= 5) {
......
......@@ -25,7 +25,7 @@ using namespace std;
extern int debug;
Node::Node(const string ipaddr, const uint unb, const uint localnr, const char type,
Node::Node(const string ipaddr, const uint unb, const uint localnr, const std::string type,
const string firmware)
: unbos(ipaddr)
{
......@@ -44,11 +44,11 @@ Node::Node(const string ipaddr, const uint unb, const uint localnr, const char t
UniboardNr=unb;
LocalNr=localnr;
GlobalNr=localnr+4*unb;
if(type!='P') throw runtime_error("invalid node type: \"" + string(1,type) + "\"");
if(type!="pn") throw runtime_error("invalid node type: \"" + type + "\"");
Type=type;
syslog(LOG_INFO,"Uniboard=%d New node IP=%s type=%c localnr=%d globalnr=%d\n",
UniboardNr,myIPaddr.c_str(),Type,LocalNr,GlobalNr);
syslog(LOG_INFO,"Uniboard=%d New node IP=%s type=%s localnr=%d globalnr=%d\n",
UniboardNr,myIPaddr.c_str(),Type.c_str(),LocalNr,GlobalNr);
}
Node::~Node()
......@@ -59,19 +59,16 @@ Node::~Node()
bool Node::get_system_info(ostringstream& strs,const string what) {
if(what=="system") {
return periph_system->read_system_info(strs);
// } else if(what=="regmap") {
// periph_system->print_regmap(strs,"gn="+to_string(GetGlobalNr()));
// return true;
} else if(what=="name") {
strs << "read_design_name:" << periph_system->read_design_name() << endl;
strs << "read_design_name:" << periph_system->read_design_name(); // << endl;
return true;
} else if(what=="stamps") {
return periph_system->read_stamps(strs);
} else if(what=="note") {
strs << "read_design_note:" << periph_system->read_design_note() << endl;
strs << "read_design_note:" << periph_system->read_design_note(); // << endl;
return true;
} else if(what=="sensors") {
return periph_system->read_unb_sensors(strs,LocalNr,Type);
return periph_system->read_unb_sensors(strs,LocalNr);
}
else return false;
}
......
......@@ -32,7 +32,7 @@ public:
};
#define GLOBALNODE_to_UNB(n) (n>>3)
#define GLOBALNODE_to_TYPE(n) ('P')
#define GLOBALNODE_to_TYPE(n) ("pn")
#define GLOBALNODE_to_NODE(n) (n&0x3)
class Node {
......@@ -43,7 +43,7 @@ class Node {
uint UniboardNr;
uint GlobalNr;
uint LocalNr;
char Type;
std::string Type;
UNBos unbos;
Periph_system *periph_system;
......@@ -55,7 +55,7 @@ class Node {
public:
Node(const std::string ipaddr,
const uint unb, const uint localnr, const char type,const std::string firmware);
const uint unb, const uint localnr, const std::string type, const std::string firmware);
~Node();
uint ipaddr_to_id(const std::string ipaddr);
......@@ -66,7 +66,7 @@ class Node {
const std::string GetFirmwareShortname(void) { return myFirmwareShortname; }
const uint GetGlobalNr() { return GlobalNr; }
const uint GetNr() { return LocalNr; }
const char GetType() { return Type; }
const std::string GetType() { return Type; }
bool get_system_info(std::ostringstream& strs,const std::string what);
bool mread(std::ostringstream& strs,const std::string addr, const uint offs,
......
......@@ -61,7 +61,7 @@ static UA_StatusCode UNB_MethodCallback(UA_Server *server,
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, (char *)"UNB_MethodCallback");
TermOutput termout(1);
TermOutput termout;
UA_String *inputStr = (UA_String*)input->data;
if(inputStr->length > 0) {
......@@ -119,7 +119,7 @@ static void add_UNB_Method(UA_Server *server, std::string regname)
int ua_server(Serverdat *sd) {
SD = sd;
TermOutput termout(1);
TermOutput termout;
std::vector<int> nodes = SD->unb->get_nodes(); // all nodes
......
......@@ -120,10 +120,11 @@ bool Periph_system::mread(std::ostringstream& strs, const std::string addr,
strs << "[";
for(uint i=0;i< nvalues;i++) {
if(i>0) strs << ",";
strs << hex << "0x" << data[i] << dec;
//strs << hex << "0x" << data[i] << dec;
strs << data[i];
datavec[i]=data[i];
}
strs << "]" << endl;
strs << "]";// << endl;
}
delete[] data;
return retval;
......@@ -136,10 +137,11 @@ bool Periph_system::mwrite(std::ostringstream& strs, const std::string addr,
strs << "[";
for(uint i=0;i<datavec.size();i++) {
if(i>0) strs << ",";
strs << hex << "0x" << datavec[i] << dec;
//strs << hex << "0x" << datavec[i] << dec;
strs << datavec[i];
data[i]=(uint32_t)datavec[i];
}
strs << "]" << endl;
strs << "]";// << endl;
bool retval = Write(addr,offs,1,data);
delete[] data;
return retval;
......@@ -206,7 +208,7 @@ bool Periph_system::read_use_phy(ostringstream& strs)
return retval;
}
bool Periph_system::read_unb_sensors(ostringstream& strs, const uint nodeNr, const char nodeType)
bool Periph_system::read_unb_sensors(ostringstream& strs, const uint nodeNr)
{
bool retval=true;
......@@ -220,7 +222,7 @@ bool Periph_system::read_unb_sensors(ostringstream& strs, const uint nodeNr, con
return retval;
}
bool Periph_system::read_unb_sensor(uint32_t *sensor, const uint nodeNr, const char nodeType)
bool Periph_system::read_unb_sensor(uint32_t *sensor, const uint nodeNr)
{
bool retval=true;
......
......@@ -31,8 +31,8 @@ public:
std::string read_design_note(void);
bool read_stamps(ostringstream& strs);
bool read_use_phy(ostringstream& strs);
bool read_unb_sensor(uint32_t *sensor, const uint nodeNr, const char nodeType);
bool read_unb_sensors(ostringstream& strs, const uint nodeId, const char nodeType);
bool read_unb_sensor(uint32_t *sensor, const uint nodeNr);
bool read_unb_sensors(ostringstream& strs, const uint nodeId);
bool read_temp_high(ostringstream& strs);
bool write_temp_high(ostringstream& strs, const int val);
bool write_wdi_override(ostringstream& strs);
......
......@@ -43,11 +43,6 @@ string print_termout(TermOutput& termout)
s += termout.strout.str();
s += "}\n";
if(termout.Verbose) {
s += "human={\n";
s += termout.strhuman.str();
s += "}\n";
}
s += "errors={\n";
s += termout.strerr.str();
s += "}\n";
......@@ -71,7 +66,7 @@ void control_server(TCPSSocket *sock, Serverdat *sd, const int clientId, std::at
CMDstatus cmdstatus={CMD_STATUS_OK, 0,0};
CMDstatus cmdstatusnew=cmdstatus;
TermOutput termout(sd->verbose[clientId]);
TermOutput termout;
unsigned char tcpbuf[1000];
while(!quit) {
......@@ -204,7 +199,7 @@ int main (int argc, char* argv[])
uint gn=(uint)nc.gn;
uint uniboardnr=GLOBALNODE_to_UNB(gn);
uint n=GLOBALNODE_to_NODE(gn);
char type=GLOBALNODE_to_TYPE(gn);
string type=GLOBALNODE_to_TYPE(gn);
Node *node = new Node(nc.ipaddr,uniboardnr,n,type,nc.firmware);
nodelist.push_back(node);
......
......@@ -27,18 +27,13 @@ class TermOutput {
public:
std::ostringstream strerr;
std::ostringstream strout;
std::ostringstream strhuman;
uint Verbose;
TermOutput(uint verbose) {
Verbose=verbose;
}
TermOutput() {}
~TermOutput() {};
void clear(void) {
strerr.str(""); strerr.clear();
strout.str(""); strout.clear();
strhuman.str(""); strhuman.clear();
}
};
......
......@@ -13,21 +13,21 @@
BitField 0x00000C00 b[31:0] WO wdi wdi reset_word
# peripheral=eth1g start=0x0800 span=0x0400 type=LITE count=01 idx=0 stop=0x0C00
# REG-SLAVE=tse no.slaves=1 len=1 (base=0x400)
DistrRAM 0x00000800 len=1024 RO eth1g tse status
DistrRAM 0x00000800 len=1024 NA eth1g tse status
# peripheral=eth1g start=0x0020 span=0x000C type=LITE count=01 idx=0 stop=0x002C
# REG-SLAVE=eth no.slaves=1 len=48 (base=0x400)
BitField 0x00000020 b[31:0] RO eth1g eth status0
BitField 0x00000021 b[31:0] RO eth1g eth status1
BitField 0x00000022 b[31:0] RO eth1g eth status2
BitField 0x00000023 b[31:0] RO eth1g eth status3
BitField 0x00000024 b[31:0] RO eth1g eth status4
BitField 0x00000025 b[31:0] RO eth1g eth status5
BitField 0x00000026 b[31:0] RO eth1g eth status6
BitField 0x00000027 b[31:0] RO eth1g eth status7
BitField 0x00000028 b[31:0] RO eth1g eth status8
BitField 0x00000029 b[31:0] RO eth1g eth status9
BitField 0x0000002A b[31:0] RO eth1g eth status10
BitField 0x0000002B b[31:0] RO eth1g eth status11
BitField 0x00000020 b[31:0] NA eth1g eth status0
BitField 0x00000021 b[31:0] NA eth1g eth status1
BitField 0x00000022 b[31:0] NA eth1g eth status2
BitField 0x00000023 b[31:0] NA eth1g eth status3
BitField 0x00000024 b[31:0] NA eth1g eth status4
BitField 0x00000025 b[31:0] NA eth1g eth status5
BitField 0x00000026 b[31:0] NA eth1g eth status6
BitField 0x00000027 b[31:0] NA eth1g eth status7
BitField 0x00000028 b[31:0] NA eth1g eth status8
BitField 0x00000029 b[31:0] NA eth1g eth status9
BitField 0x0000002A b[31:0] NA eth1g eth status10
BitField 0x0000002B b[31:0] NA eth1g eth status11
# peripheral=eth1g start=0x1000 span=0x0400 type=FULL count=01 idx=0 stop=0x1400
# RAM-SLAVE=eth
BlockRAM 0x00001000 len=1024 RW eth1g eth data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment