@@ -60,6 +60,7 @@ CMercApi::CMercApi(const std::string username, const std::string password, const
60
60
61
61
m_crc = 0 ;
62
62
m_fields = " " ;
63
+ m_fieldcnt = -1 ;
63
64
64
65
m_capabilities.has_battery_level = false ;
65
66
m_capabilities.has_charge_command = false ;
@@ -335,47 +336,51 @@ bool CMercApi::GetVehicleData(tVehicleData& data)
335
336
bool CMercApi::GetCustomData (tCustomData& data)
336
337
{
337
338
Json::Value reply;
339
+ std::vector<std::string> strarray;
338
340
bool bCustom = true ;
339
341
340
342
if (m_capabilities.has_custom_data )
341
343
{
342
- std::vector<std::string> strarray;
343
-
344
+ m_fieldcnt--;
344
345
StringSplit (m_fields, " ," , strarray);
345
- for (uint8_t i=0 ; i<strarray.size (); i++)
346
+
347
+ if (m_fieldcnt < 0 )
348
+ {
349
+ m_fieldcnt = strarray.size ();
350
+ }
351
+ else
346
352
{
347
- reply.clear ();
348
- if (GetResourceData (strarray[i], reply))
353
+ if (GetResourceData (strarray[m_fieldcnt], reply))
349
354
{
350
355
if (reply.size () == 0 )
351
356
{
352
- _log.Debug (DEBUG_NORM, " MercApi: Got empty data for resource %s" , strarray[i ].c_str ());
357
+ _log.Debug (DEBUG_NORM, " MercApi: Got empty data for resource %s" , strarray[m_fieldcnt ].c_str ());
353
358
}
354
359
else
355
360
{
356
- // _log.Debug(DEBUG_NORM, "MercApi: Got data for resource %s :\n%s", strarray[i ].c_str(),reply.toStyledString().c_str());
361
+ // _log.Debug(DEBUG_NORM, "MercApi: Got data for resource %s :\n%s", strarray[m_fieldcnt ].c_str(),reply.toStyledString().c_str());
357
362
358
- if (!reply[strarray[i ]].empty ())
363
+ if (!reply[strarray[m_fieldcnt ]].empty ())
359
364
{
360
- if (reply[strarray[i ]].isMember (" value" ))
365
+ if (reply[strarray[m_fieldcnt ]].isMember (" value" ))
361
366
{
362
- std::string resourceValue = reply[strarray[i ]][" value" ].asString ();
367
+ std::string resourceValue = reply[strarray[m_fieldcnt ]][" value" ].asString ();
363
368
364
369
Json::Value customItem;
365
- customItem[" id" ] = i ;
370
+ customItem[" id" ] = m_fieldcnt ;
366
371
customItem[" value" ] = resourceValue;
367
- customItem[" label" ] = strarray[i ];
372
+ customItem[" label" ] = strarray[m_fieldcnt ];
368
373
369
374
data.customdata .append (customItem);
370
375
371
- _log.Debug (DEBUG_NORM, " MercApi: Got data for resource (%d) %s : %s" , i , strarray[i ].c_str (), resourceValue.c_str ());
376
+ _log.Debug (DEBUG_NORM, " MercApi: Got data for resource (%d) %s : %s" , m_fieldcnt , strarray[m_fieldcnt ].c_str (), resourceValue.c_str ());
372
377
}
373
378
}
374
379
}
375
380
}
376
381
else
377
382
{
378
- _log.Debug (DEBUG_NORM," MercApi: Failed to retrieve data for resource %s!" , strarray[i ].c_str ());
383
+ _log.Debug (DEBUG_NORM," MercApi: Failed to retrieve data for resource %s!" , strarray[m_fieldcnt ].c_str ());
379
384
}
380
385
}
381
386
}
@@ -470,7 +475,7 @@ bool CMercApi::GetResourceData(std::string datatype, Json::Value& reply)
470
475
bool CMercApi::IsAwake ()
471
476
{
472
477
// Current Mercedes Me (API) does not have an 'Awake' state
473
- // So we fake one, we just request all available resources that are available for the current (BYO)CAR
478
+ // So we fake one, we just request the list of all available resources that are available for the current (BYO)CAR
474
479
475
480
std::stringstream ss;
476
481
ss << MERC_URL << MERC_API << " /" << m_VIN << " /resources" ;
@@ -521,8 +526,6 @@ bool CMercApi::ProcessAvailableResources(Json::Value& jsondata)
521
526
_log.Debug (DEBUG_NORM, " CRC32 of content is the not the same (%d).. start processing" , crc);
522
527
}
523
528
524
- m_crc = crc;
525
-
526
529
try
527
530
{
528
531
do
@@ -556,8 +559,15 @@ bool CMercApi::ProcessAvailableResources(Json::Value& jsondata)
556
559
557
560
if (ss.str ().length () > 0 )
558
561
{
562
+ std::vector<std::string> strarray;
563
+
559
564
m_fields = ss.str ();
560
- _log.Log (LOG_STATUS, " Found resource fields: %s" , m_fields.c_str ());
565
+ StringSplit (m_fields, " ," , strarray);
566
+ m_fieldcnt = strarray.size ();
567
+
568
+ _log.Log (LOG_STATUS, " Found %d resource fields: %s" , m_fieldcnt, m_fields.c_str ());
569
+
570
+ m_crc = crc;
561
571
562
572
bProcessed = true ;
563
573
}
0 commit comments