aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Document/NewLineFinder.cs
blob: 6ecf8c1e59e4312c506336a5dd33a094c9221533 (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
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace Tango.Scripting.Editors.Document
{
	static class NewLineFinder
	{
		static readonly char[] newline = { '\r', '\n' };
		
		internal static readonly string[] NewlineStrings = { "\r\n", "\r", "\n" };
		
		/// <summary>
		/// Gets the location of the next new line character, or SimpleSegment.Invalid
		/// if none is found.
		/// </summary>
		internal static SimpleSegment NextNewLine(string text, int offset)
		{
			int pos = text.IndexOfAny(newline, offset);
			if (pos >= 0) {
				if (text[pos] == '\r') {
					if (pos + 1 < text.Length && text[pos + 1] == '\n')
						return new SimpleSegment(pos, 2);
				}
				return new SimpleSegment(pos, 1);
			}
			return SimpleSegment.Invalid;
		}
		
		/// <summary>
		/// Gets the location of the next new line character, or SimpleSegment.Invalid
		/// if none is found.
		/// </summary>
		internal static SimpleSegment NextNewLine(ITextSource text, int offset)
		{
			int textLength = text.TextLength;
			int pos = text.IndexOfAny(newline, offset, textLength - offset);
			if (pos >= 0) {
				if (text.GetCharAt(pos) == '\r') {
					if (pos + 1 < textLength && text.GetCharAt(pos + 1) == '\n')
						return new SimpleSegment(pos, 2);
				}
				return new SimpleSegment(pos, 1);
			}
			return SimpleSegment.Invalid;
		}
	}
	
	partial class TextUtilities
	{
		/// <summary>
		/// Finds the next new line character starting at offset.
		/// </summary>
		/// <param name="text">The text source to search in.</param>
		/// <param name="offset">The starting offset for the search.</param>
		/// <param name="newLineType">The string representing the new line that was found, or null if no new line was found.</param>
		/// <returns>The position of the first new line starting at or after <paramref name="offset"/>,
		/// or -1 if no new line was found.</returns>
		public static int FindNextNewLine(ITextSource text, int offset, out string newLineType)
		{
			if (text == null)
				throw new ArgumentNullException("text");
			if (offset < 0 || offset > text.TextLength)
				throw new ArgumentOutOfRangeException("offset", offset, "offset is outside of text source");
			SimpleSegment s = NewLineFinder.NextNewLine(text, offset);
			if (s == SimpleSegment.Invalid) {
				newLineType = null;
				return -1;
			} else {
				if (s.Length == 2) {
					newLineType = "\r\n";
				} else if (text.GetCharAt(s.Offset) == '\n') {
					newLineType = "\n";
				} else {
					newLineType = "\r";
				}
				return s.Offset;
			}
		}
		
		/// <summary>
		/// Gets whether the specified string is a newline sequence.
		/// </summary>
		public static bool IsNewLine(string newLine)
		{
			return newLine == "\r\n" || newLine == "\n" || newLine == "\r";
		}
		
		/// <summary>
		/// Normalizes all new lines in <paramref name="input"/> to be <paramref name="newLine"/>.
		/// </summary>
		public static string NormalizeNewLines(string input, string newLine)
		{
			if (input == null)
				return null;
			if (!IsNewLine(newLine))
				throw new ArgumentException("newLine must be one of the known newline sequences");
			SimpleSegment ds = NewLineFinder.NextNewLine(input, 0);
			if (ds == SimpleSegment.Invalid) // text does not contain any new lines
				return input;
			StringBuilder b = new StringBuilder(input.Length);
			int lastEndOffset = 0;
			do {
				b.Append(input, lastEndOffset, ds.Offset - lastEndOffset);
				b.Append(newLine);
				lastEndOffset = ds.EndOffset;
				ds = NewLineFinder.NextNewLine(input, lastEndOffset);
			} while (ds != SimpleSegment.Invalid);
			// remaining string (after last newline)
			b.Append(input, lastEndOffset, input.Length - lastEndOffset);
			return b.ToString();
		}
		
		/// <summary>
		/// Gets the newline sequence used in the document at the specified line.
		/// </summary>
		public static string GetNewLineFromDocument(TextDocument document, int lineNumber)
		{
			DocumentLine line = document.GetLineByNumber(lineNumber);
			if (line.DelimiterLength == 0) {
				// at the end of the document, there's no line delimiter, so use the delimiter
				// from the previous line
				line = line.PreviousLine;
				if (line == null)
					return Environment.NewLine;
			}
			return document.GetText(line.Offset + line.Length, line.DelimiterLength);
		}
	}
}
an class="kt">void) { return PowerOffInProcess; } void PowerOffSetTemperatureThreshold (int32_t temperature) { if (temperature) { PowerOffTemperatureThreshold = temperature*100; Report("PowerOff Set Temperature",__FILE__,__LINE__,(int)PowerOffTemperatureThreshold,RpWarning,(int)3600,0); } } #define UPDATE_TIMEOUT 2 uint8_t UpdateCounter = 0; /*******************************************************************************************************/ uint32_t PowerOffScheduler(uint32_t IfIndex, uint32_t BusyFlag) { if (PowerOffMachineState > StoredMachineState) { StoredMachineState = PowerOffMachineState; PowerOffSequenceStateMachine (PowerOffMachineState); } PowerDownUpdate(PowerOffMachineState); return OK; } /*******************************************************************************************************/ uint32_t PowerOffInit(void) { LOG_ERROR(0,"Power Off Init"); PowerOffMachineState++; StopInitSequence(); setmachineActive(true); PowerIdleOutOfIdleState(); PowerOffInProcess = true; PowerOffControlId = AddControlCallback("PowerOff", PowerOffScheduler, eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); SetMachineStatus(MACHINE_STATE__PowerOff); return OK; } /*******************************************************************************************************/ uint32_t PowerOffCancel(void) { if (PowerOffMachineState >= POWER_OFF_HEAD_CLEAN) PowerOffMachineState = POWER_OFF_CANCELLED; PowerOffInProcess = false; return OK; } /************************************************************************shlomo */ uint32_t PowerOffHeadCleanControlId = 0xff; uint32_t PowerOffHeadCleanCallback(uint32_t DispenserId, uint32_t ReadValue) { if ( JobIsActive()== false) { //abort this control loop SafeRemoveControlCallback(PowerOffHeadCleanControlId, PowerOffHeadCleanCallback ); PowerOffHeadCleanControlId = 0xFF; PowerOffMachineState++; SetMachineStatus(MACHINE_STATE__PowerOff); } return OK; } /*******************************************************************************************************/ uint32_t PowerOffHeadClean(void) { //TBD if (AutoHoming_Config >= AutoHoming_PowerOff ) AutoHoming_Config = AutoHoming_JobEnd_PowerOn_off; if (ThreadCleaningJob(50) == OK) { if (PowerOffHeadCleanControlId != 0xFF) { RemoveControlCallback(PowerOffHeadCleanControlId, PowerOffHeadCleanCallback ); PowerOffHeadCleanControlId = 0xFF; //return ERROR; } PowerOffHeadCleanControlId = AddControlCallback(NULL, PowerOffHeadCleanCallback,eOneSecond , TemplateDataReadCBFunction,0,0, 0 ); } else { LOG_ERROR(0,"Clean job failed"); PowerOffMachineState++; SetMachineStatus(MACHINE_STATE__PowerOff); } // if ( PowerOffHeadCleanControlId == 0xFF) // return ERROR; return OK; } /*******************************************************************************************************/ bool DispenserHomingActive[MAX_SYSTEM_DISPENSERS] = {false,false,false,false,false,false,false,false}; uint32_t PowerOffDispenserHomingCallback(uint32_t DispenserId, uint32_t ReadValue) { DispenserHomingActive[DispenserId] = false; REPORT_MSG (DispenserId, "PowerOffDispenserHomingCallback"); return OK; } #define TI_DISPENSER_ID 4 #define DEFAULT_MIXER_CLEANING_SPEED 1000 #define DEFAULT_MIXER_CLEANING_TIMEOUT 10000 uint32_t PowerOffMixerFlushCallback(void) { //TBD int i; REPORT_MSG (PowerOffMachineState, "PowerOffMixerFlushCallback"); SafeRemoveControlCallback(PowerOffHeadCleanControlId, PowerOffMixerFlushCallback ); Control3WayValvesWithCallback ((Valves_t)TI_DISPENSER_ID, MidTank_Dispenser, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer TimerMotors_t HW_Motor_Id = DispenserIdToMotorId[TI_DISPENSER_ID]; MotorStop(HW_Motor_Id,Hard_Hiz); CurrentDispenserSpeed[TI_DISPENSER_ID] = 0; Task_sleep (20); if (AutoHoming_Config >= AutoHoming_PowerOff ) { for (i=0;i<MAX_SYSTEM_DISPENSERS;i++) { if(IDS_HomeDispenser(i,1000,PowerOffDispenserHomingCallback) == OK) { DispenserHomingActive[i] = true; REPORT_MSG (i, "PowerOffDispenserHomingCallback"); } } } PowerOffMachineState++; return OK; } uint32_t PowerOffMixerFlushDispenserStopCallback(void) { REPORT_MSG (PowerOffMachineState, "PowerOffMixerFlushDispenserStopCallback"); IDS_Dispenser_Start_Motor_and_Open_Valve(TI_DISPENSER_ID,DEFAULT_MIXER_CLEANING_SPEED,NULL); PowerOffHeadCleanControlId = AddControlCallback("Poweroff cleaning", PowerOffMixerFlushCallback,DEFAULT_MIXER_CLEANING_TIMEOUT , TemplateDataReadCBFunction,0,0, 0 ); return OK; } /*******************************************************************************************************/ uint32_t PowerOffMixerFlush(void) { int i; REPORT_MSG (PowerOffMachineState, "PowerOffMixerFlush"); Valve_Set(VALVE_MIXCHIP_WASTECH, Mixer_Waste); //if intersegment is defined throw the ink away for (i=0;i<MAX_SYSTEM_DISPENSERS;i++) { if (i!=TI_DISPENSER_ID) IDS_StopHomeDispenser(i); else { IDS_Dispenser_Close_Valve_And_Stop_Motor(i, PowerOffMixerFlushDispenserStopCallback); IDS_StopHomeDispenser(i); } } return OK; } /*******************************************************************************************************/ uint32_t PowerOffHeatersOff(void) { ProcessParameters ProcessParametersClear; ProcessParametersClear.dryerzone1temp = 0; ProcessParametersClear.dryerzone2temp = 0; ProcessParametersClear.dryerzone3temp = 0; ProcessParametersClear.mixertemp = 0; ProcessParametersClear.headzone1temp = 0; ProcessParametersClear.headzone2temp = 0; ProcessParametersClear.headzone3temp = 0; ProcessParametersClear.headzone4temp = 0; ProcessParametersClear.headzone5temp = 0; ProcessParametersClear.headzone6temp = 0; ProcessParametersClear.headzone7temp = 0; ProcessParametersClear.headzone8temp = 0; ProcessParametersClear.headzone9temp = 0; ProcessParametersClear.headzone10temp = 0; ProcessParametersClear.headzone11temp = 0; ProcessParametersClear.headzone12temp = 0; ProcessParametersClear.rblowertemp = 0; ProcessParametersClear.lblowertemp = 0; ProcessParametersClear.rblowerflow = 0; ProcessParametersClear.rblowerflow = 0; ProcessParametersClear.dyeingspeed = 40; ProcessParametersClear.headairflow = 8.0; if (HandleProcessParameters(&ProcessParametersClear,false)!= OK) { LOG_ERROR (PowerOffMachineState, "Turn Off Heaters failed"); return ERROR; } PowerOffMachineState++; return OK; } /*******************************************************************************************************/ uint32_t PowerOffStoreData(void) { //TBD REPORT_MSG (PowerOffMachineState, "Store Data"); IDS_Dispenser_Store_Data(); PowerOffMachineState++; return OK; } /*******************************************************************************************************/ int WaitForProcessCounter = 0; uint32_t PowerOffWaitForProcessesCallback(uint32_t IfIndex, uint32_t BusyFlag) { int i; bool HomingActive = false; for (i=0;i<MAX_SYSTEM_DISPENSERS;i++) { if (DispenserHomingActive[i] ==true) { HomingActive = true; } } if ((WHS_IsEmptying()|| //MidTankFillingActive()|| ThreadLoadingActive()|| SwUpgradeActive()|| (HomingActive == true))&& (WaitForProcessCounter++<900)) { REPORT_MSG (PowerOffMachineState, "Ongoing processes calback, wait for end of process"); resetIdleCounter(); } else { PowerOffMachineState++; SafeRemoveControlCallback(WaitForProcessControlId, PowerOffWaitForProcessesCallback); WaitForProcessControlId = 0xFF; } return OK; } /*******************************************************************************************************/ uint32_t PowerOffWaitForProcesses(void) { int i; REPORT_MSG (PowerOffMachineState, "Stop dispensers homing"); bool HomingActive = false; for (i=0;i<MAX_SYSTEM_DISPENSERS;i++) { if (DispenserHomingActive[i] ==true) { HomingActive = true; IDS_StopHomeDispenser(i); REPORT_MSG (i, "IDS_StopHomeDispenser"); IDS_HomeDispenserWaitForHomingEnd(i, 2*eOneMinute /*2 minutes*/ , PowerOffDispenserHomingCallback); } } if (WHS_IsEmptying()|| //MidTankFillingActive()|| ThreadLoadingActive()|| SwUpgradeActive()|| (HomingActive == true)) { WaitForProcessCounter = 0; //15 minutes wait REPORT_MSG (PowerOffMachineState, "Ongoing processes, wait for end of process"); WaitForProcessControlId = AddControlCallback("ongoing processes", PowerOffWaitForProcessesCallback, eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); } else { PowerOffMachineState++; } //TBD return OK; } /*******************************************************************************************************/ uint32_t PowerOffStopRunningJob(void) { if (JobIsActive()) { REPORT_MSG (PowerOffMachineState, "Stop running job"); JobEndReason = JOB_ABORTED_BY_USER; AbortJob("Power off pressed"); } PowerOffMachineState++; return OK; } /*******************************************************************************************************/ uint32_t PowerOffSetValvePosition(void) { //TBD PowerOffMachineState++; return OK; } double StoreMax = 500; uint32_t MaxTemp = 0; /*******************************************************************************************************/ uint32_t PowerOffWaitForTemperatureCallback(uint32_t IfIndex, uint32_t BusyFlag) { uint32_t readTemp; MaxTemp = 0; /*if (Head_Type == HEAD_TYPE_SYLKO_WITHOUT_CARD) { readTemp = MillisecGetTemperatures( MIXER_PT100); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(TEMP_SENSE_ANALOG_DYEINGH_TEMP1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(TEMP_SENSE_ANALOG_DYEINGH_TEMP2); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(TEMP_SENSE_ANALOG_DYEINGH_TEMP3); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(TEMP_SENSE_ANALOG_DYEINGH_TEMP4); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(TEMP_SENSE_ANALOG_DYEINGH_TEMP5); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD6_PT100); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; } if (Head_Type == HEAD_TYPE_SYLKO) { readTemp = MillisecGetTemperatures( HEAD_PT100_MIXER_0X8E_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_1_0X80_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_2_0X80_1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_3_0X82_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_4_0X82_1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_5_0X84_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_6_0X84_1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_7_0X86_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_8_0X86_1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_9_0X88_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_10_0X88_1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_11_0X8A_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_12_0X8A_1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; } if (Head_Type == HEAD_TYPE_ARC) { readTemp = MillisecGetTemperatures( HEAD_PT100_MIXER_0X8E_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_1_0X80_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_2_0X80_1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_ZONE_3_0X82_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_AIR_HEATER_2_0X8C_1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; readTemp = MillisecGetTemperatures(HEAD_PT100_AIR_HEATER_1_0X8C_0); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; }*/ readTemp = MillisecGetTemperatures(TEMP_SENSE_ANALOG_DRYER_TEMP1); if ((readTemp>= MaxTemp)&&(readTemp < 27000)) MaxTemp = readTemp; if (StoreMax == 500) StoreMax = MaxTemp; if ((MaxTemp>PowerOffTemperatureThreshold)&&(WaitForProcessCounter++<3600)) { Report("On going cooling down, wait for end of cooling",__FILE__,__LINE__,(int)MaxTemp,RpWarning,(int)WaitForProcessCounter,0); resetIdleCounter(); //if (WaitForProcessCounter%UPDATE_TIMEOUT == 2) // PowerDownUpdate(POWER_OFF_WAIT_FOR_TEMPERATURE); } else { Report("ended cooling down, wait for end of cooling",__FILE__,__LINE__,(int)MaxTemp,RpWarning,(int)WaitForProcessCounter,0); PowerOffMachineState = POWER_OFF_TURN_OFF_DRYER_FAN; SafeRemoveControlCallback(WaitForProcessControlId, PowerOffWaitForTemperatureCallback); WaitForProcessControlId = 0xFF; } return OK; } /*******************************************************************************************************/ uint32_t PowerOffWaitForTemperature(void) { Report("PowerOff Wait For Temperature",__FILE__,__LINE__,(int)PowerOffTemperatureThreshold,RpWarning,(int)3600,0); StoreMax = 500; WHS_Set_IFS_Clearing_Suction(NUM_OF_MIDTANKS); if (WaitForProcessControlId == 0xFF) { WaitForProcessCounter = 0; WaitForProcessControlId = AddControlCallback("poweroff cooling", PowerOffWaitForTemperatureCallback, eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); } //TBD return OK; } /*******************************************************************************************************/ uint32_t PowerOffTurnOffDryerFan(void) { int i; Control_Dryer_Fan(STOP,75);//use START or STOP, 0 - 100% PowerOffMachineState++; if (Special_Dispensers == false) { for (i=0;i<MAX_SYSTEM_DISPENSERS;i++) Control3WayValvesWithCallback ((Valves_t)i, Dispenser_Mixer, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer } //TBD return OK; } /*******************************************************************************************************/ uint32_t PowerOffTurnOffCooler(void) { uint32_t DeActivateChiller(); PowerOffMachineState++; return OK; } /*******************************************************************************************************/ uint32_t PowerOffTurnOffBlower(void) { WHS_Set_SetPoint_Q_value(0); Control_Voltage_To_Blower(500); Turn_the_Blower_Off();//Turn off PowerOffMachineState++; return OK; } /*******************************************************************************************************/ uint32_t PowerOffPowerOff(void) { int i; Task_setPri (I2C_Task_Handle,-1); for (i = 0;i<10;i++) { REPORT_MSG (10-i, "Power off in x seconds"); Task_sleep (1000); } ControlStop(); MillisecStop(); HeatersEnd(); ROM_IntMasterDisable(); Power_Off(); return OK; } /*******************************************************************************************************/ uint32_t PowerOffSequenceStateMachine( POWER_OFF_STAGES_ENUM ReadValue) { uint32_t status = OK; REPORT_MSG(ReadValue,"PowerOffSequenceStateMachine"); PowerDownUpdate(ReadValue); switch (ReadValue) { case POWER_OFF_INIT: break; case POWER_OFF_HEAD_CLEAN: status = PowerOffHeadClean(); break; case POWER_OFF_MIXER_FLUSH: status = PowerOffMixerFlush(); break; case POWER_OFF_HEATERS_OFF: status = PowerOffHeatersOff(); break; case POWER_OFF_STORE_DATA: status = PowerOffStoreData(); break; case POWER_OFF_WAIT_FOR_PROCESSES: //wait for waste emptying: ink filling: thread loading status = PowerOffWaitForProcesses(); break; case POWER_OFF_STOP_RUNNING_JOB: status = PowerOffStopRunningJob(); break; case POWER_OFF_SET_VALVE_POSITION: status = PowerOffSetValvePosition(); break; case POWER_OFF_WAIT_FOR_TEMPERATURE: status = PowerOffWaitForTemperature(); break; case POWER_OFF_TURN_OFF_DRYER_FAN: status = PowerOffTurnOffDryerFan(); break; case POWER_OFF_TURN_OFF_COOLER: status = PowerOffTurnOffCooler(); break; case POWER_OFF_TURN_OFF_BLOWER: status = PowerOffTurnOffBlower(); break; case POWER_OFF_POWER_OFF: status = PowerOffPowerOff(); break; case POWER_OFF_ERROR: case POWER_OFF_CANCELLED: RemoveControlCallback( PowerOffControlId,PowerOffScheduler); PowerOffControlId = 0xFF; RemoveControlCallback(WaitForProcessControlId, PowerOffWaitForProcessesCallback); RemoveControlCallback(WaitForProcessControlId, PowerOffWaitForTemperatureCallback); WaitForProcessControlId = 0xFF; LOG_ERROR(ReadValue,"POWER OFF Cancelled"); break; default: LOG_ERROR(ReadValue,"ERROR IN POWER OFF STATE MACHINE"); break; } return status; } char PowerDownToken[36+1] = {0}; uint32_t PowerDownUpdate(POWER_OFF_STAGES_ENUM stage) { uint32_t status = NOT_SUPPORTED; double calculate; int result; MessageContainer responseContainer; StartPowerDownResponse response = START_POWER_DOWN_RESPONSE__INIT; bool last = false; if (PowerDownToken[0] == 0) return OK; response.has_state = true; response.has_progresspercentage = true; switch (stage) { case POWER_OFF_INIT: response.state = stage +1; response.progresspercentage = 0.0; response.message = "Initializing"; break; case POWER_OFF_STOP_RUNNING_JOB: response.state = stage +1; response.progresspercentage = 2.0; response.message = "Stop running job"; break; case POWER_OFF_HEAD_CLEAN: response.state = stage +1; response.message = "Head Cleaning running"; response.progresspercentage = 10.0; if ((HeaterCheckReady()==false)&&(PoolerTotalProcessedLength < 1.0)) { response.message = "Head Cleaning heating up"; response.progresspercentage = 5.0; } calculate = (double)((PoolerTotalProcessedLength/job_length)*10); result = (int)calculate; response.progresspercentage += result; Report("Job calculation",__FILE__,(int)response.progresspercentage,(int)PoolerTotalProcessedLength,RpWarning,(int)job_length,0); if (response.progresspercentage > 20.0) response.progresspercentage = 20.0; break; case POWER_OFF_MIXER_FLUSH: response.state = stage +1; response.progresspercentage = 20.0; response.message = "Flush mixer"; break; case POWER_OFF_HEATERS_OFF: response.state = stage +1; response.progresspercentage = 22.0; response.message = "Heaters off"; break; case POWER_OFF_STORE_DATA: response.state = stage +1; response.progresspercentage = 23.0; response.message = "Store data"; break; case POWER_OFF_WAIT_FOR_PROCESSES: //wait for waste emptying: ink filling: thread loading response.state = stage +1; response.progresspercentage = 30.0; response.message = "Wait for processes"; break; case POWER_OFF_SET_VALVE_POSITION: response.state = stage +1; response.progresspercentage = 32.0; response.message = "Valves"; break; case POWER_OFF_WAIT_FOR_TEMPERATURE: response.state = stage +1; calculate = (double)((StoreMax-MaxTemp)/(StoreMax-PowerOffTemperatureThreshold))*64.0; result = (int)calculate; response.progresspercentage = 33.0 + result; Report("Wait calculation",__FILE__,MaxTemp,(int)response.progresspercentage,RpWarning,(int)result,0); response.message = "Wait for cooling down"; break; case POWER_OFF_TURN_OFF_DRYER_FAN: response.state = stage +1; response.progresspercentage = 97.0; response.message = "Drier fan off"; break; case POWER_OFF_TURN_OFF_COOLER: response.state = stage +1; response.progresspercentage = 98.0; response.message = "Cooler off"; break; case POWER_OFF_TURN_OFF_BLOWER: response.state = stage +1; response.progresspercentage = 99.0; response.message = "Blower off"; break; case POWER_OFF_POWER_OFF: case POWER_OFF_ERROR: case POWER_OFF_CANCELLED: response.state = stage +1; response.progresspercentage = 100.0; last = true; response.message = "end of process"; break; } Report("PowerDownUpdate",__FILE__,last,(int)response.progresspercentage,RpWarning,(int)stage,0); responseContainer = createContainer(MESSAGE_TYPE__StartPowerDownResponse, PowerDownToken, last, &response, &start_power_down_response__pack, &start_power_down_response__get_packed_size); responseContainer.has_continuous = true; responseContainer.continuous = true; 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); //USBCDCD_sendData(container_buffer, container_size,10); SendChars((char*)container_buffer, container_size); //MessageContainer responseContainer; return status; } uint32_t PowerDownUpdateFunc(MessageContainer* requestContainer) { uint32_t status = NOT_SUPPORTED; //MessageContainer responseContainer; // MachineUpdateInitParams InitParams; Report("PowerDownUpdateFunc",__FILE__,__LINE__,(int)0,RpWarning,(int)0,0); StartPowerDownRequest* request = start_power_down_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); ustrncpy (PowerDownToken, requestContainer->token,36); PowerDownUpdate(POWER_OFF_INIT); if (PowerOffInProcessGetState()==false) PowerOffInit(); start_power_down_request__free_unpacked(request,NULL); return status; } void PowerDownStopReporting(void) { PowerDownToken[0] = 0; } uint32_t ctlId; uint32_t AbortPowerDownResetCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) { SafeRemoveControlCallback(ctlId, AbortPowerDownResetCallBackFunction ); /*volatile short *ptr = (volatile short *)(0x60000800 | 0x3D0); *ptr = 0;*/ Power_Reset(); return OK; } uint32_t AbortPowerDownFunc(MessageContainer* requestContainer) { MessageContainer responseContainer; AbortPowerDownRequest* request = abort_power_down_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); AbortPowerDownResponse response = ABORT_POWER_DOWN_RESPONSE__INIT; //TODO Handle the request!!!! //PowerDownStopReporting(); responseContainer = createContainer(MESSAGE_TYPE__AbortPowerDownResponse, requestContainer->token, false, &response, &abort_power_down_response__pack, &abort_power_down_response__get_packed_size); responseContainer.has_continuous = true; responseContainer.continuous = true; 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); //USBCDCD_sendData(container_buffer, container_size,10); SendChars((char*)container_buffer, container_size); PowerOffMachineState = POWER_OFF_CANCELLED; PowerDownUpdate(POWER_OFF_CANCELLED); ctlId = AddControlCallback("Abort", AbortPowerDownResetCallBackFunction, 2* eOneSecond, TemplateDataReadCBFunction,0,0, 0 ); Report("HWSystemResetRequest", __FILE__,__LINE__,0, RpMessage, 2, 0); return OK; }