Skip to content
Snippets Groups Projects
Commit 304eab2f authored by al.schwinn's avatar al.schwinn
Browse files

Bug 1387 - Provide Command-Line Silecs Clien

parent b43106d5
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,7 @@ std::string arg_plcName = "";
std::string arg_deviceName = "";
std::string arg_blockName = "";
std::string arg_registerName = "";
bool arg_silent = false;
ModeType arg_mode = UNDEFINED;
uint32_t periodicInterval = 0;
......@@ -59,9 +60,11 @@ void printHelp()
std::cout << startbold << "\t-h " << endbold << "print this help" << std::endl;
std::cout << startbold << "\t-i " << endbold << "start interactive session" << std::endl; // TODO: Implement
std::cout << startbold << "\t-l " << endbold << "define LOGTOPICS" << std::endl; // TODO: Implement
std::cout << startbold << "\t-m " << endbold << "mode, can be 'GET_DEVICE', 'GET_BLOCK', 'GET_REGISTER' or 'SET_REGISTER'" << std::endl;
//std::cout << startbold << "\t-m " << endbold << "mode, can be 'GET_DEVICE', 'GET_BLOCK', 'GET_REGISTER' or 'SET_REGISTER'" << std::endl;
std::cout << startbold << "\t-m " << endbold << "mode, can be 'GET_DEVICE', 'GET_BLOCK' or 'GET_REGISTER'" << std::endl;
std::cout << startbold << "\t-p " << endbold << "periodic Interval(ms) us ? to measure" << std::endl;
std::cout << startbold << "\t-r " << endbold << "optional, register to get/set" << std::endl;
std::cout << startbold << "\t-s " << endbold << "silent, minimal output (only the register-values, no meta information)" << std::endl;
std::cout << std::endl;
......@@ -95,26 +98,96 @@ Silecs::Cluster* getSilecsClusterbyDevice(std::string deviceName, Silecs::XMLPar
return silecsService->getCluster(className,classVersion);
}
void printDevice(std::string deviceName)
std::string getSilecsBlockNamebyRegisterName(std::string registerName, Silecs::XMLParser &paramParser)
{
Silecs::ElementXML blockNode = paramParser.getFirstElementFromXPath("/SILECS-Param/SILECS-Mapping/SILECS-Class/Block[Register/@name='"+ registerName + "']");
return blockNode.getAttribute("name");
}
bool isRegisterInBlock(std::string registerName, std::string blockName, Silecs::XMLParser &paramParser)
{
Silecs::ElementXML blockNode = paramParser.getFirstElementFromXPath("/SILECS-Param/SILECS-Mapping/SILECS-Class/Block[Register/@name='"+ registerName + "']");
if( blockName == blockNode.getAttribute("name"))
return true;
return false;
}
void printBlock(std::string blockName)
std::vector<std::string> getBlockNamesFromDeviceName(std::string deviceName, Silecs::XMLParser &paramParser)
{
std::vector< std::string > blockNames;
Silecs::ElementXML classNode = paramParser.getFirstElementFromXPath("/SILECS-Param/SILECS-Mapping/SILECS-Class[Instance/@label='"+ deviceName + "']");
std::string className = classNode.getAttribute("name");
boost::ptr_vector<Silecs::ElementXML> blocks = paramParser.getElementsFromXPath_throwIfEmpty("/SILECS-Param/SILECS-Mapping/SILECS-Class[@name='"+ className + "']/Block");
boost::ptr_vector<Silecs::ElementXML>::iterator block;
for( block = blocks.begin();block!= blocks.end(); block++)
{
blockNames.push_back(block->getAttribute("name"));
}
return blockNames;
}
std::string getRegisterValueAsString(Silecs::Register* reg )
{
std::ostringstream os;
uint32_t dim1 = reg->getDimension1();
uint32_t dim2 = reg->getDimension2();
for (unsigned int i=0; i<dim1; i++)
for (unsigned int j=0; j<dim2; j++)
os << reg->getInputValAsString(i, j) << " ";
return os.str();
}
void printRegister(Silecs::Device *device, Silecs::Register* reg )
{
device->recv(arg_blockName);
if( arg_silent )
{
std::cout << getRegisterValueAsString(reg) << std::endl;
}
else
{
std::cout << "|" << device->getLabel() << "|" << reg->getBlockName() << "|" << reg->getName() << "|" << getRegisterValueAsString(reg) << "|" << std::endl;
//reg->printVal();
}
}
void printRegister(Silecs::Register* reg)
void printBlock(Silecs::Device *device, std::string blockName,Silecs::XMLParser &paramParser)
{
reg->printVal();
device->recv(blockName);
std::vector<Silecs::Register*> regCol = device->getRegisterCollection(blockName);
std::vector<Silecs::Register*>::iterator reg;
for (reg = regCol.begin();reg != regCol.end(); reg++ )
{
if(isRegisterInBlock((*reg)->getName(), blockName, paramParser))
{
printRegister(device, *reg);
}
}
}
void setRegister(std::string registerName,std::string value)
void printDevice(Silecs::Device *device, Silecs::XMLParser &paramParser)
{
std::vector<std::string> blockNames = getBlockNamesFromDeviceName(device->getLabel(), paramParser);
std::vector<std::string>::iterator blockName;
for( blockName = blockNames.begin();blockName!= blockNames.end(); blockName++)
{
device->recv(*blockName);
std::vector<Silecs::Register*> regCol = device->getRegisterCollection(*blockName);
std::vector<Silecs::Register*>::iterator reg;
for (reg = regCol.begin();reg != regCol.end(); reg++ )
{
printRegister(device, *reg);
}
}
}
void setRegister(Silecs::Register* reg,std::string value)
{
std::cout << "Error: Setting values not yet supported."<< std::endl;
exit(EXIT_FAILURE);
}
int connectInteractive(Silecs::Service *service, Silecs::XMLParser &paramParser)
{
//ask class
......@@ -134,22 +207,26 @@ int connectNonInteractive(Silecs::Service *service, Silecs::XMLParser &paramPars
Silecs::Register* reg = NULL;
if(!arg_registerName.empty())
{
reg = device->getRegister(arg_registerName);
arg_blockName = getSilecsBlockNamebyRegisterName(arg_registerName, paramParser);
}
do
{
switch(arg_mode)
{
case GET_DEVICE:
std::cout << "TODO: print device" << std::endl;
printDevice(device,paramParser);
break;
case GET_BLOCK:
std::cout << "TODO: print block" << std::endl;
printBlock(device, arg_blockName, paramParser);
break;
case GET_REGISTER:
printRegister(reg);
printRegister(device, reg);
break;
case SET_REGISTER:
std::cout << "TODO: set register" << std::endl;
setRegister(reg,"");
break;
default:
std::cout << "Unknown mode defined by -m" << std::endl;
......@@ -172,7 +249,7 @@ int main(int argc, char **argv)
bool interactiveOptionSet = false;
bool periodicOptionSet = false;
while ((opt = getopt(argc, argv, ":l:hp:r:b:d:f:m:i")) != -1)
while ((opt = getopt(argc, argv, ":l:hp:r:b:d:f:m:is")) != -1)
{
std::istringstream ss(optarg);
switch (opt)
......@@ -242,6 +319,9 @@ int main(int argc, char **argv)
std::cout << "TODO: implement interactive-mode" << std::endl;
return EXIT_FAILURE;
break;
case 's':
arg_silent = true;
break;
case '?':
std::cout << "Unrecognized option: " << optopt << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment