Esempio n. 1
0
HTTPResult http_out_get(const char* url, bool use_post, int32_t cookie, DictionaryIterator **iter_out) {
	AppMessageResult app_result = app_message_out_get(iter_out);
	if(app_result != APP_MSG_OK) {
		return app_result;
	}
	DictionaryResult dict_result = dict_write_cstring(*iter_out, HTTP_URL_KEY, url);
	if(dict_result != DICT_OK) {
		return dict_result << 12;
	}
	dict_result = dict_write_int32(*iter_out, HTTP_COOKIE_KEY, cookie);
	if(dict_result != DICT_OK) {
		return dict_result << 12;
	}
	dict_result = dict_write_int32(*iter_out, HTTP_APP_ID_KEY, our_app_id);
	if(dict_result != DICT_OK) {
		return dict_result << 12;
	}
	if(!use_post) {
		dict_result = dict_write_int8(*iter_out, HTTP_USE_GET_KEY, 1);
		if(dict_result != DICT_OK) {
			return dict_result << 12;
		}
	}
	return HTTP_OK;
}
Esempio n. 2
0
void next_rows() {
    DictionaryIterator* req;
	http_out_get("http://wristmap.argyl.es/api/v1", rowN, &req);
    dict_write_int32(req, MAP_KEY_ULAT, ulat);
	dict_write_int32(req, MAP_KEY_ULON, ulon);
    dict_write_int32(req, MAP_KEY_ZOOM, zoom);
    dict_write_int32(req, MAP_KEY_ROW, rowN);
    http_out_send();
}
Esempio n. 3
0
static int request_next_habit(struct NetworkState *state)
{
    int rval = 0;
    abort_if(!state, "state is null");

    if(state->habit_current >= state->habit_count)
        goto CLEANUP;

    DictionaryIterator *dict;
    rval = app_message_outbox_begin(&dict);
    abort_if(rval, "app_message_outbox_begin failed");

    rval = dict_write_cstring(dict, 0, "FETCH");
    abort_if(rval, "dict_write_cstring failed");

    rval = dict_write_int32(dict, 1, state->habit_current);
    abort_if(rval, "dict_write_cstring failed");

    rval = app_message_outbox_send();
    abort_if(rval, "app_message_outbox_send failed");

    state->habit_current++;

CLEANUP:
    return rval;
}
Esempio n. 4
0
void reset_sequence_number() {
    DictionaryIterator *iter = NULL;
    app_message_outbox_begin(&iter);
    if(!iter) return;
    dict_write_int32(iter, SM_SEQUENCE_NUMBER_KEY, 0xFFFFFFFF);
    app_message_outbox_send();
}
Esempio n. 5
0
File: common.c Progetto: abl/peapod
void reset_sequence_number() {
    DictionaryIterator *iter = NULL;
    app_message_out_get(&iter);
    if(!iter) return;
    dict_write_int32(iter, IPOD_SEQUENCE_NUMBER_KEY, 0xFFFFFFFF);
    app_message_out_send();
    app_message_out_release();
}
Esempio n. 6
0
AppMessageResult sm_message_out_get(DictionaryIterator **iter_out) {
    AppMessageResult result = app_message_outbox_begin(iter_out);
    if(result != APP_MSG_OK) return result;
    dict_write_int32(*iter_out, SM_SEQUENCE_NUMBER_KEY, ++s_sequence_number);
    if(s_sequence_number == 0xFFFFFFFF) {
        s_sequence_number = 1;
    }
    return APP_MSG_OK;
}
void request_room_list(){
	DictionaryIterator *body;
	APP_LOG(APP_LOG_LEVEL_INFO, "REQUESTING ROOM LIST");
	HTTPResult result = http_out_get(config.url, REQUEST_ROOMS, &body);
	if(result != HTTP_OK) {
		char str[32];
		snprintf(str, 32, "H HOG %i", result);
		show_error(str);
		return;
	}
	dict_write_cstring(body, HTTP_KEY_PASSWORD, config.password);
	dict_write_int32(body, HTTP_KEY_TYPE, HTTP_TYPE_ROOMS);
	dict_write_int32(body, HTTP_KEY_OFFSET, rooms_loaded);
	result = send_request_queue();
	if(result != HTTP_OK){
		char str[32];
		snprintf(str, 32, "H HOS %i", result);
		show_error(str);
		return;
	}
}
void device_send_command(uint16_t dev_id, uint8_t major, uint8_t minor){
	DictionaryIterator *body;
	APP_LOG(APP_LOG_LEVEL_INFO, "REQUESTING DEVICE ACTION");
	HTTPResult result = http_out_get(config.url, REQUEST_DEVICE_ACTION, &body);
	if(result != HTTP_OK) {
		char str[32];
		snprintf(str, 32, "C HOG %i", result);
		show_error(str);
		return;
	}
	dict_write_cstring(body, HTTP_KEY_PASSWORD, config.password);
	dict_write_int32(body, HTTP_KEY_TYPE, HTTP_TYPE_DEVICE_ACTION);
	dict_write_int32(body, HTTP_KEY_DEVID, dev_id);
	dict_write_uint8(body, HTTP_KEY_MAJOR, major);
	dict_write_uint8(body, HTTP_KEY_MINOR, minor);
	result = send_request_queue();
	if(result != HTTP_OK){
		char str[32];
		snprintf(str, 32, "C HOS %i", result);
		show_error(str);
		return;
	}
}
Esempio n. 9
0
int NETWORK_request_toggle(int id)
{
    int rval = 0;

    DictionaryIterator *dict;
    rval = app_message_outbox_begin(&dict);
    abort_if(rval, "app_message_outbox_begin failed");

    rval = dict_write_cstring(dict, 0, "TOGGLE");
    abort_if(rval, "dict_write_cstring failed");

    rval = dict_write_int32(dict, 1, id);
    abort_if(rval, "dict_write_cstring failed");

    rval = app_message_outbox_send();
    abort_if(rval, "app_message_outbox_send failed");

    log_debug("--> %s", "COUNT");

CLEANUP:
    return rval;
}
void nw_switch_to_notification(uint8_t index)
{
    pickedNotification = index;
    nw_ui_refresh_notification();
    nw_ui_scroll_to_notification_start();

#ifdef  PBL_COLOR
    if (notificationBitmap != NULL)
    {
        gbitmap_destroy(notificationBitmap);
        notificationBitmap = NULL;
        nw_ui_set_notification_image(NULL);
    }

    Notification* newNotification = nw_get_displayed_notification();
    if (newNotification != NULL && newNotification->imageSize != 0)
    {

        if (bitmapReceivingBuffer != NULL)
            free(bitmapReceivingBuffer);
        bitmapReceivingBuffer = malloc(newNotification->imageSize);
        bitmapReceivingBufferHead = 0;

        //Request image for currently selected notification

        DictionaryIterator *iterator;
        app_message_outbox_begin(&iterator);
        dict_write_uint8(iterator, 0, 5);
        dict_write_uint8(iterator, 1, 0);
        dict_write_int32(iterator, 2, newNotification->id);
        app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
        app_message_outbox_send();

    }
    #endif
}
Esempio n. 11
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();
    }
}