aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/StubRealTimeUsage.c
blob: 765e183cb950f7a0f3a58a9bd4c64e752abe49f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 { 
/*
 * 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);
}