2 * Copyright (C) 2012 TOYOTA MOTOR CORPORATION.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "ambinterface.h"
25 #include "messageformat.h"
26 #include "mwinterface.h"
27 #include "viccommunicator.h"
29 VICCommunicator::VICCommunicator()
33 VICCommunicator::~VICCommunicator()
38 VICCommunicator::initialize(AMBIF *amb, MWIF *mw, Converter *conv)
47 VICCommunicator::setAMBVehicleInfo(MWVehicleInfo *vehicleinfo)
49 AMBVehicleInfo ambvehicleinfo[maxambdatasize];
50 DebugOut(8) << "VICCOMM" << " in setAMBVehicleInfo(" << vehicleinfo->name
51 << ")" << " status[0] = " << vehicleinfo->status[0] << "\n";
52 resetAmbBuf(&ambvehicleinfo[0], maxambdatasize);
53 int ret = converter->convertMWtoAMB(vehicleinfo, &ambvehicleinfo[0],
55 for (int i = 0; i < ret; i++) {
56 ambif->requestUpdate(&ambvehicleinfo[i]);
57 DebugOut(8) << "VICCOMM" << " out setAMBVehicleInfo(AMBname = "
58 << ambvehicleinfo[i].name << ","
59 << ambvehicleinfo[i].value->toString() << ")\n";
61 for (int i = 0; i < maxambdatasize; i++) {
62 if (ambvehicleinfo[i].value != NULL) {
63 delete ambvehicleinfo[i].value;
66 DebugOut(10) << "VICCOMM" << " out setAMBVehicleInfo(MWname = "
67 << vehicleinfo->name << ")\n";
71 VICCommunicator::getAMBVehicleInfo(MWVehicleInfo *vehicleinfo)
73 AMBVehicleInfo *ambvehicleinfo[maxambdatasize];
74 AMBVehicleInfo tempambvehicleinfo[maxambdatasize];
76 DebugOut(8) << "VICCOMM" << " in getAMBVehicleInfo(" << vehicleinfo->name
77 << "," << vehicleinfo->status[0] << ")\n";
78 resetAmbBuf(&tempambvehicleinfo[0], maxambdatasize);
79 int ret = converter->convertMWtoAMB(vehicleinfo, &tempambvehicleinfo[0],
81 for (int i = 0; i < ret; i++) {
82 delete tempambvehicleinfo[i].value;
83 ambvehicleinfo[i] = ambif->getPropertyRequest(
84 tempambvehicleinfo[i].name);
85 DebugOut(8) << "VICCOMM" << " getAMBVehicleInfo(AMBname = "
86 << ambvehicleinfo[i]->name << ","
87 << ambvehicleinfo[i]->value->toString() << ")\n";
88 converter->convertAMBtoMW(ambvehicleinfo[i], vehicleinfo);
90 DebugOut(8) << "VICCOMM" << " out getAMBVehicleInfo(MWname = "
91 << vehicleinfo->name << "," << vehicleinfo->status[0] << ")\n";
95 VICCommunicator::setMWVehicleInfo(AMBVehicleInfo *vehicleinfo)
97 MWVehicleInfo mwvehicleinfo;
98 DebugOut(8) << "VICCOMM" << " in setMWVehicleInfo(AMBname = "
99 << vehicleinfo->name << "," << vehicleinfo->value->toString()
101 resetMwBuf(&mwvehicleinfo);
102 converter->convertAMBtoMW(vehicleinfo, &mwvehicleinfo);
103 mwif->send(&mwvehicleinfo);
104 DebugOut(8) << "VICCOMM" << " out setMWVehicleInfo(MWname = "
105 << mwvehicleinfo.name << "," << mwvehicleinfo.status[0] << ")\n";
109 VICCommunicator::getMWVehicleInfo(AMBVehicleInfo *vehicleinfo)
115 VICCommunicator::resetAmbBuf(AMBVehicleInfo *vehicleinfo, size_t len)
117 for (int i = 0; i < static_cast<int>(len); i++) {
118 vehicleinfo[i].name = "";
119 vehicleinfo[i].value = NULL;
120 vehicleinfo[i].isCustom = false;
125 VICCommunicator::resetMwBuf(MWVehicleInfo *vehicleinfo)
127 vehicleinfo->name = "";
128 vehicleinfo->recordtime.tv_sec = 0;
129 vehicleinfo->recordtime.tv_usec = 0;
130 memset(vehicleinfo->status, 0, STATUSSIZE);