From 0ca2242d9c89114405ea1638f09c58392c3c01cf Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 16 Nov 2017 21:13:05 +0200 Subject: Implemented Continuous message on CCS working ! --- .../twine_graphicslib/graphics_adapter.c | 8 +- .../twine_graphicslib/graphics_adapter.h | 2 +- .../PMR/Stubs/ProgressRequest.pb-c.c | 43 ++++++++- .../PMR/Stubs/ProgressRequest.pb-c.h | 6 +- Software/Code_Composer/twine_usblib_demo/main.c | 102 +++++++++++++++------ Software/PMR/Messages/Stubs/ProgressRequest.proto | 3 +- .../ExtensionMethods/IParameterizedExtensions.cs | 2 +- .../Tango.PMR/Stubs/ProgressRequest.cs | 64 ++++++++++++- Software/Visual_Studio/Tango.Stubs/StubBase.cs | 1 - .../Visual_Studio/Tango.Stubs/Stubs/Progress.cs | 15 ++- 10 files changed, 202 insertions(+), 44 deletions(-) diff --git a/Software/Code_Composer/twine_graphicslib/graphics_adapter.c b/Software/Code_Composer/twine_graphicslib/graphics_adapter.c index 5d165599f..6990a58d9 100644 --- a/Software/Code_Composer/twine_graphicslib/graphics_adapter.c +++ b/Software/Code_Composer/twine_graphicslib/graphics_adapter.c @@ -14,7 +14,8 @@ #include "drivers/frame.h" #include "drivers/kentec320x240x16_ssd2119.h" -#define LINE_HEIGHT 25 +#define LINE_HEIGHT 12 +#define MAX_POSITION 240 int current_position = 0; char current_line[100]; @@ -49,6 +50,11 @@ void draw_string(char* data, size_t length) void writeLine(char* text) { + if (current_position >= MAX_POSITION) + { + clear(); + } + strcpy(current_line, text); GrStringDraw(&g_sContext, current_line, strlen(current_line), 0, current_position, true); current_position += LINE_HEIGHT; diff --git a/Software/Code_Composer/twine_graphicslib/graphics_adapter.h b/Software/Code_Composer/twine_graphicslib/graphics_adapter.h index 405b88166..134312def 100644 --- a/Software/Code_Composer/twine_graphicslib/graphics_adapter.h +++ b/Software/Code_Composer/twine_graphicslib/graphics_adapter.h @@ -18,7 +18,7 @@ // //***************************************************************************** static tContext g_sContext; -#define TEXT_FONT g_psFontCmss18b +#define TEXT_FONT g_psFontCmss12 #define TEXT_HEIGHT (GrFontHeightGet(TEXT_FONT)) #define BUFFER_METER_HEIGHT TEXT_HEIGHT #define BUFFER_METER_WIDTH 150 diff --git a/Software/Code_Composer/twine_usblib_demo/PMR/Stubs/ProgressRequest.pb-c.c b/Software/Code_Composer/twine_usblib_demo/PMR/Stubs/ProgressRequest.pb-c.c index 1eddd4d17..9e074f376 100644 --- a/Software/Code_Composer/twine_usblib_demo/PMR/Stubs/ProgressRequest.pb-c.c +++ b/Software/Code_Composer/twine_usblib_demo/PMR/Stubs/ProgressRequest.pb-c.c @@ -52,9 +52,42 @@ void progress_request__free_unpacked assert(message->base.descriptor == &progress_request__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } -#define progress_request__field_descriptors NULL -#define progress_request__field_indices_by_name NULL -#define progress_request__number_ranges NULL +static const ProtobufCFieldDescriptor progress_request__field_descriptors[2] = +{ + { + "Amount", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_INT32, + offsetof(ProgressRequest, has_amount), + offsetof(ProgressRequest, amount), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "Delay", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_INT32, + offsetof(ProgressRequest, has_delay), + offsetof(ProgressRequest, delay), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned progress_request__field_indices_by_name[] = { + 0, /* field[0] = Amount */ + 1, /* field[1] = Delay */ +}; +static const ProtobufCIntRange progress_request__number_ranges[1 + 1] = +{ + { 1, 0 }, + { 0, 2 } +}; const ProtobufCMessageDescriptor progress_request__descriptor = { PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, @@ -63,10 +96,10 @@ const ProtobufCMessageDescriptor progress_request__descriptor = "ProgressRequest", "", sizeof(ProgressRequest), - 0, + 2, progress_request__field_descriptors, progress_request__field_indices_by_name, - 0, progress_request__number_ranges, + 1, progress_request__number_ranges, (ProtobufCMessageInit) progress_request__init, NULL,NULL,NULL /* reserved[123] */ }; diff --git a/Software/Code_Composer/twine_usblib_demo/PMR/Stubs/ProgressRequest.pb-c.h b/Software/Code_Composer/twine_usblib_demo/PMR/Stubs/ProgressRequest.pb-c.h index 0b6b641ad..1ce2b6d6b 100644 --- a/Software/Code_Composer/twine_usblib_demo/PMR/Stubs/ProgressRequest.pb-c.h +++ b/Software/Code_Composer/twine_usblib_demo/PMR/Stubs/ProgressRequest.pb-c.h @@ -26,10 +26,14 @@ typedef struct _ProgressRequest ProgressRequest; struct _ProgressRequest { ProtobufCMessage base; + protobuf_c_boolean has_amount; + int32_t amount; + protobuf_c_boolean has_delay; + int32_t delay; }; #define PROGRESS_REQUEST__INIT \ { PROTOBUF_C_MESSAGE_INIT (&progress_request__descriptor) \ - } + , 0, 0, 0, 0 } /* ProgressRequest methods */ diff --git a/Software/Code_Composer/twine_usblib_demo/main.c b/Software/Code_Composer/twine_usblib_demo/main.c index 84cbf46b7..b2245b705 100644 --- a/Software/Code_Composer/twine_usblib_demo/main.c +++ b/Software/Code_Composer/twine_usblib_demo/main.c @@ -30,6 +30,8 @@ #include "MessageContainer.pb-c.h" #include "CalculateRequest.pb-c.h" #include "CalculateResponse.pb-c.h" +#include "ProgressRequest.pb-c.h"; +#include "ProgressResponse.pb-c.h"; //***************************************************************************** // @@ -49,6 +51,7 @@ static volatile uint32_t g_ui32SysTickCount = 0; // Flags used to pass commands from interrupt context to the main loop. static volatile uint32_t g_ui32Flags; +MessageContainer createContainer(MessageType type, char* token, protobuf_c_boolean completed, void* response, size_t (*packPtr)(void*, uint8_t*), size_t (*sizePtr)(void*)); //***************************************************************************** // @@ -73,18 +76,22 @@ void USB0Handler(void) void receive_callback(char* buffer, size_t length) { - //SendChars(buffer,length); + //SendChars(buffer,length); //draw_string(buffer, length); //draw_image((uint8_t *)buffer); - clear(); + writeLine("Received "); + writeFloat(length); + writeString(" bytes"); + writeLine("Parsing message..."); - MessageContainer* container = message_container__unpack(NULL, length, (uint8_t*)buffer); + MessageContainer* requestContainer = message_container__unpack(NULL, length, (uint8_t*)buffer); + MessageContainer responseContainer; - if (container->type == MESSAGE_TYPE__CalculateRequest) + if (requestContainer->type == MESSAGE_TYPE__CalculateRequest) { - CalculateRequest* request = calculate_request__unpack(NULL, container->data.len, container->data.data); + CalculateRequest* request = calculate_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); writeLine("Calculate Request: "); writeFloat(request->a); @@ -95,36 +102,74 @@ void receive_callback(char* buffer, size_t length) 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 = MESSAGE_TYPE__CalculateResponse; - - 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 = malloc(message_container__get_packed_size(&responseContainer)); - size = message_container__pack(&responseContainer, output); + responseContainer = createContainer(MESSAGE_TYPE__CalculateResponse, requestContainer->token, true, &response, &calculate_response__pack, &calculate_response__get_packed_size); writeLine("Sending Response: "); writeFloat(response.sum); - SendChars(output, size); + free(request); } + else if (requestContainer->type == MESSAGE_TYPE__ProgressRequest) + { + ProgressRequest* request = progress_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + + writeLine("Progress Request..."); + + ProgressResponse response = PROGRESS_RESPONSE__INIT; + response.has_progress = true; + + int i = 0; + for (i = 0; i < request->amount; i++) + { + response.progress = i; + responseContainer = createContainer(MESSAGE_TYPE__ProgressResponse, requestContainer->token, false, &response, &progress_response__pack, &progress_response__get_packed_size); + uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + writeLine("Sending Progress: "); + writeFloat(response.progress); + SendChars((char*)container_buffer, container_size); + + int co = 0; + for (co = 0; co < request->delay; co++) + { + __delay_cycles(1000000); + } + } + + responseContainer = createContainer(MESSAGE_TYPE__ProgressResponse, requestContainer->token, true, &response, &progress_response__pack, &progress_response__get_packed_size); + uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + writeLine("Progress Completed!"); + SendChars((char*)container_buffer, container_size); + return; + } + + uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + SendChars((char*)container_buffer, container_size); + free(container_buffer); + free(requestContainer); +} + +MessageContainer createContainer(MessageType type, char* token, protobuf_c_boolean completed, void* response, size_t (*packPtr)(void*, uint8_t*), size_t (*sizePtr)(void*)) +{ + MessageContainer container = MESSAGE_CONTAINER__INIT; + container.completed = completed; + container.token = token; + container.has_completed = true; + container.has_data = true; + container.has_type = true; + container.type = type; + + - free(container); + uint8_t* response_buffer = malloc((*sizePtr)(response)); + size_t response_size = (*packPtr)(response, response_buffer); + container.data.data = response_buffer; + container.data.len = response_size; -// Person* p = person__unpack (NULL, length, (uint8_t*)buffer); -// void* buf = malloc (length); -// person__pack (p, buf); -// SendChars(buf,length); -// free(p); -// free(buf); + free(response); + return container; } int main(void) @@ -148,6 +193,7 @@ int main(void) ROM_SysTickEnable(); init_graphics(ui32SysClock); + clear(); RegisterReceiveCallback(&receive_callback); StartUSB(ui32SysClock); diff --git a/Software/PMR/Messages/Stubs/ProgressRequest.proto b/Software/PMR/Messages/Stubs/ProgressRequest.proto index 82c658df9..7ba54710b 100644 --- a/Software/PMR/Messages/Stubs/ProgressRequest.proto +++ b/Software/PMR/Messages/Stubs/ProgressRequest.proto @@ -5,5 +5,6 @@ option java_package = "com.twine.tango.pmr.stubs"; message ProgressRequest { - + int32 Amount = 1; + int32 Delay = 2; } \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs index 5ee853f35..7a7ae103d 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs @@ -77,7 +77,7 @@ public static class IParameterizedExtensions item.Name = propertyInfo.Name.ToTitle(); item.Index = index; item.Type = propertyInfo.PropertyType; - item.Value = propertyInfo.GetValue(instance, null); + item.Value = attribute.Default; if (attribute != null) { diff --git a/Software/Visual_Studio/Tango.PMR/Stubs/ProgressRequest.cs b/Software/Visual_Studio/Tango.PMR/Stubs/ProgressRequest.cs index 1eda06217..559449535 100644 --- a/Software/Visual_Studio/Tango.PMR/Stubs/ProgressRequest.cs +++ b/Software/Visual_Studio/Tango.PMR/Stubs/ProgressRequest.cs @@ -22,13 +22,13 @@ namespace Tango.PMR.Stubs { static ProgressRequestReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( - "ChVQcm9ncmVzc1JlcXVlc3QucHJvdG8SD1RhbmdvLlBNUi5TdHVicyIRCg9Q", - "cm9ncmVzc1JlcXVlc3RCGwoZY29tLnR3aW5lLnRhbmdvLnBtci5zdHVic2IG", - "cHJvdG8z")); + "ChVQcm9ncmVzc1JlcXVlc3QucHJvdG8SD1RhbmdvLlBNUi5TdHVicyIwCg9Q", + "cm9ncmVzc1JlcXVlc3QSDgoGQW1vdW50GAEgASgFEg0KBURlbGF5GAIgASgF", + "QhsKGWNvbS50d2luZS50YW5nby5wbXIuc3R1YnNiBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Stubs.ProgressRequest), global::Tango.PMR.Stubs.ProgressRequest.Parser, null, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Stubs.ProgressRequest), global::Tango.PMR.Stubs.ProgressRequest.Parser, new[]{ "Amount", "Delay" }, null, null, null) })); } #endregion @@ -59,6 +59,8 @@ namespace Tango.PMR.Stubs { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public ProgressRequest(ProgressRequest other) : this() { + amount_ = other.amount_; + delay_ = other.delay_; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -66,6 +68,28 @@ namespace Tango.PMR.Stubs { return new ProgressRequest(this); } + /// Field number for the "Amount" field. + public const int AmountFieldNumber = 1; + private int amount_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Amount { + get { return amount_; } + set { + amount_ = value; + } + } + + /// Field number for the "Delay" field. + public const int DelayFieldNumber = 2; + private int delay_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Delay { + get { return delay_; } + set { + delay_ = value; + } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { return Equals(other as ProgressRequest); @@ -79,12 +103,16 @@ namespace Tango.PMR.Stubs { if (ReferenceEquals(other, this)) { return true; } + if (Amount != other.Amount) return false; + if (Delay != other.Delay) return false; return true; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; + if (Amount != 0) hash ^= Amount.GetHashCode(); + if (Delay != 0) hash ^= Delay.GetHashCode(); return hash; } @@ -95,11 +123,25 @@ namespace Tango.PMR.Stubs { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { + if (Amount != 0) { + output.WriteRawTag(8); + output.WriteInt32(Amount); + } + if (Delay != 0) { + output.WriteRawTag(16); + output.WriteInt32(Delay); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; + if (Amount != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Amount); + } + if (Delay != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Delay); + } return size; } @@ -108,6 +150,12 @@ namespace Tango.PMR.Stubs { if (other == null) { return; } + if (other.Amount != 0) { + Amount = other.Amount; + } + if (other.Delay != 0) { + Delay = other.Delay; + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -118,6 +166,14 @@ namespace Tango.PMR.Stubs { default: input.SkipLastField(); break; + case 8: { + Amount = input.ReadInt32(); + break; + } + case 16: { + Delay = input.ReadInt32(); + break; + } } } } diff --git a/Software/Visual_Studio/Tango.Stubs/StubBase.cs b/Software/Visual_Studio/Tango.Stubs/StubBase.cs index cbeb6d1d3..96c50cdc7 100644 --- a/Software/Visual_Studio/Tango.Stubs/StubBase.cs +++ b/Software/Visual_Studio/Tango.Stubs/StubBase.cs @@ -28,7 +28,6 @@ namespace Tango.Stubs protected set { _state = value; RaisePropertyChanged(nameof(State)); } } - public StubBase(ITransporter transporter) { Transporter = transporter; diff --git a/Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs b/Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs index e378791d2..dc03f538e 100644 --- a/Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs +++ b/Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core; using Tango.Logging; using Tango.PMR; using Tango.PMR.Stubs; @@ -15,11 +16,23 @@ namespace Tango.Stubs.Stubs { public Progress(ITransporter transporter) : base(transporter) { + Amount = 100; + Delay = 4; } + [ParameterItem(Minimum = null, Maximum = null, Default = 100.0)] + public double Amount { get; set; } + + [ParameterItem(Minimum = null, Maximum = null, Default = 4.0)] + public double Delay { get; set; } + protected override Task OnRun(Action multiResponseCallback) { - Transporter.SendContinuousRequest(MessageFactory.CreateTangoMessage(), (response) => + Transporter.SendContinuousRequest(MessageFactory.CreateTangoMessage(new ProgressRequest() + { + Amount = (int)Amount, + Delay = (int)Delay, + }), (response) => { multiResponseCallback(response.Progress.ToString()); }); -- cgit v1.3.1