无法在Windows 10上使用Kaa教程运行程序-"您的第一个Kaa应用程序"



教程链接:http://kaaproject.github.io/kaa/docs/v0.10.0/Programming-guide/Your-first-Kaa-application/

我正在执行"启动应用程序"步骤。我正在使用C++SDK。

我正在尝试在教程中创建程序,但无法运行该程序。这些说明适用于Linux,需要我运行一些命令。由于我无法做到这一点,我想如果我在Visual Studio中打开它,它就会工作。

当我打开Visual Studio时,我发现"开始"按钮被"附加…"按钮取代了。我以前从未见过这种情况。

有人能帮我弄清楚如何运行这个程序吗?

谢谢。

代码:

#include <boost/asio.hpp>
#include <kaa/Kaa.hpp>
#include <kaa/IKaaClient.hpp>
#include <kaa/configuration/manager/IConfigurationReceiver.hpp>
#include <kaa/configuration/storage/FileConfigurationStorage.hpp>
#include <kaa/log/strategies/RecordCountLogUploadStrategy.hpp>
#include <memory>
#include <string>
#include <cstdint>
class ConfigurationCollection : public kaa::IConfigurationReceiver {
public:
ConfigurationCollection()
: kaaClient_(kaa::Kaa::newClient())
, samplePeriod_(0)
, interval_(samplePeriod_)
, timer_(service_, interval_) 
{
// Set a custom strategy for uploading logs.
kaaClient_->setLogUploadStrategy(
std::make_shared<kaa::RecordCountLogUploadStrategy>(1, kaaClient_->getKaaClientContext()));
// Set up a configuration subsystem.
kaa::IConfigurationStoragePtr storage(
std::make_shared<kaa::FileConfigurationStorage>(std::string(savedConfig_)));
kaaClient_->setConfigurationStorage(storage);
kaaClient_->addConfigurationListener(*this);
auto handlerUpdate = [this](const boost::system::error_code& err) 
{
this->update();
};
timer_.async_wait(handlerUpdate);
}
~ConfigurationCollection() 
{
// Stop the Kaa endpoint.
kaaClient_->stop();
std::cout << "Simple client demo stopped" << std::endl;
}
void run() 
{
// Run the Kaa endpoint.
kaaClient_->start();
// Read default sample period
samplePeriod_ = kaaClient_->getConfiguration().samplePeriod;
std::cout << "Default sample period: " << samplePeriod_<< std::endl;
// Default sample period
timer_.expires_from_now(boost::posix_time::seconds(samplePeriod_));
service_.run();
}
private:
static constexpr auto savedConfig_ = "saved_config.cfg";
std::shared_ptr<kaa::IKaaClient> kaaClient_;
int32_t samplePeriod_;
boost::asio::io_service service_;
boost::posix_time::seconds interval_;
boost::asio::deadline_timer timer_;
int32_t getTemperature() 
{
// For sake of example random data is used
return rand() % 10 + 25;
}
void update() 
{
kaa::KaaUserLogRecord logRecord;
logRecord.temperature = getTemperature();
// Send value of temperature
kaaClient_->addLogRecord(logRecord);
// Show log
std::cout << "Sampled temperature: " << logRecord.temperature << std::endl;
// Set a new  period of the send data
timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(samplePeriod_));
// Posts the timer event
auto handlerUpdate = [this](const boost::system::error_code& err) 
{
this->update();
};
timer_.async_wait(handlerUpdate);
}
void updateConfiguration(const kaa::KaaRootConfiguration &configuration) 
{
std::cout << "Received configuration data. New sample period: "
<< configuration.samplePeriod << " seconds" << std::endl;
samplePeriod_ = configuration.samplePeriod;
}
void onConfigurationUpdated(const kaa::KaaRootConfiguration &configuration) 
{
updateConfiguration(configuration);
}
};
int main() 
{
ConfigurationCollection configurationCollection;
try {
// It does control of the transmit and receive data
configurationCollection.run();
} catch (std::exception& e) {
std::cout << "Exception: " << e.what();
}
return 0;
}

Windows页面http://kaaproject.github.io/kaa/docs/v0.10.0/Programming-guide/Using-Kaa-endpoint-SDKs/C++/SDK Windows/解释了C++SDK和Windows平台应用程序的编译过程。

最新更新