Changeset 3505
- Timestamp:
- 11/25/07 21:10:02 (5 years ago)
- Location:
- trunk/src/target/OM-2007.2/libraries/libmokogsmd2
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
libmokogsmd/moko-gsmd-connection.c (modified) (19 diffs)
-
libmokogsmd/moko-gsmd-connection.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/target/OM-2007.2/libraries/libmokogsmd2/ChangeLog
r3455 r3505 1 2007-11-25 Michael Lauer <mickey@openmoko.org> 2 3 * libmokogsmd/moko-gsmd-connection.[c|h]: 4 Register network message handler with libgsmd to get 5 answers for trigger messages. 6 Keep trying to connect to gsmd, if not available on startup. 7 Add new g_signal for incoming operator name 8 9 1 10 2007-11-20 Thomas Wood <thomas@openedhand.com> 2 11 -
trunk/src/target/OM-2007.2/libraries/libmokogsmd2/libmokogsmd/moko-gsmd-connection.c
r3455 r3505 29 29 30 30 #define DEBUG_THIS_FILE 31 #undef DEBUG_THIS_FILE31 //#undef DEBUG_THIS_FILE 32 32 33 33 #ifdef DEBUG_THIS_FILE … … 41 41 #define GSMD_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MOKO_TYPE_GSMD_CONNECTION, MokoGsmdConnectionPrivate)) 42 42 43 #define MOKO_GSMD_CHECK_CONNECTION_GET_PRIV \ 44 g_return_if_fail( MOKO_IS_GSMD_CONNECTION( self ) ); \ 45 MokoGsmdConnectionPrivate* priv = GSMD_CONNECTION_GET_PRIVATE( self ); \ 46 if ( !priv->handle ) moko_gsmd_connection_init( self ); \ 47 g_return_if_fail( priv->handle ); 43 48 44 49 GQuark … … 92 97 SIGNAL_GSMD_EVT_IN_DS = 15, /* SMS Status Report */ 93 98 SIGNAL_GSMD_EVT_IN_ERROR = 16, /* CME/CMS error */ 99 100 SIGNAL_GSMD_NET_CURRENT_OPERATOR = 100, /* Current Operator */ 101 94 102 LAST_SIGNAL, 95 103 }; … … 242 250 //TODO add SIGNAL_GSMD_EVT_IN_DS = 15, /* SMS Status Report */ 243 251 244 moko_gsmd_connection_signals[SIGNAL_GSMD_EVT_ OUT_STATUS] = g_signal_new252 moko_gsmd_connection_signals[SIGNAL_GSMD_EVT_IN_ERROR] = g_signal_new 245 253 ("cme-cms-error", 246 254 G_TYPE_FROM_CLASS (klass), … … 255 263 NULL ); 256 264 265 moko_gsmd_connection_signals[SIGNAL_GSMD_NET_CURRENT_OPERATOR] = g_signal_new 266 ("network-current-operator", 267 G_TYPE_FROM_CLASS (klass), 268 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 269 G_STRUCT_OFFSET (MokoGsmdConnectionClass, network_current_operator), 270 NULL, 271 NULL, 272 g_cclosure_marshal_VOID__STRING, 273 G_TYPE_NONE, 274 1, 275 G_TYPE_STRING, 276 NULL); 277 278 257 279 /* virtual methods */ 258 280 … … 299 321 if ( size < 0 ) 300 322 { 301 g_warning( "moko_gsmd_connection_source_dispatch:%s %s", 302 "read error from libgsmd:", 303 strerror( errno ) ); 323 g_warning( "moko_gsmd_connection_source_dispatch:%s %s", "read error from libgsmd:", strerror( errno ) ); 304 324 } 305 325 else … … 313 333 } 314 334 315 int 316 _moko_gsmd_connection_eventhandler (struct lgsm_handle *lh, 317 int evt_type, 318 struct gsmd_evt_auxdata *aux) 335 static int net_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) 336 { 337 printf( "=================== new code here ==========================\n"); 338 339 moko_debug( "moko_gsmd_connection_network_eventhandler type = %d", gmh->msg_subtype ); 340 MokoGsmdConnection* self = moko_gsmd_connection_instance; 341 342 struct gsmd_msg_auxdata* aux = (struct gsmd_msg_auxdata*) ((void *) gmh + sizeof(*gmh)); 343 344 switch ( gmh->msg_subtype ) 345 { 346 case GSMD_NETWORK_SIGQ_GET: 347 g_signal_emit( G_OBJECT(self), 348 moko_gsmd_connection_signals[SIGNAL_GSMD_EVT_SIGNAL], 349 0, 350 aux->u.signal.sigq.rssi ); 351 break; 352 case GSMD_NETWORK_OPER_GET: 353 g_signal_emit( G_OBJECT(self), 354 moko_gsmd_connection_signals[SIGNAL_GSMD_NET_CURRENT_OPERATOR], 355 0, 356 aux->u.current_operator.name ); 357 break; 358 } 359 printf( "=================== old code here ==========================\n"); 360 361 const struct gsmd_signal_quality *sq = (struct gsmd_signal_quality *) 362 ((void *) gmh + sizeof(*gmh)); 363 const char *oper = (char *) gmh + sizeof(*gmh); 364 const struct gsmd_msg_oper *opers = (struct gsmd_msg_oper *) 365 ((void *) gmh + sizeof(*gmh)); 366 const struct gsmd_own_number *num = (struct gsmd_own_number *) 367 ((void *) gmh + sizeof(*gmh)); 368 static const char *oper_stat[] = { 369 [GSMD_OPER_UNKNOWN] = "of unknown status", 370 [GSMD_OPER_AVAILABLE] = "available", 371 [GSMD_OPER_CURRENT] = "our current operator", 372 [GSMD_OPER_FORBIDDEN] = "forbidden", 373 }; 374 static const char *srvname[] = { 375 [GSMD_SERVICE_ASYNC_MODEM] = "asynchronous modem", 376 [GSMD_SERVICE_SYNC_MODEM] = "synchronous modem", 377 [GSMD_SERVICE_PAD_ACCESS] = "PAD Access (asynchronous)", 378 [GSMD_SERVICE_PACKET_ACCESS] = "Packet Access (synchronous)", 379 [GSMD_SERVICE_VOICE] = "voice", 380 [GSMD_SERVICE_FAX] = "fax", 381 }; 382 383 //printf( "a = %p, b = %p\n", (void*)aux->u.current_operator.name, oper ); 384 385 switch (gmh->msg_subtype) 386 { 387 case GSMD_NETWORK_SIGQ_GET: 388 if (sq->rssi == 99) 389 printf("Signal undetectable\n"); 390 else 391 printf("Signal quality %i dBm\n", -113 + sq->rssi * 2); 392 if (sq->ber == 99) 393 printf("Error rate undetectable\n"); 394 else 395 printf("Bit error rate %i\n", sq->ber); 396 break; 397 case GSMD_NETWORK_OPER_GET: 398 if (oper[0]) 399 printf("Our current operator is %s\n", oper); 400 else 401 printf("No current operator\n"); 402 break; 403 case GSMD_NETWORK_OPER_LIST: 404 for (; !opers->is_last; opers ++) 405 printf("%8.*s %16.*s, %.*s for short, is %s\n", 406 sizeof(opers->opname_num), 407 opers->opname_num, 408 sizeof(opers->opname_longalpha), 409 opers->opname_longalpha, 410 sizeof(opers->opname_shortalpha), 411 opers->opname_shortalpha, 412 oper_stat[opers->stat]); 413 break; 414 case GSMD_NETWORK_GET_NUMBER: 415 printf("\t%s\t%10s%s%s%s\n", num->addr.number, num->name, 416 (num->service == GSMD_SERVICE_UNKNOWN) ? 417 "" : " related to ", 418 (num->service == GSMD_SERVICE_UNKNOWN) ? 419 "" : srvname[num->service], 420 (num->service == GSMD_SERVICE_UNKNOWN) ? 421 "" : " services"); 422 break; 423 default: 424 return -EINVAL; 425 } 426 } 427 428 int 429 _moko_gsmd_connection_eventhandler (struct lgsm_handle *lh, int evt_type, struct gsmd_evt_auxdata *aux) 319 430 { 320 431 moko_debug( "moko_gsmd_connection_eventhandler type = %d", evt_type ); … … 410 521 } 411 522 412 static void 413 moko_gsmd_connection_init(MokoGsmdConnection* self) 414 { 415 moko_debug( "moko_gsmd_connection_init" ); 416 /* fail here on more than one MokoGsmdConnection object per process */ 417 g_assert( !moko_gsmd_connection_instance); 418 419 moko_gsmd_connection_instance = self; 420 523 static gboolean 524 moko_gsmd_connection_try_connect(MokoGsmdConnection* self) 525 { 526 moko_debug( "moko_gsmd_connection_try_reconnect" ); 421 527 MokoGsmdConnectionPrivate* priv = GSMD_CONNECTION_GET_PRIVATE(self); 422 528 … … 431 537 "can't connect to gsmd. You won't receive any events." ); 432 538 433 return ;539 return TRUE; // can't connect, please call me again 434 540 } 435 541 } … … 447 553 }; 448 554 449 priv->source = (MokoGsmdConnectionSource*) g_source_new( &funcs, 450 sizeof( MokoGsmdConnectionSource) );555 priv->source = (MokoGsmdConnectionSource*) g_source_new( &funcs, 556 sizeof( MokoGsmdConnectionSource) ); 451 557 priv->source->handle = priv->handle; 452 558 priv->source->pollfd.fd = lgsm_fd( priv->handle ); … … 459 565 for ( int i = GSMD_EVT_IN_CALL; i < __NUM_GSMD_EVT; ++i ) 460 566 { 461 rc |= lgsm_evt_handler_register( priv->handle, i, 567 rc |= lgsm_evt_handler_register( priv->handle, i, 462 568 _moko_gsmd_connection_eventhandler ); 463 569 moko_debug( "-- registered for event %d, return code %d", i, rc ); … … 465 571 466 572 lgsm_register_handler( priv->handle, GSMD_MSG_PASSTHROUGH, &pt_msghandler); 573 lgsm_register_handler( priv->handle, GSMD_MSG_NETWORK, &net_msghandler); 574 575 return FALSE; // connection established, don't call again 576 } 577 578 static void 579 moko_gsmd_connection_init(MokoGsmdConnection* self) 580 { 581 moko_debug( "moko_gsmd_connection_init" ); 582 moko_gsmd_connection_instance = self; 583 584 g_timeout_add_seconds( 5, (GSourceFunc)moko_gsmd_connection_try_connect, self ); 467 585 } 468 586 … … 491 609 } 492 610 493 void 611 void 494 612 moko_gsmd_connection_send_pin(MokoGsmdConnection* self, const gchar* pin) 495 613 { … … 510 628 } 511 629 512 void 630 void 513 631 moko_gsmd_connection_network_register(MokoGsmdConnection* self) 514 632 { … … 524 642 525 643 int 526 moko_gsmd_connection_get_network_status (MokoGsmdConnection* self)644 moko_gsmd_connection_get_network_status(MokoGsmdConnection* self) 527 645 { 528 646 MokoGsmdConnectionPrivate* priv; … … 539 657 } 540 658 541 void 659 void 542 660 moko_gsmd_connection_voice_accept(MokoGsmdConnection* self) 543 661 { 544 662 MokoGsmdConnectionPrivate* priv; 545 663 546 664 g_return_if_fail ( MOKO_IS_GSMD_CONNECTION ( self ) ); 547 665 priv = GSMD_CONNECTION_GET_PRIVATE( self ); 548 666 549 667 g_return_if_fail( priv->handle ); 550 668 … … 552 670 } 553 671 554 void 672 void 555 673 moko_gsmd_connection_voice_hangup(MokoGsmdConnection* self) 556 674 { 557 675 MokoGsmdConnectionPrivate* priv; 558 676 559 677 g_return_if_fail ( MOKO_IS_GSMD_CONNECTION ( self ) ); 560 678 priv = GSMD_CONNECTION_GET_PRIVATE( self ); 561 679 562 680 g_return_if_fail( priv->handle ); 563 681 564 682 lgsm_voice_hangup( priv->handle ); 565 683 } 566 684 567 void 685 void 568 686 moko_gsmd_connection_voice_dial(MokoGsmdConnection* self, const gchar* number) 569 687 { … … 576 694 577 695 priv = GSMD_CONNECTION_GET_PRIVATE( self ); 578 696 579 697 g_return_if_fail( priv->handle ); 580 698 581 699 582 700 addr.type = 129; /* ??? */ … … 585 703 } 586 704 587 void 705 void 588 706 moko_gsmd_connection_voice_dtmf(MokoGsmdConnection* self, const gchar number) 589 707 { 590 708 MokoGsmdConnectionPrivate* priv; 591 709 592 710 g_return_if_fail ( MOKO_IS_GSMD_CONNECTION (self) ); 593 711 594 712 priv = GSMD_CONNECTION_GET_PRIVATE( self ); 595 713 596 714 g_return_if_fail( priv->handle ); 597 715 598 716 lgsm_voice_dtmf( priv->handle, number ); 599 717 } 600 718 601 void 719 void 602 720 moko_gsmd_connection_trigger_signal_strength_event(MokoGsmdConnection* self) 603 721 { 604 MokoGsmdConnectionPrivate* priv; 605 606 g_return_if_fail ( MOKO_IS_GSMD_CONNECTION (self) ); 607 608 priv = GSMD_CONNECTION_GET_PRIVATE( self ); 609 610 g_return_if_fail( priv->handle ); 611 722 MOKO_GSMD_CHECK_CONNECTION_GET_PRIV 612 723 lgsm_signal_quality( priv->handle ); 613 724 } 725 726 void 727 moko_gsmd_connection_trigger_current_operator_event(MokoGsmdConnection* self) 728 { 729 MOKO_GSMD_CHECK_CONNECTION_GET_PRIV 730 lgsm_oper_get( priv->handle ); 731 } -
trunk/src/target/OM-2007.2/libraries/libmokogsmd2/libmokogsmd/moko-gsmd-connection.h
r3377 r3505 13 13 * GNU Public License for more details. 14 14 * 15 * Current Version: $Rev$ ($Date: 2006/12/21 18:03:04 $) [$Author: mickey $]16 15 */ 17 16 … … 40 39 GObjectClass parent_class; 41 40 42 /* Voice signals */ 43 void (*incoming_call) (MokoGsmdConnection *self, int type); 44 void (*call_status_progress) (MokoGsmdConnection *self, int type); 45 void (*pin_requested) (MokoGsmdConnection *self, int type); 41 /* Call signals */ 42 void (*incoming_call) (MokoGsmdConnection* self, int type); 43 void (*call_status_progress) (MokoGsmdConnection* self, int type); 44 void (*pin_requested) (MokoGsmdConnection* self, int type); 45 void (*incoming_clip) (MokoGsmdConnection* self, const gchar* number); 46 46 47 47 /* SMS signals */ … … 49 49 /* GPRS signals */ 50 50 51 /* Misc signals */ 52 void (*incoming_clip) (MokoGsmdConnection *self, const gchar *number); 53 void (*network_registration) (MokoGsmdConnection *self, 54 int type, 55 int lac, 56 int cell); 57 void (*trigger_signal_strength_event) (MokoGsmdConnection *self); 58 void (*signal_strength_changed) (MokoGsmdConnection *self, int strength); 51 /* Network signals */ 52 void (*network_registration) (MokoGsmdConnection* self, int type, int lac, int cell); 53 void (*signal_strength_changed) (MokoGsmdConnection* self, int strength); 54 void (*network_current_operator) (MokoGsmdConnection* self, const gchar* name ); 55 56 /* Misc */ 59 57 void (*cme_cms_error) (MokoGsmdConnection *self, int code); 60 58 … … 113 111 void moko_gsmd_connection_network_register (MokoGsmdConnection *self); 114 112 int moko_gsmd_connection_get_network_status (MokoGsmdConnection *self); 113 void moko_gsmd_connection_trigger_current_operator_event(MokoGsmdConnection* self); 114 void moko_gsmd_connection_trigger_signal_strength_event(MokoGsmdConnection* self); 115 115 116 116 /* TODO add type, i.e. MOKO_GSMD_CONNECTION_NETREG_AUTO */
Note: See TracChangeset
for help on using the changeset viewer.
