still not working 100%

* The problem is clear though: storing the revived strings!
* sending string is still apparently somewhat funny -.-
This commit is contained in:
dyedgreen
2016-06-22 21:46:52 +02:00
parent 3eeb297eda
commit 4af5561d7e
2 changed files with 43 additions and 27 deletions
+42 -27
View File
@@ -7,6 +7,18 @@
#define MAX_STEP_COUNT 20 #define MAX_STEP_COUNT 20
#define MAX_STEP_CHARS 128 #define MAX_STEP_CHARS 128
// The RouteData struct
struct RouteData {
// App message state TODO: Is this necessary?
bool ready;
bool callback;
// Data fields
int distance;
int time;
char steps[MAX_STEP_COUNT][MAX_STEP_CHARS];
int count;
};
// The main window // The main window
static Window *window; static Window *window;
static int window_height; static int window_height;
@@ -18,12 +30,7 @@ static DictationSession *dictation_session;
static char *address; static char *address;
// TODO: implement a timer, that kills the proccess if the message is never send (needed?) // TODO: implement a timer, that kills the proccess if the message is never send (needed?)
static bool AppMessageIsReady; struct RouteData *route_data;
static bool AppMessageSendOnCallback;
static int RouteDataDistance;
static int RouteDataTime;
static char RouteDataSteps[MAX_STEP_COUNT][MAX_STEP_CHARS];
static int RouteDataStepsCount;
// Function declarations // Function declarations
static void app_message_send_search_data(); static void app_message_send_search_data();
@@ -93,7 +100,7 @@ static void dictation_session_callback(DictationSession *session, DictationSessi
app_message_send_search_data(); app_message_send_search_data();
} else { } else {
// Dictation failed, remove this window // Dictation failed, remove this window
window_stack_remove(window, true); window_stack_remove(window, false);
} }
} }
@@ -111,9 +118,9 @@ static void app_message_inbox_recived_callback(DictionaryIterator *iter, void *c
message = dict_find(iter, MESSAGE_KEY_READY); message = dict_find(iter, MESSAGE_KEY_READY);
if (message) { if (message) {
// Set status to ready // Set status to ready
AppMessageIsReady = (bool)message->value->int16; route_data->ready = (bool)message->value->int16;
// Send pending search data // Send pending search data
if (AppMessageSendOnCallback) { if (route_data->callback) {
app_message_send_search_data(); app_message_send_search_data();
} }
} }
@@ -144,25 +151,24 @@ static void app_message_inbox_recived_callback(DictionaryIterator *iter, void *c
// Test if the recived message is for key DISTANCE // Test if the recived message is for key DISTANCE
message = dict_find(iter, MESSAGE_KEY_DISTANCE); message = dict_find(iter, MESSAGE_KEY_DISTANCE);
if (message) { if (message) {
RouteDataDistance = (int)message->value->int32; route_data->distance = (int)message->value->int32;
} }
// Test if the recived message is for key TIME // Test if the recived message is for key TIME
message = dict_find(iter, MESSAGE_KEY_TIME); message = dict_find(iter, MESSAGE_KEY_TIME);
if (message) { if (message) {
RouteDataTime = (int)message->value->int32; route_data->time = (int)message->value->int32;
} }
// Test if the recived message is for key INSTRUCTIONS // Test if the recived message is for key INSTRUCTIONS
for (int i = 0; i < MAX_STEP_COUNT; i++) { for (int i = 0; i < MAX_STEP_COUNT; i++) {
message = dict_find(iter, MESSAGE_KEY_INSTRUCTIONS + i); message = dict_find(iter, MESSAGE_KEY_INSTRUCTIONS + i);
if (message) { if (message) {
// Copy the string into the string array // Copy the string into the string array FIXME
static char *empty; strcpy(route_data->steps[i], message->value->cstring);
strncat(empty, message->value->cstring, MAX_STEP_CHARS); route_data->steps[i][MAX_STEP_CHARS] = '\n';
strcpy(RouteDataSteps[i], empty);
// Store the new length of the RouteDataSteps // Store the new length of the RouteDataSteps
RouteDataStepsCount = i + 1; route_data->count = i + 1;
} }
} }
} }
@@ -182,14 +188,12 @@ static void app_message_outbox_failed_callback(DictionaryIterator *iter, AppMess
// Send the search data to the phone // Send the search data to the phone
static void app_message_send_search_data() { static void app_message_send_search_data() {
// Send the data to the phone if conn is ready // Send the data to the phone if conn is ready
if (AppMessageIsReady) { if (route_data->ready) {
// Create a string with the correct length // Create a string with the correct length
char message[sizeof(address) + 1]; char message[sizeof(address) + 1];
// Add the type as the first char // Format the string FIXME (cuts of after 'mee' for the test string ???)
message[0] = '0' + selected_type_enum; snprintf(message, sizeof(message), "%i%s", selected_type_enum, address);
// Add the address // Make sure the string is terminated correctely (just in case)
strcat(message, address);
// Make sure the string is terminated correctely, just in case
message[sizeof(message) - 1] = '\n'; message[sizeof(message) - 1] = '\n';
// Write string to bluetooth storage // Write string to bluetooth storage
@@ -203,15 +207,18 @@ static void app_message_send_search_data() {
window_display_error(Network); window_display_error(Network);
} }
} else { } else {
AppMessageSendOnCallback = true; route_data->callback = true;
} }
} }
// Set up the whole app message thing (once the address is worked out) // Set up the whole app message thing (once the address is worked out)
static void app_message_start() { static void app_message_start() {
// Set up the data
route_data = malloc(sizeof(struct RouteData));
// Set initial values // Set initial values
AppMessageIsReady = true; route_data->ready = true;
AppMessageSendOnCallback = false; route_data->callback = false;
// Register all callbacks // Register all callbacks
app_message_register_inbox_received(app_message_inbox_recived_callback); app_message_register_inbox_received(app_message_inbox_recived_callback);
app_message_register_inbox_dropped(app_message_inbox_dropped_callback); app_message_register_inbox_dropped(app_message_inbox_dropped_callback);
@@ -220,6 +227,13 @@ static void app_message_start() {
app_message_open(APP_MESSAGE_INBOX_SIZE_MINIMUM, APP_MESSAGE_OUTBOX_SIZE_MINIMUM); app_message_open(APP_MESSAGE_INBOX_SIZE_MINIMUM, APP_MESSAGE_OUTBOX_SIZE_MINIMUM);
} }
static void app_message_destroy_resources() {
// Remove all app message callbacks
app_message_deregister_callbacks();
// Clear the data
free(route_data);
}
// ******************** // ********************
// * WINDOW LIFECYCLE * // * WINDOW LIFECYCLE *
@@ -241,8 +255,9 @@ static void window_unload() {
// Destroy the dictation session // Destroy the dictation session
dictation_session_destroy(dictation_session); dictation_session_destroy(dictation_session);
// Remove all app message callbacks // Destroy app message stuff
app_message_deregister_callbacks(); app_message_destroy_resources();
route_data = NULL;
// Destroy the window // Destroy the window
window_destroy(window); window_destroy(window);
+1
View File
@@ -74,6 +74,7 @@ function sendRoute(success, distance, time, stepList) {
// Build message // Build message
var keyDistance = keys.DISTANCE; var keyDistance = keys.DISTANCE;
var keyTime = keys.TIME; var keyTime = keys.TIME;
var dict = {};
dict[keyDistance] = +distance; dict[keyDistance] = +distance;
dict[keyTime] = +time; dict[keyTime] = +time;