Commit b29e958c authored by Leon Hiemstra's avatar Leon Hiemstra

opening multiple/separate connections with UNB

parent 44a68c0f
......@@ -50,7 +50,7 @@ extern int debug;
* 2 Add the command in this method [command()], to get it parsed when called
* 3 Append it's method down below in this file
*/
CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Serverdat *sd,
CMDstatus CMD::command(const uint clientId, string line, TermOutput& termout, string& cmdname, Serverdat *sd,
std::vector<std::vector<char>> binary_data)
{
// With telnet, a \r\n is added to the transmitted string
......@@ -86,13 +86,13 @@ CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Server
* vvvvv parse user command vvvvv
*/
if(cmd == INFO) {
req_ret = Info(argc,argv,termout,sd);
req_ret = Info(clientId, argc,argv,termout,sd);
} else if(cmd == MMREAD) {
req_ret = MMread(argc,argv,termout,sd);
req_ret = MMread(clientId, argc,argv,termout,sd);
} else if(cmd == MMWRITE) {
req_ret = MMwrite(argc,argv,termout,sd);
req_ret = MMwrite(clientId, argc,argv,termout,sd);
} else if(cmd == RELOAD) {
req_ret = Reload(argc,argv,termout,sd);
req_ret = Reload(clientId, argc,argv,termout,sd);
/*
* ^^^^^ parse user command ^^^^^
*
......@@ -123,7 +123,7 @@ CMDstatus CMD::command(string line, TermOutput& termout, string& cmdname, Server
/***********************
* Begin user commands *
***********************/
CMDstatus CMD::Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
CMDstatus CMD::Info(const uint clientId, int argc, char* argv[], TermOutput& termout, Serverdat *sd)
{
CMDstatus ret = {CMD_STATUS_ERROR,0,0};
std::vector<int> nodes;
......@@ -188,7 +188,7 @@ CMDstatus CMD::Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
return ret;
}
CMDstatus CMD::MMread(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
CMDstatus CMD::MMread(const uint clientId, int argc, char* argv[], TermOutput& termout, Serverdat *sd)
{
CMDstatus ret = {CMD_STATUS_ERROR,0,0};
......@@ -232,7 +232,7 @@ CMDstatus CMD::MMread(int argc, char* argv[], TermOutput& termout, Serverdat *sd
if(vm.count("file")) { addr_str = vm["file"].as<string>(); }
if(vm.count("offs")) { offs = vm["offs"].as<uint>(); }
if(vm.count("nvalues")) { nvalues = vm["nvalues"].as<int>(); }
if(sd->unb->read(termout, addr_str, offs, nvalues)) ret.status = CMD_STATUS_OK;
if(sd->unb->read(clientId, termout, addr_str, offs, nvalues)) ret.status = CMD_STATUS_OK;
} else throw runtime_error("missing argument(s)");
} catch(po::error& e) {
......@@ -243,7 +243,7 @@ CMDstatus CMD::MMread(int argc, char* argv[], TermOutput& termout, Serverdat *sd
return ret;
}
CMDstatus CMD::MMwrite(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
CMDstatus CMD::MMwrite(const uint clientId, int argc, char* argv[], TermOutput& termout, Serverdat *sd)
{
CMDstatus ret = {CMD_STATUS_ERROR,0,0};
......@@ -298,7 +298,7 @@ CMDstatus CMD::MMwrite(int argc, char* argv[], TermOutput& termout, Serverdat *s
data[i]=(int)data64[i];
}
}
if(sd->unb->write(termout, addr_str, offs, data)) ret.status=CMD_STATUS_OK;
if(sd->unb->write(clientId, termout, addr_str, offs, data)) ret.status=CMD_STATUS_OK;
} else throw runtime_error("missing argument(s)");
} catch(po::error& e) {
termout.strerr << e.what() << endl;
......@@ -308,7 +308,7 @@ CMDstatus CMD::MMwrite(int argc, char* argv[], TermOutput& termout, Serverdat *s
return ret;
}
CMDstatus CMD::Reload(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
CMDstatus CMD::Reload(const uint clientId, int argc, char* argv[], TermOutput& termout, Serverdat *sd)
{
CMDstatus ret = {CMD_STATUS_ERROR,0,0};
......
......@@ -60,10 +60,10 @@ private:
std::list<std::string> cmd_history;
// (3)
CMDstatus Info(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus MMread(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus MMwrite(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus Reload(int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus Info(const uint clientId, int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus MMread(const uint clientId, int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus MMwrite(const uint clientId, int argc, char* argv[], TermOutput& termout, Serverdat *sd);
CMDstatus Reload(const uint clientId, int argc, char* argv[], TermOutput& termout, Serverdat *sd);
public:
CMD() {
......@@ -78,7 +78,7 @@ private:
~CMD() {};
CMDstatus command(std::string line, TermOutput& termout, std::string& cmdname,
CMDstatus command(const uint clientId, std::string line, TermOutput& termout, std::string& cmdname,
Serverdat *sd,std::vector<std::vector<char>> binary_data=
std::vector<std::vector<char>>());
bool supported_cmd(std::string cmd);
......
......@@ -98,7 +98,7 @@ RegisterMap * Common::get_RegisterMap(int node)
return n->get_RegisterMap();
}
bool Common::monitor(TermOutput& termout)
bool Common::monitor(const uint clientId, TermOutput& termout)
{
bool retval=false;
uint retcnt=0;
......@@ -110,7 +110,7 @@ bool Common::monitor(TermOutput& termout)
if(idx > 0) termout.strout << ",";
termout.strout << "(" << node_nr << ",0,[";
try {
if(node->cread(termout.strout, "system")) {
if(node->cread(clientId, termout.strout, "system")) {
retcnt++;
}
} catch(std::exception& e) {
......@@ -165,7 +165,7 @@ bool Common::pread(TermOutput& termout, const string addr, const uint offs, cons
return retval;
}
bool Common::read(TermOutput& termout, const string addr, const uint offs, const int len)
bool Common::read(const uint clientId, TermOutput& termout, const string addr, const uint offs, const int len)
{
bool ret, retval = false;
uint retcnt=0;
......@@ -189,11 +189,11 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const
RegisterMap *regmap = node->get_RegisterMap();
uint32_t nvalues = (len<0 ? regmap->getSpan(relative_addr) : len);
std::vector<int> datavec;
if((ret=node->mread(strs, relative_addr, offs, datavec, nvalues))) {
if((ret=node->mread(clientId, strs, relative_addr, offs, datavec, nvalues))) {
retcnt++;
}
} else if(type == "dev") {
if((ret=node->cread(strs, peripheral))) {
if((ret=node->cread(clientId, strs, peripheral))) {
retcnt++;
} else {
termout.strerr << "no such peripheral: " << peripheral;
......@@ -215,7 +215,7 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const
return retval;
}
bool Common::write(TermOutput& termout, const string addr,
bool Common::write(const uint clientId, TermOutput& termout, const string addr,
const uint offs, const std::vector<int>& data)
{
bool ret, retval = false;
......@@ -235,9 +235,9 @@ bool Common::write(TermOutput& termout, const string addr,
ret = false;
try {
if(type == "mm") {
if((ret=node->mwrite(relative_addr, offs, data))) retcnt++;
if((ret=node->mwrite(clientId, relative_addr, offs, data))) retcnt++;
} else if(type == "dev") {
if((ret=node->cwrite(peripheral))) {
if((ret=node->cwrite(clientId, peripheral))) {
retcnt++;
} else {
termout.strerr << "no such peripheral: " << peripheral;
......
......@@ -49,12 +49,12 @@ public:
~Common();
std::vector<int> get_nodes(void);
bool monitor(TermOutput& termout);
bool monitor(const uint clientId, TermOutput& termout);
bool write(TermOutput& termout, const std::string addr,
bool write(const uint clientId, TermOutput& termout, const std::string addr,
const uint offs, const std::vector<int>& data);
bool read(TermOutput& termout, const string addr, const uint offs, const int len);
bool read(const uint clientId, TermOutput& termout, const string addr, const uint offs, const int len);
bool pread(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);
......
......@@ -42,11 +42,16 @@ using namespace std;
extern int debug;
Node::Node(const string ipaddr, const uint unb, const uint localnr, const std::string type,
const string firmware, const uint firmware_version, const int nof_pipes) : unbos(ipaddr)
const string firmware, const uint firmware_version, const int nof_pipes)
{
myIPaddr = ipaddr;
Nof_pipes = nof_pipes;
periph_system = new Periph_system(unbos, firmware, firmware_version);
unbos_connection = new UNBos*[nof_pipes];
for(int i=0;i<Nof_pipes;i++) {
unbos_connection[i] = new UNBos(ipaddr);
}
periph_system = new Periph_system(unbos_connection[0], firmware, firmware_version);
UniboardNr = unb;
LocalNr = localnr;
......@@ -60,7 +65,6 @@ Node::Node(const string ipaddr, const uint unb, const uint localnr, const std::s
read_pipe = new int*[nof_pipes];
write_pipe = new int*[nof_pipes];
Nof_pipes = nof_pipes;
for(int i=0;i<Nof_pipes;i++) {
read_pipe[i] = new int[2];
write_pipe[i] = new int[2];
......@@ -86,28 +90,33 @@ Node::~Node()
}
delete []*read_pipe;
delete []*write_pipe;
for(int i=0;i<Nof_pipes;i++) {
delete unbos_connection[i];
}
delete []*unbos_connection;
}
bool Node::cread(ostringstream& strs,const string peripheral) {
bool Node::cread(const uint clientID, ostringstream& strs,const string peripheral) {
if(peripheral == "system") {
return periph_system->read_system_info(strs);
return periph_system->read_system_info(unbos_connection[clientID], strs);
} else if(peripheral == "name") {
strs << "read_design_name:" << periph_system->read_design_name();
strs << "read_design_name:" << periph_system->read_design_name(unbos_connection[clientID]);
return true;
} else if(peripheral == "stamps") {
return periph_system->read_stamps(strs);
return periph_system->read_stamps(unbos_connection[clientID], strs);
} else if(peripheral == "note") {
strs << "read_design_note:" << periph_system->read_design_note();
strs << "read_design_note:" << periph_system->read_design_note(unbos_connection[clientID]);
return true;
} else if(peripheral == "sensors") {
return periph_system->read_unb_sensors(strs,LocalNr);
return periph_system->read_unb_sensors(unbos_connection[clientID], strs,LocalNr);
} else if(peripheral == "status") {
return periph_system->read_unb_status(strs);
}
else return false;
}
bool Node::cwrite(const string peripheral) {
bool Node::cwrite(const uint clientID, const string peripheral) {
cerr << "cwrite() not yet implemented TODO";
return false;
}
......@@ -118,13 +127,13 @@ RegisterMap * Node::get_RegisterMap(void)
}
bool Node::mread(std::ostringstream& strs,const std::string addr, const uint offs,
bool Node::mread(const uint clientID, std::ostringstream& strs,const std::string addr, const uint offs,
std::vector<int>& data, const uint len) {
return periph_system->mread(strs, addr, offs, data, len);
return periph_system->mread(unbos_connection[clientID], strs, addr, offs, data, len);
}
bool Node::mwrite(const std::string addr, const uint offs,
bool Node::mwrite(const uint clientID, const std::string addr, const uint offs,
const std::vector<int>& data) {
return periph_system->mwrite(addr, offs, data);
return periph_system->mwrite(unbos_connection[clientID], addr, offs, data);
}
bool Node::pread(std::ostringstream& strs, const std::string relative_addr,
......
......@@ -59,9 +59,9 @@ class Node {
uint GlobalNr;
uint LocalNr;
std::string Type;
UNBos unbos;
int Nof_pipes;
UNBos **unbos_connection;
int **write_pipe;
int **read_pipe;
......@@ -86,11 +86,11 @@ class Node {
const uint GetNr() { return LocalNr; }
const std::string GetType() { return Type; }
bool cread(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 cread(const uint clientID, std::ostringstream& strs, const std::string peripheral);
bool cwrite(const uint clientID, const std::string peripheral);
bool mread(const uint clientID, std::ostringstream& strs,const std::string addr, const uint offs,
std::vector<int>& data, const uint len);
bool mwrite(const std::string addr, const uint offs,
bool mwrite(const uint clientID, const std::string addr, const uint offs,
const std::vector<int>& data);
bool pread(std::ostringstream& strs, const std::string relative_addr, const std::string type,
......
......@@ -86,9 +86,11 @@ static UA_StatusCode UNB_MethodCallback(UA_Server *server,
cout <<"inputStr->data=" << inputStr->data <<endl;
try {
while(!SD.opcua_mutex.try_lock()) { cerr << "mutex not ready\n"; usleep(100000); }
SD.unb->read(termout,std::string((char *)inputStr->data),0,-1); // TODO: make read/write
SD.opcua_mutex.unlock();
uint UNB_client_ID = c_CLIENT_ID_UASERVER;
while(!SD.control_mutex[UNB_client_ID].try_lock()) { cerr << "mutex not ready\n"; usleep(100000); }
SD.unb->read(UNB_client_ID,termout,std::string((char *)inputStr->data),0,-1); // TODO: make read/write
SD.control_mutex[UNB_client_ID].unlock();
} catch(runtime_error& e) {
cerr << "UNB_MethodCallback: " << e.what() << endl;
termout.strout << e.what();
......
......@@ -38,15 +38,15 @@ using namespace std;
extern int debug;
Periph_system::Periph_system(UNBos &commdev,
Periph_system::Periph_system(UNBos *unbos,
const string expected_design_name,
const uint expected_firmware_version) : unbos(commdev)
const uint expected_firmware_version)
{
my_expected_design_name = expected_design_name;
my_expected_firmware_version = expected_firmware_version;
my_current_status = "offline";
registerMap = new RegisterMap(read_reg_map());
registerMap = new RegisterMap(read_reg_map(unbos));
// Add composite registers:
registerMap->add_register("dev/system", 0, 0, 0xffffffff, 0, "RO", "COMP");
......@@ -57,13 +57,13 @@ Periph_system::Periph_system(UNBos &commdev,
registerMap->add_register("dev/status", 0, 0, 0xffffffff, 0, "RO", "COMP");
try {
std::string design_name = read_design_name();
std::string design_name = read_design_name(unbos);
} catch(std::exception& e) {
cerr << "Periph_system::Periph_system:read_design_name(): " << e.what() << endl;
}
}
bool Periph_system::Read(const string addr_str, const uint32_t offset, const uint32_t nvalues,
bool Periph_system::Read(UNBos *unbos, const string addr_str, const uint32_t offset, const uint32_t nvalues,
uint32_t *data_ptr)
{
bool ret;
......@@ -74,7 +74,7 @@ bool Periph_system::Read(const string addr_str, const uint32_t offset, const uin
uint32_t shift = registerMap->getShift(addr_str);
bool isfifo = registerMap->type_isfifo(addr_str);
ret = unbos.readRegister(addr,nvalues,data_ptr,isfifo);
ret = unbos->readRegister(addr,nvalues,data_ptr,isfifo);
if(ret && (shift != 0 || mask != 0xffffffff)) {
for(uint32_t i=0; i < nvalues; i++) {
data_ptr[i] &= mask;
......@@ -84,7 +84,7 @@ bool Periph_system::Read(const string addr_str, const uint32_t offset, const uin
return ret;
}
bool Periph_system::Write(const string addr_str, const uint32_t offset, const uint32_t nvalues,
bool Periph_system::Write(UNBos *unbos, const string addr_str, const uint32_t offset, const uint32_t nvalues,
uint32_t *data_ptr)
{
uint32_t addr = registerMap->getValidAddr(addr_str,offset,nvalues);
......@@ -100,7 +100,7 @@ bool Periph_system::Write(const string addr_str, const uint32_t offset, const ui
data_ptr[i] &= mask;
}
}
return unbos.writeRegister(addr,nvalues,data_ptr,isfifo);
return unbos->writeRegister(addr,nvalues,data_ptr,isfifo);
}
bool Periph_system::read_unb_status(ostringstream& strs)
......@@ -125,11 +125,11 @@ bool Periph_system::read_unb_status(ostringstream& strs)
system_info[9:8] = hardware version [1:0] (= 0 for UniBoard 1A and 1B)
system_info[7:0] = node id[7;0]
*/
bool Periph_system::read_system_info(ostringstream& strs)
bool Periph_system::read_system_info(UNBos *unbos, ostringstream& strs)
{
uint32_t data;
bool retval = Read("mm/unb2b/system/info",0,1,&data);
std::string design_name = read_design_name();
bool retval = Read(unbos, "mm/unb2b/system/info",0,1,&data);
std::string design_name = read_design_name(unbos);
strs << "design_name=" << design_name << ", ";
char str[1000];
......@@ -152,17 +152,17 @@ bool Periph_system::read_system_info(ostringstream& strs)
design_name.c_str(), firmware_version,
my_expected_design_name.c_str(), my_expected_firmware_version);
//my_current_status = "offline";
//registerMap->setAllPermission_NA();
my_current_status = "offline";
registerMap->setAllPermission_NA();
}
return retval;
}
bool Periph_system::mread(std::ostringstream& strs, const std::string addr,
bool Periph_system::mread(UNBos *unbos, std::ostringstream& strs, const std::string addr,
const uint offs, std::vector<int>& datavec, const uint nvalues)
{
uint32_t *data = new uint32_t[nvalues*sizeof(uint32_t)+1];
bool retval = Read(addr,offs,nvalues,data);
bool retval = Read(unbos, addr,offs,nvalues,data);
if(retval) {
datavec.resize(nvalues);
for(uint i=0; i < nvalues; i++) {
......@@ -175,36 +175,36 @@ bool Periph_system::mread(std::ostringstream& strs, const std::string addr,
return retval;
}
bool Periph_system::mwrite(const std::string addr,
bool Periph_system::mwrite(UNBos *unbos, const std::string addr,
const uint offs, const std::vector<int>& datavec)
{
uint32_t *data = new uint32_t[datavec.size()*sizeof(uint32_t)];
for(uint i = 0;i < datavec.size(); i++) {
data[i] = (uint32_t)datavec[i];
}
bool retval = Write(addr, offs, datavec.size(), data);
bool retval = Write(unbos, addr, offs, datavec.size(), data);
delete[] data;
return retval;
}
string Periph_system::read_design_name(void)
string Periph_system::read_design_name(UNBos *unbos)
{
uint32_t nof_design_name_regs = 4;
uint32_t nvalues = nof_design_name_regs;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)+1];
bool retval = Read("mm/unb2b/system/info", 2, nvalues, data);
bool retval = Read(unbos, "mm/unb2b/system/info", 2, nvalues, data);
char *str_ptr = (char *)data;
string name = string(str_ptr);
delete[] data;
return (retval ? name : "? (error)");
}
string Periph_system::read_design_note(void)
string Periph_system::read_design_note(UNBos *unbos)
{
uint32_t nof_design_name_regs = 4;
uint32_t nvalues = nof_design_name_regs;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)+1];
bool retval = Read("mm/unb2b/system/info", 20, nvalues,data);
bool retval = Read(unbos, "mm/unb2b/system/info", 20, nvalues,data);
data[nvalues] = 0; // add end of string char
char *str_ptr = (char *)data;
string note = string(str_ptr);
......@@ -212,12 +212,12 @@ string Periph_system::read_design_note(void)
return (retval ? note : "? (error)");
}
bool Periph_system::read_stamps(ostringstream& strs)
bool Periph_system::read_stamps(UNBos *unbos, ostringstream& strs)
{
uint32_t nof_regs = 3;
uint32_t nvalues = nof_regs;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)+1];
bool retval = Read("mm/unb2b/system/info", 15, nvalues, data);
bool retval = Read(unbos, "mm/unb2b/system/info", 15, nvalues, data);
strs << " Stamp: date=" << data[0] << endl;
strs << " Stamp: time=" << data[1] << endl;
......@@ -226,13 +226,13 @@ bool Periph_system::read_stamps(ostringstream& strs)
return retval;
}
bool Periph_system::read_unb_sensors(ostringstream& strs, const uint nodeNr)
bool Periph_system::read_unb_sensors(UNBos *unbos, ostringstream& strs, const uint nodeNr)
{
bool retval = true;
uint32_t nvalues = 1;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)];
retval = Read("mm/unb2b/fpga/temp", 0, nvalues, data);
retval = Read(unbos, "mm/unb2b/fpga/temp", 0, nvalues, data);
char str[1000];
sprintf(str," FPGA temperature = %d [degC]\n", data[0]); strs << str;
......@@ -240,34 +240,33 @@ bool Periph_system::read_unb_sensors(ostringstream& strs, const uint nodeNr)
return retval;
}
bool Periph_system::read_unb_sensor(uint32_t *sensor, const uint nodeNr)
bool Periph_system::read_unb_sensor(UNBos *unbos, uint32_t *sensor, const uint nodeNr)
{
bool retval = true;
uint32_t nvalues = 1;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)];
retval = Read("mm/unb2b/fpga/temp", 0, nvalues, data);
retval = Read(unbos, "mm/unb2b/fpga/temp", 0, nvalues, data);
*sensor = data[0];
delete[] data;
return retval;
}
bool Periph_system::write_wdi_override(ostringstream& strs)
bool Periph_system::write_wdi_override(UNBos *unbos, ostringstream& strs)
{
uint32_t data = 0xB007FAC7;
return Write("mm/wdi/wdi/reset_word", 0, 1, &data);
return Write(unbos, "mm/wdi/wdi/reset_word", 0, 1, &data);
}
RegisterMap Periph_system::read_reg_map(void)
RegisterMap Periph_system::read_reg_map(UNBos *unbos)
{
RegisterMap reg;
uint32_t nvalues = REG_ADDR_ROM_SYSTEM_SPAN;
uint32_t addr = REG_ADDR_ROM_SYSTEM;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)];
if(!unbos.readRegister(addr, nvalues, data)) {
if(!unbos->readRegister(addr, nvalues, data)) {
delete[] data;
//throw runtime_error("unbos.Read()");
cerr << "unbos.readRegister failed" << endl;
return reg;
}
......
......@@ -28,34 +28,33 @@
class Periph_system {
private:
UNBos &unbos;
RegisterMap *registerMap;
std::string my_expected_design_name;
uint my_expected_firmware_version;
std::string my_current_status;
bool Read(const string addr_str, const uint32_t offset, const uint32_t nvalues,
bool Read(UNBos *unbos, const string addr_str, const uint32_t offset, const uint32_t nvalues,
uint32_t *data_ptr);
bool Write(const string addr_str, const uint32_t offset, const uint32_t nvalues,
bool Write(UNBos *unbos, const string addr_str, const uint32_t offset, const uint32_t nvalues,
uint32_t *data_ptr);
public:
Periph_system(UNBos &unbos, const string expected_design_name, const uint expected_firmware_version);
Periph_system(UNBos *unbos, const string expected_design_name, const uint expected_firmware_version);
~Periph_system() {};
bool read_system_info(std::ostringstream& strs);
bool mread(std::ostringstream& strs, const std::string addr, const uint offs,
bool read_system_info(UNBos *unbos, std::ostringstream& strs);
bool mread(UNBos *unbos, std::ostringstream& strs, const std::string addr, const uint offs,
std::vector<int>& data, const uint len);
bool mwrite(const std::string addr, const uint offs,
bool mwrite(UNBos *unbos, const std::string addr, const uint offs,
const std::vector<int>& data);
std::string read_design_name(void);
std::string read_design_note(void);
std::string read_design_name(UNBos *unbos);
std::string read_design_note(UNBos *unbos);
bool read_unb_status(std::ostringstream& strs);
bool read_stamps(ostringstream& strs);
bool read_unb_sensor(uint32_t *sensor, const uint nodeNr);
bool read_unb_sensors(ostringstream& strs, const uint nodeId);
bool write_wdi_override(ostringstream& strs);
RegisterMap read_reg_map(void);
bool read_stamps(UNBos *unbos, ostringstream& strs);
bool read_unb_sensor(UNBos *unbos, uint32_t *sensor, const uint nodeNr);
bool read_unb_sensors(UNBos *unbos, ostringstream& strs, const uint nodeId);
bool write_wdi_override(UNBos *unbos, ostringstream& strs);
RegisterMap read_reg_map(UNBos *unbos);
RegisterMap * getRegisterMap(void) { return registerMap; };
void print_regmap(ostringstream& strs, std::string prefix) { registerMap->print(strs, prefix); };
};
......
......@@ -65,7 +65,7 @@ string print_termout(TermOutput& termout)
return s;
}
void monitor(void)
void monitor(const int clientId)
{
CMD Cmd;
string line;
......@@ -74,18 +74,18 @@ void monitor(void)
CMDstatus cmdstatusnew = cmdstatus;
TermOutput termout;
while(ServerRunning) {
usleep(1000000);
}
// while(ServerRunning) {
// usleep(1000000);
// }
while(ServerRunning) {
usleep(1000000);
while(!SD.monitor_mutex.try_lock()) { cerr << "mutex not ready\n"; usleep(100000); }
SD.unb->monitor(termout);
SD.monitor_mutex.unlock();
while(!SD.control_mutex[clientId].try_lock()) { cerr << "mutex not ready\n"; usleep(100000); }
SD.unb->monitor(clientId, termout);
SD.control_mutex[clientId].unlock();
if(cmdstatusnew.status != CMD_EMPTY) cmdstatus = cmdstatusnew;
cout << "Monitor thread: " << print_termout(termout) << endl;
cout << "Monitor thread (id=" << clientId << "): " << print_termout(termout) << endl;
termout.clear();
//if(retries <= 0) {
......@@ -129,7 +129,7 @@ void control_server(TCPSSocket *sock, const int clientId, std::atomic<size_t> *n
if (pos != string::npos) tcpbuf[pos] = 0;
while(!SD.control_mutex[clientId].try_lock()) { cerr << "mutex not ready\n"; usleep(100000); }
cmdstatusnew = Cmd.command(string((char *)tcpbuf), termout, cmdname, &SD);
cmdstatusnew = Cmd.command(clientId, string((char *)tcpbuf), termout, cmdname, &SD);
SD.control_mutex[clientId].unlock();
if(cmdstatusnew.status != CMD_EMPTY) cmdstatus = cmdstatusnew;
string s = print_termout(termout);
......@@ -176,8 +176,6 @@ void server_init(bool warm_start)
for(uint c=0; c<c_MAX_CONTROL_SERVERS; c++) {
SD.control_mutex[c].lock();
}
SD.monitor_mutex.lock();
SD.opcua_mutex.lock();
cerr << "done, it is mine. Now (re)init all" << endl;
if(warm_start) {
......@@ -203,8 +201,6 @@ void server_init(bool warm_start)
for(uint c=0; c<c_MAX_CONTROL_SERVERS; c++) {
SD.control_mutex[c].unlock();
}
SD.monitor_mutex.unlock();
SD.opcua_mutex.unlock();
cout << "...done" << endl;
}
......@@ -227,12 +223,11 @@ int main (int argc, char* argv[])
// defaults:
int control_tcpport = c_TCP_CONTROL_SOCKET;
bool nodaemon = false;
int verbose = 1;
debug=0;
SD.configfile = "/etc/uniboard.conf";
std::atomic<size_t> ncthreads(0);
std::thread *control_server_thread[c_MAX_CONTROL_SERVERS];
std::thread *control_server_thread[c_MAX_CONTROL_TCPSOCKETS];
std::thread *monitor_thread;
po::options_description desc("Allowed options");
......@@ -244,7 +239,6 @@ int main (int argc, char* argv[])
("nodaemon", po::value<bool>(&nodaemon)->zero_tokens(),
"With this flag, the server runs NOT as daemon")
("debug", po::value(&debug), "Prints out debug info (default=0)")
("verbose", po::value(&verbose), "More messages and infos")
("configfile", po::value<string>(&SD.configfile)->default_value(SD.configfile),
"Specify uniboard configuration file location")
;
......@@ -287,26 +281,21 @@ int main (int argc, char* argv[])
if(daemon(1, 0) < 0) cerr << "Error fork as daemon: " << strerror(errno) << endl;
}
for(uint c=0; c<c_MAX_CONTROL_SERVERS; c++) {
SD.tcpport = control_tcpport;
SD.verbose[c] = verbose;
}
SD.tcpport = control_tcpport;
server_init(false);
TCPSSocket sock(control_tcpport, "", c_MAX_CONTROL_SERVERS);
for(uint c=0; c<c_MAX_CONTROL_SERVERS; c++) {
TCPSSocket sock(control_tcpport, "", c_MAX_CONTROL_TCPSOCKETS);
for(uint c=0; c<c_MAX_CONTROL_TCPSOCKETS; c++) {
control_server_thread[c] = new std::thread(control_server, &sock, c, &ncthreads);
++ncthreads;
}
monitor_thread = new std::thread(monitor);
monitor_thread = new std::thread(monitor,c_CLIENT_ID_MONITOR);
ua_server();
monitor_thread->join();
delete monitor_thread;
for(uint c=0; c<c_MAX_CONTROL_SERVERS; c++) { control_server_thread[c]->join(); }
for(uint c=0; c<c_MAX_CONTROL_SERVERS; c++) { delete control_server_thread[c]; }
for(uint c=0; c<c_MAX_CONTROL_TCPSOCKETS; c++) { control_server_thread[c]->join(); }
for(uint c=0; c<c_MAX_CONTROL_TCPSOCKETS; c++) { delete control_server_thread[c]; }
closelog(); // close syslog connection
......
......@@ -30,7 +30,11 @@ using namespace std;
#include "map.h"
#include "io/tcpsocket.h"
#define c_MAX_CONTROL_SERVERS 3
#define c_MAX_CONTROL_SERVERS 5
#define c_MAX_CONTROL_TCPSOCKETS (c_MAX_CONTROL_SERVERS-2)