aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Code_Composer/twine_usblib_demo/main.c
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2017-11-16 18:07:34 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2017-11-16 18:07:34 +0200
commitfc703faaa6326e28e146e00615db01c48ded0ece (patch)
tree26b8b3134ab8562d8a7bf3c04bf99b897c5c3edb /Software/Code_Composer/twine_usblib_demo/main.c
parent4be586d903da2b0dbba23f4978e14ad7d51edcbf (diff)
downloadTango-fc703faaa6326e28e146e00615db01c48ded0ece.tar.gz
Tango-fc703faaa6326e28e146e00615db01c48ded0ece.zip
Implemented PMR for CCS!
First test working. Parsed and returned Calculate Stub! Implemented custom proto C compiling to achieve shorter struct names!
Diffstat (limited to 'Software/Code_Composer/twine_usblib_demo/main.c')
-rw-r--r--Software/Code_Composer/twine_usblib_demo/main.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/Software/Code_Composer/twine_usblib_demo/main.c b/Software/Code_Composer/twine_usblib_demo/main.c
index db6f6fec5..3b9da30da 100644
--- a/Software/Code_Composer/twine_usblib_demo/main.c
+++ b/Software/Code_Composer/twine_usblib_demo/main.c
@@ -1,7 +1,9 @@
#include <protobuf-c/person-pb-c.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <stdio.h>
#include <stdint.h>
+#include <string.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
@@ -75,33 +77,44 @@ void receive_callback(char* buffer, size_t length)
//draw_string(buffer, length);
//draw_image((uint8_t *)buffer);
- Tango__PMR__Common__MessageContainer* container = tango__pmr__common__message_container__unpack(NULL, length, (uint8_t*)buffer);
+ MessageContainer* container = message_container__unpack(NULL, length, (uint8_t*)buffer);
- if (container->type == TANGO__PMR__COMMON__MESSAGE_TYPE__CalculateRequest)
+ if (container->type == MESSAGE_TYPE__CalculateRequest)
{
- Tango__PMR__Stubs__CalculateRequest* request = tango__pmr__stubs__calculate_request__unpack(NULL, container->data.len, container->data.data);
+ CalculateRequest* request = calculate_request__unpack(NULL, container->data.len, container->data.data);
- Tango__PMR__Stubs__CalculateResponse* response = NULL;
- tango__pmr__stubs__calculate_response__init(response);
- response->sum = request->a + request->b;
- response->has_sum = true;
+ char screen_text[100];
+ strcpy(screen_text, "Calculate Request: ");
- Tango__PMR__Common__MessageContainer responseContainer = TANGO__PMR__COMMON__MESSAGE_CONTAINER__INIT;
+ char num_buf[5];
+ ltoa(request->a, num_buf);
+ strcat(screen_text, num_buf);
+ strcat(screen_text, " + ");
+ ltoa(request->b, num_buf);
+ strcat(screen_text, num_buf);
+
+ draw_string(screen_text,strlen(screen_text));
+
+ CalculateResponse response = CALCULATE_RESPONSE__INIT;
+ response.sum = request->a + request->b;
+ response.has_sum = true;
+
+ MessageContainer responseContainer = MESSAGE_CONTAINER__INIT;
responseContainer.completed = true;
responseContainer.token = container->token;
responseContainer.has_completed = true;
responseContainer.has_data = true;
responseContainer.has_type = true;
- responseContainer.type = TANGO__PMR__COMMON__MESSAGE_TYPE__CalculateResponse;
+ responseContainer.type = MESSAGE_TYPE__CalculateResponse;
- uint8_t* d;
- size_t size = tango__pmr__stubs__calculate_response__pack(response, d);
+ uint8_t* d = malloc(calculate_response__get_packed_size(&response));
+ size_t size = calculate_response__pack(&response, d);
responseContainer.data.data = d;
responseContainer.data.len = size;
- uint8_t* output = NULL;
- size = tango__pmr__common__message_container__pack(&responseContainer, &output);
+ uint8_t* output = malloc(message_container__get_packed_size(&responseContainer));
+ size = message_container__pack(&responseContainer, output);
SendChars(output, size);
}