| 1 |
/*=========================================================================== |
| 2 |
FILE: |
| 3 |
SampleCM.cpp |
| 4 |
|
| 5 |
DESCRIPTION: |
| 6 |
Generic class to act as Sample CM interface |
| 7 |
|
| 8 |
PUBLIC CLASSES AND METHODS: |
| 9 |
cSampleCM |
| 10 |
Generic class to act as Sample CM interface |
| 11 |
|
| 12 |
Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 13 |
|
| 14 |
Redistribution and use in source and binary forms, with or without |
| 15 |
modification, are permitted provided that the following conditions are met: |
| 16 |
* Redistributions of source code must retain the above copyright |
| 17 |
notice, this list of conditions and the following disclaimer. |
| 18 |
* Redistributions in binary form must reproduce the above copyright |
| 19 |
notice, this list of conditions and the following disclaimer in the |
| 20 |
documentation and/or other materials provided with the distribution. |
| 21 |
* Neither the name of Code Aurora Forum nor |
| 22 |
the names of its contributors may be used to endorse or promote |
| 23 |
products derived from this software without specific prior written |
| 24 |
permission. |
| 25 |
|
| 26 |
|
| 27 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 28 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 29 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 30 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 31 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 32 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 33 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 34 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 35 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 36 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 37 |
POSSIBILITY OF SUCH DAMAGE. |
| 38 |
===========================================================================*/ |
| 39 |
|
| 40 |
//--------------------------------------------------------------------------- |
| 41 |
// Include Files |
| 42 |
//--------------------------------------------------------------------------- |
| 43 |
#include "SampleCM.h" |
| 44 |
#include "GobiCMDLL.h" |
| 45 |
#include "GobiCMCallback.h" |
| 46 |
#include "GobiConnectionMgmtAPIStructs.h" |
| 47 |
|
| 48 |
#include <sys/inotify.h> |
| 49 |
#include <unistd.h> |
| 50 |
#include <string> |
| 51 |
#include <dirent.h> |
| 52 |
#include <iomanip> |
| 53 |
|
| 54 |
// Global pointer for callbacks to reference |
| 55 |
class cSampleCM * gpCM; |
| 56 |
|
| 57 |
/*=========================================================================*/ |
| 58 |
// Free Methods |
| 59 |
/*=========================================================================*/ |
| 60 |
|
| 61 |
/*=========================================================================== |
| 62 |
METHOD: |
| 63 |
GetTickCount (Free Method) |
| 64 |
|
| 65 |
DESCRIPTION: |
| 66 |
Provide a number for sequencing reference, similar to the windows |
| 67 |
::GetTickCount(). |
| 68 |
|
| 69 |
NOTE: This number is based on the time since epoc, not |
| 70 |
uptime. |
| 71 |
|
| 72 |
PARAMETERS: |
| 73 |
|
| 74 |
RETURN VALUE: |
| 75 |
ULONGLONG - Number of milliseconds system has been up |
| 76 |
===========================================================================*/ |
| 77 |
ULONGLONG GetTickCount() |
| 78 |
{ |
| 79 |
timespec curtime; |
| 80 |
clock_gettime( CLOCK_REALTIME, &curtime ); |
| 81 |
|
| 82 |
ULONGLONG outtime = curtime.tv_sec * 1000LL; |
| 83 |
outtime += curtime.tv_nsec / 1000000LL; |
| 84 |
|
| 85 |
return outtime; |
| 86 |
} |
| 87 |
|
| 88 |
/*=========================================================================== |
| 89 |
METHOD: |
| 90 |
DeviceDetectionThread (Free Method) |
| 91 |
|
| 92 |
DESCRIPTION: |
| 93 |
Scans for and detects devices |
| 94 |
|
| 95 |
PARAMETERS: |
| 96 |
pData [ I ] - cSampleCM object |
| 97 |
|
| 98 |
RETURN VALUE: |
| 99 |
void * - always NULL |
| 100 |
===========================================================================*/ |
| 101 |
void * DeviceDetectionThread( void * pData ) |
| 102 |
{ |
| 103 |
cSampleCM * pCM = (cSampleCM *)pData; |
| 104 |
if (pCM == NULL) |
| 105 |
{ |
| 106 |
return NULL; |
| 107 |
} |
| 108 |
|
| 109 |
// Get inotify handle |
| 110 |
int inotify = inotify_init(); |
| 111 |
if (inotify == -1) |
| 112 |
{ |
| 113 |
TRACE( "inotify_init failed\n" ); |
| 114 |
return NULL; |
| 115 |
} |
| 116 |
|
| 117 |
// Start a watch on the /dev directory |
| 118 |
int inotifyFlags = IN_CREATE | IN_MODIFY | IN_DELETE; |
| 119 |
int watchD = inotify_add_watch( inotify, "/dev/", inotifyFlags ); |
| 120 |
if (watchD == -1) |
| 121 |
{ |
| 122 |
TRACE( "inotify_add_watch failed\n" ); |
| 123 |
close( inotify ); |
| 124 |
return NULL; |
| 125 |
} |
| 126 |
|
| 127 |
// Does a device already exist? |
| 128 |
dirent ** ppDevFiles; |
| 129 |
|
| 130 |
// Yes, scandir really takes a triple pointer for its second param |
| 131 |
int numDevs = scandir( "/dev/", &ppDevFiles, NULL, NULL ); |
| 132 |
for (int i = 0; i < numDevs; i++) |
| 133 |
{ |
| 134 |
std::string deviceID = "/dev/"; |
| 135 |
deviceID += ppDevFiles[i]->d_name; |
| 136 |
free( ppDevFiles[i] ); |
| 137 |
|
| 138 |
if (deviceID.find( "qcqmi" ) != std::string::npos) |
| 139 |
{ |
| 140 |
pCM->Connect( deviceID.c_str() ); |
| 141 |
break; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
// Cleanup from scandir |
| 146 |
if (numDevs != -1) |
| 147 |
{ |
| 148 |
free( ppDevFiles ); |
| 149 |
} |
| 150 |
else |
| 151 |
{ |
| 152 |
TRACE( "Scandir failed\n" ); |
| 153 |
} |
| 154 |
|
| 155 |
// Begin async reading |
| 156 |
fd_set inputSet, outputSet; |
| 157 |
FD_ZERO( &inputSet ); |
| 158 |
FD_SET( pCM->mDeviceDetectionStopPipe[READING], &inputSet ); |
| 159 |
FD_SET( inotify, &inputSet ); |
| 160 |
int largestFD = std::max( pCM->mDeviceDetectionStopPipe[READING], inotify ); |
| 161 |
|
| 162 |
while (true) |
| 163 |
{ |
| 164 |
// No FD_COPY() available in android |
| 165 |
memcpy( &outputSet, &inputSet, sizeof( fd_set ) ); |
| 166 |
|
| 167 |
// Wait for data on either the inotify or the stop pipe |
| 168 |
int status = select( largestFD + 1, &outputSet, NULL, NULL, NULL ); |
| 169 |
if (status <= 0) |
| 170 |
{ |
| 171 |
break; |
| 172 |
} |
| 173 |
else if (FD_ISSET( pCM->mDeviceDetectionStopPipe[READING], &outputSet ) == true) |
| 174 |
{ |
| 175 |
// Time to close |
| 176 |
break; |
| 177 |
} |
| 178 |
else if (FD_ISSET( inotify, &outputSet ) == true) |
| 179 |
{ |
| 180 |
// Perform a read |
| 181 |
BYTE buffer[1024] = { 0 }; |
| 182 |
int rc = read( inotify, &buffer[0], 1024 ); |
| 183 |
if (rc < (int)sizeof( inotify_event )) |
| 184 |
{ |
| 185 |
continue; |
| 186 |
} |
| 187 |
|
| 188 |
// Typecast the buffer to an inotify event |
| 189 |
struct inotify_event * pIEvent = (struct inotify_event *)&buffer[0]; |
| 190 |
|
| 191 |
// Check the length of the name |
| 192 |
if (pIEvent->len < 5) |
| 193 |
{ |
| 194 |
continue; |
| 195 |
} |
| 196 |
|
| 197 |
// Is this a matching device? |
| 198 |
if (strncmp( pIEvent->name, "qcqmi", 5 ) != 0) |
| 199 |
{ |
| 200 |
continue; |
| 201 |
} |
| 202 |
|
| 203 |
std::string deviceID = "/dev/"; |
| 204 |
deviceID += pIEvent->name; |
| 205 |
|
| 206 |
if (pIEvent->mask & IN_CREATE |
| 207 |
|| pIEvent->mask & IN_MODIFY) |
| 208 |
{ |
| 209 |
pCM->Connect( deviceID.c_str() ); |
| 210 |
} |
| 211 |
|
| 212 |
if (pIEvent->mask & IN_DELETE) |
| 213 |
{ |
| 214 |
// Was it the connected device which was removed? |
| 215 |
if (pCM->mDeviceID.compare( deviceID ) == 0) |
| 216 |
{ |
| 217 |
pCM->Disconnect(); |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
// Cleanup |
| 224 |
inotify_rm_watch( inotify, watchD ); |
| 225 |
close( inotify ); |
| 226 |
|
| 227 |
return NULL; |
| 228 |
} |
| 229 |
|
| 230 |
/*=========================================================================== |
| 231 |
METHOD: |
| 232 |
UpdateNetworkInfoThread (Free Method) |
| 233 |
|
| 234 |
DESCRIPTION: |
| 235 |
Updates the network stats every 1s (while device is present) |
| 236 |
|
| 237 |
PARAMETERS: |
| 238 |
pData [ I ] - cSampleCM object |
| 239 |
|
| 240 |
RETURN VALUE: |
| 241 |
void * - always NULL |
| 242 |
===========================================================================*/ |
| 243 |
void * UpdateNetworkInfoThread( void * pData ) |
| 244 |
{ |
| 245 |
cSampleCM * pCM = (cSampleCM*)pData; |
| 246 |
if (pCM == NULL) |
| 247 |
{ |
| 248 |
return NULL; |
| 249 |
} |
| 250 |
|
| 251 |
// Update once |
| 252 |
pCM->CheckConnectedStats(); |
| 253 |
|
| 254 |
int rc; |
| 255 |
do |
| 256 |
{ |
| 257 |
// Update rates and times every 1s |
| 258 |
pCM->UpdateRateDisplay(); |
| 259 |
pCM->UpdateTimeDisplay(); |
| 260 |
|
| 261 |
DWORD temp; |
| 262 |
rc = pCM->mUpdateNetworkInfoEvent.Wait( 1000, temp ); |
| 263 |
|
| 264 |
} while (rc == ETIME); |
| 265 |
|
| 266 |
return NULL; |
| 267 |
} |
| 268 |
|
| 269 |
/*=========================================================================== |
| 270 |
METHOD: |
| 271 |
ParseStats (Free Method) |
| 272 |
|
| 273 |
DESCRIPTION: |
| 274 |
Parse the stats file and obtain the TX/RX bytes and connection duration |
| 275 |
|
| 276 |
NOTE: The stats text file consists of one line in the following format: |
| 277 |
Total RX Bytes; Total TX Bytes; Total Duration |
| 278 |
|
| 279 |
PARAMETERS: |
| 280 |
line [ I ] - Line to parse |
| 281 |
lifeTotalRX [ O ] - Total RX bytes |
| 282 |
lifeTotalTX [ O ] - Total TX bytes |
| 283 |
lifeTotalDuration [ O ] - Total connection duration |
| 284 |
|
| 285 |
RETURN VALUE: |
| 286 |
bool |
| 287 |
===========================================================================*/ |
| 288 |
bool ParseStats( |
| 289 |
std::istringstream & line, |
| 290 |
ULONGLONG & lifeTotalRX, |
| 291 |
ULONGLONG & lifeTotalTX, |
| 292 |
ULONGLONG & lifeTotalDuration ) |
| 293 |
{ |
| 294 |
|
| 295 |
ULONGLONG temp1, temp2, temp3; |
| 296 |
char c1, c2; |
| 297 |
|
| 298 |
// Attempt to parse into temp variables, skipping whitespace |
| 299 |
line >> std::skipws >> temp1 >> c1 >> temp2 >> c2 >> temp3; |
| 300 |
|
| 301 |
// Was parsing successful? |
| 302 |
if (line.fail() == true) |
| 303 |
{ |
| 304 |
TRACE( "failed to parse stats file\n" ); |
| 305 |
return false; |
| 306 |
} |
| 307 |
else |
| 308 |
{ |
| 309 |
TRACE( "read %llu, %llu, %llu", temp1, temp2, temp3 ); |
| 310 |
lifeTotalRX = temp1; |
| 311 |
lifeTotalTX = temp2; |
| 312 |
lifeTotalDuration = temp3; |
| 313 |
|
| 314 |
return true; |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
/*=========================================================================*/ |
| 319 |
// cSampleCM Methods |
| 320 |
/*=========================================================================*/ |
| 321 |
|
| 322 |
/*=========================================================================== |
| 323 |
METHOD: |
| 324 |
~cSampleCM (Public Method) |
| 325 |
|
| 326 |
DESCRIPTION: |
| 327 |
Destructor - Stops the data session, |
| 328 |
Stops device detection thread, |
| 329 |
Writes stats to file |
| 330 |
|
| 331 |
RETURN VALUE: |
| 332 |
None |
| 333 |
===========================================================================*/ |
| 334 |
cSampleCM::~cSampleCM() |
| 335 |
{ |
| 336 |
// These functions will most likely fail. That's ok. |
| 337 |
OnCancelDataSession(); |
| 338 |
OnStopDataSession(); |
| 339 |
|
| 340 |
Disconnect(); |
| 341 |
|
| 342 |
// Close device detection thread, if open |
| 343 |
if (mDeviceDetectionStopPipe[WRITING] != -1) |
| 344 |
{ |
| 345 |
if (mDeviceDetectionThreadID != 0) |
| 346 |
{ |
| 347 |
BYTE byte = 1; |
| 348 |
write( mDeviceDetectionStopPipe[WRITING], &byte, 1 ); |
| 349 |
|
| 350 |
pthread_join( mDeviceDetectionThreadID, NULL ); |
| 351 |
|
| 352 |
mDeviceDetectionThreadID = 0; |
| 353 |
} |
| 354 |
|
| 355 |
close( mDeviceDetectionStopPipe[WRITING] ); |
| 356 |
close( mDeviceDetectionStopPipe[READING] ); |
| 357 |
mDeviceDetectionStopPipe[READING] = -1; |
| 358 |
mDeviceDetectionStopPipe[WRITING] = -1; |
| 359 |
} |
| 360 |
|
| 361 |
// Write stats to file |
| 362 |
std::string config = getenv( "HOME" ); |
| 363 |
config += "/.GobiSampleCMStats.txt"; |
| 364 |
|
| 365 |
int flags = O_CREAT | O_TRUNC | O_WRONLY; |
| 366 |
mode_t mode = S_IRUSR | S_IWUSR; |
| 367 |
int statsFile = open( config.c_str(), flags, mode ); |
| 368 |
if (statsFile < 0) |
| 369 |
{ |
| 370 |
TRACE( "Unable to create stats file\n" ); |
| 371 |
} |
| 372 |
else |
| 373 |
{ |
| 374 |
std::ostringstream out; |
| 375 |
out << mLifeTotalRX << "; " |
| 376 |
<< mLifeTotalTX << "; " |
| 377 |
<< mLifeTotalDuration; |
| 378 |
|
| 379 |
int rc = write( statsFile, out.str().c_str(), out.str().size() ); |
| 380 |
if (rc < 0) |
| 381 |
{ |
| 382 |
TRACE( "Unable to write stats to file\n" ); |
| 383 |
} |
| 384 |
|
| 385 |
close( statsFile ); |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
/*=========================================================================== |
| 390 |
METHOD: |
| 391 |
Init (Public Method) |
| 392 |
|
| 393 |
DESCRIPTION: |
| 394 |
Initialize GUI, begin waiting for devices |
| 395 |
|
| 396 |
RETURN VALUE: |
| 397 |
bool |
| 398 |
===========================================================================*/ |
| 399 |
bool cSampleCM::Init() |
| 400 |
{ |
| 401 |
Disconnect(); |
| 402 |
|
| 403 |
// Read in the stats file |
| 404 |
std::string config = getenv( "HOME" ); |
| 405 |
config += "/.GobiSampleCMStats.txt"; |
| 406 |
|
| 407 |
int statsFile = open( config.c_str(), O_RDONLY ); |
| 408 |
if (statsFile < 0) |
| 409 |
{ |
| 410 |
// Non-fatal error |
| 411 |
TRACE( "Unable to open config file %s", config.c_str() ); |
| 412 |
} |
| 413 |
else |
| 414 |
{ |
| 415 |
CHAR buf[100]; |
| 416 |
int len = read( statsFile, &buf[0], 100 ); |
| 417 |
if (len < 0) |
| 418 |
{ |
| 419 |
// Non-fatal error |
| 420 |
TRACE( "failed to read from file\n" ); |
| 421 |
} |
| 422 |
else |
| 423 |
{ |
| 424 |
std::string asString( &buf[0], len ); |
| 425 |
std::istringstream line( asString ); |
| 426 |
|
| 427 |
ULONGLONG lrx, ltx, ld; |
| 428 |
if (ParseStats( line, lrx, ltx, ld ) == true) |
| 429 |
{ |
| 430 |
mLifeTotalRX = lrx; |
| 431 |
mLifeTotalTX = ltx; |
| 432 |
mLifeTotalDuration = ld; |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
close( statsFile ); |
| 437 |
} |
| 438 |
|
| 439 |
// Life totals will just be zeros if the file was not present |
| 440 |
std::ostringstream tmp; |
| 441 |
tmp << mLifeTotalRX; |
| 442 |
SetLifeRx( tmp.str() ); |
| 443 |
|
| 444 |
tmp.str( "" ); |
| 445 |
tmp << mLifeTotalTX; |
| 446 |
SetLifeTx( tmp.str() ); |
| 447 |
|
| 448 |
tmp.str( "" ); |
| 449 |
tmp << std::setfill( '0' ) << std::setw( 2 ) << (mLifeTotalDuration / 3600) % 60 |
| 450 |
<< std::setw( 1 ) << ":" |
| 451 |
<< std::setfill( '0' ) << std::setw( 2 ) << (mLifeTotalDuration / 60) % 60 |
| 452 |
<< std::setw( 1 ) << ":" |
| 453 |
<< std::setfill( '0' ) << std::setw( 2 ) << mLifeTotalDuration % 60; |
| 454 |
SetLifeDuration( tmp.str() ); |
| 455 |
|
| 456 |
// Set the global pointer, used by callbacks |
| 457 |
gpCM = this; |
| 458 |
|
| 459 |
// Initialize command pipe |
| 460 |
int ret = pipe( mDeviceDetectionStopPipe ); |
| 461 |
if (ret != 0) |
| 462 |
{ |
| 463 |
// Should never happen, but just in case... |
| 464 |
return false; |
| 465 |
} |
| 466 |
|
| 467 |
// Begin scanning for devices |
| 468 |
ret = pthread_create( &mDeviceDetectionThreadID, |
| 469 |
0, |
| 470 |
DeviceDetectionThread, |
| 471 |
this ); |
| 472 |
if (ret != 0) |
| 473 |
{ |
| 474 |
return false; |
| 475 |
} |
| 476 |
|
| 477 |
return true; |
| 478 |
} |
| 479 |
|
| 480 |
/*=========================================================================== |
| 481 |
METHOD: |
| 482 |
Connect (Public Method) |
| 483 |
|
| 484 |
DESCRIPTION: |
| 485 |
Initializes the Gobi API to the current device |
| 486 |
|
| 487 |
PARAMETERS: |
| 488 |
pInterface [ I ] - Interace to connect to |
| 489 |
|
| 490 |
RETURN VALUE: |
| 491 |
ULONG |
| 492 |
===========================================================================*/ |
| 493 |
ULONG cSampleCM::Connect( LPCSTR pInterface ) |
| 494 |
{ |
| 495 |
// Are we already connected to a device? |
| 496 |
if (mDeviceID.size() != 0) |
| 497 |
{ |
| 498 |
return eGOBI_ERR_MULTIPLE_DEVICES; |
| 499 |
} |
| 500 |
|
| 501 |
// Connect to the device |
| 502 |
ULONG rc = mGobi.Connect( pInterface ); |
| 503 |
if (rc != eGOBI_ERR_NONE) |
| 504 |
{ |
| 505 |
TRACE( "GobiConnect error %lu\n", rc ); |
| 506 |
return rc; |
| 507 |
} |
| 508 |
|
| 509 |
UpdateDeviceInfo(); |
| 510 |
UpdateConnectionInfo(); |
| 511 |
|
| 512 |
// Any connection at this point is an external connection |
| 513 |
UpdateSessionState( true, mSessionState ); |
| 514 |
|
| 515 |
// Success |
| 516 |
mDeviceID = pInterface; |
| 517 |
return rc; |
| 518 |
} |
| 519 |
|
| 520 |
/*=========================================================================== |
| 521 |
METHOD: |
| 522 |
Disconnect (Public Method) |
| 523 |
|
| 524 |
DESCRIPTION: |
| 525 |
Calls GobiDisconnect |
| 526 |
|
| 527 |
RETURN VALUE: |
| 528 |
ULONG |
| 529 |
===========================================================================*/ |
| 530 |
ULONG cSampleCM::Disconnect() |
| 531 |
{ |
| 532 |
// Stop a data session, if present |
| 533 |
OnCancelDataSession(); |
| 534 |
OnStopDataSession(); |
| 535 |
|
| 536 |
mGobi.Disconnect(); |
| 537 |
|
| 538 |
// Reset state |
| 539 |
mSessionID = 0xFFFFFFFF; |
| 540 |
mInitialState = 0xFFFFFFFF; |
| 541 |
mDataBearerTech = 0; |
| 542 |
|
| 543 |
// Store life total |
| 544 |
mLifeTotalDuration += mTotalDuration; |
| 545 |
|
| 546 |
// Reset all totals |
| 547 |
mStartTime = 0; |
| 548 |
mPreviousRX = 0; |
| 549 |
mPreviousTX = 0; |
| 550 |
mTotalRX = 0; |
| 551 |
mTotalTX = 0; |
| 552 |
mTotalDuration = 0; |
| 553 |
|
| 554 |
SetState( "No Device" ); |
| 555 |
SetRSSI( "Unknown" ); |
| 556 |
SetTech( "Unknown" ); |
| 557 |
SetRx( "Unknown" ); |
| 558 |
SetTx( "Unknown" ); |
| 559 |
SetMaxRx( "Unknown" ); |
| 560 |
SetMaxTx( "Unknown" ); |
| 561 |
SetRoam( "Unknown" ); |
| 562 |
SetDuration( "Unknown" ); |
| 563 |
SetLifeDuration( "Unknown" ); |
| 564 |
SetLifeRx( "Unknown" ); |
| 565 |
SetLifeTx( "Unknown" ); |
| 566 |
SetManufact( "Unknown" ); |
| 567 |
SetModel( "Unknown" ); |
| 568 |
SetHardware( "Unknown" ); |
| 569 |
SetFirmware( "Unknown" ); |
| 570 |
SetMDN( "Unknown" ); |
| 571 |
SetMIN( "Unknown" ); |
| 572 |
SetESN( "Unknown" ); |
| 573 |
SetMEID( "Unknown" ); |
| 574 |
SetIMEI( "Unknown" ); |
| 575 |
SetIMSI( "Unknown" ); |
| 576 |
|
| 577 |
return eGOBI_ERR_NONE; |
| 578 |
} |
| 579 |
|
| 580 |
/*=========================================================================== |
| 581 |
ETHOD: |
| 582 |
OnStartDataSession (Public Method) |
| 583 |
|
| 584 |
DESCRIPTION: |
| 585 |
Starts a data session |
| 586 |
|
| 587 |
PARAMETERS: |
| 588 |
pFailureCode [ O ] - Call failure code, if provided |
| 589 |
|
| 590 |
RETURN VALUE: |
| 591 |
ULONG |
| 592 |
===========================================================================*/ |
| 593 |
ULONG cSampleCM::OnStartDataSession( ULONG * pFailureCode ) |
| 594 |
{ |
| 595 |
mbInitiatedStartDataSession = true; |
| 596 |
|
| 597 |
// Use provided values, if not empty strings |
| 598 |
LPCSTR pAPN = (mAPN.size() == 0) ? 0 : mAPN.c_str(); |
| 599 |
LPCSTR pUsername = (mUsername.size() == 0) ? 0 : mUsername.c_str(); |
| 600 |
LPCSTR pPassword = (mPassword.size() == 0) ? 0 : mPassword.c_str(); |
| 601 |
|
| 602 |
ULONG rc = mGobi.StartDataSession( pAPN, |
| 603 |
pUsername, |
| 604 |
pPassword, |
| 605 |
&mSessionID, |
| 606 |
pFailureCode ); |
| 607 |
if (rc == eGOBI_ERR_NONE) |
| 608 |
{ |
| 609 |
mPreviousRX = 0; |
| 610 |
mPreviousTX = 0; |
| 611 |
mTotalRX = 0; |
| 612 |
mTotalTX = 0; |
| 613 |
mTotalDuration = 0; |
| 614 |
mStartTime = GetTickCount(); |
| 615 |
} |
| 616 |
else |
| 617 |
{ |
| 618 |
mbInitiatedStartDataSession = false; |
| 619 |
} |
| 620 |
|
| 621 |
return rc; |
| 622 |
} |
| 623 |
|
| 624 |
/*=========================================================================== |
| 625 |
METHOD: |
| 626 |
CancelDataSession (Public Method) |
| 627 |
|
| 628 |
DESCRIPTION: |
| 629 |
Cancels an in progress data session request |
| 630 |
|
| 631 |
RETURN VALUE: |
| 632 |
ULONG |
| 633 |
===========================================================================*/ |
| 634 |
ULONG cSampleCM::OnCancelDataSession() |
| 635 |
{ |
| 636 |
return mGobi.CancelDataSession(); |
| 637 |
} |
| 638 |
|
| 639 |
/*=========================================================================== |
| 640 |
METHOD: |
| 641 |
OnStopDataSession (Public Method) |
| 642 |
|
| 643 |
DESCRIPTION: |
| 644 |
Calls WDSStopNetworkInterface |
| 645 |
|
| 646 |
RETURN VALUE: |
| 647 |
ULONG |
| 648 |
===========================================================================*/ |
| 649 |
ULONG cSampleCM::OnStopDataSession() |
| 650 |
{ |
| 651 |
if (mSessionID == 0xFFFFFFFF) |
| 652 |
{ |
| 653 |
return eGOBI_ERR_GENERAL; |
| 654 |
} |
| 655 |
|
| 656 |
mbInitiatedStopDataSession = true; |
| 657 |
mDataBearerTech = 0; |
| 658 |
|
| 659 |
ULONG rc = mGobi.StopDataSession( mSessionID ); |
| 660 |
mSessionID = 0xFFFFFFFF; |
| 661 |
|
| 662 |
return rc; |
| 663 |
} |
| 664 |
|
| 665 |
/*=========================================================================== |
| 666 |
METHOD: |
| 667 |
OnSignalStrengthCBNotification (Internal Method) |
| 668 |
|
| 669 |
DESCRIPTION: |
| 670 |
Handle signal strength callback notification |
| 671 |
|
| 672 |
PARAMETERS: |
| 673 |
signalStr [ I ] - Signal strength |
| 674 |
radioInterface [ I ] - Radio interface |
| 675 |
===========================================================================*/ |
| 676 |
void cSampleCM::OnSignalStrengthCBNotificaion( |
| 677 |
INT8 signalStr, |
| 678 |
ULONG radioInterface ) |
| 679 |
{ |
| 680 |
// Update mServiceSignals |
| 681 |
mServiceSignals[radioInterface] = signalStr; |
| 682 |
|
| 683 |
if (mSessionState == eQMIConnectionStatus_Connected) |
| 684 |
{ |
| 685 |
mDataBearerTech = 0; |
| 686 |
} |
| 687 |
|
| 688 |
UpdateSignalAndTech(); |
| 689 |
} |
| 690 |
|
| 691 |
/*=========================================================================== |
| 692 |
METHOD: |
| 693 |
OnSessionStateCBNotification (Internal Method) |
| 694 |
|
| 695 |
DESCRIPTION: |
| 696 |
Handle session state callback notification |
| 697 |
|
| 698 |
PARAMETERS: |
| 699 |
state [ I ] - Session state |
| 700 |
===========================================================================*/ |
| 701 |
void cSampleCM::OnSessionStateCBNotification( ULONG state ) |
| 702 |
{ |
| 703 |
// Was the state change triggered externally? |
| 704 |
bool bStateChangeExternal = false; |
| 705 |
|
| 706 |
// Save session state |
| 707 |
if (state == eQMIConnectionStatus_Connected) |
| 708 |
{ |
| 709 |
// Started externally |
| 710 |
if (mbInitiatedStartDataSession == false) |
| 711 |
{ |
| 712 |
bStateChangeExternal = true; |
| 713 |
mStartTime = GetTickCount(); |
| 714 |
} |
| 715 |
} |
| 716 |
else |
| 717 |
{ |
| 718 |
mDataBearerTech = 0; |
| 719 |
|
| 720 |
// Stopped externally |
| 721 |
if (mbInitiatedStopDataSession == false) |
| 722 |
{ |
| 723 |
// Store all life total variables |
| 724 |
mLifeTotalDuration += mTotalDuration; |
| 725 |
|
| 726 |
// Reset all totals |
| 727 |
bStateChangeExternal = true; |
| 728 |
mStartTime = 0; |
| 729 |
mPreviousRX = 0; |
| 730 |
mPreviousTX = 0; |
| 731 |
mTotalRX = 0; |
| 732 |
mTotalTX = 0; |
| 733 |
mTotalDuration = 0; |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
// Update the session state |
| 738 |
UpdateSessionState( bStateChangeExternal, state ); |
| 739 |
|
| 740 |
// Update the signal strength and technology |
| 741 |
UpdateSignalAndTech(); |
| 742 |
|
| 743 |
// Reset to false |
| 744 |
mbInitiatedStartDataSession = false; |
| 745 |
mbInitiatedStopDataSession = false; |
| 746 |
} |
| 747 |
|
| 748 |
/*=========================================================================== |
| 749 |
METHOD: |
| 750 |
OnDataBearerCBNotification (Internal Method) |
| 751 |
|
| 752 |
DESCRIPTION: |
| 753 |
Handle data bearer callback notification |
| 754 |
|
| 755 |
PARAMETERS: |
| 756 |
dataBearerTech [ I ] - Data bearer technology |
| 757 |
===========================================================================*/ |
| 758 |
void cSampleCM::OnDataBearerCBNotification( ULONG dataBearerTech ) |
| 759 |
{ |
| 760 |
if (dataBearerTech != eQMIDataBearerTechnologies_Unknown) |
| 761 |
{ |
| 762 |
mDataBearerTech = dataBearerTech; |
| 763 |
UpdateSignalAndTech(); |
| 764 |
} |
| 765 |
} |
| 766 |
|
| 767 |
/*=========================================================================== |
| 768 |
METHOD: |
| 769 |
OnDataCapsNotification (Internal Method) |
| 770 |
|
| 771 |
DESCRIPTION: |
| 772 |
Handle data capabilities callback notification |
| 773 |
|
| 774 |
PARAMETERS: |
| 775 |
numDataCaps [ I ] - Number of data capabilities |
| 776 |
pDataCaps [ I ] - Data Capabilites |
| 777 |
===========================================================================*/ |
| 778 |
void cSampleCM::OnDataCapsNotification( |
| 779 |
ULONG numDataCaps, |
| 780 |
eQMINASDataServiceCapabilities2 * pDataCaps ) |
| 781 |
{ |
| 782 |
// Clear saved data capabilities in order to update |
| 783 |
mDataCapabilities.clear(); |
| 784 |
|
| 785 |
// Populate list with new capabilities |
| 786 |
for (ULONG c = 0; c < numDataCaps; c++) |
| 787 |
{ |
| 788 |
ULONG dataCaps = pDataCaps[c]; |
| 789 |
if ( (dataCaps != 0xFFFFFFFF) |
| 790 |
&& (dataCaps != 0) ) |
| 791 |
{ |
| 792 |
mDataCapabilities.push_back( pDataCaps[c] ); |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
UpdateSignalAndTech(); |
| 797 |
} |
| 798 |
|
| 799 |
/*=========================================================================== |
| 800 |
METHOD: |
| 801 |
OnByteTotalsNotification (Internal Method) |
| 802 |
|
| 803 |
DESCRIPTION: |
| 804 |
Handle byte totals callback notification |
| 805 |
|
| 806 |
PARAMETERS: |
| 807 |
rx [ I ] - received bytes |
| 808 |
tx [ I ] - transmitted bytes |
| 809 |
===========================================================================*/ |
| 810 |
void cSampleCM::OnByteTotalsNotification( ULONGLONG rx, ULONGLONG tx ) |
| 811 |
{ |
| 812 |
mTotalTX = tx; |
| 813 |
mTotalRX = rx; |
| 814 |
} |
| 815 |
|
| 816 |
/*=========================================================================== |
| 817 |
METHOD: |
| 818 |
UpdateSignalAndTech (Public Method) |
| 819 |
|
| 820 |
DESCRIPTION: |
| 821 |
Update the signal strength and technology display |
| 822 |
===========================================================================*/ |
| 823 |
void cSampleCM::UpdateSignalAndTech() |
| 824 |
{ |
| 825 |
std::string radioStr = "Unknown"; |
| 826 |
std::string ssStr = "Unknown"; |
| 827 |
ULONG radioVal = eQMINASRadioInterfaces_NoneNoService; |
| 828 |
|
| 829 |
// If connected, use data bearer |
| 830 |
if (mDataBearerTech != 0) |
| 831 |
{ |
| 832 |
switch (mDataBearerTech) |
| 833 |
{ |
| 834 |
case eQMIDataBearerTechnologies_CDMA20001x: |
| 835 |
radioStr = "CDMA 1xRTT"; |
| 836 |
radioVal = eQMINASRadioInterfaces_CDMA20001x; |
| 837 |
break; |
| 838 |
|
| 839 |
case eQMIDataBearerTechnologies_CDMA20001xEVDORev0: |
| 840 |
radioStr = "CDMA 1xEVDO Rev 0"; |
| 841 |
radioVal = eQMINASRadioInterfaces_CDMA2000HRPD; |
| 842 |
break; |
| 843 |
|
| 844 |
case eQMIDataBearerTechnologies_GPRS: |
| 845 |
radioStr = "GRPS"; |
| 846 |
radioVal = eQMINASRadioInterfaces_GSM; |
| 847 |
break; |
| 848 |
|
| 849 |
case eQMIDataBearerTechnologies_WCDMA: |
| 850 |
radioStr = "WCDMA"; |
| 851 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 852 |
break; |
| 853 |
|
| 854 |
case eQMIDataBearerTechnologies_CDMA20001xEVDORevA: |
| 855 |
radioStr = "CDMA 1xEVDO Rev A"; |
| 856 |
radioVal = eQMINASRadioInterfaces_CDMA2000HRPD; |
| 857 |
break; |
| 858 |
|
| 859 |
case eQMIDataBearerTechnologies_EGPRS: |
| 860 |
radioStr = "EDGE"; |
| 861 |
radioVal = eQMINASRadioInterfaces_GSM; |
| 862 |
break; |
| 863 |
|
| 864 |
case eQMIDataBearerTechnologies_HSDPAWCDMA: |
| 865 |
radioStr = "HSDPA DL, WCDMA UL"; |
| 866 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 867 |
break; |
| 868 |
|
| 869 |
case eQMIDataBearerTechnologies_WCDMAHSUPA: |
| 870 |
radioStr = "WCDMA DL, HSUPA UL"; |
| 871 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 872 |
break; |
| 873 |
|
| 874 |
case eQMIDataBearerTechnologies_HSDPAHSUPA: |
| 875 |
radioStr = "HSDPA DL, HSUPA UL"; |
| 876 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 877 |
break; |
| 878 |
|
| 879 |
case eQMIDataBearerTechnologies_LTE: |
| 880 |
radioStr = "LTE"; |
| 881 |
radioVal = eQMINASRadioInterfaces_LTE; |
| 882 |
break; |
| 883 |
|
| 884 |
case eQMIDataBearerTechnologies_CDMA2000EHRPD: |
| 885 |
radioStr = "CDMA 1xEVDO eHRPD"; |
| 886 |
radioVal = eQMINASRadioInterfaces_CDMA2000HRPD; |
| 887 |
break; |
| 888 |
|
| 889 |
case eQMIDataBearerTechnologies_HSDPAPlusWCDMA: |
| 890 |
radioStr = "HSDPA+ DL, WCDMA UL"; |
| 891 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 892 |
break; |
| 893 |
|
| 894 |
case eQMIDataBearerTechnologies_HSDPAPlusHSUPA: |
| 895 |
radioStr = "HSDPA+ DL, HSUPA UL"; |
| 896 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 897 |
break; |
| 898 |
|
| 899 |
case eQMIDataBearerTechnologies_DualCellHSDPAPlusWCDMA: |
| 900 |
radioStr = "Dual Cell HSDPA+ DL, WCDMA UL"; |
| 901 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 902 |
break; |
| 903 |
|
| 904 |
case eQMIDataBearerTechnologies_DualCellHSDPAPlusHSUPA: |
| 905 |
radioStr = "Dual Cell HSDPA+ DL, HSUPA UL"; |
| 906 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 907 |
break; |
| 908 |
} |
| 909 |
|
| 910 |
if ( (radioVal != eQMINASRadioInterfaces_NoneNoService) |
| 911 |
&& (mServiceSignals.find( radioVal ) != mServiceSignals.end()) |
| 912 |
&& (mServiceSignals[radioVal] != SCHAR_MAX) ) |
| 913 |
{ |
| 914 |
std::ostringstream temp; |
| 915 |
temp << (INT)mServiceSignals[radioVal]; |
| 916 |
ssStr = temp.str(); |
| 917 |
} |
| 918 |
} |
| 919 |
else |
| 920 |
{ |
| 921 |
// When not connected we have to pick the most preferred data capability |
| 922 |
eQMINASDataServiceCapabilities2 mostPreferredCap |
| 923 |
= (eQMINASDataServiceCapabilities2)0xff; |
| 924 |
std::list <ULONG>::const_iterator pIter; |
| 925 |
std::list <ULONG>::const_iterator pDataCapsItr; |
| 926 |
|
| 927 |
pIter = mPreferredServices.begin(); |
| 928 |
|
| 929 |
bool bDone = false; |
| 930 |
while ( (pIter != mPreferredServices.end()) |
| 931 |
&& (bDone != true) ) |
| 932 |
{ |
| 933 |
pDataCapsItr = mDataCapabilities.begin(); |
| 934 |
while (pDataCapsItr != mDataCapabilities.end()) |
| 935 |
{ |
| 936 |
if (*pIter == *pDataCapsItr) |
| 937 |
{ |
| 938 |
mostPreferredCap = (eQMINASDataServiceCapabilities2)*pIter; |
| 939 |
bDone = true; |
| 940 |
break; |
| 941 |
} |
| 942 |
|
| 943 |
pDataCapsItr++; |
| 944 |
} |
| 945 |
|
| 946 |
pIter++; |
| 947 |
} |
| 948 |
|
| 949 |
// Determine the best radio interface reported |
| 950 |
eQMINASRadioInterfaces preferredRadioIf; |
| 951 |
preferredRadioIf = eQMINASRadioInterfaces_NoneNoService; |
| 952 |
|
| 953 |
if (mServiceSignals.find( eQMINASRadioInterfaces_LTE ) != mServiceSignals.end()) |
| 954 |
{ |
| 955 |
preferredRadioIf = eQMINASRadioInterfaces_LTE; |
| 956 |
} |
| 957 |
else if (mServiceSignals.find( eQMINASRadioInterfaces_CDMA2000HRPD ) != mServiceSignals.end()) |
| 958 |
{ |
| 959 |
preferredRadioIf = eQMINASRadioInterfaces_CDMA2000HRPD; |
| 960 |
} |
| 961 |
else if (mServiceSignals.find( eQMINASRadioInterfaces_CDMA20001x ) != mServiceSignals.end()) |
| 962 |
{ |
| 963 |
preferredRadioIf = eQMINASRadioInterfaces_CDMA20001x; |
| 964 |
} |
| 965 |
else if (mServiceSignals.find( eQMINASRadioInterfaces_UMTS ) != mServiceSignals.end()) |
| 966 |
{ |
| 967 |
preferredRadioIf = eQMINASRadioInterfaces_UMTS; |
| 968 |
} |
| 969 |
else if (mServiceSignals.find( eQMINASRadioInterfaces_GSM ) != mServiceSignals.end()) |
| 970 |
{ |
| 971 |
preferredRadioIf = eQMINASRadioInterfaces_GSM; |
| 972 |
} |
| 973 |
|
| 974 |
radioStr = "Unknown"; |
| 975 |
ssStr = "Unknown"; |
| 976 |
radioVal = eQMINASRadioInterfaces_NoneNoService; |
| 977 |
|
| 978 |
// Determine sig strength and radio interface to display based on |
| 979 |
// most preferred data capabilities |
| 980 |
switch (preferredRadioIf) |
| 981 |
{ |
| 982 |
case eQMINASRadioInterfaces_CDMA2000HRPD: |
| 983 |
radioStr = "CDMA 1xEVDO"; |
| 984 |
if ( (mostPreferredCap == eQMINASDataServiceCapabilities2_CDMA1xEVDORevB) |
| 985 |
|| (mostPreferredCap == eQMINASDataServiceCapabilities2_CDMA1xEVDORevA) |
| 986 |
|| (mostPreferredCap == eQMINASDataServiceCapabilities2_CDMA1xEVDORev0) ) |
| 987 |
{ |
| 988 |
radioVal = eQMINASRadioInterfaces_CDMA2000HRPD; |
| 989 |
if ( (mServiceSignals.find( radioVal ) != mServiceSignals.end()) |
| 990 |
&& (mServiceSignals[radioVal] != SCHAR_MAX) ) |
| 991 |
{ |
| 992 |
std::ostringstream temp; |
| 993 |
temp << (INT)mServiceSignals[radioVal]; |
| 994 |
ssStr = temp.str(); |
| 995 |
} |
| 996 |
} |
| 997 |
break; |
| 998 |
|
| 999 |
case eQMINASRadioInterfaces_CDMA20001x: |
| 1000 |
radioStr = "CDMA 1xRTT"; |
| 1001 |
if (mostPreferredCap == eQMINASDataServiceCapabilities2_CDMA) |
| 1002 |
{ |
| 1003 |
radioVal = eQMINASRadioInterfaces_CDMA20001x; |
| 1004 |
if ( (mServiceSignals.find( radioVal ) != mServiceSignals.end()) |
| 1005 |
&& (mServiceSignals[radioVal] != SCHAR_MAX) ) |
| 1006 |
{ |
| 1007 |
std::ostringstream temp; |
| 1008 |
temp << (INT)mServiceSignals[radioVal]; |
| 1009 |
ssStr = temp.str(); |
| 1010 |
} |
| 1011 |
} |
| 1012 |
break; |
| 1013 |
|
| 1014 |
case eQMINASRadioInterfaces_UMTS: |
| 1015 |
radioStr = "WCDMA"; |
| 1016 |
if ( (mostPreferredCap == eQMINASDataServiceCapabilities2_DCHSDPAPlus) |
| 1017 |
|| (mostPreferredCap == eQMINASDataServiceCapabilities2_HSDPAPlus) |
| 1018 |
|| (mostPreferredCap == eQMINASDataServiceCapabilities2_HSDPA) |
| 1019 |
|| (mostPreferredCap == eQMINASDataServiceCapabilities2_HSUPA) |
| 1020 |
|| (mostPreferredCap == eQMINASDataServiceCapabilities2_WCDMA) ) |
| 1021 |
{ |
| 1022 |
radioVal = eQMINASRadioInterfaces_UMTS; |
| 1023 |
if ( (mServiceSignals.find( radioVal ) != mServiceSignals.end()) |
| 1024 |
&& (mServiceSignals[radioVal] != SCHAR_MAX) ) |
| 1025 |
{ |
| 1026 |
std::ostringstream temp; |
| 1027 |
temp << (INT)mServiceSignals[radioVal]; |
| 1028 |
ssStr = temp.str(); |
| 1029 |
} |
| 1030 |
} |
| 1031 |
break; |
| 1032 |
|
| 1033 |
case eQMINASRadioInterfaces_GSM: |
| 1034 |
radioStr = "GSM"; |
| 1035 |
if ( (mostPreferredCap == eQMINASDataServiceCapabilities2_GPRS) |
| 1036 |
|| (mostPreferredCap == eQMINASDataServiceCapabilities2_EGPRS) |
| 1037 |
|| (mostPreferredCap == eQMINASDataServiceCapabilities2_GSM) ) |
| 1038 |
{ |
| 1039 |
radioVal = eQMINASRadioInterfaces_GSM; |
| 1040 |
if ( (mServiceSignals.find( radioVal ) != mServiceSignals.end()) |
| 1041 |
&& (mServiceSignals[radioVal] != SCHAR_MAX) ) |
| 1042 |
{ |
| 1043 |
std::ostringstream temp; |
| 1044 |
temp << (INT)mServiceSignals[radioVal]; |
| 1045 |
ssStr = temp.str(); |
| 1046 |
} |
| 1047 |
} |
| 1048 |
break; |
| 1049 |
|
| 1050 |
case eQMINASRadioInterfaces_LTE: |
| 1051 |
radioStr = "LTE"; |
| 1052 |
if (mostPreferredCap == eQMINASDataServiceCapabilities2_LTE) |
| 1053 |
{ |
| 1054 |
radioVal = eQMINASRadioInterfaces_LTE; |
| 1055 |
if ( (mServiceSignals.find( radioVal ) != mServiceSignals.end()) |
| 1056 |
&& (mServiceSignals[radioVal] != SCHAR_MAX) ) |
| 1057 |
{ |
| 1058 |
std::ostringstream temp; |
| 1059 |
temp << (INT)mServiceSignals[radioVal]; |
| 1060 |
ssStr = temp.str(); |
| 1061 |
} |
| 1062 |
} |
| 1063 |
break; |
| 1064 |
|
| 1065 |
case eQMINASRadioInterfaces_NoneNoService: |
| 1066 |
if ( (mServiceSignals.find( eQMINASRadioInterfaces_CDMA2000HRPD ) != mServiceSignals.end()) |
| 1067 |
&& (mServiceSignals[eQMINASRadioInterfaces_CDMA2000HRPD] != SCHAR_MAX) ) |
| 1068 |
{ |
| 1069 |
radioStr = "CDMA 1xEVDO"; |
| 1070 |
std::ostringstream temp; |
| 1071 |
temp << (INT)mServiceSignals[eQMINASRadioInterfaces_CDMA2000HRPD]; |
| 1072 |
ssStr = temp.str(); |
| 1073 |
} |
| 1074 |
else if ( (mServiceSignals.find( eQMINASRadioInterfaces_CDMA20001x ) != mServiceSignals.end()) |
| 1075 |
&& (mServiceSignals[eQMINASRadioInterfaces_CDMA20001x] != SCHAR_MAX) ) |
| 1076 |
{ |
| 1077 |
radioStr = "CDMA 1xRTT"; |
| 1078 |
std::ostringstream temp; |
| 1079 |
temp << (INT)mServiceSignals[eQMINASRadioInterfaces_CDMA20001x]; |
| 1080 |
ssStr = temp.str(); |
| 1081 |
} |
| 1082 |
else if ( (mServiceSignals.find( eQMINASRadioInterfaces_UMTS ) != mServiceSignals.end()) |
| 1083 |
&& (mServiceSignals[eQMINASRadioInterfaces_UMTS] != SCHAR_MAX) ) |
| 1084 |
{ |
| 1085 |
radioStr = "WCDMA"; |
| 1086 |
std::ostringstream temp; |
| 1087 |
temp << (INT)mServiceSignals[eQMINASRadioInterfaces_UMTS]; |
| 1088 |
ssStr = temp.str(); |
| 1089 |
} |
| 1090 |
else if ( (mServiceSignals.find( eQMINASRadioInterfaces_GSM ) != mServiceSignals.end()) |
| 1091 |
&& (mServiceSignals[eQMINASRadioInterfaces_GSM] != SCHAR_MAX) ) |
| 1092 |
{ |
| 1093 |
radioStr = "GSM"; |
| 1094 |
std::ostringstream temp; |
| 1095 |
temp << (INT)mServiceSignals[eQMINASRadioInterfaces_GSM]; |
| 1096 |
ssStr = temp.str(); |
| 1097 |
} |
| 1098 |
else if ( (mServiceSignals.find( eQMINASRadioInterfaces_LTE ) != mServiceSignals.end()) |
| 1099 |
&& (mServiceSignals[eQMINASRadioInterfaces_LTE] != SCHAR_MAX) ) |
| 1100 |
{ |
| 1101 |
radioStr = "LTE"; |
| 1102 |
std::ostringstream temp; |
| 1103 |
temp << (INT)mServiceSignals[eQMINASRadioInterfaces_LTE]; |
| 1104 |
ssStr = temp.str(); |
| 1105 |
} |
| 1106 |
break; |
| 1107 |
|
| 1108 |
default: |
| 1109 |
radioStr = "Unknown"; |
| 1110 |
ssStr = "Unknown"; |
| 1111 |
} |
| 1112 |
} |
| 1113 |
|
| 1114 |
SetRSSI( ssStr ); |
| 1115 |
SetTech( radioStr ); |
| 1116 |
} |
| 1117 |
|
| 1118 |
/*=========================================================================== |
| 1119 |
METHOD: |
| 1120 |
UpdateSessionState (Public Method) |
| 1121 |
|
| 1122 |
DESCRIPTION: |
| 1123 |
Update the session state display |
| 1124 |
Start/stop UpdateNetworkInfo thread |
| 1125 |
|
| 1126 |
PARAMETERS: |
| 1127 |
bExternal [ I ] - Was the state change triggered externally |
| 1128 |
state [ I ] - State of session |
| 1129 |
|
| 1130 |
RETURN VALUE: |
| 1131 |
None |
| 1132 |
===========================================================================*/ |
| 1133 |
void cSampleCM::UpdateSessionState( |
| 1134 |
bool bExternal, |
| 1135 |
ULONG state ) |
| 1136 |
{ |
| 1137 |
mSessionState = state; |
| 1138 |
|
| 1139 |
if (bExternal == true) |
| 1140 |
{ |
| 1141 |
mInitialState = state; |
| 1142 |
} |
| 1143 |
|
| 1144 |
LPCSTR pState = "Unknown"; |
| 1145 |
switch (state) |
| 1146 |
{ |
| 1147 |
// Disconnected |
| 1148 |
case 1: |
| 1149 |
{ |
| 1150 |
pState = "Disconnected"; |
| 1151 |
|
| 1152 |
// Stop the network info thread, if running |
| 1153 |
if (mUpdateNetworkInfoThreadID != 0) |
| 1154 |
{ |
| 1155 |
mUpdateNetworkInfoEvent.Set( 0 ); |
| 1156 |
|
| 1157 |
pthread_join( mUpdateNetworkInfoThreadID, NULL ); |
| 1158 |
mUpdateNetworkInfoThreadID = 0; |
| 1159 |
|
| 1160 |
mLifeTotalDuration += mTotalDuration; |
| 1161 |
} |
| 1162 |
|
| 1163 |
// Reset all totals |
| 1164 |
mPreviousRX = 0; |
| 1165 |
mPreviousTX = 0; |
| 1166 |
mTotalRX = 0; |
| 1167 |
mTotalTX = 0; |
| 1168 |
mTotalDuration = 0; |
| 1169 |
mStartTime = 0; |
| 1170 |
|
| 1171 |
UpdateRateDisplay(); |
| 1172 |
UpdateTimeDisplay(); |
| 1173 |
} |
| 1174 |
break; |
| 1175 |
|
| 1176 |
// Connected |
| 1177 |
case 2: |
| 1178 |
{ |
| 1179 |
if (bExternal == true) |
| 1180 |
{ |
| 1181 |
pState = "External Con"; |
| 1182 |
} |
| 1183 |
else |
| 1184 |
{ |
| 1185 |
pState = "Connected"; |
| 1186 |
} |
| 1187 |
|
| 1188 |
// Start the network info thread, if not running |
| 1189 |
if (mUpdateNetworkInfoThreadID == 0) |
| 1190 |
{ |
| 1191 |
// Begin updating network info |
| 1192 |
int rc = pthread_create( &mUpdateNetworkInfoThreadID, |
| 1193 |
0, |
| 1194 |
UpdateNetworkInfoThread, |
| 1195 |
this ); |
| 1196 |
if (rc != 0) |
| 1197 |
{ |
| 1198 |
TRACE( "error starting network info thread\n" ); |
| 1199 |
} |
| 1200 |
} |
| 1201 |
} |
| 1202 |
break; |
| 1203 |
|
| 1204 |
// Suspended |
| 1205 |
case 3: |
| 1206 |
pState = "Suspended"; |
| 1207 |
break; |
| 1208 |
|
| 1209 |
// Connecting |
| 1210 |
case 4: |
| 1211 |
if (bExternal == true) |
| 1212 |
{ |
| 1213 |
pState = "Ext Connecting"; |
| 1214 |
} |
| 1215 |
else |
| 1216 |
{ |
| 1217 |
pState = "Connecting"; |
| 1218 |
} |
| 1219 |
break; |
| 1220 |
} |
| 1221 |
|
| 1222 |
SetState( pState ); |
| 1223 |
} |
| 1224 |
|
| 1225 |
/*=========================================================================== |
| 1226 |
METHOD: |
| 1227 |
UpdateRateDisplay (Public Method) |
| 1228 |
|
| 1229 |
DESCRIPTION: |
| 1230 |
Calculate and update the tx, rx rates being displayed |
| 1231 |
|
| 1232 |
PARAMETERS: |
| 1233 |
None |
| 1234 |
|
| 1235 |
RETURN VALUE: |
| 1236 |
None |
| 1237 |
===========================================================================*/ |
| 1238 |
void cSampleCM::UpdateRateDisplay() |
| 1239 |
{ |
| 1240 |
// Update TX/RX Bytes |
| 1241 |
ULONGLONG deltaRX = 0; |
| 1242 |
ULONGLONG deltaTX = 0; |
| 1243 |
|
| 1244 |
// Only update rates if connected |
| 1245 |
if (mSessionState == eQMIConnectionStatus_Connected) |
| 1246 |
{ |
| 1247 |
// First time through, don't use the deltas |
| 1248 |
if (mTotalRX != 0) |
| 1249 |
{ |
| 1250 |
deltaRX = mTotalRX - mPreviousRX; |
| 1251 |
} |
| 1252 |
|
| 1253 |
if (mTotalTX != 0) |
| 1254 |
{ |
| 1255 |
deltaTX = mTotalTX - mPreviousTX; |
| 1256 |
} |
| 1257 |
|
| 1258 |
// Update life total byte variables |
| 1259 |
mLifeTotalRX += deltaRX; |
| 1260 |
mLifeTotalTX += deltaTX; |
| 1261 |
|
| 1262 |
mPreviousRX = mTotalRX; |
| 1263 |
mPreviousTX = mTotalTX; |
| 1264 |
} |
| 1265 |
|
| 1266 |
std::ostringstream tmp; |
| 1267 |
tmp << deltaRX; |
| 1268 |
SetRx( tmp.str() ); |
| 1269 |
|
| 1270 |
tmp.str( "" ); |
| 1271 |
tmp << deltaTX; |
| 1272 |
SetTx( tmp.str() ); |
| 1273 |
|
| 1274 |
tmp.str( "" ); |
| 1275 |
tmp << mLifeTotalRX; |
| 1276 |
SetLifeRx( tmp.str() ); |
| 1277 |
|
| 1278 |
tmp.str( "" ); |
| 1279 |
tmp << mLifeTotalTX; |
| 1280 |
SetLifeTx( tmp.str() ); |
| 1281 |
} |
| 1282 |
|
| 1283 |
/*=========================================================================== |
| 1284 |
METHOD: |
| 1285 |
UpdateTimeDisplay (Public Method) |
| 1286 |
|
| 1287 |
DESCRIPTION: |
| 1288 |
Calculate and update the connection time being displayed |
| 1289 |
|
| 1290 |
PARAMETERS: |
| 1291 |
None |
| 1292 |
|
| 1293 |
RETURN VALUE: |
| 1294 |
None |
| 1295 |
===========================================================================*/ |
| 1296 |
void cSampleCM::UpdateTimeDisplay() |
| 1297 |
{ |
| 1298 |
DWORD elapsedTime = 0; |
| 1299 |
DWORD lifeTotalTime = 0; |
| 1300 |
|
| 1301 |
// Update session duration |
| 1302 |
if ( (mSessionState == eQMIConnectionStatus_Connected) |
| 1303 |
&& (mStartTime != 0) ) |
| 1304 |
{ |
| 1305 |
// Convert ms to seconds |
| 1306 |
mTotalDuration = (GetTickCount() - mStartTime) / 1000; |
| 1307 |
elapsedTime = (DWORD)mTotalDuration; |
| 1308 |
lifeTotalTime = (DWORD)(mLifeTotalDuration + mTotalDuration); |
| 1309 |
} |
| 1310 |
else |
| 1311 |
{ |
| 1312 |
elapsedTime = 0; |
| 1313 |
lifeTotalTime = (DWORD)mLifeTotalDuration; |
| 1314 |
} |
| 1315 |
|
| 1316 |
std::ostringstream timeStr; |
| 1317 |
|
| 1318 |
// Format both into hh:mm:ss |
| 1319 |
// "%02d:%02d:%02d" |
| 1320 |
timeStr << std::setfill( '0' ) << std::setw( 2 ) << (elapsedTime / 3600) % 60 |
| 1321 |
<< std::setw( 1 ) << ":" |
| 1322 |
<< std::setfill( '0' ) << std::setw( 2 ) << (elapsedTime / 60) % 60 |
| 1323 |
<< std::setw( 1 ) << ":" |
| 1324 |
<< std::setfill( '0' ) << std::setw( 2 ) << elapsedTime % 60; |
| 1325 |
SetDuration( timeStr.str() ); |
| 1326 |
|
| 1327 |
timeStr.str( "" ); |
| 1328 |
timeStr << std::setfill( '0' ) << std::setw( 2 ) << (lifeTotalTime / 3600) % 60 |
| 1329 |
<< std::setw( 1 ) << ":" |
| 1330 |
<< std::setfill( '0' ) << std::setw( 2 ) << (lifeTotalTime / 60) % 60 |
| 1331 |
<< std::setw( 1 ) << ":" |
| 1332 |
<< std::setfill( '0' ) << std::setw( 2 ) << lifeTotalTime % 60; |
| 1333 |
SetLifeDuration( timeStr.str() ); |
| 1334 |
} |
| 1335 |
|
| 1336 |
/*=========================================================================== |
| 1337 |
METHOD: |
| 1338 |
CheckConnectedStats (Public Method) |
| 1339 |
|
| 1340 |
DESCRIPTION: |
| 1341 |
Check stats which are only valid during a connection |
| 1342 |
===========================================================================*/ |
| 1343 |
void cSampleCM::CheckConnectedStats() |
| 1344 |
{ |
| 1345 |
ULONG rc = mGobi.GetDataBearerTechnology( &mDataBearerTech ); |
| 1346 |
if (rc != eGOBI_ERR_NONE || mDataBearerTech == ULONG_MAX) |
| 1347 |
{ |
| 1348 |
TRACE( "GetDataBearerTechnology error %lu\n", rc ); |
| 1349 |
return; |
| 1350 |
} |
| 1351 |
|
| 1352 |
ULONGLONG duration; |
| 1353 |
rc = mGobi.GetSessionDuration( &duration ); |
| 1354 |
if (rc != eGOBI_ERR_NONE) |
| 1355 |
{ |
| 1356 |
TRACE( "GetSessionDuration error %lu\n", rc ); |
| 1357 |
return; |
| 1358 |
} |
| 1359 |
|
| 1360 |
mStartTime = GetTickCount() - duration; |
| 1361 |
|
| 1362 |
UpdateSignalAndTech(); |
| 1363 |
} |
| 1364 |
|
| 1365 |
/*=========================================================================== |
| 1366 |
METHOD: |
| 1367 |
UpdateDeviceInfo (Public Method) |
| 1368 |
|
| 1369 |
DESCRIPTION: |
| 1370 |
Update the device info stats |
| 1371 |
===========================================================================*/ |
| 1372 |
void cSampleCM::UpdateDeviceInfo() |
| 1373 |
{ |
| 1374 |
ULONG status = 0; |
| 1375 |
|
| 1376 |
BYTE strSz1 = 255; |
| 1377 |
BYTE strSz2 = 255; |
| 1378 |
BYTE strSz3 = 255; |
| 1379 |
CHAR str1[255]; |
| 1380 |
CHAR str2[255]; |
| 1381 |
CHAR str3[255]; |
| 1382 |
str1[0] = 0; |
| 1383 |
str2[0] = 0; |
| 1384 |
str3[0] = 0; |
| 1385 |
|
| 1386 |
// Get manufacturer |
| 1387 |
status = mGobi.GetManufacturer( strSz1, str1 ); |
| 1388 |
if (status != 0) |
| 1389 |
{ |
| 1390 |
TRACE( "GetManufacturer() = %lu\n", status ); |
| 1391 |
return; |
| 1392 |
} |
| 1393 |
|
| 1394 |
if (str1[0] != 0) |
| 1395 |
{ |
| 1396 |
SetManufact( &str1[0] ); |
| 1397 |
} |
| 1398 |
|
| 1399 |
// Get model ID |
| 1400 |
str1[0] = 0; |
| 1401 |
status = mGobi.GetModelID( strSz1, str1 ); |
| 1402 |
if (status != 0) |
| 1403 |
{ |
| 1404 |
TRACE( "GetModelID() = %lu\n", status ); |
| 1405 |
return; |
| 1406 |
} |
| 1407 |
|
| 1408 |
if (str1[0] != 0) |
| 1409 |
{ |
| 1410 |
std::ostringstream tmp; |
| 1411 |
if (strncmp( "88", &str1[0], 2 ) == 0) |
| 1412 |
{ |
| 1413 |
tmp << "Gobi MDM-1000"; |
| 1414 |
} |
| 1415 |
else if (strncmp( "12", &str1[0], 2 ) == 0) |
| 1416 |
{ |
| 1417 |
tmp << "Gobi MDM-2000"; |
| 1418 |
} |
| 1419 |
else |
| 1420 |
{ |
| 1421 |
tmp << "Unknown (" << &str1[0] << ")"; |
| 1422 |
} |
| 1423 |
|
| 1424 |
SetModel( tmp.str() ); |
| 1425 |
} |
| 1426 |
|
| 1427 |
// Get firmware revision |
| 1428 |
str1[0] = 0; |
| 1429 |
status = mGobi.GetFirmwareRevision( strSz1, str1 ); |
| 1430 |
if (status != 0) |
| 1431 |
{ |
| 1432 |
TRACE( "GetFirmwareRevision() = %lu\n", status ); |
| 1433 |
return; |
| 1434 |
} |
| 1435 |
|
| 1436 |
if (str1[0] != 0) |
| 1437 |
{ |
| 1438 |
SetFirmware( &str1[0] ); |
| 1439 |
} |
| 1440 |
|
| 1441 |
// Get hardware revision |
| 1442 |
str1[0] = 0; |
| 1443 |
status = mGobi.GetHardwareRevision( strSz1, str1 ); |
| 1444 |
if (status != 0) |
| 1445 |
{ |
| 1446 |
TRACE( "GetHardwareRevision() = %lu\n", status ); |
| 1447 |
return; |
| 1448 |
} |
| 1449 |
|
| 1450 |
if (str1[0] != 0) |
| 1451 |
{ |
| 1452 |
SetHardware( &str1[0] ); |
| 1453 |
} |
| 1454 |
|
| 1455 |
// Get MDN/MIN |
| 1456 |
str1[0] = 0; |
| 1457 |
str2[0] = 0; |
| 1458 |
status = mGobi.GetVoiceNumber( strSz1, str1, strSz2, str2 ); |
| 1459 |
if (status != 0) |
| 1460 |
{ |
| 1461 |
if (status == 1016) |
| 1462 |
{ |
| 1463 |
// Not provisioned |
| 1464 |
SetMDN( "Not provisioned" ); |
| 1465 |
SetMIN( "Not provisioned" ); |
| 1466 |
} |
| 1467 |
else |
| 1468 |
{ |
| 1469 |
TRACE( "GetVoiceNumber() = %lu\n", status ); |
| 1470 |
return; |
| 1471 |
} |
| 1472 |
} |
| 1473 |
|
| 1474 |
if (str1[0] != 0) |
| 1475 |
{ |
| 1476 |
SetMDN( &str1[0] ); |
| 1477 |
} |
| 1478 |
|
| 1479 |
if (str2[0] != 0) |
| 1480 |
{ |
| 1481 |
SetMIN( &str2[0] ); |
| 1482 |
} |
| 1483 |
|
| 1484 |
// Get ESN/IMEI/MEID |
| 1485 |
str1[0] = 0; |
| 1486 |
str2[0] = 0; |
| 1487 |
str3[0] = 0; |
| 1488 |
status = mGobi.GetSerialNumbers( strSz1, |
| 1489 |
str1, |
| 1490 |
strSz2, |
| 1491 |
str2, |
| 1492 |
strSz3, |
| 1493 |
str3 ); |
| 1494 |
if (status != 0) |
| 1495 |
{ |
| 1496 |
if (status == 1016) |
| 1497 |
{ |
| 1498 |
// Not provisioned |
| 1499 |
SetESN( "Not provisioned" ); |
| 1500 |
SetIMEI( "Not provisioned" ); |
| 1501 |
SetMEID( "Not provisioned" ); |
| 1502 |
} |
| 1503 |
else |
| 1504 |
{ |
| 1505 |
TRACE( "GetSerialNumbers() = %lu\n", status ); |
| 1506 |
return; |
| 1507 |
} |
| 1508 |
} |
| 1509 |
|
| 1510 |
if (str1[0] != 0) |
| 1511 |
{ |
| 1512 |
SetESN( &str1[0] ); |
| 1513 |
} |
| 1514 |
|
| 1515 |
if (str2[0] != 0) |
| 1516 |
{ |
| 1517 |
SetIMEI( &str2[0] ); |
| 1518 |
} |
| 1519 |
|
| 1520 |
if (str3[0] != 0) |
| 1521 |
{ |
| 1522 |
SetMEID( &str3[0] ); |
| 1523 |
} |
| 1524 |
|
| 1525 |
// Get IMSI |
| 1526 |
str1[0] = 0; |
| 1527 |
status = mGobi.GetIMSI( strSz1, str1 ); |
| 1528 |
if (status != 0) |
| 1529 |
{ |
| 1530 |
if (status == 1016) |
| 1531 |
{ |
| 1532 |
// Not provisioned |
| 1533 |
SetIMSI( "Not provisioned" ); |
| 1534 |
} |
| 1535 |
else |
| 1536 |
{ |
| 1537 |
TRACE( "GetIMSI() = %lu\n", status ); |
| 1538 |
return; |
| 1539 |
} |
| 1540 |
} |
| 1541 |
|
| 1542 |
if (str1[0] != 0) |
| 1543 |
{ |
| 1544 |
SetIMSI( &str1[0] ); |
| 1545 |
} |
| 1546 |
} |
| 1547 |
|
| 1548 |
/*=========================================================================== |
| 1549 |
METHOD: |
| 1550 |
UpdateConnectionInfo (Public Method) |
| 1551 |
|
| 1552 |
DESCRIPTION: |
| 1553 |
Update the connection info stats |
| 1554 |
===========================================================================*/ |
| 1555 |
void cSampleCM::UpdateConnectionInfo() |
| 1556 |
{ |
| 1557 |
// Re-usable buffer |
| 1558 |
std::ostringstream tmp; |
| 1559 |
|
| 1560 |
// Get session state |
| 1561 |
ULONG rc = mGobi.GetSessionState( &mSessionState ); |
| 1562 |
if (rc != eGOBI_ERR_NONE || mSessionState == ULONG_MAX) |
| 1563 |
{ |
| 1564 |
TRACE( "GetSessionState error %lu\n", rc ); |
| 1565 |
return; |
| 1566 |
} |
| 1567 |
|
| 1568 |
UpdateSessionState( mSessionID != 0xFFFFFFFF, mSessionState ); |
| 1569 |
|
| 1570 |
// If connected, refresh data bearer technology and session duration |
| 1571 |
if (mSessionState == eQMIConnectionStatus_Connected) |
| 1572 |
{ |
| 1573 |
CheckConnectedStats(); |
| 1574 |
} |
| 1575 |
|
| 1576 |
INT8 signalStrengths[MAX_SIGNALS]; |
| 1577 |
ULONG radioInterfaces[MAX_SIGNALS]; |
| 1578 |
|
| 1579 |
// Get the signal strengths |
| 1580 |
rc = mGobi.GetSignalStrengths( &signalStrengths[0], |
| 1581 |
&radioInterfaces[0] ); |
| 1582 |
if (rc != eGOBI_ERR_NONE && rc != eGOBI_ERR_NO_SIGNAL) |
| 1583 |
{ |
| 1584 |
TRACE( "GetSignalStrengths error %lu\n", rc ); |
| 1585 |
return; |
| 1586 |
} |
| 1587 |
|
| 1588 |
// Map signal strengths to RadioIf types |
| 1589 |
for (ULONG s = 0; s < MAX_SIGNALS; s++) |
| 1590 |
{ |
| 1591 |
INT8 signal = signalStrengths[s]; |
| 1592 |
|
| 1593 |
switch (radioInterfaces[s]) |
| 1594 |
{ |
| 1595 |
case eQMINASRadioInterfaces_NoneNoService: |
| 1596 |
mServiceSignals[eQMINASRadioInterfaces_NoneNoService] = signal; |
| 1597 |
break; |
| 1598 |
|
| 1599 |
case eQMINASRadioInterfaces_CDMA20001x: |
| 1600 |
mServiceSignals[eQMINASRadioInterfaces_CDMA20001x] = signal; |
| 1601 |
break; |
| 1602 |
|
| 1603 |
case eQMINASRadioInterfaces_CDMA2000HRPD: |
| 1604 |
mServiceSignals[eQMINASRadioInterfaces_CDMA2000HRPD] = signal; |
| 1605 |
break; |
| 1606 |
|
| 1607 |
case eQMINASRadioInterfaces_AMPS: |
| 1608 |
mServiceSignals[eQMINASRadioInterfaces_AMPS] = signal; |
| 1609 |
break; |
| 1610 |
|
| 1611 |
case eQMINASRadioInterfaces_GSM: |
| 1612 |
mServiceSignals[eQMINASRadioInterfaces_GSM] = signal; |
| 1613 |
break; |
| 1614 |
|
| 1615 |
case eQMINASRadioInterfaces_UMTS: |
| 1616 |
mServiceSignals[eQMINASRadioInterfaces_UMTS] = signal; |
| 1617 |
break; |
| 1618 |
|
| 1619 |
case eQMINASRadioInterfaces_LTE: |
| 1620 |
mServiceSignals[eQMINASRadioInterfaces_LTE] = signal; |
| 1621 |
break; |
| 1622 |
} |
| 1623 |
} |
| 1624 |
|
| 1625 |
ULONG curTX = 0; |
| 1626 |
ULONG curRX = 0; |
| 1627 |
ULONG maxTX = 0; |
| 1628 |
ULONG maxRX = 0; |
| 1629 |
|
| 1630 |
// Get the connection rate |
| 1631 |
rc = mGobi.GetConnectionRate( &curTX, &curRX, &maxTX, &maxRX ); |
| 1632 |
if (rc != 0) |
| 1633 |
{ |
| 1634 |
TRACE( "GetConnectionRate error %lu\n", rc ); |
| 1635 |
return; |
| 1636 |
} |
| 1637 |
|
| 1638 |
// Store the max data rates |
| 1639 |
tmp.str( "" ); |
| 1640 |
tmp << maxRX; |
| 1641 |
SetMaxRx( tmp.str() ); |
| 1642 |
|
| 1643 |
tmp.str( "" ); |
| 1644 |
tmp << maxTX; |
| 1645 |
SetMaxTx( tmp.str() ); |
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
ULONG dataCapabilities[MAX_DATA_CAPABILITIES]; |
| 1650 |
WORD srvMCC = 0; |
| 1651 |
WORD srvMNC = 0; |
| 1652 |
BYTE srvNameSize = 255; |
| 1653 |
CHAR srvName[255]; |
| 1654 |
srvName[0] = 0; |
| 1655 |
WORD sid = 0; |
| 1656 |
WORD nid = 0; |
| 1657 |
ULONG roam = 0; |
| 1658 |
|
| 1659 |
// Get the serving network info |
| 1660 |
rc = mGobi.GetServingNetwork( &dataCapabilities[0], |
| 1661 |
&srvMCC, |
| 1662 |
&srvMNC, |
| 1663 |
srvNameSize, |
| 1664 |
&srvName[0], |
| 1665 |
&sid, |
| 1666 |
&nid, |
| 1667 |
&roam ); |
| 1668 |
if (rc != 0) |
| 1669 |
{ |
| 1670 |
TRACE( "GetServingNetwork error %lu\n", rc ); |
| 1671 |
return; |
| 1672 |
} |
| 1673 |
|
| 1674 |
// Store data capabilities |
| 1675 |
for (ULONG c = 0; c < MAX_DATA_CAPABILITIES; c++) |
| 1676 |
{ |
| 1677 |
if ( (dataCapabilities[c] != ULONG_MAX) |
| 1678 |
&& (dataCapabilities[c] != 0) ) |
| 1679 |
{ |
| 1680 |
mDataCapabilities.push_back( dataCapabilities[c] ); |
| 1681 |
} |
| 1682 |
} |
| 1683 |
|
| 1684 |
if (roam == 0xFFFFFFFF) |
| 1685 |
{ |
| 1686 |
SetRoam( "Unknown" ); |
| 1687 |
} |
| 1688 |
else |
| 1689 |
{ |
| 1690 |
tmp.str( "" ); |
| 1691 |
tmp << roam; |
| 1692 |
SetRoam( tmp.str() ); |
| 1693 |
} |
| 1694 |
|
| 1695 |
// Update the signal strength and technology fields |
| 1696 |
if (mSessionState != eQMIConnectionStatus_Connected) |
| 1697 |
{ |
| 1698 |
mDataBearerTech = 0; |
| 1699 |
} |
| 1700 |
|
| 1701 |
UpdateSignalAndTech(); |
| 1702 |
|
| 1703 |
// Setup callbacks |
| 1704 |
rc = mGobi.SetWDSEventReportCB( WDSEventReportCallback, 1 ); |
| 1705 |
if (rc != eGOBI_ERR_NONE) |
| 1706 |
{ |
| 1707 |
TRACE( "SetWDSEventReportCB error %lu\n", rc ); |
| 1708 |
return; |
| 1709 |
} |
| 1710 |
|
| 1711 |
rc = mGobi.SetWDSSessionStateCB( WDSSessionStateCallback ); |
| 1712 |
if (rc != eGOBI_ERR_NONE) |
| 1713 |
{ |
| 1714 |
TRACE( "SetWDSSessionStateCB error %lu\n", rc ); |
| 1715 |
return; |
| 1716 |
} |
| 1717 |
|
| 1718 |
BYTE thresSz = 5; |
| 1719 |
INT8 thres[5] = {-90, -85, -80, -75, -70}; |
| 1720 |
rc = mGobi.SetNASEventReportCB( NASEventReportCallback, |
| 1721 |
thresSz, |
| 1722 |
&thres[0] ); |
| 1723 |
if (rc != eGOBI_ERR_NONE) |
| 1724 |
{ |
| 1725 |
TRACE( "SetNASEventReportCB error %lu\n", rc ); |
| 1726 |
return; |
| 1727 |
} |
| 1728 |
|
| 1729 |
rc = mGobi.SetNASServingSystemCB( NASServingSystemCallback ); |
| 1730 |
if (rc != eGOBI_ERR_NONE) |
| 1731 |
{ |
| 1732 |
TRACE( "SetNASServingSystemCB error %lu\n", rc ); |
| 1733 |
return; |
| 1734 |
} |
| 1735 |
} |