1 #ifndef RAPP_CLOUD_HAZARD_DETECTION
2 #define RAPP_CLOUD_HAZARD_DETECTION
23 const std::shared_ptr<rapp::object::picture> image,
24 std::function<
void(
double door_angle)> callback,
32 boost::property_tree::ptree tree;
33 tree.put(
"file", fname);
35 boost::property_tree::write_json(ss, tree,
false);
36 post_ =
"--" + boundary +
"\r\n"
37 +
"Content-Disposition: form-data; name=\"json\"\r\n\r\n"
39 post_ +=
"--"+boundary+
"\r\n"
40 +
"Content-Disposition: form-data; name=\"file_uri\"; filename=\""+fname+
"\"\r\n"
41 +
"Content-Type: image/"+image->type()+
"\r\n"
42 +
"Content-Transfer-Encoding: binary\r\n\r\n";
44 auto imagebytes = image->bytearray();
45 post_.insert(
post_.end(), imagebytes.begin(), imagebytes.end());
47 post_ +=
"--"+boundary+
"--";
48 header_ =
"POST /hop/hazard_detection_door_check HTTP/1.1\r\n";
49 header_ +=
"Content-Type: multipart/form-data; boundary="+boundary+
"\r\n\r\n";
58 std::stringstream ss(json);
61 boost::property_tree::ptree tree;
62 boost::property_tree::read_json(ss, tree);
64 for (
auto child : tree.get_child(
"door_angle")) {
65 door_angle = child.second.get_value<
double>();
68 for (
auto child : tree.get_child(
"error")) {
69 const std::string value = child.second.get_value<std::string>();
71 std::cerr <<
"hazard_detection_door_check JSON error: " << value << std::endl;
75 catch(boost::property_tree::json_parser::json_parser_error & je) {
76 std::cerr <<
"hazard_detection_door_check::handle_reply Error parsing: "
77 << je.filename() <<
" on line: " << je.line() << std::endl;
78 std::cerr << je.message() << std::endl;
104 const std::shared_ptr<rapp::object::picture> image,
105 std::function<
void(
double light_level)> callback,
113 boost::property_tree::ptree tree;
114 tree.put(
"file", fname);
115 std::stringstream ss;
116 boost::property_tree::write_json(ss, tree,
false);
117 post_ =
"--" + boundary +
"\r\n"
118 +
"Content-Disposition: form-data; name=\"json\"\r\n\r\n"
120 post_ +=
"--"+boundary+
"\r\n"
121 +
"Content-Disposition: form-data; name=\"file_uri\"; filename=\""+fname+
"\"\r\n"
122 +
"Content-Type: image/"+image->type()+
"\r\n"
123 +
"Content-Transfer-Encoding: binary\r\n\r\n";
125 auto imagebytes = image->bytearray();
126 post_.insert(
post_.end(), imagebytes.begin(), imagebytes.end());
128 post_ +=
"--"+boundary+
"--";
129 header_ =
"POST /hop/hazard_detection_light_check HTTP/1.1\r\n";
130 header_ +=
"Content-Type: multipart/form-data; boundary="+boundary+
"\r\n\r\n";
140 std::stringstream ss(json);
143 boost::property_tree::ptree tree;
144 boost::property_tree::read_json(ss, tree);
146 for (
auto child : tree.get_child(
"light_level")) {
147 light_level = child.second.get_value<
double>();
150 for (
auto child : tree.get_child(
"error")) {
151 const std::string value = child.second.get_value<std::string>();
152 if (!value.empty()) {
153 std::cerr <<
"hazard_detection_light_check JSON error: " << value << std::endl;
157 catch(boost::property_tree::json_parser::json_parser_error & je) {
158 std::cerr <<
"hazard_detection_light_check::handle_reply Error parsing: "
159 << je.filename() <<
" on line: " << je.line() << std::endl;
160 std::cerr << je.message() << std::endl;
std::string header_
Header that will be used.
std::string random_boundary() const
Create a random boundary for the multipart/form in HTTP.
void handle_reply(std::string json)
handle the rapp-platform JSON reply
std::string post_
Actual post Data.
hazard_detection_door_check(const std::shared_ptr< rapp::object::picture > image, std::function< void(double door_angle)> callback, std::string token)
Constructor.
void handle_reply(std::string json)
handle the rapp-platform JSON reply
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
std::function< void(double)> delegate__
The callback called upon completion of receiving the detected faces.
hazard_detection_light_check(const std::shared_ptr< rapp::object::picture > image, std::function< void(double light_level)> callback, std::string token)
Constructor.
base class for asynchronous http websockets used for connecting to cloud services ...
std::function< void(double)> delegate__
The callback called upon completion of receiving the detected faces.