How do I calculate my host PC’s data usage on Legato system?
-
my host PC’s data usage and interface.
-
data usage on modem
How do I calculate my host PC’s data usage on Legato system?
my host PC’s data usage and interface.
data usage on modem
how about using the API le_mdc_GetBytesCounters()?
Here is the sample code:
Thanks.
I got data usage used by host pc and legato system.
use data on pc and legato system.
use data only on legato system. (disable host pc’s Sierra Wireless Mobile Broadband Network Adapter)
Code
Call TestConnectivity(profileRef) every 5 seconds
uint64_t latestRxBytes = 0, latestTxBytes = 0;
//! [Statistics]
//--------------------------------------------------------------------------------------------------
/**
* Test the connectivity.
*/
//--------------------------------------------------------------------------------------------------
void TestConnectivity(
le_mdc_ProfileRef_t profileRef)
{
// int status;
// char systemCmd[200] = {0};
char itfName[LE_MDC_INTERFACE_NAME_MAX_BYTES] = "\0";
// le_mdc_DataBearerTechnology_t downlinkDataBearerTech;
// le_mdc_DataBearerTechnology_t uplinkDataBearerTech;
uint64_t rxBytes = 0, txBytes = 0;
// uint64_t latestRxBytes = 0, latestTxBytes = 0;
// LE_ASSERT_OK(le_mdc_GetDataBearerTechnology(profileRef,
// &downlinkDataBearerTech,
// &uplinkDataBearerTech));
// LE_INFO("downlinkDataBearerTech %d, uplinkDataBearerTech %d",
// downlinkDataBearerTech, uplinkDataBearerTech);
// Get interface name
LE_ASSERT_OK(le_mdc_GetInterfaceName(profileRef, itfName, LE_MDC_INTERFACE_NAME_MAX_BYTES));
// if (le_mdc_IsIPv4(profileRef))
// {
// snprintf(systemCmd, sizeof(systemCmd), "ping -c 60 www.sierrawireless.com -I %s", itfName);
// }
// else
// {
// // TODO ping6 needs raw access to socket and therefore root permissions => find a different
// // way to test the connectivity
// snprintf(systemCmd, sizeof(systemCmd), "ping6 -c 4 www.sierrawireless.com -I %s", itfName);
// }
// Ping to test the connectivity
// status = system(systemCmd);
// if (WEXITSTATUS(status))
// {
// le_mdc_StopSession(profileRef);
// }
// LE_ASSERT(!WEXITSTATUS(status));
// Get data counters
LE_ASSERT_OK(le_mdc_GetBytesCounters(&rxBytes, &txBytes));
latestRxBytes += rxBytes;
latestTxBytes += txBytes;
LE_INFO("rxBytesTotal %" PRIu64 ", txBytesTotal %" PRIu64 "rxBytes %" PRIu64 ", txBytes %" PRIu64,
latestRxBytes, latestTxBytes, rxBytes, txBytes);
LE_ASSERT_OK(le_mdc_ResetBytesCounter());
// Stop data counters and ping to test the connectivity
// LE_ASSERT_OK(le_mdc_StopBytesCounter());
// status = system(systemCmd);
// if (WEXITSTATUS(status))
// {
// le_mdc_StopSession(profileRef);
// }
// LE_ASSERT(!WEXITSTATUS(status));
// Get data counters
// LE_ASSERT_OK(le_mdc_GetBytesCounters(&rxBytes, &txBytes));
// LE_INFO("rxBytes %"PRIu64", txBytes %"PRIu64, rxBytes - latestRxBytes, txBytes - latestTxBytes);
// LE_ASSERT(latestRxBytes == rxBytes);
// LE_ASSERT(latestTxBytes == txBytes);
// Start data counters
// LE_ASSERT_OK(le_mdc_StartBytesCounter());
}