Commit 2e05526f authored by Leon Hiemstra's avatar Leon Hiemstra

support ranges in /unb[] and pn[]. Removed 'cat'

parent 05171c29
......@@ -25,7 +25,7 @@ make
# Configure server:
edit /etc/uniboard2.conf
vi src/uniboard2.conf
Usage:
Startup server process:
......
This diff is collapsed.
......@@ -33,8 +33,7 @@ private:
const std::string HELP="help";
const std::string QUIT="quit";
const std::string INFO="ls";
const std::string CAT="cat";
const std::string MREAD="mread";
const std::string MREAD="read";
const std::string MWRITE="mwrite";
......@@ -44,7 +43,6 @@ private:
// (3)
CMDstatus Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus Cat(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);
......@@ -54,7 +52,6 @@ private:
supported_cmds.push_back(HELP);
supported_cmds.push_back(QUIT);
supported_cmds.push_back(INFO);
supported_cmds.push_back(CAT);
supported_cmds.push_back(MREAD);
supported_cmds.push_back(MWRITE);
}
......
......@@ -23,6 +23,7 @@
#include <arpa/inet.h> //inet_aton
#include "common.h"
#include "tools/parse.h"
extern int debug;
......@@ -86,27 +87,38 @@ RegisterMap * Common::get_RegisterMap(TermOutput& termout, int node)
return n->get_RegisterMap(termout.strout);
}
bool Common::mread(TermOutput& termout, std::vector<int> nodes, const string addr,
const uint offs, const uint len)
bool Common::read(TermOutput& termout, const string addr, const uint offs, const int len)
{
bool retval=false;
uint retcnt=0;
std::vector<int> nodes = path_to_node(addr);
std::string relative_addr = addr_to_relative_addr(addr);
std::string type = addr_to_type(addr);
std::string peripheral = addr_to_peripheral(addr);
for(uint idx=0;idx<nodes.size();idx++) {
auto node = select_node(nodes[idx]);
print_node_id(termout.strout,node);
if(idx>0) termout.strout << ",";
termout.strout << "[" << node->GetGlobalNr() << "],";
//termout.strout << "[" << node->GetGlobalNr() << "],";
termout.strout << "[";
std::vector<int> datavec;
if(node->mread(termout.strout,addr,offs,datavec,len)) {
retcnt++;
for(uint i=0;i<datavec.size();i++) {
if(i>0) termout.strout << ",";
termout.strout << datavec[i];
if(type == "mm") {
RegisterMap *regmap = node->get_RegisterMap(termout.strout);
uint32_t nvalues = (len<0 ? (regmap->getSpan(relative_addr) / 4) : len);
std::vector<int> datavec;
if(node->mread(termout.strout,relative_addr,offs,datavec,nvalues)) {
retcnt++;
}
} else if(type == "dev") {
if(node->get_system_info(termout.strout,peripheral)) {
retcnt++;
} else {
termout.strerr << "no such peripheral: " << peripheral;
}
} else {
termout.strerr << "no such type: " << type;
}
termout.strout << "]";
}
......@@ -114,44 +126,12 @@ bool Common::mread(TermOutput& termout, std::vector<int> nodes, const string add
return retval;
}
bool Common::read(TermOutput& termout, const string addr)
{
bool retval=false;
uint retcnt=0;
auto node = select_node(path_to_node(addr));
std::string relative_addr = addr_to_relative_addr(addr);
std::string type = addr_to_type(addr);
std::string peripheral = addr_to_peripheral(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.strout,relative_addr,0,datavec,nvalues)) {
retcnt++;
}
} else if(type == "dev") {
if(node->get_system_info(termout.strout,peripheral)) {
retcnt++;
} else {
termout.strerr << "no such peripheral: " << peripheral;
}
} else {
termout.strerr << "no such type: " << type;
}
termout.strout << "]";
retval = retcnt;
return retval;
}
bool Common::mwrite(TermOutput& termout, std::vector<int> nodes, const string addr,
bool Common::mwrite(TermOutput& termout, const string addr,
const uint offs, const std::vector<int>& data)
{
bool retval=false;
uint retcnt=0;
std::vector<int> nodes;
for(uint idx=0;idx<nodes.size();idx++) {
auto node = select_node(nodes[idx]);
......@@ -189,11 +169,11 @@ std::vector<int> Common::unb_pn__to__nodes(std::vector<int> unbs, std::vector<in
nodes.push_back(pn+(4*unb));
}
}
cout << "unb_pn__to__nodes:";
for(auto n : nodes) {
cout << n << " ";
}
cout << endl;
// cout << "unb_pn__to__nodes:";
// for(auto n : nodes) {
// cout << n << " ";
// }
// cout << endl;
return nodes;
}
......@@ -215,42 +195,62 @@ uint Common::ipaddr_to_id(const string ipaddr)
return (unb*8+node);
}
int Common::unb_name_to_number(const std::string unb_name)
std::vector<int> Common::unb_name_to_number(const std::string unb_name)
{
int number = -1;
std::vector<int> unbs;
cout << "Common::unb_name_to_number: unb_name=" << unb_name << endl;
if(unb_name.length() >= 4) {
char *s = new char[unb_name.length() + 1];
s[unb_name.length()] = '\0';
for(uint i=0;i<unb_name.length();i++) {
s[i] = unb_name.c_str()[i];
}
if(s[0] == 'u' && s[1] == 'n' && s[2] == 'b') {
char *s_ptr = &s[3];
number = atoi(s_ptr);
if(unb_name[0] == 'u' && unb_name[1] == 'n' && unb_name[2] == 'b') {
std::string unb_range = unb_name.substr(3);
cout << "unb_range=" << unb_range << endl;
try {
unbs.push_back(std::stoi(unb_range,nullptr));
} catch (const std::invalid_argument& ia) {
cerr << "Common::unb_name_to_number: Invalid argument: " << ia.what() << " - but trying vector..." << endl;
istringstream vecstr(unb_range);
unbs=parse_int_vector_range(vecstr);
}
}
delete[] s;
}
return number;
// cout << "Common::unb_name_to_number: found unb:" << endl;
// for(auto u : unbs) {
// cout << u << " ";;
// }
// cout << endl;
return unbs;
}
int Common::pn_name_to_number(const std::string pn_name)
std::vector<int> Common::pn_name_to_number(const std::string pn_name)
{
int number = -1;
std::vector<int> pns;
if(pn_name.length() >= 3) {
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';
if(pn_name[0] == 'p' && pn_name[1] == 'n') {
std::string pn_range = pn_name.substr(2);
cout << "pn_range=" << pn_range << endl;
try {
pns.push_back(std::stoi(pn_range,nullptr));
} catch (const std::invalid_argument& ia) {
cerr << "Common::pn_name_to_number: Invalid argument: " << ia.what() << " - but trying vector..." << endl;
istringstream vecstr(pn_range);
pns=parse_int_vector_range(vecstr);
}
}
}
return number;
// cout << "Common::pn_name_to_number: found pns:" << endl;
// for(auto p : pns) {
// cout << p << " ";;
// }
// cout << endl;
return pns;
}
int Common::path_to_node(std::string path_str)
std::vector<int> Common::path_to_node(std::string path_str)
{
int node = -1;
std::vector<int> nodes;
std::stringstream ss(path_str);
std::string token;
std::vector<std::string> tokens;
......@@ -260,14 +260,24 @@ int Common::path_to_node(std::string path_str)
if(tokens.size() >= 3) {
if(tokens[0] == "") {
// ok, is absolute path starting with '/'
int unb = unb_name_to_number(tokens[1]);
int pn = pn_name_to_number(tokens[2]);
if(unb>=0 && pn>=0) {
node = pn+(4*unb);
std::vector<int> unb = unb_name_to_number(tokens[1]);
std::vector<int> pn = pn_name_to_number(tokens[2]);
for(auto u : unb) {
for(auto p : pn) {
if(u>=0 && p>=0) {
nodes.push_back(p+(4*u));
}
}
}
}
}
return node;
// cout << "Common::path_to_node: found nodes:" << endl;
// for(auto n : nodes) {
// cout << n << " ";;
// }
// cout << endl;
return nodes;
}
std::string Common::addr_to_relative_addr(std::string addr)
......
......@@ -34,12 +34,10 @@ public:
bool get_system_info(TermOutput& termout, std::vector<int> nodes, const std::string what);
bool mread(TermOutput& termout, std::vector<int> nodes, const std::string addr,
const uint offs, const uint len);
bool mwrite(TermOutput& termout, std::vector<int> nodes, const std::string addr,
bool mwrite(TermOutput& termout, const std::string addr,
const uint offs, const std::vector<int>& data);
bool read(TermOutput& termout, const string addr);
bool read(TermOutput& termout, const string addr, const uint offs, const int len);
std::vector<int> unb_pn__to__nodes(std::vector<int> unbs, std::vector<int> pns);
......@@ -48,9 +46,9 @@ public:
std::string string_node_id(int node);
int path_to_node(std::string path_str);
int unb_name_to_number(const std::string unb_name);
int pn_name_to_number(const std::string pn_name);
std::vector<int> path_to_node(std::string path_str);
std::vector<int> unb_name_to_number(const std::string unb_name);
std::vector<int> pn_name_to_number(const std::string pn_name);
std::string addr_to_relative_addr(std::string addr);
std::string addr_to_peripheral(std::string addr);
......
......@@ -68,7 +68,7 @@ static UA_StatusCode UNB_MethodCallback(UA_Server *server,
cout <<"inputStr->data=" << inputStr->data <<endl;
try {
SD->unb->read(termout,std::string((char *)inputStr->data)); // TODO: make read/write
SD->unb->read(termout,std::string((char *)inputStr->data),0,-1); // TODO: make read/write
} catch(runtime_error& e) {
cerr << "UNB_MethodCallback: " << e.what() << endl;
termout.strout << e.what();
......
......@@ -52,7 +52,7 @@ std::vector<std::string> RegisterMap::getRegnames_full(std::string prefix)
{
std::vector<std::string> regnames;
for(auto m : reg) {
regnames.push_back(m.second.access + " " + prefix + m.first);
regnames.push_back(m.second.access + " " + to_string(m.second.span) + " " + prefix + m.first);
}
return regnames;
}
......
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