Exemplo n.º 1
0
static void transmit_to_phone(){
  DictionaryIterator *iterator;
  app_message_outbox_begin(&iterator);
  dict_write_int16(iterator, 0, x);
  dict_write_int16(iterator, 1, y);
  dict_write_int8(iterator, 2, 0); //TCP_Ready
  if(app_message_outbox_send()==APP_MSG_BUSY)delay++;
  else if(delay>0) delay--;
}
Exemplo n.º 2
0
void send_accel(AccelData accel) {
    
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
 
    dict_write_int16(iter, 'x', accel.x);
    dict_write_int16(iter, 'y', accel.y);
    dict_write_int16(iter, 'z', accel.z);
    
    app_message_outbox_send();
}
// Request data from JavaScript
static void get_data(void) {
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  
  if (iter == NULL) {
    return;
  }
  
  dict_write_int16(iter, GET_DATA, 1);
  app_message_outbox_send();
}
Exemplo n.º 4
0
// Cancel all queued incoming app messages
static void cancel_app_messages() {
	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);

	if (iter == NULL) {
		return;
	}

	dict_write_int16(iter, CANCEL_MESSAGES, 1);
	app_message_outbox_send();
}
Exemplo n.º 5
0
/*!
 * Sends the accelerometer and velocity data to the phone
 *
 * \return Result of outbox success
 */
AppMessageResult send_msg() {
    DictionaryIterator *iter;

    AppMessageResult ret;

    if ((ret = app_message_outbox_begin(&iter)) != APP_MSG_OK) {
        return ret;
    }

    dict_write_int16(iter, 0, v[0]);
    dict_write_int16(iter, 1, v[1]);
    dict_write_int16(iter, 2, v[2]);
    dict_write_int16(iter, 3, a[0]);
    dict_write_int16(iter, 4, a[1]);
    dict_write_int16(iter, 5, a[2]);
    dict_write_int16(iter, 6, g[0]);
    dict_write_int16(iter, 7, g[1]);
    dict_write_int16(iter, 8, g[2]);

    return app_message_outbox_send();
}
Exemplo n.º 6
0
static void sendpickedEntry(int16_t pos, uint8_t mode)
{
	DictionaryIterator *iterator;
	AppMessageResult result = app_message_outbox_begin(&iterator);
	if (result != APP_MSG_OK)
	{
			pickedEntry = pos;
			pickedMode = mode;
			return;
	}

	dict_write_uint8(iterator, 0, 2);
	dict_write_uint8(iterator, 1, 1);
	dict_write_int16(iterator, 2, pos);
	dict_write_uint8(iterator, 3, mode);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();

	pickedEntry = -1;
}
Exemplo n.º 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();
    }
}