aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Automation/UI.cs
blob: 2c200e10f350b2995cf656554a29fc3edf318b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.MachineStudio.Common.Automation
{
    public class UI
    {
        public static String LoginButton { get; set; } = nameof(LoginButton);
    }
}
alic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * 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/KeepAliveRequest.pb-c.h>
#include <PMR/Connection/KeepAliveResponse.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 "drivers/FPGA/FPGA.h"

#include "StateMachines/Printing/PrintingSTM.h"

#include "Modules/heaters/heaters_ex.h"
#include "modules/Diagnostics/Diagnostics.h"
#include "Modules/AlarmHandling/AlarmHandling.h"
#include "Modules/Stubs_Handler/Stub_HW_Version.h"

char HexToDecimal(char hex)
{
    int i = hex % 0x10;
    int j = hex / 0x10;
    return j*10+i;
}
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;

    if (GeneralHwReady == false)
    {
        return;
    }
    unsigned char Major = 0;
    unsigned char Year = 0 ;
    unsigned char Month = 0;
    unsigned char Day = 0;

	char Version[30] = {0};
	char FPGA1Version[30] = {0};
	char FPGA2Version[30] = {0};
	char FPGA3Version[30] = {0};
	char BoardVersion[30] = {0};
	char AssyVersion[30] = {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, 30, "%d.%d.%d.%d",_gTangoVersion.m_major,_gTangoVersion.m_minor,_gTangoVersion.m_patch,_gTangoVersion.m_build);
    DevInfo.version = Version;

    FPGA_ReadVersion(1, &Major, &Year, &Month, &Day);
    usnprintf(FPGA1Version, 30, "FPGA1: Ver %d %d/%d/20%d",HexToDecimal(Major), HexToDecimal(Day),HexToDecimal(Month),HexToDecimal(Year));
    DevInfo.fpga1version = FPGA1Version;

    FPGA_ReadVersion(2, &Major, &Year, &Month, &Day);
    usnprintf(FPGA2Version, 30, "FPGA2: Ver %d %d/%d/20%d",HexToDecimal(Major), HexToDecimal(Day),HexToDecimal(Month),HexToDecimal(Year));
    DevInfo.fpga2version = FPGA2Version;

    FPGA_ReadVersion(3, &Major, &Year, &Month, &Day);
    usnprintf(FPGA3Version, 30, "FPGA3: Ver %d %d/%d/20%d",HexToDecimal(Major), HexToDecimal(Day),HexToDecimal(Month),HexToDecimal(Year));
    DevInfo.fpga3version = FPGA3Version;

    Read_HW_Version(BoardVersion, AssyVersion);

    DevInfo.boardrevision = BoardVersion;
    DevInfo.assemblyversion = AssyVersion;



    responseContainer = createContainer(MESSAGE_TYPE__ConnectResponse, requestContainer->token, true, &response, &connect_response__pack, &connect_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);
    my_free(responseContainer.data.data);
    SendChars((char*)container_buffer, container_size);
    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();
    JobStopReporting();
    AlarmHandlingStop();
    //UART_ResetBuffers();
    //-------------------------------------------------------------------------------------------
    uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    my_free(responseContainer.data.data);
    SendChars((char*)container_buffer, container_size);
    //disconnect_request__free_unpacked(request,NULL);
    //CommunicationMailboxFlush();
    //USBCDCD_Reinit();

}
int KeepAliveOneSecondCounter = 0;
#define KEEPALIVE_COMMUNICATION_ABORT_LIMIT 30
bool KeepAliveActive = false;
void KeepAliveRequestFunc(MessageContainer* requestContainer)
{
    MessageContainer responseContainer;

    //KeepAliveRequest* request = keep_alive_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
    KeepAliveResponse response =   KEEP_ALIVE_RESPONSE__INIT;

    KeepAliveOneSecondCounter = 0;
    KeepAliveActive = true;
    responseContainer = createContainer(MESSAGE_TYPE__KeepAliveResponse, requestContainer->token, true, &response, &keep_alive_response__pack, &keep_alive_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);
    my_free(responseContainer.data.data);
    SendChars((char*)container_buffer, container_size);
    //keep_alive_request__free_unpacked(request,NULL);
}
void KeepAliveOneSecondCall(void)
{
    if (KeepAliveActive == false)
        return;
    KeepAliveOneSecondCounter++;
    if (KeepAliveOneSecondCounter > KEEPALIVE_COMMUNICATION_ABORT_LIMIT)
    {
        Report("keepalive ",__FILE__,__LINE__,KeepAliveOneSecondCounter,RpWarning,msec_millisecondCounter, 0);
        //LOG_ERROR(KeepAliveOneSecondCounter, "Communication keepalive failed");
        KeepAliveOneSecondCounter = 0;
        KeepAliveActive = false;
        ReportStopReporting();
        DiagnosticsStop();
        JobStopReporting();
        AlarmHandlingStop();
        //CommunicationMailboxFlush();

        USBCDCD_init();
        //USBCDCD_Reinit();
        //UART_ResetBuffers();
    }
}