Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

DeviceInfo.cpp

Committer:
xinlei
Date:
2015-03-03
Revision:
77:f6717e4eccc4
Parent:
74:ca3001991fdc
Child:
96:ea056f6be2e8

File content as of revision 77:f6717e4eccc4:

#include <stdlib.h>
#include <string.h>
#include "DeviceInfo.h"
#include "logging.h"

DeviceInfo::DeviceInfo(MDMSerial& mdm, MDMParser::DevStatus& devStatus) :
    _mdm(mdm)
{
    *_cellId = '\0';
    memcpy(&_devStatus, &devStatus, sizeof(MDMParser::DevStatus));
    memset(&_netStatus, 0, sizeof(MDMParser::NetStatus));
    memset(&_signalQuality, 0, sizeof(DeviceInfo::SignalQuality));
}

const char * DeviceInfo::imsi()
{
    return _devStatus.imsi;
}

const char * DeviceInfo::imei()
{
    return _devStatus.imei;
}

const char * DeviceInfo::cellId()
{
    if (!refreshNetStatus())
        return NULL;

    if (snprintf(_cellId, sizeof(_cellId), "%X", _netStatus.ci) < 1)
        return NULL;
    return _cellId;
}

const char * DeviceInfo::iccid()
{
    return _devStatus.ccid;
}

DeviceInfo::SignalQuality * DeviceInfo::signalQuality(bool realTime)
{
    if (!realTime && _signalQuality.rssi)
        return &_signalQuality;

    memset(&_signalQuality, 0, sizeof(DeviceInfo::SignalQuality));
    if (!refreshNetStatus()) {
        aError("Can not refresh network status!\r\n");
        return NULL;
    }
    
//    if ((_netStatus.rssi == 0) || (_netStatus.ber == 0)) {
//        aWarning("Network status is unavailable!\r\n");
//        aDebug("RSSI: %d dBm, BER: %d%%\r\n", _netStatus.rssi, _netStatus.ber);
//        return NULL;
//    }

    _signalQuality.rssi = _netStatus.rssi;
    _signalQuality.ber = _netStatus.ber;
    return &_signalQuality;
}

bool DeviceInfo::refreshNetStatus()
{
    return _mdm.checkNetStatus(&_netStatus);
}