aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Segment.cs
blob: 8737e04138be90f5b323bc6c626ce728daa43e1a (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace Tango.BL.Entities
{
    public partial class Segment
    {
        private double _lastLength;
        private LinearGradientBrush _brush;

        public override void Save(ObservablesContext context)
        {
            for (int i = 0; i < BrushStops.Count; i++)
            {
                BrushStops[i].StopIndex = i;
            }

            base.Save(context);
        }

        protected override void RaisePropertyChanged(string propName)
        {
            base.RaisePropertyChanged(propName);

            if (propName == nameof(Length) && _lastLength != Length)
            {
                BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged());
                _lastLength = Length;
                RaisePropertyChanged(nameof(LengthWithFactor));
            }

            if (propName == nameof(BrushStops))
            {
                if (BrushStops != null)
                {
                    BrushStops.CollectionChanged -= BrushStops_CollectionChanged;
                    BrushStops.CollectionChanged += BrushStops_CollectionChanged;

                    foreach (var stop in BrushStops.ToList())
                    {
                        stop.RaiseOffsetChanged();
                    }

                    RaiseSegmentBrushChanged();
                }
            }
        }

        private void BrushStops_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            foreach (var stop in BrushStops.ToList())
            {
                stop.RaiseOffsetChanged();
            }

            if (BrushStops.Count > 0)
            {
                BrushStops.First().OffsetPercent = 0;
            }
            if (BrushStops.Count > 1)
            {
                BrushStops.Last().OffsetPercent = 100;
            }

            RaiseSegmentBrushChanged();
        }

        private TimeSpan _remainingTime;
        [NotMapped]
        [JsonIgnore]
        public TimeSpan RemainingTime
        {
            get { return _remainingTime; }
            set { _remainingTime = value; RaisePropertyChangedAuto(); }
        }

        private TimeSpan _estimatedDuration;
        [NotMapped]
        [JsonIgnore]
        public TimeSpan EstimatedDuration
        {
            get { return _estimatedDuration; }
            set { _estimatedDuration = value; }
        }

        private double _progress;
        [NotMapped]
        [JsonIgnore]
        public double Progress
        {
            get { return _progress; }
            set { _progress = value; RaisePropertyChangedAuto(); }
        }

        private bool _started;
        [NotMapped]
        [JsonIgnore]
        public bool Started
        {
            get { return _started; }
            set { _started = value; RaisePropertyChangedAuto(); }
        }

        private bool _completed;
        [NotMapped]
        [JsonIgnore]
        public bool Completed
        {
            get { return _completed; }
            set { _completed = value; RaisePropertyChangedAuto(); }
        }

        [NotMapped]
        [JsonIgnore]
        public Brush SegmentBrush
        {
            get
            {
                return GetSegmentBrush();
            }
        }

        private bool _isInterSegment;
        [NotMapped]
        [JsonIgnore]
        public bool IsInterSegment
        {
            get { return _isInterSegment; }
            set { _isInterSegment = value; RaisePropertyChangedAuto(); }
        }

        [NotMapped]
        public bool HasOutOfGamutBrushStop
        {
            get { return BrushStops.Any(x => x.IsOutOfGamut); }
        }

        [NotMapped]
        [JsonIgnore]
        public double LengthWithFactor
        {
            get { return Job != null && !IsInterSegment ? (Length + Length * (Job.LengthPercentageFactor / 100)) : Length; }
        }

        internal void RaiseHasOutOfGamutBrushStop()
        {
            RaisePropertyChanged(nameof(HasOutOfGamutBrushStop));
        }

        public override Segment Clone()
        {
            Segment cloned = base.Clone();

            cloned.BrushStops = BrushStops.Select(x => x.Clone()).ToSynchronizedObservableCollection();

            foreach (var stop in cloned.BrushStops)
            {
                stop.SegmentGuid = cloned.Guid;
                stop.Segment = cloned;
            }

            return cloned;
        }

        public Segment Clone(Job job)
        {
            Segment cloned = base.Clone();

            cloned.BrushStops = BrushStops.Select(x => x.Clone(cloned)).ToSynchronizedObservableCollection();

            cloned.Job = job;
            cloned.JobGuid = job.Guid;

            return cloned;
        }

        public override void DefferedDelete(ObservablesContext context)
        {
            BrushStops.ToList().ForEach(x => x.DefferedDelete(context));
            BrushStops.Clear();
            base.DefferedDelete(context);
        }

        public LinearGradientBrush GetSegmentBrush()
        {
            if (_brush == null || _brush.GradientStops.Count != BrushStops.Count)
            {
                GradientStopCollection stops = new GradientStopCollection();

                foreach (var stop in BrushStops.ToList().OrderBy(x => x.StopIndex).ToList())
                {
                    stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d));
                }

                LinearGradientBrush brush = new LinearGradientBrush();
                brush.StartPoint = new Point(0, 0);
                brush.EndPoint = new Point(1, 0);

                brush.GradientStops = stops;

                _brush = brush;
                return brush;
            }
            else
            {
                for (int i = 0; i < BrushStops.Count; i++)
                {
                    _brush.GradientStops[i].Color = BrushStops[i].Color;
                    _brush.GradientStops[i].Offset = BrushStops[i].OffsetPercent / 100d;
                }

                return _brush;
            }
        }

        public System.Drawing.Brush CreateGdiBrush(int width, int height)
        {
            if (BrushStops.Count > 1)
            {
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.PointF(0, 0), new System.Drawing.Point(width, height), System.Drawing.Color.Black, System.Drawing.Color.Black);

                System.Drawing.Drawing2D.ColorBlend blend = new System.Drawing.Drawing2D.ColorBlend();

                List<System.Drawing.Color> colors = new List<System.Drawing.Color>();
                List<float> offsets = new List<float>();

                foreach (var stop in BrushStops.ToList().OrderBy(x => x.OffsetPercent))
                {
                    colors.Add(stop.Color.ToGdiColor());
                    offsets.Add((float)stop.OffsetPercent / 100f);
                }

                blend.Colors = colors.ToArray();
                blend.Positions = offsets.ToArray();

                brush.InterpolationColors = blend;

                return brush;
            }
            else if (BrushStops.Count == 1)
            {
                return new System.Drawing.SolidBrush(BrushStops.First().Color.ToGdiColor());
            }
            else
            {
                return System.Drawing.Brushes.Black;
            }
        }

        public void RaiseSegmentBrushChanged()
        {
            RaisePropertyChanged(nameof(SegmentBrush));
        }

        public void RaiseLengthWithFactorChanged()
        {
            RaisePropertyChanged(nameof(LengthWithFactor));
        }

        public BrushStop AddBrushStop()
        {
            BrushStop stop = new BrushStop();

            if (Job.ColorSpace != null)
            {
                stop.ColorSpace = Job.ColorSpace;
            }
            else
            {
                stop.ColorSpaceGuid = Job.ColorSpaceGuid;
            }

            if (BrushStops.Count > 0)
            {
                stop.StopIndex = BrushStops.Max(x => x.StopIndex) + 1;
                stop.OffsetPercent = 100;
            }
            else
            {
                stop.StopIndex = 1;
            }

            stop.Segment = this;
            stop.Color = Colors.Black;

            BrushStops.Add(stop);

            return stop;
        }

        public Segment GetNextSegment()
        {
            return Job.OrderedSegments.FirstOrDefault(x => x.SegmentIndex > SegmentIndex);
        }

        public Segment GetPreviousSegment()
        {
            return Job.OrderedSegments.LastOrDefault(x => x.SegmentIndex < SegmentIndex);
        }

        /// <summary>
        /// Gets the duration estimation for this job.
        /// </summary>
        /// <param name="processParameters">The process parameters.</param>
        /// <returns></returns>
        public TimeSpan GetEstimatedDuration(ProcessParametersTable processParameters)
        {
            if (processParameters.DyeingSpeed == 0)
            {
                throw new ArgumentException("Process parameters dying speed cannot be zero.");
            }
            return TimeSpan.FromSeconds(Length / (processParameters.DyeingSpeed / 100d));
        }
    }
}
> NULL; } BrushStopPtr = my_malloc (BrushStopSize); if (BrushStopPtr) { Fresult = f_read(JobRequestFileHandle,BrushStopPtr,BrushStopSize,&ImmediateRead ); if (Fresult == FR_OK) { readbBytes += ImmediateRead; BrushStop = job_description_file_brush_stop__unpack(NULL, BrushStopSize, BrushStopPtr); if (BrushStop == NULL) Report("brush_stop__unpack error!",__FILE__,BrushStopSize,(int)readbBytes,RpWarning,(int)ImmediateRead,0); }//brushstop malloc ok else { LOG_ERROR (Fresult, "f_read error"); //status = ERROR; } my_free(BrushStopPtr); BrushStopPtr = NULL; }//brushstop size read ok else { LOG_ERROR (BrushStopPtr, "malloc error"); //status = ERROR; } }// if brush stop count else { LOG_ERROR (0, "f_read error brush stop size error"); //status = ERROR; } //REPORT_MSG(BrushStop->index,"BrushStop file Read Index"); return BrushStop; } void FreeBrushStopFileData(JobDescriptionFileBrushStop *BrushStop) { //REPORT_MSG(BrushStop->index,"Free BrushStop file Read Index"); if (BrushStop) job_description_file_brush_stop__free_unpacked (BrushStop,NULL); BrushStop = NULL; if (BrushStopPtr) my_free(BrushStopPtr); BrushStopPtr = NULL; } /************************************************************************************************************************************/ /* this function is for development initial stages. it analyses the hardware configuration to determine which modules are operational * according to the configuration map */ uint32_t PrintingHWConfiguration(void *Configuration) { /* * Module_Thread, Module_Winder, Module_IDS, Module_Heaters, Module_Waste, * */ uint32_t i; HardwareConfiguration *request = Configuration; if (request->n_winders == 1) Configured[Module_Winder] = true; //if ((IFS_Availability[1] == IFS_RECOGNIZED_INIT_PASSED)&&(IFS_Availability[2] == IFS_RECOGNIZED_INIT_PASSED)) //ifs installed -check cartridges Configured[Module_Waste] = true; if (request->n_motors) { for (i = 0; i < request->n_motors ; i++) { if ((request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_LDRIVING)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_RDRIVING)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING)) { Configured[Module_Thread] = true; //break; } if ((request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_1)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_2)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_3)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_4)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_5)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_6)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_7)|| (request->motors[i]->hardwaremotortype == HARDWARE_MOTOR_TYPE__MOTO_DISPENSER_8)) { Configured[Module_IDS] = true; //break; } } } if (request->n_pidcontrols <= HARDWARE_PID_CONTROL_TYPE__Dispenser8) { for (i = 0; i < request->n_pidcontrols ; i++) { if (isHeater(request->pidcontrols[i]->hardwarepidcontroltype)) { Configured[Module_Heaters] = true; break; } } } /*if (request->n_dispensers <= MAX_SYSTEM_DISPENSERS) { for (i = 0; i < request->n_dispensers ; i++) { if(request->dispensers[i]->index) { Configured[Module_IDS] = true; break; } } }*/ memcpy(&JobConfigured,&Configured,sizeof(JobConfigured)); return OK; } /******************************************************************************************************************** *function describes entry point of motor in profile execution - accelerate from stop position *function described above used to operate motor operation flow and movement state during profile execution *********************************************************************************************************************/ uint32_t PreSegmentReady(int ModuleId, ModuleStateEnum result) { int i; bool ready = true; uint32_t status = OK; JobMessageStruc Message; PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message.messageData; assert (ModuleId<MAX_SYSTEM_MODULES); assert (result<=ModuleFail); if (PreSegmentWaiting[ModuleId] != ModuleWaiting) { LOG_ERROR (ModuleId, "Message from unrelated module!!"); return OK; } PreSegmentWaiting[ModuleId] = result; if (result == ModuleFail) { status = ERROR; Report("PreSegmentReady Fail!",__FILE__,__LINE__,(int)ModuleId,RpWarning,(int)result,0); } for (i=0;i<MAX_SYSTEM_MODULES ;i++) { if (PreSegmentWaiting[i] == ModuleWaiting) ready = false; } if ((ready == false)&&(status == OK)) return OK; else { Message.messageId = PrintMessage; if (status == OK) { SendJobProgress(0.0, 0, false, "PreSegment Ready"); PrtMessage->messageId = PreSegmentResultsOk; } else { PrtMessage->messageId = PreSegmentResultsFail; SendJobProgress(0.0, 0, false, "PreSegment Failed"); Report("PreSegment Fail!",__FILE__,__LINE__,(int)ModuleId,RpWarning,(int)result,0); } //memcpy(Message.messageData,JobDetails,MAX_MSG_LEN); Message.msglen = 10; if (JobmsgQ != NULL) Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT); } return 0; } //******************************************************************************************************************** static uint32_t PreSegmentState(void *SegmentDetails, int SegmentId,int SegmentIdPointer) { SendJobProgress(0.0, SegmentId, false, "PreSegment Start"); if (Configured[Module_Thread]) { PreSegmentWaiting[Module_Thread] = ModuleWaiting; } if (Configured[Module_Winder]) { PreSegmentWaiting[Module_Winder] = ModuleWaiting; } if (Configured[Module_IDS]) { PreSegmentWaiting[Module_IDS] = ModuleWaiting; } if (Configured[Module_Thread]) { ThreadPreSegmentState(SegmentDetails,SegmentId); } if (Configured[Module_Winder]) { Winder_Presegment(SegmentDetails,SegmentId); //must be after ThreadPreSegmentState } if (Configured[Module_IDS]) { IDSPreSegmentState(SegmentDetails,SegmentId); } return OK; } //******************************************************************************************************************** uint32_t SegmentReady(int ModuleId, ModuleStateEnum result) { int i; bool ready = true; uint32_t status = OK; JobMessageStruc Message; PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message.messageData; assert (ModuleId<MAX_SYSTEM_MODULES); assert (result<=ModuleFail); //REPORT_MSG (ModuleId, "SegmentReady"); Report("SegmentReady",__FILE__,__LINE__,(int)ModuleId,RpWarning,(int)result,0); if (SegmentWaiting[ModuleId] != ModuleWaiting) { LOG_ERROR (ModuleId, "Message from unrelated module!!"); return OK; } SegmentWaiting[ModuleId] = result; if (result == ModuleFail) status = ERROR; for (i=0;i<MAX_SYSTEM_MODULES ;i++) { if (SegmentWaiting[i] == ModuleWaiting) ready = false; } if ((ready == false)&&(status == OK)) return OK; else { Message.messageId = PrintMessage; if (status == OK) { PrtMessage->messageId = SegmentResultsOk; SendJobProgress(0.0, 0, false, "Segment Done"); } else { PrtMessage->messageId = SegmentResultsFail; SendJobProgress(0.0, 0, false, "Segment Fail"); } //memcpy(Message.messageData,JobDetails,MAX_MSG_LEN); Message.msglen = 10; if (JobmsgQ != NULL) Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT); } return 0; } //******************************************************************************************************************** static uint32_t SegmentState(void *SegmentDetails, int SegmentId,int SegmentIdPointer) { SendJobProgress(0.0, SegmentId, false, "Segment Start"); if (Configured[Module_IDS]) { //SegmentWaiting[Module_IDS] = ModuleWaiting; IDSSegmentState(SegmentDetails,SegmentId); } if (Configured[Module_Thread]) { SegmentWaiting[Module_Thread] = ModuleWaiting; ThreadSegmentState(SegmentDetails,SegmentId); } if (Configured[Module_Winder]) { //SegmentWaiting[Module_Winder] = ModuleWaiting; //Winder_Segment(JobDetails); } return OK; } //******************************************************************************************************************** uint32_t DistanceToSpoolReady(int ModuleId, ModuleStateEnum result) { int i; bool ready = true; uint32_t status = OK; JobMessageStruc Message; PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message.messageData; assert (ModuleId<MAX_SYSTEM_MODULES); assert (result<=ModuleFail); if (DistanceToSpoolWaiting[ModuleId] != ModuleWaiting) { LOG_ERROR (ModuleId, "Message from unrelated module!!"); return OK; } DistanceToSpoolWaiting[ModuleId] = result; if (result == ModuleFail) status = ERROR; for (i=0;i<MAX_SYSTEM_MODULES ;i++) { if (DistanceToSpoolWaiting[i] == ModuleWaiting) ready = false; } if ((ready == false)&&(status == OK)) return OK; else { Message.messageId = PrintMessage; if (status == OK) { PrtMessage->messageId = FinishResultsOk; SendJobProgress(0.0, 0, false, "DistanceToSpool Done"); } else { //SuspendLargeMessages = true; //DiagnosticsStop(); PrtMessage->messageId = FinishResultsFail; SendJobProgress(0.0, 0, false, "DistanceToSpool Fail"); LOG_ERROR(1,"SuspendLargeMessages DistanceToSpoolReady"); } //memcpy(Message.messageData,JobDetails,MAX_MSG_LEN); Message.msglen = 10; if (JobmsgQ != NULL) Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT); } return 0; } //******************************************************************************************************************** static uint32_t DistanceToSpoolState(void *JobDetails) { SendJobProgress(0.0, 0, false, "DistanceToSpool Start"); if (Configured[Module_IDS]) { DistanceToSpoolWaiting[Module_IDS] = ModuleWaiting; IDSDistanceToSpoolState(); } if (Configured[Module_Thread]) { DistanceToSpoolWaiting[Module_Thread] = ModuleWaiting; ThreadDistanceToSpoolState(); } if (Configured[Module_Winder]) { //DistanceToSpoolWaiting[Module_Winder] = ModuleWaiting; WinderDistanceToSpoolState(); //Winder_DistanceToSpool(JobDetails); } return OK; } //******************************************************************************************************************** char ErMsg[50]; uint32_t EndState(void *JobDetails, char *Message) { //ROM_IntMasterDisable(); //SuspendLargeMessages = true; //LOG_ERROR(2,"SuspendLargeMessages EndState"); //DiagnosticsStop(); if (Configured[Module_Winder]) { PrepareWaiting[Module_Winder] = ModuleIdle; SegmentWaiting[Module_Winder] = ModuleIdle; PreSegmentWaiting[Module_Winder] = ModuleIdle; DistanceToSpoolWaiting[Module_Winder] = ModuleIdle; // EndWaiting[Module_Winder] = ModuleWaiting; Winder_End(); } if (Configured[Module_IDS]) { PrepareWaiting[Module_IDS] = ModuleIdle; SegmentWaiting[Module_IDS] = ModuleIdle; PreSegmentWaiting[Module_IDS] = ModuleIdle; DistanceToSpoolWaiting[Module_IDS] = ModuleIdle; //EndWaiting[Module_IDS] = ModuleWaiting; IDSEndState(); } if (Configured[Module_Heaters]) { PrepareWaiting[Module_Heaters] = ModuleIdle; //EndWaiting[Module_Heaters] = ModuleWaiting; //heaters preparation starts on process parameters handling // do not call HeatersEnd(); because the heaters should stay ready for coming jobs } if (Configured[Module_Thread]) { PrepareWaiting[Module_Thread] = ModuleIdle; SegmentWaiting[Module_Thread] = ModuleIdle; PreSegmentWaiting[Module_Thread] = ModuleIdle; DistanceToSpoolWaiting[Module_Thread] = ModuleIdle; //EndWaiting[Module_Thread] = ModuleWaiting; ThreadEndState(); } CloseJobFile(); //ROM_IntMasterEnable(); SendJobProgress(0.0,0,true,Message); if ((JoggingJobActive==false)&&(CleaningJobActive == false)) { WHS_Set_JobEndSuction(); } if (JoggingJobActive == true) { JoggingJobActive = false; //memcpy(&Configured,&CopyConfigured,sizeof(CopyConfigured)); //usnprintf(ErMsg, 80,"Copy Configured T %d W %d I %d H %d W %d",CopyConfigured[Module_Thread],CopyConfigured[Module_Winder],CopyConfigured[Module_IDS],CopyConfigured[Module_Heaters],CopyConfigured[Module_Waste]); //Report(ErMsg, __FILE__, __LINE__, 0, RpWarning, 0, 0); } if (CleaningJobActive == true) { //FreeCleaningJobData(JobDetails); CleaningJobActive = false; //memcpy(&Configured,&CopyConfigured,sizeof(CopyConfigured)); //usnprintf(ErMsg, 80,"Copy Configured T %d W %d I %d H %d W %d",CopyConfigured[Module_Thread],CopyConfigured[Module_Winder],CopyConfigured[Module_IDS],CopyConfigured[Module_Heaters],CopyConfigured[Module_Waste]); //Report(ErMsg, __FILE__, __LINE__, 0, RpWarning, 0, 0); } return OK; } //******************************************************************************************************************** /*static uint32_t ExitState(void *JobDetails) { return OK; }*/ //******************************************************************************************************************** /*void PrintingsInit(void) { } */ //******************************************************************************************************************** void StartPrinting(void) { } //******************************************************************************************************************** //******************************************************************************************************************** int SegmentId = 0,UnitId = 0, SegmentIdPointer = 0; JobDescriptionFileSegment *Segment; JobSegment SSegment; //******************************************************************************************************************** //******************************************************************************************************************** void PrintSTMMsgHandler(void * msg) { JobMessageStruc *Message = msg; PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message->messageData; Report("PrintSTMMsgHandler",__FILE__,__LINE__, Message->messageId,RpMessage,PrtMessage->messageId,0); if ((Message->messageId != PrintMessage)&&(Message->messageId != Abort)) { //REPORT_ERR ... return; } switch(PrtMessage->messageId) { case PrintRequest: SetMachineStatus(MACHINE_STATE__RunningJob); SegmentId = 0; SegmentIdPointer = 0; UnitId = 0; if (CurrentJob->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile) { Segment = GetNextSegmentFromJobFile(); SSegment.length = Segment->length; SSegment.has_length = Segment->has_length; SSegment.n_brushstops = Segment->brushstopscount; PreSegmentState(&SSegment,SegmentId,SegmentIdPointer); } else { PreSegmentState(CurrentJob->segments[SegmentIdPointer],SegmentId,SegmentIdPointer); } break; case PreSegmentResultsOk: if (CurrentJob->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile) { SegmentState(&SSegment,SegmentId,SegmentIdPointer); } else { SegmentState(CurrentJob->segments[SegmentIdPointer],SegmentId,SegmentIdPointer); } break; case PreSegmentResultsFail: EndState(CurrentJob, "PreSegment Failed"); //ExitState(Message->messageData); break; case SegmentResultsOk: SegmentId++; SegmentIdPointer++; //REPORT_MSG(SegmentId, "SegmentResultsOk segmentId"); if ((SegmentId % n_unit_segments)==0) //finished a unit { Report("unit finished",__FILE__,__LINE__, SegmentId,RpMessage,n_unit_segments,0); UnitId++; if (UnitId < n_units) { if (CurrentJob->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile) { //rewind file if (RewindJobFile() != FR_OK) { JobEndReason = JOB_FILE_PROBLEM; usnprintf(AlarmReasonStr, 100, "Job file processing error"); if (dryerbufferlength <= 0.1) EndState(CurrentJob, "Job Ended"); else DistanceToSpoolState(CurrentJob); } Report("start unit ",__FILE__,__LINE__, UnitId,RpMessage,n_units,0); } SegmentIdPointer = 0; } } Report("SegmentResultsOk segmentId",__FILE__,__LINE__, SegmentId,RpMessage,n_segments,0); if (SegmentId >= n_segments) { if (dryerbufferlength <= 0.1) EndState(CurrentJob, "Job Ended"); else Report("DistanceToSpoolState segmentId",__FILE__,__LINE__, SegmentId,RpMessage,n_segments,0); DistanceToSpoolState(CurrentJob); } else { if (CurrentJob->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile) { if ((Segment) && (Segment->base.descriptor->sizeof_message != 40)) LOG_ERROR(SegmentId, "Error releasing Segment"); else if (Segment) { if (SegmentIdPointer) //do not perform after a rewind { if (IDSCheckSegmentData(Segment, SegmentId) == OK) { FreeSegmentFileData(Segment); } else { JobEndReason = JOB_FILE_PROBLEM; usnprintf(AlarmReasonStr, 100, "Job file processing error"); if (dryerbufferlength <= 0.1) EndState(CurrentJob, "Job Ended"); else DistanceToSpoolState(CurrentJob); } } else Report("not checking after a rewind ",__FILE__,__LINE__, SegmentId,RpMessage,SegmentIdPointer,0); } else { LOG_ERROR(SegmentId, "Error Segment is null"); } Segment = GetNextSegmentFromJobFile(); if ((Segment == NULL)||(Segment->length <0.1)) { Report("SegmentLoading failed",__FILE__,__LINE__, Segment,RpMessage,(int)(Segment->length*100),0); JobEndReason = JOB_FILE_PROBLEM; usnprintf(AlarmReasonStr, 100, "Job file processing error"); if (dryerbufferlength <= 0.1) EndState(CurrentJob, "Job Ended"); else DistanceToSpoolState(CurrentJob); } else { SSegment.length = Segment->length; SSegment.has_length = Segment->has_length; SSegment.n_brushstops = Segment->brushstopscount; PreSegmentState(&SSegment,SegmentId,SegmentIdPointer); } } else { PreSegmentState(CurrentJob->segments[SegmentIdPointer],SegmentId,SegmentIdPointer); } } break; case SegmentResultsFail: EndState(CurrentJob, "Segment Failed"); break; case FinishResultsOk: EndState(CurrentJob, "Job Ended"); break; case FinishResultsFail: EndState(CurrentJob, "Job Distance t Spool Failed"); break; case PrintSystemFailure: Report("PrintSystemFailure - Job aborted",__FILE__,__LINE__, SegmentId,RpMessage,n_segments,0); EndState(CurrentJob, Message->messageData); break; default: break; } }