{
AMBIF *ambif = new AMBIF(routingengine, config);
AMBConfig *conf = new AMBConfig();
- conf->readConfig(config["configfile"]);
+ if (!conf->readConfig(config["configfile"])) {
+ DebugOut(DebugOut::Error) << "Failed to Load Configfile for VIC-Plugin.\n";
+ delete ambif;
+ delete conf;
+ return NULL;
+ }
VICCommunicator *communicator = new VICCommunicator();
MWIF *mwif = new MWIF();
Converter *converter = new Converter();
if (!ambif->initialize(communicator, conf)) {
- DebugOut() << "Failed to initialize AMBIF\n";
+ DebugOut(DebugOut::Error) << "Failed to initialize AMBIF\n";
delete ambif;
delete conf;
delete communicator;
return NULL;
}
if (!communicator->initialize(ambif, mwif, converter)) {
- DebugOut() << "Failed to initialize VICCommunicator\n";
+ DebugOut(DebugOut::Error) << "Failed to initialize VICCommunicator\n";
delete ambif;
delete conf;
delete communicator;
return NULL;
}
if (!mwif->initialize(communicator, conf)) {
- DebugOut() << "Failed to initialize MWIF\n";
+ DebugOut(DebugOut::Error) << "Failed to initialize MWIF\n";
delete ambif;
delete conf;
delete communicator;
return NULL;
}
if (!converter->initialize(conf)) {
- DebugOut() << "Failed to initialize Converter\n";
+ DebugOut(DebugOut::Error) << "Failed to initialize Converter\n";
delete ambif;
delete conf;
delete communicator;
}
return ambif;
}
-
AMBIF::AMBIF(AbstractRoutingEngine *engine,
std::map<std::string, std::string> config) :
AbstractSource(engine, config)
AMBIF::getPropertyAsync(AsyncPropertyReply *reply)
{
reply->success = false;
- DebugOut() << "AMBIF " << "Get Request property : " << reply->property
+ DebugOut(10) << "AMBIF " << "Get Request property : " << reply->property
<< std::endl;
lock();
AMBVehicleInfo *vehicleinfo = find(reply->property);
- DebugOut() << "AMBIF " << "Find Data : " << reply->property << std::endl;
+ DebugOut(50) << "AMBIF " << "Find Data : " << reply->property << std::endl;
if (vehicleinfo != NULL) {
reply->value = vehicleinfo->value;
reply->success = true;
AsyncPropertyReply *
AMBIF::setProperty(AsyncSetPropertyRequest request)
{
- DebugOut() << "AMBIF" << "Set Request propety : " << request.property
+ DebugOut(10) << "AMBIF" << "Set Request propety : " << request.property
<< std::endl;
lock();
AMBVehicleInfo *vehicleinfo = find(request.property);
}
AsyncPropertyReply *reply = new AsyncPropertyReply(request);
reply->success = true;
- DebugOut(10) << "AMBIF" << "Update Value!" << std::endl;
+ DebugOut(50) << "AMBIF" << "Update Value!" << std::endl;
delete vehicleinfo->value;
vehicleinfo->value = request.value->copy();
reply->value = vehicleinfo->value;
communicator->setMWVehicleInfo(vehicleinfo);
- DebugOut() << "AMBIF setProperty " << "Set Value(" << request.property
+ DebugOut(50) << "AMBIF setProperty " << "Set Value(" << request.property
<< "," << reply->value->toString() << ")" << std::endl;
reply->completed(reply);
- routingEngine->updateProperty(vehicleinfo->name, vehicleinfo->value,
- uuid());
+ #if LATER1024
+ routingEngine->updateProperty(vehicleinfo->value, uuid());
+ #else
+ routingEngine->updateProperty(vehicleinfo->name, vehicleinfo->value, uuid());
+ #endif
unLock();
return reply;
}
return Get | Set;
}
+#if LATER1024
+const string
+#else
string
+#endif
AMBIF::uuid()
{
return "f68f8b9a-fafb-4284-8ced-b45b5d720185";
AMBIF::propertyChanged(VehicleProperty::Property property,
AbstractPropertyType *value, std::string uuid)
{
+ DebugOut(1) << "INFO CHG_VIC_INF Receive notification from Core. Property is " << property << ".\n";
AMBVehicleInfo *vehicleinfo = find(property);
lock();
if (vehicleinfo != NULL) {
bool
AMBIF::initialize(VICCommunicator *comm, AMBConfig *conf)
{
- DebugOut() << "AMBIF Initialize\n";
+ DebugOut(50) << "AMBIF Initialize\n";
communicator = comm;
mutex = PTHREAD_MUTEX_INITIALIZER;
if (vi.value == nullptr) {
if (!registVehicleInfo(vi.name, (*itr2).type,
(*itr2).defaultvalue)) {
- DebugOut() << "AMBIF Initialize Couldn't regist property["
+ DebugOut(50) << "AMBIF Initialize Couldn't regist property["
<< vi.name << "]\n";
continue;
}
vi.name, (*itr2).defaultvalue);
vi.isCustom = true;
}
+ vi.zone = (*itr2).zone;
vehicleinfoArray.push_back(vi);
propertylist.push_back(vi.name);
- DebugOut() << "AMBIF Initialize regist propertyname = " << vi.name
+ DebugOut(50) << "AMBIF Initialize regist propertyname = " << vi.name
<< "\n";
}
}
- routingEngine->setSupported(supported(), this);
+ routingEngine->updateSupported(supported(), PropertyList(), this);
+ DebugOut(1) << "INFO CHG_VIC_INF The number of AMB vehicle info is " << vehicleinfoArray.size() << ".\n";
return true;
}
AMBVehicleInfo *
AMBIF::getPropertyRequest(std::string propertyname)
{
- DebugOut() << "AMBIF getPropertyRequest(" << propertyname << ")\n";
+ DebugOut(50) << "AMBIF getPropertyRequest(" << propertyname << ")\n";
AsyncPropertyRequest request;
request.property = propertyname;
request.completed = [](AsyncPropertyReply *reply) {
if (reply->success) {
- DebugOut() << "AMBIF getPropertyRequest completed success!!.\n";
+ DebugOut(50) << "AMBIF getPropertyRequest completed success!!.\n";
}
else {
- DebugOut() << "AMBIF getPropertyRequest completed false!!.\n";
+ DebugOut(50) << "AMBIF getPropertyRequest completed false!!.\n";
}
};
}
delete reply;
unLock();
- DebugOut() << "AMBIF getPropertyRequest after call "
+ DebugOut(50) << "AMBIF getPropertyRequest after call "
<< vehicleinfo->value->toString() << std::endl;
return vehicleinfo;
}
request.completed =
[](AsyncPropertyReply *reply) {
if (reply->success) {
- DebugOut()<<"AMBIF" << reply->property << ":" << reply->value->toString() << std::endl;
+ DebugOut(50)<<"AMBIF" << reply->property << ":" << reply->value->toString() << std::endl;
}
else {
- DebugOut()<<"AMBIF" << reply->property << " isn't registered." << std::endl;
+ DebugOut(50)<<"AMBIF" << reply->property << " isn't registered." << std::endl;
}
};
AsyncPropertyReply *reply = routingEngine->setProperty(request);
void
AMBIF::updateProperty(AMBVehicleInfo *vehicleinfo)
{
- routingEngine->updateProperty(vehicleinfo->name, vehicleinfo->value,
- uuid());
+ if (vehicleinfo->name == VehicleProperty::VehicleSpeed) {
+ static uint16_t prevspd = -1;
+ static const uint16_t unusablespd = -1;
+ uint16_t spd = vehicleinfo->value->value<uint16_t>();
+ if ((prevspd == unusablespd && spd > 0) || (prevspd == 0 && spd > 0)) {
+ DebugOut(3) << "PERF CHG_VIC_INF VIC-Plugin notify Code of update "
+ << vehicleinfo->name
+ << ". VehicleSpeed is 1km/h or more.\n";
+ }
+ else if ((prevspd == unusablespd && spd == 0) ||
+ (prevspd > 0 && spd == 0)) {
+ DebugOut(3) << "PERF CHG_VIC_INF VIC-Plugin notify Code of update "
+ << vehicleinfo->name << ". VehicleSpeed is 0km/h.\n";
+ }
+ prevspd = spd;
+ }
+ #if LATER1024
+ routingEngine->updateProperty(vehicleinfo->value, uuid());
+ #else
+ routingEngine->updateProperty(vehicleinfo->name, vehicleinfo->value, uuid());
+ #endif
AMBVehicleInfo *ambvehicleinfo = find(vehicleinfo->name);
lock();
if (ambvehicleinfo != NULL) {
void
AMBIF::requestUpdate(AMBVehicleInfo *vehicleinfo)
{
- DebugOut() << "AMBIF requestUpdate request property name is "
+ DebugOut(50) << "AMBIF requestUpdate request property name is "
<< vehicleinfo->name << "\n";
if (find(vehicleinfo->name) != NULL) {
+ vehicleinfo->value->zone = vehicleinfo->zone;
+ vehicleinfo->value->priority = AbstractPropertyType::Instant;
+ DebugOut(50) << "AMBIF requestUpdate request property name is "
+ << vehicleinfo->name << ", zone is " << vehicleinfo->zone << "\n";
updateProperty(vehicleinfo);
}
else {
bool
AMBIF::registVehicleInfo(std::string propertyName, DataType type, string value)
{
- DebugOut() << "AMBIF registVehicleInfo(" << propertyName << ")\n";
+ DebugOut(50) << "AMBIF registVehicleInfo(" << propertyName << ")\n";
VehicleProperty::PropertyTypeFactoryCallback factory;
switch (type) {
case INT:
AMBVehicleInfo *
AMBIF::find(std::string propertyName)
{
- for (auto itr = vehicleinfoArray.begin(); itr != vehicleinfoArray.end();
- itr++) {
- if ((*itr).name == propertyName) {
- return &(*itr);
- }
+ AMBVehicleInfo vi;
+ vi.name = propertyName;
+ std::vector<AMBVehicleInfo>::iterator itr;
+ if ((itr = std::find(vehicleinfoArray.begin(), vehicleinfoArray.end(), vi))
+ != vehicleinfoArray.end()) {
+ return &(*itr);
}
return NULL;
}
+
+#if LATER1024
+PropertyInfo AMBIF::getPropertyInfo(const VehicleProperty::Property & property) {
+ if (propertyInfoMap.find(property) != propertyInfoMap.end()) {
+ return propertyInfoMap[property];
+ }
+ Zone::ZoneList zones;
+ AMBVehicleInfo vi;
+ vi.name = property;
+ std::vector<AMBVehicleInfo>::iterator itr, itr_idx, itr_end;
+ itr_idx = vehicleinfoArray.begin();
+ itr_end = vehicleinfoArray.end();
+ while ((itr = std::find(itr_idx, itr_end, vi)) != itr_end) {
+ zones.push_back((*itr).zone);
+ itr_idx = (++itr);
+ }
+ if (zones.empty()) {
+ return PropertyInfo::invalid();
+ }
+ else {
+ PropertyInfo info(0, zones);
+ propertyInfoMap[vi.name] = info;
+ return propertyInfoMap[vi.name];
+ }
+}
+#endif