aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/General/process.c
blob: 872f772e2fe52fc125acd6cfefb86d41771f7642 (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
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; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* 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 */
/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
/* Generated from: FileChunkDownloadResponse.proto */

/* Do not generate deprecated warnings for self */
#ifndef PROTOBUF_C__NO_DEPRECATED
#define PROTOBUF_C__NO_DEPRECATED
#endif

#include "FileChunkDownloadResponse.pb-c.h"
void   file_chunk_download_response__init
                     (FileChunkDownloadResponse         *message)
{
  static const FileChunkDownloadResponse init_value = FILE_CHUNK_DOWNLOAD_RESPONSE__INIT;
  *message = init_value;
}
size_t file_chunk_download_response__get_packed_size
                     (const FileChunkDownloadResponse *message)
{
  assert(message->base.descriptor == &file_chunk_download_response__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t file_chunk_download_response__pack
                     (const FileChunkDownloadResponse *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &file_chunk_download_response__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t file_chunk_download_response__pack_to_buffer
                     (const FileChunkDownloadResponse *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &file_chunk_download_response__descriptor);
  return protobuf_c_message_pack_t
/*
 * process.c
 *
 *  Created on: 4 ���� 2018
 *      Author: shlomo
 */
//********************************************************************************************************************
#include <DataDef.h>
#include "include.h"
#include "process.h"

#include "heaters/heaters_ex.h"
#include "PMR/Printing/ProcessParameters.pb-c.h"
#include "PMR/Printing/UploadProcessParametersRequest.pb-c.h"
#include "PMR/Printing/UploadProcessParametersResponse.pb-c.h"
#include "PMR/Hardware/HardwarePidControlType.pb-c.h"
#include "PMR/common/MessageContainer.pb-c.h"

#include "drivers/Valves/Valve.h"
#include "drivers/I2C_Communication/ADC_MUX/ADC_MUX.h"

#include "modules/ids/ids_ex.h"
#include "Common/SWUpdate/FileSystem.h"
#include "StateMachines/Initialization/PowerIdle.h"
#include "StateMachines/Initialization/InitSequence.h"

#include "drivers/Flash_ram/FlashProgram.h"
#include <Drivers/I2C_Communication/I2C_Task.h>
#include "drivers/Flash_ram/MCU_E2Prom.h"

#include <Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC_Blower/WHS_Blower.h>

double dyeingspeed = 0;
double dryerbufferlength = 0;
double mininkuptake = 0;
double feedertension = 0;
double pullertension = 0;
double windertension = 0;
double headairflow = 5.0;
double dryerairflow = 5.0;
double pressurebuildup = 0;
double dryerzone1temp = 0;
int32_t tableindex = 0;
double headBlowersFlow[2] = {1.5,1.5};

double dryerbufferMeters = 0;
double dryerbufferCentimeters = 0;

#define MAX_ALLOWED_TEMPERATURE 280
int MaxAllowedTemperature = MAX_ALLOWED_TEMPERATURE;
char ProcessParamsConfigPath[50] = "0://SysInfo//ProcessP.cfg";

bool MachineReadyForHeating = false;
void SetMachineReadyForHeating(bool value)
{
    MachineReadyForHeating = value;
}
ProcessParameters ProcessParametersKeep;
void HeatersStopControlOnHeatersOff(ProcessParameters* ProcessParams)
{
    uint32_t temp_sum = 0;
    temp_sum += ProcessParams->dryerzone1temp;
    temp_sum += ProcessParams->dryerzone2temp;
    temp_sum += ProcessParams->dryerzone3temp;
    temp_sum += ProcessParams->mixertemp;
    temp_sum += ProcessParams->headzone1temp;
    temp_sum += ProcessParams->headzone2temp;
    temp_sum += ProcessParams->headzone3temp;
    temp_sum += ProcessParams->headzone4temp;
    temp_sum += ProcessParams->headzone5temp;
    temp_sum += ProcessParams->headzone6temp;
    temp_sum += ProcessParams->headzone7temp;
    temp_sum += ProcessParams->headzone8temp;
    temp_sum += ProcessParams->headzone9temp;
    temp_sum += ProcessParams->headzone10temp;
    temp_sum += ProcessParams->headzone11temp;
    temp_sum += ProcessParams->headzone12temp;

    if (temp_sum == 0)// heating off
    {
        HeatersControlStop();
        REPORT_MSG(temp_sum,"Heating control off - temperatures off");
    }
    else
    {
        HeatersControlStart();
    }
}
char ProcessErrorMsg[50];
uint32_t HandleProcessParameters(ProcessParameters* ProcessParams,bool saveData)
{
    uint32_t status = 0,Bytes = 0;
    if (ProcessParams==NULL)
        {
            status = ERROR_CODE__INVALID_PARAMETER;
            ReportWithPackageFilter(InitFilter,"HandleProcessParameters NULL",__FILE__,(int)__LINE__,(int)0,RpWarning,(int)0,0);
            usnprintf(ProcessErrorMsg, 50, "ProcessParameters NULL");
            return status;
        }
    if (ProcessParams->dryerzone1temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->dryerzone2temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->dryerzone3temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->mixertemp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->headzone1temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->headzone2temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->headzone3temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->headzone4temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->headzone5temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (ProcessParams->headzone6temp > MaxAllowedTemperature) status = ERROR_CODE__INVALID_PARAMETER;
    if (status != 0)
    {
        status = ERROR_CODE__INVALID_PARAMETER;
        ReportWithPackageFilter(InitFilter,"HandleProcessParameters Temperature too high",__FILE__,(int)__LINE__,(int)status,RpWarning,(int)0,0);
        usnprintf(ProcessErrorMsg, 50, "ProcessParameters Temperature too high");
        return status;
    }
    if (ProcessParams)
    {
        memcpy (&ProcessParametersKeep,ProcessParams,sizeof(ProcessParameters));
    }
    if (saveData == true)
    {
        if ((ProcessParams->dryerzone1temp > 0.1)&&(ProcessParams->headzone2temp > 0.1)&&(ProcessParams->headzone3temp > 0.1)&&(ProcessParams->headzone1temp > 0.1))//NOT turning off heaters
        {
            Bytes = sizeof(ProcessParameters);
            FileWrite(ProcessParams,Bytes,ProcessParamsConfigPath,BIOS_WAIT_FOREVER);
            EraseFlashSection(PROCESS_PARAMETERS_MAP_IN_FLASH);
            ReadAppAndProgram(PROCESS_PARAMETERS_MAP_IN_FLASH, 4,&Bytes);
            ReadAppAndProgram(PROCESS_PARAMETERS_MAP_IN_FLASH+4, Bytes, ProcessParams);
            REPORT_MSG(Bytes,"Bytes write to flash");
        }
        else
        {
            if (ProcessParams->has_headairflow == false)
                ProcessParams->headairflow = headairflow;
            if (ProcessParams->has_lblowerflow == false)
                ProcessParams->lblowerflow = headBlowersFlow[HEAD_FAN_LEFT];
            if (ProcessParams->has_rblowerflow == false)
                ProcessParams->rblowerflow = headBlowersFlow[HEAD_FAN_RIGHT];
            if (ProcessParams->has_feedertension == false)
                ProcessParams->feedertension = feedertension;
            if (ProcessParams->has_windertension == false)
                ProcessParams->windertension = windertension;
            if (ProcessParams->has_pullertension == false)
                ProcessParams->pullertension = pullertension;
            ReportWithPackageFilter(InitFilter,"HandleProcessParameters temp off blower on",__FILE__,(int)__LINE__,(int)ProcessParams->headairflow,RpWarning,(int)ProcessParametersKeep.headairflow,0);
        }
    }
    HeatersStopControlOnHeatersOff(ProcessParams);
    dyeingspeed = ProcessParams->dyeingspeed;
    dryerbufferlength = ProcessParams->dryerbufferlength;
    dryerbufferMeters = dryerbufferlength*0.76+0.9;
    dryerbufferCentimeters = dryerbufferlength*76+90;



    mininkuptake = ProcessParams->mininkuptake;
    feedertension = ProcessParams->feedertension;
    pullertension = ProcessParams->pullertension;
    windertension = ProcessParams->windertension;
    headairflow = ProcessParams->headairflow;
    dryerairflow = ProcessParams->dryerairflow;
    pressurebuildup = ProcessParams->pressurebuildup;
    dryerzone1temp = ProcessParams->dryerzone1temp;

    if (MachineReadyForHeating == false)
    {
        ReportWithPackageFilter(InitFilter,"HandleProcessParameters Init not ready",__FILE__,(int)__LINE__,(int)status,RpWarning,(int)GetMachineState(),0);
        status = ERROR_CODE__GENERAL_ERROR;
        usnprintf(ProcessErrorMsg, 50, "ProcessParameters Init not ready");
        return status;
    }

    //Report("drier buffer length",__FILE__,(int)dryerbufferlength,(int)dryerbufferMeters*100,RpWarning,(int)dryerbufferCentimeters,0);
    ReportWithPackageFilter(InitFilter,"HandleProcessParameters Head type",__FILE__,(int)headairflow,(int)Head_Type,RpWarning,(int)dryerbufferCentimeters,0);

    WHS_Set_SetPoint_Q_value(headairflow);

    if (ProcessParams->mixertemp>1)
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__MixerHeater, true,ProcessParams->mixertemp);
    else
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__MixerHeater, false,ProcessParams->mixertemp);
    if (ProcessParams->headzone1temp>1)
    {
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ1, true,ProcessParams->headzone1temp);
    }
    else
    {
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ1, false,ProcessParams->headzone1temp);
    }
    if (ProcessParams->headzone2temp>1)
    {
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ2, true,ProcessParams->headzone2temp);
    }
    else
    {
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ2, false,ProcessParams->headzone2temp);
    }
    if (ProcessParams->headzone3temp>1)
    {
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ3, true,ProcessParams->headzone3temp);
    }
    else
    {
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ3, false,ProcessParams->headzone3temp);
    }
    if(Head_Type != HEAD_TYPE_ARC)
    {
        Trigger_HeaterWriting();
        if (ProcessParams->headzone4temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ4, true,ProcessParams->headzone4temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ4, false,ProcessParams->headzone4temp);
        }
        if (ProcessParams->headzone5temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ5, true,ProcessParams->headzone5temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ5, false,ProcessParams->headzone5temp);
        }
        if (ProcessParams->headzone6temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ6, true,ProcessParams->headzone6temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ6, false,ProcessParams->headzone6temp);
        }
    }
    if (ProcessParams->dryerzone1temp>1)
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__DryerAirTemperature, true,ProcessParams->dryerzone1temp);
    else
        status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__DryerAirTemperature, false,ProcessParams->dryerzone1temp);
    if(Head_Type == HEAD_TYPE_FLAT)
    {
        if (ProcessParams->headzone7temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ7, true,ProcessParams->headzone7temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ7, false,ProcessParams->headzone7temp);
        }
        Trigger_HeaterWriting();
        if (ProcessParams->headzone8temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ8, true,ProcessParams->headzone8temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ8, false,ProcessParams->headzone8temp);
        }
        if (ProcessParams->headzone9temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ9, true,ProcessParams->headzone9temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ9, false,ProcessParams->headzone9temp);
        }
        if (ProcessParams->headzone10temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ10, true,ProcessParams->headzone10temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ10, false,ProcessParams->headzone10temp);
        }
        Trigger_HeaterWriting();
        if (ProcessParams->headzone11temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ11, true,ProcessParams->headzone11temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ11, false,ProcessParams->headzone11temp);
        }
        if (ProcessParams->headzone12temp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ12, true,ProcessParams->headzone12temp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ12, false,ProcessParams->headzone12temp);
        }
    }
    if(Head_Type == HEAD_TYPE_ARC)
    {
        Trigger_HeaterWriting();
        if (ProcessParams->rblowertemp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadCoverHeater1, true,ProcessParams->rblowertemp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadCoverHeater1, false,ProcessParams->rblowertemp);
        }
        Trigger_HeaterWriting();
        if (ProcessParams->lblowertemp>1)
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadCoverHeater2, true,ProcessParams->lblowertemp);
        }
        else
        {
            status |= HeaterCommandRequestMessage(HARDWARE_PID_CONTROL_TYPE__HeadCoverHeater2, false,ProcessParams->lblowertemp);
        }

        status |= HeadBlowerCommandRequestMessage(HEAD_FAN_RIGHT, ProcessParams->rblowerflow);
        status |= HeadBlowerCommandRequestMessage(HEAD_FAN_LEFT, ProcessParams->lblowerflow);
        Trigger_HeaterWriting();
    }

    if (status)
    {
        ReportWithPackageFilter(InitFilter,"HandleProcessParameters start heaters error",__FILE__,(int)__LINE__,(int)status,RpWarning,(int)GetMachineState(),0);
        status = ERROR_CODE__JOB_TEMPERATURE_ALARM;
        usnprintf(ProcessErrorMsg, 50, "ProcessParameters start heaters error");
    }
   return status;//status;
}

void ProcessRequestFunc(MessageContainer* requestContainer)
{
    MessageContainer responseContainer;
    uint8_t* container_buffer;
    uint32_t status = 0;

    UploadProcessParametersRequest* request = upload_process_parameters_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
    ProcessParameters*  ProcessParams = request->processparameters;
    ////////////////////////////////////////////////////////////////////////
    /*UploadProcessParametersRequest* requesttest;
    uint8_t* buffer = NULL;
    uint32_t Bytes = 0;

    ProcessParameters*  ProcessParamsTest;
    FileRead(ProcessParamsConfigPath, &Bytes, &buffer);
    requesttest = upload_process_parameters_request__unpack(NULL, Bytes, buffer);
    //           ProcessParameters*  ProcessParams = process_parameters__unpack(NULL, Bytes, buffer);
           if (requesttest)
           {
               ProcessParamsTest = request->processparameters;
           }
       free (buffer);
       upload_process_parameters_request__free_unpacked(requesttest,NULL);
*/
/////////////////////////////////////////////////////////
    UploadProcessParametersResponse response = UPLOAD_PROCESS_PARAMETERS_RESPONSE__INIT;
    responseContainer = createContainer(MESSAGE_TYPE__UploadProcessParametersResponse, requestContainer->token, true, &response, &upload_process_parameters_response__pack, &upload_process_parameters_response__get_packed_size);

    //REPORT_MSG (ProcessParams->dryerzone1temp,"Process Params Dryer");
    PowerIdleOutOfIdleState();

    if (status == 0)
        status = HandleProcessParameters(ProcessParams,true);
    if ((status)&&(status != ERROR_CODE__GENERAL_ERROR)) //ignore init not ready result
    {
        responseContainer.has_error = true;
        responseContainer.error = (ErrorCode)status;
        responseContainer.errormessage = ProcessErrorMsg;
    }
    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(container_buffer, container_size);
    upload_process_parameters_request__free_unpacked(request,NULL);

}
uint32_t LoadProcessParamsFromFile(void)
{
    FRESULT Fresult = FR_OK;
    uint8_t* buffer = NULL;
    uint32_t Bytes = 0;

    Fresult = FileRead(ProcessParamsConfigPath, &Bytes, &buffer);
    if (Fresult == FR_OK)
    {
        ProcessParameters*  ProcessParams = (ProcessParameters*)buffer;

        if (ProcessParams!=NULL)
        {
            if ((ProcessParams->dryerzone1temp > 0.1)&&(ProcessParams->headzone2temp > 0.1)&&(ProcessParams->headzone3temp > 0.1)&&(ProcessParams->headzone4temp > 0.1))//NOT turning off heaters
            {
                Bytes = sizeof(ProcessParameters);
                EraseFlashSection(PROCESS_PARAMETERS_MAP_IN_FLASH);
                ReadAppAndProgram(PROCESS_PARAMETERS_MAP_IN_FLASH, 4,&Bytes);
                ReadAppAndProgram(PROCESS_PARAMETERS_MAP_IN_FLASH+4, Bytes, ProcessParams);
                REPORT_MSG(Bytes,"ProcessParameters Bytes write to flash");
                free (buffer);
            }
        }
        else
        {
            Report("process parameters not loaded",__FILE__,__LINE__,(int)0,RpWarning,(int)0,0);
            return ERROR;
        }
    }

    return Fresult;
}
uint32_t ProcessParamsInit(void)
{
    FRESULT Fresult = FR_NOT_READY;
    uint32_t Bytes;

    memcpy(&Bytes,(void *)PROCESS_PARAMETERS_MAP_IN_FLASH,sizeof(Bytes));
    REPORT_MSG(Bytes,"Bytes read from flash");

    if ((Bytes)&&(Bytes < 1000))
    {
        ProcessParameters*  ProcessParams = (ProcessParameters *)(PROCESS_PARAMETERS_MAP_IN_FLASH+4);
        Fresult = HandleProcessParameters(ProcessParams,false);
    }
    else
    {
        if (LoadProcessParamsFromFile()==OK)
        {
            memcpy(&Bytes,(void *)PROCESS_PARAMETERS_MAP_IN_FLASH,sizeof(Bytes));
            REPORT_MSG(Bytes,"ProcessParams Bytes read from flash");

            if ((Bytes)&&(Bytes < 1000))
            {
                ProcessParameters*  ProcessParams = (ProcessParameters *)(PROCESS_PARAMETERS_MAP_IN_FLASH+4);
                Fresult = HandleProcessParameters(ProcessParams,false);
            }
        }
    }

    return Fresult;
}