aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Stub_Valve.c
blob: c6ea742a75124bc7ff8792b36d1500e3a0887d70 (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
#include <Container.h>
#include <DataDef.h>
#include <PMR/Common/MessageContainer.pb-c.h>
#include <PMR/Stubs/StubValveRequest.pb-c.h>
#include <PMR/Stubs/StubValveResponse.pb-c.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/gpio.h"

#include "Drivers/USB_Communication/USBCDCD.h"
#include "drivers/Valves/Valve.h"


#include "Stub_Status.h"

void Stub_ValveRequest(MessageContainer* requestContainer)
{
    MessageContainer responseContainer;
    uint32_t status = PASSED;

    StubValveRequest* request = stub_valve_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);

	/*
	request->valveid
	request->inkflow
	request->valveon
    */

    if(request->inkflow == 3)
    {
        Control3WayValvesWithCallback (request->valveid, request->valveon, NULL);
    }
    else
    {
        Valve_Set(request->valveid, request->valveon);
    }

    StubValveResponse response =   STUB_VALVE_RESPONSE__INIT;

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

    responseContainer = createContainer(MESSAGE_TYPE__StubValveResponse, requestContainer->token, true, &response, &stub_valve_response__pack, &stub_valve_response__get_packed_size);

    //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_valve_request__free_unpacked(request,NULL);
}