Exemple #1
0
void messaging_requestNewWeatherData() {
  // just send an empty message for now
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  dict_write_uint32(iter, 0, 0);
  app_message_outbox_send();
}
static void in_received_handler(DictionaryIterator *iter, void *context) {
  Tuple *tuple;

  // send the launch_arg when we receive ready from JS
  tuple = dict_find(iter, APP_KEY_READY);
  if (tuple) {
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    dict_write_uint32(iter, APP_KEY_ACTION, launch_get_args());
    dict_write_end(iter);
    app_message_outbox_send();
  }

  // update text
  tuple = dict_find(iter, APP_KEY_TEXT);
  if (tuple) {
    snprintf(text, sizeof(text), "%s", tuple->value->cstring);
    text_layer_set_text(text_layer, text);
  }

  // quit the app
  tuple = dict_find(iter, APP_KEY_QUIT);
  if (tuple) {
    window_stack_pop_all(false);
  }
}
Exemple #3
0
// Write out the current elapsed time in ms to the AppMessage outbox
static void down_click_handler(ClickRecognizerRef recognizer, void *context){
    const uint32_t time_ms = timer.elapsed_ms;

    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    dict_write_uint32(iter, TIME_KEY, time_ms);
    dict_write_end(iter);
    app_message_outbox_send();
}
static void send_initial_packet() {
	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 0);
	dict_write_uint8(iterator, 1, 0);
	dict_write_uint16(iterator, 2, PROTOCOL_VERSION);
	dict_write_uint32(iterator, 3, getCapabilities(appmessage_max_size));

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();
}
static void bluetooth_connection(bool connected) {
    if (connected) {
        // Ask for recommandation game.
        DictionaryIterator* iterator;
        app_message_outbox_begin(&iterator);
        // Code value doesn't really matter.
        dict_write_uint32(iterator, PEBBLE_KEYS_GAME, 0xB00B5);
        app_message_outbox_send();
        // Reschedule the timer.
        timer_schedule(NULL);
    }
    else {
        timer_unschedule();
        statium_watchface_layer_set_text(application.layer, _("Bluetooth is off"));
    }
}
Exemple #6
0
void send_update_request()
{
    if( s_currently_updating == 0 )
    {
        s_currently_updating = 1;
    
        DictionaryIterator* iter = NULL;
        app_message_outbox_begin( &iter );
        
        dict_write_uint32( iter, REQ_BUS_STOP_ID, common_get_current_bus_stop_id() );
        dict_write_uint8( iter, REQ_UPDATE_BUS_STOP_LIST, 0 );
        
        app_message_outbox_send();
        
        refresh_update_status();
    }    
}
Exemple #7
0
static void out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, void *context)
{
    // Log Error
    
    time_t now = time(NULL);
    struct tm *clock_time = localtime(&now);
    
    char error_time_text[] = "00:00:00";
    
    strftime(error_time_text, sizeof(error_time_text), "%T", clock_time);
    
    if (reason == APP_MSG_OK)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_OK", error_time_text);
    }
    else if (reason == APP_MSG_SEND_TIMEOUT)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_SEND_TIMEOUT", error_time_text);
    }
    else if (reason == APP_MSG_SEND_REJECTED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_SEND_REJECTED", error_time_text);
    }
    else if (reason == APP_MSG_NOT_CONNECTED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_NOT_CONNECTED", error_time_text);
    }
    else if (reason == APP_MSG_APP_NOT_RUNNING)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_APP_NOT_RUNNING", error_time_text);
    }
    else if (reason == APP_MSG_INVALID_ARGS)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_INVALID_ARGS", error_time_text);
    }
    else if (reason == APP_MSG_BUSY)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_BUSY", error_time_text);
    }
    else if (reason == APP_MSG_BUFFER_OVERFLOW)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_BUFFER_OVERFLOW", error_time_text);
    }
    else if (reason == APP_MSG_ALREADY_RELEASED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_ALREADY_RELEASED", error_time_text);
    }
    else if (reason == APP_MSG_CALLBACK_ALREADY_REGISTERED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_CALLBACK_ALREADY_REGISTERED", error_time_text);
    }
    else if (reason == APP_MSG_CALLBACK_NOT_REGISTERED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_CALLBACK_NOT_REGISTERED", error_time_text);
    }
    
    // Error Handling
    
    if ((reason == APP_MSG_SEND_TIMEOUT || reason == APP_MSG_BUSY) && bluetooth_connection_service_peek())
    {
        // Try Reseanding Message
        
        // Create New Output Iterator
        
        DictionaryIterator *iterator;
        
        if (app_message_outbox_begin(&iterator) != APP_MSG_OK)
        {
            return;
        }
        
        // For Each Tuple in Failed Dictionary Iterator, Read Value, Classify Value, and Write to New Iterator
        
        Tuple *tuple = dict_read_first(failed);
        
        while (tuple)
        {
            switch (tuple->type)
            {
                case TUPLE_BYTE_ARRAY:
                    dict_write_data	(iterator, tuple->key, tuple->value->data, tuple->length);
                    break;
                case TUPLE_CSTRING:
                    dict_write_cstring(iterator, tuple->key, tuple->value->cstring);
                    break;
                case TUPLE_UINT:
                    if (tuple->length == 1)
                    {
                        dict_write_uint8(iterator, tuple->key, tuple->value->uint8);
                    }
                    else if (tuple->length == 2)
                    {
                        dict_write_uint16(iterator, tuple->key, tuple->value->uint16);
                    }
                    else
                    {
                        dict_write_uint32(iterator, tuple->key, tuple->value->uint32);
                    }
                    break;
                case TUPLE_INT:
                    if (tuple->length == 1)
                    {
                        dict_write_int8(iterator, tuple->key, tuple->value->int8);
                    }
                    else if (tuple->length == 2)
                    {
                        dict_write_int16(iterator, tuple->key, tuple->value->int16);
                    }
                    else
                    {
                        dict_write_int32(iterator, tuple->key, tuple->value->int32);
                    }
                    break;
                default:
                    break;
            }
            
            tuple = dict_read_next(failed);
        }
        
        // Resend App Message
        
        app_message_outbox_send();
    }
}
Exemple #8
0
void register_uint32(AppKey type, uint32_t i) {
	dict_write_uint32(dict, type, i);
}