aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_HW_Version.c
blob: 2d7137a1683510d10225a2ec449da3a93a1b283f (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <Container.h>
#include <DataDef.h>

#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_uart.h"
#include "driverlib/rom_map.h"
#include "driverlib/rom.h"
#include "driverlib/gpio.h"

#include "Drivers/USB_Communication/USBCDCD.h"
#include "Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"
#include "Drivers/FPGA/FPGA.h"

#include "MessageContainer.pb-c.h"
#include <PMR/Stubs/StubHWVersionResponse.pb-c.h>
#include <PMR/Stubs/StubHWVersionRequest.pb-c.h>


#include "Stub_Status.h"




void Stub_HWVersionRequest(MessageContainer* requestContainer)
{
    uint32_t status = FAILED;
    unsigned char Brd_ID  = 0;
    unsigned char Assy_ID = 0;

    MessageContainer responseContainer;

    StubHWVersionRequest* request = stub_hwversion_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);

    status = Read_HW_Version(&Brd_ID, &Assy_ID);

    StubHWVersionResponse response =   STUB_HWVERSION_RESPONSE__INIT;

    status_response(status,&response.status, &response.statusword ,&response.has_statusword);

    response.brd_id = Brd_ID ;
    response.has_brd_id = true;
    response.assy_id = Assy_ID;
    response.has_assy_id = true;
    
    responseContainer = createContainer(MESSAGE_TYPE__StubHWVersionResponse, requestContainer->token, true, &response, &stub_hwversion_response__pack, &stub_hwversion_response__get_packed_size);

    Write_status_response(status);

    //free(request);
    //-------------------------------------------------------------------------------------------
    uint8_t* container_buffer = 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);
    //free(container_buffer);
    //free(requestContainer);

    stub_hwversion_request__free_unpacked(request,NULL);

}