aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/StubRealTimeUsage.c
blob: 765e183cb950f7a0f3a58a9bd4c64e752abe49f5 (plain)
1
2
3
4
5
6
7
8
9
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.h
/*
 * StubRealTimeUsage.c

 *
 *  Created on: 15 may 2018
 *      Author: shlomo
 */
/*
 * Stub_RealTimeUsage.c
 *
 *  Created on: May 14, 2018
 *      Author: avi
 */



#include <Container.h>
#include <DataDef.h>

#include <PMR/Stubs/StubRealTimeUsageResponse.pb-c.h>
#include <PMR/Stubs/StubRealTimeUsageRequest.pb-c.h>

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_uart.h"

#include "Drivers/USB_Communication/USBCDCD.h"


#include "MessageContainer.pb-c.h"

#include "Stub_Status.h"
#include "common/utilities/idle_task.h"


#include "Modules/thread/thread.h"


void Stub_RealTimeUsageRequest(MessageContainer* requestContainer)
{

    MessageContainer responseContainer;

    StubRealTimeUsageRequest* request = stub_real_time_usage_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);

    StubRealTimeUsageResponse response =   STUB_REAL_TIME_USAGE_RESPONSE__INIT;


    response.n_percentile = 101;
    response.percentile = my_malloc(sizeof(response.percentile)*response.n_percentile);
    if (response.percentile)
        IdleTaskGetLoadTable(response.percentile);
    else
        response.n_percentile = 0;
    //free(request);
    //-------------------------------------------------------------------------------------------
    responseContainer = createContainer(MESSAGE_TYPE__StubRealTimeUsageResponse, requestContainer->token, true, &response, &stub_real_time_usage_response__pack, &stub_real_time_usage_response__get_packed_size);
    uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    free(responseContainer.data.data);
    SendChars((char*)container_buffer, container_size);
    if (response.percentile)
        free(response.percentile);

    stub_real_time_usage_request__free_unpacked(request,NULL);
}