aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Communication/Connection.c
blob: f7d86cf2757a7111209fc992e770b07d02c9b31b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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; fo
/*
 * Connection.c

 *
 *  Created on: 4 June 2018
 *      Author: shlomo
 */

#include <Container.h>
#include <DataDef.h>
#include <PMR/Common/MessageContainer.pb-c.h>
#include <PMR/Connection/ConnectRequest.pb-c.h>
#include <PMR/Connection/ConnectResponse.pb-c.h>
#include <PMR/Connection/DisConnectRequest.pb-c.h>
#include <PMR/Connection/DisConnectResponse.pb-c.h>
#include <PMR/Connection/DeviceInformation.pb-c.h>

#include "Common/SW_Info/SW_Info.h"
#include "Common/report/report.h"
#include <utils/ustdlib.h>
#include "StateMachines/Printing/PrintingSTM.h"
#include "drivers/Uart_Comm/Uart.h"


void ConnectionRequest(MessageContainer* requestContainer)
{
    MessageContainer responseContainer;

    ConnectRequest* request = connect_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
    DeviceInformation DevInfo = DEVICE_INFORMATION__INIT;
    ConnectResponse response =   CONNECT_RESPONSE__INIT;

    char Version[20] = {0};
    response.deviceinformation = &DevInfo;
    /*
    extern TangoVersion_t _gTangoVersion;
    extern char Dat[50];
    extern char _gTangoName [MAX_STRING_LEN];//d
      */
    DevInfo.builddate = Dat;
    DevInfo.name = _gTangoName;
    usnprintf(Version, 20, "%d.%d.%d.%d",_gTangoVersion.m_major,_gTangoVersion.m_minor,_gTangoVersion.m_patch,_gTangoVersion.m_build);
    DevInfo.version = Version;

    responseContainer = createContainer(MESSAGE_TYPE__ConnectResponse, requestContainer->token, true, &response, &connect_response__pack, &connect_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);
    free(responseContainer.data.data);
    SendChars((char*)container_buffer, container_size);
    //free(container_buffer);
    //free(requestContainer);
    connect_request__free_unpacked(request,NULL);
}
void DisconnectionRequest(MessageContainer* requestContainer)
{
    MessageContainer responseContainer;

    DisconnectRequest* request = disconnect_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
    DisconnectResponse response =   DISCONNECT_RESPONSE__INIT;

    responseContainer = createContainer(MESSAGE_TYPE__DisconnectResponse, requestContainer->token, true, &response, &disconnect_response__pack, &disconnect_response__get_packed_size);
    ReportStopReporting();
    DiagnosticsStop();
    HeatingStopReporting();
    JoStopReporting();
    UART_ResetBuffers();
    //-------------------------------------------------------------------------------------------
    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);
    disconnect_request__free_unpacked(request,NULL);
}