aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Procedure.c
blob: d1ba28d7edac6fda80844a1cd0ea7248f2c0bac5 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <Container.h>
#include <PMR/Common/MessageContainer.pb-c.h>
#include <PMR/Stubs/ProcedureRequest.pb-c.h>
#include <PMR/Stubs/ProcedureResponse.pb-c.h>
#include "include.h"
#include "driverlib/gpio.h"

#include "Communication/Connection.h"

#include "Drivers/USB_Communication/USBCDCD.h"
#include "drivers/Flash_Memory/FATFS/ff.h"
#include "drivers/Flash_Memory/FATFS/Control_File_System.h"
#include "drivers/Flash_ram/FlashProgram.h"
#include "drivers/adc_sampling/adc.h"
#include "drivers/Heater/TemperatureSensor.h"
#include "drivers/ADC_Sampling/adc.h"
#include "drivers/Flash_ram/MCU_E2Prom.h"
#include "Drivers/SSI_Comm/Dancer/Dancer.h"
#include "Drivers/I2C_Communication/Head_Card/PT100/Head_PT100_ADC.h"
#include "Drivers/I2C_Communication/Head_Card/Fan/fan_click.h"
#include "Drivers/I2C_Communication/Head_Card/Fan/Head_Fan.h"
#include "drivers/Motors/Motor.h"
#include "drivers/Valves/Valve.h"
#include "drivers/FPGA/FPGA_SPI_Comm.h"
#include <Drivers/I2C_Communication/I2C.h>
#include <Drivers/I2C_Communication/Head_Card/I2C_Head_Mux.h>
#include "Drivers/I2C_Communication/Head_Card/IO_Ports/Head_IO.h"
#include "drivers/adc_sampling/adc.h"
#include <Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.h>
#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h>
#include <Drivers/I2C_Communication/I2C_Task.h>
#include <Drivers/I2C_Communication/WHS_Card/D_AD5272_Rheostat/WHS_Rheostat.h>
#include <Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC_Blower/WHS_Blower.h>
#include <Drivers/I2C_Communication/WHS_Card/D_MAX11614_ADC/WHS_MAX11614_A2D.h>
#include <Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.h>
#include "Drivers/I2C_Communication/Dispenser_Card/EEPROM/Dispenser_EEPROM.h"
#include "drivers/Uart_Comm/WHS_Controller_Comm/WHS_UART/WHS_Uart.h"
#include <Drivers/I2C_Communication/WHS_Card/IO_Extender_Ports_TCA9555/WHS_IO.h>
#include "drivers/Heater/TemperatureSensor.h"
#include "Drivers/I2C_Communication/Head_Card/PT100/ADS122X04.h"

#include "Modules/IFS/ifs.h"
#include "Modules/IDS/ids_ex.h"
#include "Modules/IDS/ids.h"
#include "Modules/Control/MillisecTask.h"
#include "modules/thread/thread_ex.h"
#include "modules/heaters/heaters_ex.h"
#include "modules/waste/waste_ex.h"
#include "AlarmHandling/AlarmHandling.h"

#include "StateMachines/Initialization/PowerOffSequence.h"
#include "StateMachines/Initialization/PowerIdle.h"

extern HeadBoardTempSensConfigStruc  HeadTempSensConfig[MAX_HEAD_CARD_TEMP_SENS_ID];
extern float NumberOfRotationPerPassage;  // how many rotations per spool passage
extern void HeaterSafetyTestSetLimits(int limit);

//#include "graphics_adapter.h"
extern uint8_t Input_Voltage;
extern uint8_t Test_Read_Buf[4];

extern uint8_t Head_Fan_PWM_Command[2];
extern uint16_t Head_Fan_Tach[2];
extern bool doorState;

uint32_t temp1,temp2;

void Stub_ProcedureRequest(MessageContainer* requestContainer)
{
    MessageContainer responseContainer;
    bool ResetNeeded = false;

    ProcedureRequest* request = procedure_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
    int rc, i,n_param = request->n_param;
    ProcedureResponse response = PROCEDURE_RESPONSE__INIT;
    BTSRParameters *BtsrPrameters = NULL;
    char str[200];
/*  protobuf_c_boolean has_type;
  int32_t type;
  protobuf_c_boolean has_timeout;
  int32_t timeout;
  char *testname;
  size_t n_param;
  float *param;
 * */
    //writeLine("Procedure Request...");
    Report(request->testname,__FILE__,__LINE__,(int)request->type,RpWarning,(int) request->n_param,0);

    if (request->has_type)
    {
        switch (request->type)
        {
        case 1:
            BtsrPrameters = my_malloc(sizeof(BTSRParameters));
            BtsrPrameters->btsryarntype = request->param[0];
            BtsrPrameters->btsrapplicationtype = request->param[1];
            BtsrPrameters->feedingtension = request->param[2];
            BtsrPrameters->exittension =  request->param[3];
            BtsrPrameters->tensionerror = request->param[4];
            BtsrPrameters->threadlengthfactor = request->param[5];
            rc = BtsrSaveParamsToEeprom(BtsrPrameters);
            free(BtsrPrameters);
            response.replymessage = request->testname;
            if (n_param)
            {
                response.replyvalue = (float*)my_malloc(sizeof(float *)*(request->n_param));
                response.n_replyvalue = request->n_param;
                for(i=0;i<n_param;i++)
                {
                    Report(request->testname,__FILE__,__LINE__,(int)request->type,RpWarning,(int) request->n_param,0);
                    response.replyvalue[i] = request->param[i];
                }
            }
            response.time = msec_millisecondCounter;
            response.type = request->type;
            break;
        case 2:
            BtsrPrameters = my_malloc(sizeof(BTSRParameters));
            rc = BtsrReadParamsFromEeprom(BtsrPrameters);
            sprintf(str, "type = %d, app = %d, tension = %f, exittension = %f, tensionerror = %f, lengthfactor = %f", BtsrPrameters->btsryarntype,
                    BtsrPrameters->btsrapplicationtype, BtsrPrameters->feedingtension, BtsrPrameters->exittension, BtsrPrameters->tensionerror, BtsrPrameters->threadlengthfactor);
            response.replymessage = str;
            if (n_param)
            {
                response.replyvalue = (float*)my_malloc(sizeof(float *)*(request->n_param));
                response.n_replyvalue = request->n_param;
                for(i=0;i<n_param;i++)
                {
                    Report(request->testname,__FILE__,__LINE__,(int)request->type,RpWarning,(int) request->n_param,0);
                    response.replyvalue[i] = request->param[i];
                }
            }
            response.time = msec_millisecondCounter;
            response.type = request->type;
            free(BtsrPrameters);
            break;
            default:
                response.replymessage = request->testname;
                if (n_param)
                {
                    response.replyvalue = (float*)my_malloc(sizeof(float *)*(request->n_param));
                    response.n_replyvalue = request->n_param;
                    for(i=0;i<n_param;i++)
                    {
                        Report(request->testname,__FILE__,__LINE__,(int)request->type,RpWarning,(int) request->n_param,0);
                        response.replyvalue[i] = request->param[i];

                    }
                }
                response.time = msec_millisecondCounter;
                response.type = request->type;
                break;
        }
    }

    responseContainer = createContainer(MESSAGE_TYPE__ProcedureResponse, requestContainer->token, true, &response, &procedure_response__pack, &procedure_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);
    my_free(responseContainer.data.data);
    if (response.replyvalue)
        my_free(response.replyvalue);
    if (request)
        procedure_request__free_unpacked(request,NULL);
    //writeLine("Procedure Completed!");
    SendChars((char*)container_buffer, container_size);
    //free(container_buffer);
    if (ResetNeeded == true)
    {
        REPORT_MSG(255,"Update successful, Rebooting in 5 seconds");
        Task_sleep (eOneSecond*5);
        Power_Reset();
        ResetNeeded = false;
    }

    return;

}