Skip to content
Snippets Groups Projects
Commit 0d81340a authored by Kenneth Hiemstra's avatar Kenneth Hiemstra
Browse files

make write() work. fix response format

parent e4487c94
Branches
Tags
No related merge requests found
...@@ -100,11 +100,10 @@ CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Server ...@@ -100,11 +100,10 @@ CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Server
*/ */
} else if(cmd == HELP) { } else if(cmd == HELP) {
req_ret.status=CMD_STATUS_OK; req_ret.status=CMD_STATUS_OK;
termout.strout << "Available commands:" << endl; termout.strout << endl << "Available commands:" << endl;
for(uint i=0; i < supported_cmds.size(); i++) { for(uint i=0; i < supported_cmds.size(); i++) {
termout.strout << i << ". " << supported_cmds[i] << endl; termout.strout << i << ". " << supported_cmds[i] << 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; termout.strout << endl << "Syntax help: use option -h for each command" << endl;
} else if(cmd == QUIT) { } else if(cmd == QUIT) {
req_ret.status = CMD_REQUEST_QUIT; req_ret.status = CMD_REQUEST_QUIT;
...@@ -172,7 +171,7 @@ CMDstatus CMD::Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd) ...@@ -172,7 +171,7 @@ CMDstatus CMD::Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
if(nodes.size()==0) throw runtime_error("missing file(s), add /unb.../pn..."); if(nodes.size()==0) throw runtime_error("missing file(s), add /unb.../pn...");
for(auto node : nodes) { for(auto node : nodes) {
RegisterMap *regmap = sd->unb->get_RegisterMap(termout, node); RegisterMap *regmap = sd->unb->get_RegisterMap(node);
std::string prefix = sd->unb->string_node_id(node); std::string prefix = sd->unb->string_node_id(node);
std::vector<std::string> regnames = regmap->getRegnames_full(prefix); std::vector<std::string> regnames = regmap->getRegnames_full(prefix);
...@@ -248,7 +247,7 @@ CMDstatus CMD::Mwrite(int argc, char* argv[], TermOutput& termout, Serverdat *sd ...@@ -248,7 +247,7 @@ CMDstatus CMD::Mwrite(int argc, char* argv[], TermOutput& termout, Serverdat *sd
{ {
CMDstatus ret = {CMD_STATUS_ERROR,0,0}; CMDstatus ret = {CMD_STATUS_ERROR,0,0};
po::options_description generic("Memory mapped write"); po::options_description generic("Generic write");
generic.add_options() generic.add_options()
("help,h", "shows this help text") ("help,h", "shows this help text")
("offs", po::value<uint>(),"offset from base address (per dword)") ("offs", po::value<uint>(),"offset from base address (per dword)")
......
...@@ -92,10 +92,10 @@ std::vector<int> Common::get_nodes(void) ...@@ -92,10 +92,10 @@ std::vector<int> Common::get_nodes(void)
return nodes; return nodes;
} }
RegisterMap * Common::get_RegisterMap(TermOutput& termout, int node) RegisterMap * Common::get_RegisterMap(int node)
{ {
auto n = select_node(node); auto n = select_node(node);
return n->get_RegisterMap(termout.strout); return n->get_RegisterMap();
} }
bool Common::monitor(TermOutput& termout) bool Common::monitor(TermOutput& termout)
...@@ -108,7 +108,7 @@ bool Common::monitor(TermOutput& termout) ...@@ -108,7 +108,7 @@ bool Common::monitor(TermOutput& termout)
auto node = select_node(nodes[idx]); auto node = select_node(nodes[idx]);
uint node_nr = node_number(node); uint node_nr = node_number(node);
if(idx > 0) termout.strout << ","; if(idx > 0) termout.strout << ",";
termout.strout << "(" << node_nr << ",0,"; termout.strout << "(" << node_nr << ",0,[";
try { try {
if(node->cread(termout.strout, "system")) { if(node->cread(termout.strout, "system")) {
retcnt++; retcnt++;
...@@ -116,7 +116,7 @@ bool Common::monitor(TermOutput& termout) ...@@ -116,7 +116,7 @@ bool Common::monitor(TermOutput& termout)
} catch(std::exception& e) { } catch(std::exception& e) {
termout.strerr << e.what() << endl; termout.strerr << e.what() << endl;
} }
termout.strout << ")"; termout.strout << "])";
} }
termout.strout << "]"; termout.strout << "]";
retval = (retcnt==nodes.size()); retval = (retcnt==nodes.size());
...@@ -126,31 +126,33 @@ bool Common::monitor(TermOutput& termout) ...@@ -126,31 +126,33 @@ bool Common::monitor(TermOutput& termout)
bool Common::read(TermOutput& termout, const string addr, const uint offs, const int len) bool Common::read(TermOutput& termout, const string addr, const uint offs, const int len)
{ {
bool retval=false; bool ret, retval = false;
uint retcnt=0; uint retcnt=0;
std::vector<int> nodes = path_to_node(addr); std::vector<int> nodes = path_to_node(addr);
std::string relative_addr = addr_to_relative_addr(addr); std::string relative_addr = addr_to_relative_addr(addr);
std::string type = addr_to_type(addr); std::string type = addr_to_type(addr);
std::string peripheral = addr_to_peripheral(addr); std::string peripheral = addr_to_peripheral(addr);
ostringstream strs;
termout.strout << "["; termout.strout << "[";
for(uint idx=0;idx<nodes.size();idx++) { for(uint idx=0;idx<nodes.size();idx++) {
auto node = select_node(nodes[idx]); auto node = select_node(nodes[idx]);
//print_node_id(termout.strout,node);
uint node_nr = node_number(node); uint node_nr = node_number(node);
if(idx > 0) termout.strout << ","; if(idx > 0) termout.strout << ",";
termout.strout << "(" << node_nr << ",0,";
strs.str(""); strs.clear();
ret = false;
try {
if(type == "mm") { if(type == "mm") {
RegisterMap *regmap = node->get_RegisterMap(termout.strout); RegisterMap *regmap = node->get_RegisterMap();
uint32_t nvalues = (len<0 ? regmap->getSpan(relative_addr) : len); uint32_t nvalues = (len<0 ? regmap->getSpan(relative_addr) : len);
std::vector<int> datavec; std::vector<int> datavec;
if(node->mread(termout.strout, relative_addr, offs, datavec, nvalues)) { if((ret=node->mread(strs, relative_addr, offs, datavec, nvalues))) {
retcnt++; retcnt++;
} }
} else if(type == "dev") { } else if(type == "dev") {
if(node->cread(termout.strout, peripheral)) { if((ret=node->cread(strs, peripheral))) {
retcnt++; retcnt++;
} else { } else {
termout.strerr << "no such peripheral: " << peripheral; termout.strerr << "no such peripheral: " << peripheral;
...@@ -158,7 +160,10 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const ...@@ -158,7 +160,10 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const
} else { } else {
termout.strerr << "no such type: " << type; termout.strerr << "no such type: " << type;
} }
termout.strout << ")"; } catch(std::exception& e) {
termout.strerr << e.what() << endl;
}
termout.strout << "(" << node_nr << (ret ? ",0,[" : ",1,[") << strs.str() << "])";
} }
termout.strout << "]"; termout.strout << "]";
retval = (retcnt==nodes.size()); retval = (retcnt==nodes.size());
...@@ -172,7 +177,7 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const ...@@ -172,7 +177,7 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const
bool Common::write(TermOutput& termout, const string addr, bool Common::write(TermOutput& termout, const string addr,
const uint offs, const std::vector<int>& data) const uint offs, const std::vector<int>& data)
{ {
bool retval = false; bool ret, retval = false;
uint retcnt = 0; uint retcnt = 0;
std::vector<int> nodes = path_to_node(addr); std::vector<int> nodes = path_to_node(addr);
...@@ -183,15 +188,15 @@ bool Common::write(TermOutput& termout, const string addr, ...@@ -183,15 +188,15 @@ bool Common::write(TermOutput& termout, const string addr,
termout.strout << "["; termout.strout << "[";
for(uint idx = 0; idx<nodes.size(); idx++) { for(uint idx = 0; idx<nodes.size(); idx++) {
auto node = select_node(nodes[idx]); auto node = select_node(nodes[idx]);
//print_node_id(termout.strout, node);
uint node_nr = node_number(node); uint node_nr = node_number(node);
if(idx > 0) termout.strout << ","; if(idx > 0) termout.strout << ",";
termout.strout << "(" << node_nr << ",0,";
ret = false;
try {
if(type == "mm") { if(type == "mm") {
if(node->mwrite(termout.strout, addr, offs, data)) retcnt++; if((ret=node->mwrite(relative_addr, offs, data))) retcnt++;
} else if(type == "dev") { } else if(type == "dev") {
if(node->cwrite(termout.strout, peripheral)) { if((ret=node->cwrite(peripheral))) {
retcnt++; retcnt++;
} else { } else {
termout.strerr << "no such peripheral: " << peripheral; termout.strerr << "no such peripheral: " << peripheral;
...@@ -199,9 +204,13 @@ bool Common::write(TermOutput& termout, const string addr, ...@@ -199,9 +204,13 @@ bool Common::write(TermOutput& termout, const string addr,
} else { } else {
termout.strerr << "no such type: " << type; termout.strerr << "no such type: " << type;
} }
termout.strout << ")"; } catch(std::exception& e) {
termout.strerr << e.what() << endl;
}
termout.strout << "(" << node_nr << "," << (ret ? "0)" : "1)");
} }
termout.strout << "]";
retval = (retcnt==nodes.size()); retval = (retcnt==nodes.size());
if(nodes.size() == 0) { if(nodes.size() == 0) {
termout.strerr << "no nodes"; termout.strerr << "no nodes";
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
std::vector<int> unb_pn__to__nodes(std::vector<int> unbs, std::vector<int> pns); std::vector<int> unb_pn__to__nodes(std::vector<int> unbs, std::vector<int> pns);
uint ipaddr_to_id(const string ipaddr); uint ipaddr_to_id(const string ipaddr);
RegisterMap * get_RegisterMap(TermOutput& termout, int node); RegisterMap * get_RegisterMap(int node);
std::string string_node_id(int node); std::string string_node_id(int node);
......
...@@ -82,12 +82,12 @@ bool Node::cread(ostringstream& strs,const string peripheral) { ...@@ -82,12 +82,12 @@ bool Node::cread(ostringstream& strs,const string peripheral) {
else return false; else return false;
} }
bool Node::cwrite(ostringstream& strs,const string peripheral) { bool Node::cwrite(const string peripheral) {
strs << "cwrite() not yet implemented TODO"; cerr << "cwrite() not yet implemented TODO";
return false; return false;
} }
RegisterMap * Node::get_RegisterMap(std::ostringstream& strs) RegisterMap * Node::get_RegisterMap(void)
{ {
return periph_system->getRegisterMap(); return periph_system->getRegisterMap();
} }
...@@ -97,8 +97,8 @@ bool Node::mread(std::ostringstream& strs,const std::string addr, const uint off ...@@ -97,8 +97,8 @@ bool Node::mread(std::ostringstream& strs,const std::string addr, const uint off
std::vector<int>& data, const uint len) { std::vector<int>& data, const uint len) {
return periph_system->mread(strs, addr, offs, data, len); return periph_system->mread(strs, addr, offs, data, len);
} }
bool Node::mwrite(std::ostringstream& strs,const std::string addr, const uint offs, bool Node::mwrite(const std::string addr, const uint offs,
const std::vector<int>& data) { const std::vector<int>& data) {
return periph_system->mwrite(strs, addr, offs, data); return periph_system->mwrite(addr, offs, data);
} }
...@@ -83,13 +83,13 @@ class Node { ...@@ -83,13 +83,13 @@ class Node {
const std::string GetType() { return Type; } const std::string GetType() { return Type; }
bool cread(std::ostringstream& strs, const std::string peripheral); bool cread(std::ostringstream& strs, const std::string peripheral);
bool cwrite(std::ostringstream& strs, const std::string peripheral); bool cwrite(const std::string peripheral);
bool mread(std::ostringstream& strs,const std::string addr, const uint offs, bool mread(std::ostringstream& strs,const std::string addr, const uint offs,
std::vector<int>& data, const uint len); std::vector<int>& data, const uint len);
bool mwrite(std::ostringstream& strs,const std::string addr, const uint offs, bool mwrite(const std::string addr, const uint offs,
const std::vector<int>& data); const std::vector<int>& data);
RegisterMap * get_RegisterMap(std::ostringstream& strs); RegisterMap * get_RegisterMap(void);
}; };
#endif /* NODE_H */ #endif /* NODE_H */
...@@ -155,7 +155,7 @@ int ua_server_init(bool warm_start) ...@@ -155,7 +155,7 @@ int ua_server_init(bool warm_start)
addVariable(mUaServer); addVariable(mUaServer);
for(auto node : nodes) { for(auto node : nodes) {
RegisterMap *regmap = SD.unb->get_RegisterMap(termout, node); RegisterMap *regmap = SD.unb->get_RegisterMap(node);
std::string prefix = SD.unb->string_node_id(node); std::string prefix = SD.unb->string_node_id(node);
std::vector<std::string> regnames = regmap->getRegnames(prefix); std::vector<std::string> regnames = regmap->getRegnames(prefix);
......
...@@ -126,14 +126,13 @@ bool Periph_system::read_system_info(ostringstream& strs) ...@@ -126,14 +126,13 @@ bool Periph_system::read_system_info(ostringstream& strs)
uint32_t data; uint32_t data;
bool retval = Read("mm/system/info/info",0,1,&data); bool retval = Read("mm/system/info/info",0,1,&data);
std::string design_name = read_design_name(); std::string design_name = read_design_name();
strs << "[design_name=" << design_name << ", "; strs << "design_name=" << design_name << ", ";
char str[1000]; char str[1000];
// FIXME: get rid of magic constants in masks, should be in CCFG: // FIXME: get rid of magic constants in masks, should be in CCFG:
uint firmware_version = (data & 0x00F00000) >> 20; uint firmware_version = (data & 0x00F00000) >> 20;
uint firmware_subversion = (data & 0x000F0000) >> 16; uint firmware_subversion = (data & 0x000F0000) >> 16;
uint hardware_version = (data & 0x00000300) >> 8; sprintf(str,"fw_version=%d.%d",firmware_version,firmware_subversion); strs << str;
sprintf(str,"fw_version=%d.%d]",firmware_version,firmware_subversion); strs << str;
if(design_name == my_expected_design_name && firmware_version >= my_expected_firmware_version) { if(design_name == my_expected_design_name && firmware_version >= my_expected_firmware_version) {
my_current_status = "online"; my_current_status = "online";
...@@ -162,32 +161,24 @@ bool Periph_system::mread(std::ostringstream& strs, const std::string addr, ...@@ -162,32 +161,24 @@ bool Periph_system::mread(std::ostringstream& strs, const std::string addr,
bool retval = Read(addr,offs,nvalues,data); bool retval = Read(addr,offs,nvalues,data);
if(retval) { if(retval) {
datavec.resize(nvalues); datavec.resize(nvalues);
strs << "[";
for(uint i=0; i < nvalues; i++) { for(uint i=0; i < nvalues; i++) {
if(i>0) strs << ","; if(i>0) strs << ",";
//strs << hex << "0x" << data[i] << dec;
strs << data[i]; strs << data[i];
datavec[i] = data[i]; datavec[i] = data[i];
} }
strs << "]";// << endl;
} }
delete[] data; delete[] data;
return retval; return retval;
} }
bool Periph_system::mwrite(std::ostringstream& strs, const std::string addr, bool Periph_system::mwrite(const std::string addr,
const uint offs, const std::vector<int>& datavec) const uint offs, const std::vector<int>& datavec)
{ {
uint32_t *data = new uint32_t[datavec.size()*sizeof(uint32_t)]; uint32_t *data = new uint32_t[datavec.size()*sizeof(uint32_t)];
strs << "[";
for(uint i = 0;i < datavec.size(); i++) { for(uint i = 0;i < datavec.size(); i++) {
if(i>0) strs << ",";
//strs << hex << "0x" << datavec[i] << dec;
strs << datavec[i];
data[i] = (uint32_t)datavec[i]; data[i] = (uint32_t)datavec[i];
} }
strs << "]";// << endl; bool retval = Write(addr, offs, datavec.size(), data);
bool retval = Write(addr, offs, 1, data);
delete[] data; delete[] data;
return retval; return retval;
} }
......
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
bool read_system_info(std::ostringstream& strs); bool read_system_info(std::ostringstream& strs);
bool mread(std::ostringstream& strs, const std::string addr, const uint offs, bool mread(std::ostringstream& strs, const std::string addr, const uint offs,
std::vector<int>& data, const uint len); std::vector<int>& data, const uint len);
bool mwrite(std::ostringstream& strs, const std::string addr, const uint offs, bool mwrite(const std::string addr, const uint offs,
const std::vector<int>& data); const std::vector<int>& data);
std::string read_design_name(void); std::string read_design_name(void);
std::string read_design_note(void); std::string read_design_note(void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment