-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now there's a central class GigEVision which keeps singelton objects for the GenICam, Gvcp and Gvsp managers, so every subsystem can access the other through that class. Reimplemented the manager classes to have an implementation file, and not be header-only.
- Loading branch information
hirsch
committed
Aug 14, 2009
1 parent
a80c25e
commit 7da3dab
Showing
11 changed files
with
486 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include <cstdlib> | ||
#include <exception> | ||
#include <sstream> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <functional> | ||
#include <boost/format.hpp> | ||
#include <boost/algorithm/string.hpp> | ||
#include <boost/filesystem/operations.hpp> | ||
#include <boost/bind.hpp> | ||
#include <boost/lambda/lambda.hpp> | ||
#include <zip.h> | ||
|
||
#include "GigEVision.h" | ||
#include "Gvcp.h" | ||
#include "GenICam.h" | ||
|
||
GenICamManager::GenICamManager(GigEVision& gev): | ||
m_gev(gev) | ||
{ | ||
|
||
} | ||
|
||
void GenICamManager::ReadXmlFile() | ||
{ | ||
std::vector<uint8_t> data = m_gev.Gvcp().ReadBlock(GENICAM_ZIPFILEINFO_ADDRESS, 512); | ||
std::string sTxt(data.begin(), data.end()); | ||
|
||
std::vector<std::string> aParts; | ||
boost::algorithm::split(aParts, sTxt, boost::algorithm::is_any_of(";")); | ||
|
||
if(aParts.size() != 3) | ||
throw std::runtime_error("Error getting genicam file location on camera"); | ||
|
||
int nAddr, nSize; | ||
std::stringstream ss; | ||
ss << std::hex << aParts[1]; | ||
ss >> nAddr; | ||
ss.clear(); | ||
ss << std::hex << aParts[2]; | ||
ss >> nSize; | ||
|
||
data = m_gev.Gvcp().ReadBlock(nAddr, nSize); | ||
|
||
// TODO: find a way to decompress the zip-file in menory without writing the file to disk | ||
// TODO: use a platform independent path | ||
std::string sFilename("/tmp/genicam.zip"); | ||
std::string retData; | ||
|
||
try | ||
{ | ||
std::ofstream os(sFilename.c_str(), std::ios::binary); | ||
os.write((char*)(&data[0]), data.size()); | ||
os.flush(); | ||
|
||
struct zip* zz = zip_open(sFilename.c_str(), 0, 0); | ||
if(zz == 0) | ||
throw std::runtime_error("Error opening genicam zipfile"); | ||
|
||
struct zip_file* zf = zip_fopen_index(zz, 0, 0); | ||
if(zf == 0) | ||
throw std::runtime_error("Error opening file in zip archive"); | ||
|
||
boost::array<uint8_t, 1024> buff; | ||
|
||
int nRead = 0; | ||
while((nRead = zip_fread(zf, buff.data(), buff.size())) != 0) | ||
std::copy(buff.begin(), buff.begin()+nRead, std::back_inserter(retData)); | ||
|
||
// clean up file from disk | ||
boost::filesystem::remove(sFilename); | ||
} | ||
catch(std::exception& e) | ||
{ | ||
boost::filesystem::remove(sFilename); | ||
throw e; | ||
} | ||
|
||
setenv("GENICAM_ROOT_V1_1", GENICAM_ROOT_PATH, true); | ||
m_cam._LoadXMLFromString(retData.c_str()); | ||
} | ||
|
||
uint32_t GenICamManager::GetAddress(const std::string& sKey) | ||
{ | ||
GenApi::INode* pN = m_cam._GetNode(sKey.c_str()); | ||
uint32_t nAddr = 0; | ||
if(pN != 0) | ||
{ | ||
GenICam::gcstring val, att; | ||
if(pN->GetProperty("Address", val, att)) | ||
{ | ||
nAddr = boost::lexical_cast<uint32_t>(val); | ||
} | ||
if(pN->GetProperty("pAddress", val, att) && val.length() > 0) | ||
{ | ||
std::string sTmp(val); | ||
std::vector<std::string> parts; | ||
boost::algorithm::split(parts, sTmp, boost::algorithm::is_any_of("\t")); | ||
for(size_t i=0; i<parts.size(); ++i) | ||
{ | ||
GenApi::INode* pAddrNode = m_cam._GetNode(parts[i].c_str()); | ||
assert(pAddrNode); | ||
GenICam::gcstring sAddr, sAtt; | ||
assert(pAddrNode->GetProperty("Value", sAddr, sAtt)); | ||
nAddr += boost::lexical_cast<uint32_t>(sAddr); | ||
} | ||
} | ||
} | ||
else | ||
throw std::runtime_error(str(boost::format("Can't find address for '%1%'") % sKey)); | ||
|
||
return nAddr; | ||
} | ||
|
||
void GenICamManager::PrintNodes(bool bWithProperties) const | ||
{ | ||
GenApi::NodeList_t nodes; | ||
m_cam._GetNodes(nodes); | ||
|
||
for(GenApi::NodeList_t::const_iterator it = nodes.begin(); it!=nodes.end(); ++it) | ||
{ | ||
std::cout << "Node: " << (*it)->GetName(true) << std::endl; | ||
if(bWithProperties) | ||
{ | ||
GenICam::gcstring_vector props; | ||
(*it)->GetPropertyNames(props); | ||
for(GenICam::gcstring_vector::const_iterator pit = props.begin(); pit!=props.end(); ++pit) | ||
std::cout << "\tProp: " << *pit << std::endl; | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "GenICam.h" | ||
#include "Gvcp.h" | ||
#include "Gvsp.h" | ||
|
||
#include "GigEVision.h" | ||
|
||
GigEVision::GigEVision(): | ||
m_genicam(new GenICamManager(*this)), | ||
m_gvcp(new GvcpManager(*this)), | ||
m_gvsp(new GvspManager(*this, 12221)) | ||
{ } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef GIGEVISION_H | ||
#define GIGEVISION_H | ||
|
||
#include <memory> | ||
#include <boost/asio.hpp> | ||
|
||
// forwarding | ||
class GenICamManager; | ||
class GvcpManager; | ||
class GvspManager; | ||
|
||
class GigEVision | ||
{ | ||
public: | ||
GigEVision(); | ||
|
||
GenICamManager& GenICam() { return *m_genicam; } | ||
GvcpManager& Gvcp() { return *m_gvcp; } | ||
GvspManager& Gvsp() { return *m_gvsp; } | ||
boost::asio::io_service& Service() { return m_service; } | ||
|
||
private: | ||
boost::asio::io_service m_service; | ||
std::auto_ptr<GenICamManager> m_genicam; | ||
std::auto_ptr<GvcpManager> m_gvcp; | ||
std::auto_ptr<GvspManager> m_gvsp; | ||
}; | ||
|
||
|
||
#endif // GIGEVISION_H |
Oops, something went wrong.