#pragma once #include #include #include #include #include using namespace std; class HepuTarget { private: public: const string cmd = "ivpTrackingCtrl"; string token; bool bTracking; int channelid; int trackingTime; struct TrackingRect{ int x; int y; int w; int h; }; TrackingRect trackingRect; HepuTarget(){}; ~HepuTarget(){}; void objectToJson(string& str){ rapidjson::StringBuffer strBuf; rapidjson::Writer writer(strBuf); this->objectToJson(writer); str = strBuf.GetString(); } void objectToJson(rapidjson::Writer& writer){ writer.StartObject(); writer.Key("cmd"); writer.String(cmd.c_str()); writer.Key("param"); writer.StartObject(); writer.Key("token"); writer.String(token.c_str()); writer.Key("bTracking"); writer.Bool(bTracking); writer.Key("channelid"); writer.Int(channelid); writer.Key("trackingTime"); writer.Int(trackingTime); writer.Key("trackingRect"); writer.StartObject(); writer.Key("x"); writer.Int(trackingRect.x); writer.Key("y"); writer.Int(trackingRect.y); writer.Key("w"); writer.Int(trackingRect.w); writer.Key("h"); writer.Int(trackingRect.h); writer.EndObject(); writer.EndObject(); writer.EndObject(); } bool jsonToObject(std::string& json){ rapidjson::Document doc; doc.Parse(json.c_str()); if(!doc.IsObject()){ return false; } const auto end = doc.MemberEnd(); if(end == doc.FindMember("cmd") || !doc["cmd"].IsString()){ return false; }else{ if(cmd != doc["cmd"].GetString()) return false; } if(end == doc.FindMember("param") || !doc["param"].IsObject()) { return false; }else{ if(end == doc.FindMember("token") || !doc["token"].IsString()) { return false; }else{ token = doc["token"].GetString(); } if(end == doc.FindMember("bTracking") || !doc["bTracking"].IsBool()) { return false; }else{ bTracking = doc["bTracking"].GetBool(); } if(end == doc.FindMember("channelid") || !doc["channelid"].IsInt()) { return false; }else{ channelid = doc["channelid"].GetInt(); } if(end == doc.FindMember("trackingTime") || !doc["trackingTime"].IsInt()) { return false; }else{ trackingTime = doc["trackingTime"].GetInt(); } if(end == doc.FindMember("trackingRect") || !doc["trackingRect"].IsObject()) { return false; }else{ if(end == doc.FindMember("x") || !doc["x"].IsInt()) { return false; }else{ trackingRect.x = doc["x"].GetInt(); } if(end == doc.FindMember("y") || !doc["y"].IsInt()) { return false; }else{ trackingRect.y = doc["y"].GetInt(); } if(end == doc.FindMember("w") || !doc["w"].IsInt()) { return false; }else{ trackingRect.w = doc["w"].GetInt(); } if(end == doc.FindMember("h") || !doc["h"].IsInt()) { return false; }else{ trackingRect.h = doc["h"].GetInt(); } } } return true; } };