uint8_t getLight(Light *light, GetLightCallback callback) { DictionaryIterator *iter = NULL; AppMessageResult result = app_message_outbox_begin(&iter); if (result != APP_MSG_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send request, status %d", result); return false; } DictionaryResult result2 = dict_write_data(iter, TAG_LIGHT, (uint8_t *)light, sizeof(Light)); if (result2 != DICT_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send data, status %d", result2); return false; } uint16_t r = REQUEST_GET; result2 = dict_write_data(iter, TAG_REQUEST_TYPE, (uint8_t *)&r, sizeof(uint16_t)); if (result2 != DICT_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send request, status %d", result2); return false; } result2 = dict_write_data(iter, TAG_ADDRESS, (uint8_t *)&light, sizeof(Light *)); if (result2 != DICT_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send request, status %d", result2); return false; } result2 = dict_write_data(iter, TAG_CALLBACK, (uint8_t *)&callback, sizeof(GetLightCallback)); if (result2 != DICT_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send request, status %d", result2); return false; } app_message_outbox_send(); return true; }
/** * Sends inbox size to phone as a * little-endian byte array of length 4. */ void broadcast_inbox_size(uint32_t size) { DictionaryIterator *dict; app_message_outbox_begin(&dict); dict_write_data(dict, INBOX_SIZE_KEY, (uint8_t *)&size, 4); dict_write_end(dict); app_message_outbox_send(); }
static void send_settings_to_phone() { if (!JS_ready) return; DictionaryIterator *iter; app_message_outbox_begin(&iter); int dummy_int; dict_write_cstring(iter, KEY_APP_VERSION, app_version); dummy_int=CURRENT_STORAGE_VERSION; dict_write_int(iter, KEY_VERSION, &dummy_int, sizeof(int), true); dummy_int=data_timestamp; dict_write_int(iter, KEY_TIMESTAMP, &dummy_int, sizeof(int), true); dummy_int=settings.Show_clock; dict_write_int(iter, KEY_SHOW_CLOCK, &dummy_int, sizeof(int), true); dummy_int=settings.Auto_sort; dict_write_int(iter, KEY_AUTO_SORT, &dummy_int, sizeof(int), true); dummy_int=settings.Hrs_day_x10; dict_write_int(iter, KEY_HRS_PER_DAY, &dummy_int, sizeof(int), true); dummy_int=settings.Last_reset; dict_write_int(iter, KEY_LAST_RESET, &dummy_int, sizeof(int), true); if (timer.Active) dict_write_data(iter, KEY_TIMER, (void*) &timer, sizeof(timer)); jobs_list_write_dict(iter, KEY_JOBS); if (export_after_save) { dummy_int=true; dict_write_int(iter, KEY_EXPORT, &dummy_int, sizeof(int), true); export_after_save=false; } dict_write_end(iter); LOG("sending outbox..."); app_message_outbox_send(); }
static bool send_msg(uint8_t *buffer, size_t length) { DictionaryIterator *iter = NULL; if (app_message_outbox_begin(&iter) != APP_MSG_OK) { return false; } dict_write_data(iter, 0, buffer, length); return (app_message_outbox_send() == APP_MSG_OK); }
void pbl_capture_send() { struct GContext *gctx = app_get_current_graphics_context(); unsigned char *ptr = (unsigned char *)(*gctx->ptr); int pbl_capture_sentLen = 0; DictionaryResult ret; DictionaryIterator imgChunk; uint8_t buff[MAX_OUT_MESSAGE_SIZE]; int len = 0; for (int y=0; y<168; y++) { for (int x=0; x<18; x++) { http_capture_frameBuffer[len++] = *ptr++; } ptr++; ptr++; } app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); while (pbl_capture_sentLen < IMAGE_SIZE) { DictionaryResult res = dict_write_begin(&imgChunk, buff, MAX_OUT_MESSAGE_SIZE); if (res != DICT_OK) { return; } uint8_t msg = mMT_SendImage; ret = dict_write_int(&imgChunk, KEY_COMMAND, &msg, 1, false); if (DICT_OK != ret) { return; } uint16_t pos = pbl_capture_sentLen; ret = dict_write_int(&imgChunk, KEY_IMG_SIZE, &pos, 2, false); if (DICT_OK != ret) { return; } ret = dict_write_data(&imgChunk, KEY_IMG_START, http_capture_frameBuffer + pbl_capture_sentLen, BODY_LEN); if (DICT_OK != ret) { return; } pbl_capture_sentLen += BODY_LEN; dict_write_end(&imgChunk); mq_post(&imgChunk); } }
DictionaryResult dict_write_tuplet(DictionaryIterator *iter, const Tuplet * const tup) { const TupletData* const tuplet=(const TupletData* const) tup; switch (tuplet->type) { case TUPLE_BYTE_ARRAY: return dict_write_data(iter, tuplet->key, tuplet->data.bytes.data, tuplet->data.bytes.length); case TUPLE_CSTRING: return dict_write_cstring(iter, tuplet->key, tuplet->data.cstring.data); case TUPLE_INT: return dict_write_int(iter, tuplet->key, &(tuplet->data.integer.storage), tuplet->data.integer.width, true); case TUPLE_UINT: return dict_write_int(iter, tuplet->key, &(tuplet->data.integer.storage), tuplet->data.integer.width, false); } return DICT_INVALID_ARGS; }
static void sendListToPhone() { if (droppedMessage == false) { // Begin a dictionary and add the current list and status. Send to the phone DictionaryIterator *iter; app_message_outbox_begin(&iter); // Construct the dictionary data uint8_t tempStatus[CHECKLIST_MAX_ITEMS]; for (int i = 0; i < numItems; i++) { tempStatus[i] = checklistStatusArr[checklistOrderArr[i]]; // Have to alter the order of statuses to display order } dict_write_cstring(iter, KEY_LIST_STRING, globalBuffer); dict_write_data(iter, KEY_LIST_STATUS, tempStatus, sizeof(tempStatus)); dict_write_uint8(iter, KEY_LAST_CHECK, lastCheckedItem); // Send the data to phone for it to work on! app_message_outbox_send(); } }
void send_byte_array(){ static const uint8_t data[] = {0}; const uint32_t size = dict_calc_buffer_size(1, sizeof(data)+1); // Stack-allocated buffer in which to create the Dictionary: uint8_t buffer[size]; DictionaryIterator *iter; app_message_outbox_begin(&iter); // Begin: dict_write_begin(iter, buffer, sizeof(buffer)); // Write the Data: dict_write_data(iter, XVALUE_KEY, data, sizeof(data)); const uint32_t final_size = dict_write_end(iter); app_message_outbox_send(); APP_LOG(APP_LOG_LEVEL_DEBUG, "**WATCH**: A message has been sent from pebble to the phone"); }
void comm_transmit_events() { if (!ready_to_transmit()) { return; } if (resetSignaled) { LOG(APP_LOG_LEVEL_DEBUG, "reset signaled, refusing to send event log"); return; } if (event_log_size() == 0) { LOG(APP_LOG_LEVEL_DEBUG, "event log is empty, nothing to transmit"); return; } uint8_t bufferSize = log_calculate_serialized_size(); uint8_t buffer[bufferSize]; log_serialize(buffer); DictionaryIterator *iterator = start_outbound_mesage(MESSAGE_TYPE_EVENT_TRANSMISSION); if (!iterator) return; uint8_t result = dict_write_data(iterator, MESSAGE_KEY_EVENT_BLOB, buffer, bufferSize); if (result != DICT_OK) { LOG(APP_LOG_LEVEL_ERROR, "serialization to dictionary failed, reason: %i", (int)result); return; } result = app_message_outbox_send(); if (result != APP_MSG_OK) { LOG(APP_LOG_LEVEL_ERROR, "send failed, reason: %i", (int)result); return; } transmitInProgress = true; eventsInMessage = event_log_size(); }
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(); } }