aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2019-04-02 15:16:32 +0300
committerShlomo Hecht <shlomo@twine-s.com>2019-04-02 15:16:32 +0300
commit3f6aecd92ceca69ffa5fc07ea0bbe93fd4097c85 (patch)
treea0e69764fe4eca3fc445f44e1f963a2a72e4327f /Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c
parent3713f74d0d811b869af5522a576e36f7e6a0ed2e (diff)
downloadTango-3f6aecd92ceca69ffa5fc07ea0bbe93fd4097c85.tar.gz
Tango-3f6aecd92ceca69ffa5fc07ea0bbe93fd4097c85.zip
Embedded SW Release note - Version 1.3.8.2
File upload: prevent on job, reduce priority (watchdog) Report: packages filters introduced, please feel free to use them. robustness in communication improved large number of segments and gradient support - initial at the end of job the screw does not return back rockers - adjust values before and after loading the cart
Diffstat (limited to 'Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c')
-rw-r--r--Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c233
1 files changed, 219 insertions, 14 deletions
diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c
index 53057c170..c52ed8b4c 100644
--- a/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c
+++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/PrintingSTM.c
@@ -25,6 +25,10 @@
#include "PMR/Hardware/UploadHardWareConfigurationRequest.pb-c.h"
#include "PMR/Hardware/HardwareMotorType.pb-c.h"
#include "modules/General/process.h"
+#include "PMR/Printing/JobDescriptionFileBrushStop.pb-c.h"
+#include "PMR/Printing/JobDescriptionFileSegment.pb-c.h"
+#include "Common/SWUpdate/FileSystem.h"
+#include "drivers/Flash_Memory/fatfs/ff.h"
////////////////////////////////State machine operation////////////////////////////////////
//the state machine operation is used to operate in runtime correct profile flow execution
//by recieved esign flow of the user from the UI
@@ -38,7 +42,7 @@ static uint32_t PreSegmentState(void *Segment, int);
static uint32_t SegmentState(void *Segment, int);
uint32_t EndState(void *JobDetails, char *Message);
//static uint32_t ExitState(void *JobDetails);
-
+uint16_t n_segments = 0;
/**********************************************************************
* the array and enum of PrintingState_t below must be in sync order
***********************************************************************/
@@ -65,9 +69,174 @@ ModuleStateEnum EndWaiting[MAX_SYSTEM_MODULES] = {ModuleIdle,ModuleIdle,M
bool Configured[MAX_SYSTEM_MODULES] = {false,false,false,false,false};
bool SuspendLargeMessages = false;
+/*
+Parsing the job description file.
+The job description file simply contains an array of segments and their brush stops.
+The job description file is meant to be read brush stop by brush stop while the job is in progress.
+The following diagram represents a single job description file segment structure.
+The process of reading the whole file is simply repeating that reading order.
-/********************************************************************************************************************
- * this function is for development initial stages. it analyses the hardware configuration to determine which modules are operational
+Each JobDescriptionFileSegment contains a “BrushStopsCount” field that should be used to determine how many brush stops are associated
+with the current segment and how many times the process of reading brush stops should be repeated.
+1. 32bit integer containing the next JobFileDescriptionSegment message byte count
+2. JobDescriptionFileSegment message
+3. 32bit integer containing the next JobDescriptionFileBrushStop message byte count
+4. JobDescriptionFileBrushStop message
+
+1. Read segment message length.
+2. Read segment message.
+a. Read brush stop message length.
+b. Read brush stop message.
+c. Go to step 2.a x Segment.BrushStopsCount.
+3. Go to step 1 until end of file.
+*/
+
+//job file reading functions
+uint32_t bBytes = 0,readbBytes = 0,ImmediateRead = 0,SegmentSize = 0,BrushStopSize = 0;
+FRESULT Fresult = FR_OK;
+uint8_t *SegmentPtr = 0, *BrushStopPtr = 0;
+FIL *JobRequestFileHandle = 0; //the system supports a single active file
+FRESULT OpenJobFile()
+{
+ //n_segments = 0;
+ if (CurrentJob->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile)
+ {
+ JobRequestFileHandle = my_malloc(sizeof(FIL));
+
+ Fresult = FileOpen(CurrentJob->jobdescriptionfile, &bBytes, JobRequestFileHandle);
+ if (Fresult == FR_OK)
+ {
+ readbBytes = 0;
+ }
+ REPORT_MSG(bBytes,"OpenJobFile");
+ }
+ return Fresult;
+}
+FRESULT CloseJobFile()
+{
+ Fresult = f_close(JobRequestFileHandle);
+ readbBytes = 0;
+ ImmediateRead = 0;
+ SegmentSize = 0;
+ BrushStopSize = 0;
+ my_free (JobRequestFileHandle);
+ JobRequestFileHandle = NULL;
+ if (BrushStopPtr)
+ my_free(BrushStopPtr);
+ if (SegmentPtr)
+ my_free(SegmentPtr);
+ REPORT_MSG(Fresult,"CloseJobFile");
+
+ return Fresult;
+}
+JobDescriptionFileSegment *GetNextSegmentFromJobFile()
+{
+ uint32_t status = OK;
+ JobDescriptionFileSegment *Segment = NULL;
+ if (JobRequestFileHandle == NULL)
+ {
+ LOG_ERROR(JobRequestFileHandle,"JobRequestFileHandle == NULL");
+ return NULL;
+ }
+ if(readbBytes < bBytes)
+ {
+ Fresult = f_read(JobRequestFileHandle,&SegmentSize,4,&ImmediateRead );
+ if (Fresult == FR_OK)
+ {
+ readbBytes += ImmediateRead;
+ if (SegmentPtr)
+ my_free(SegmentPtr);
+ SegmentPtr = my_malloc (SegmentSize);
+ if (SegmentPtr)
+ {
+ Fresult = f_read(JobRequestFileHandle,SegmentPtr,SegmentSize,&ImmediateRead );
+ if (Fresult == FR_OK)
+ {
+ readbBytes += ImmediateRead;
+ //n_segments++;
+ Segment = job_description_file_segment__unpack(NULL, SegmentSize, SegmentPtr);
+ }
+ }// read segment data
+ my_free(SegmentPtr);
+ }//segment malloc
+ else
+ {
+ LOG_ERROR (SegmentPtr, "malloc error");
+ status = ERROR;
+ }
+ }//segment read size
+ else
+ {
+ LOG_ERROR (Fresult, "f_read error");
+ status = ERROR;
+ }
+ return Segment;
+}
+void FreeSegmentFileData(JobDescriptionFileSegment *Segment)
+{
+ job_description_file_segment__free_unpacked(Segment,NULL);
+ Segment = NULL;
+ if (SegmentPtr)
+ my_free(SegmentPtr);
+}
+JobDescriptionFileBrushStop *GetNextBrushStopFromJobFile()
+{
+ uint32_t status = OK;
+ JobDescriptionFileBrushStop *BrushStop = NULL;
+ if (JobRequestFileHandle == NULL)
+ {
+ LOG_ERROR(JobRequestFileHandle,"JobRequestFileHandle == NULL");
+ return NULL;
+ }
+ Fresult = f_read(JobRequestFileHandle,&BrushStopSize,4,&ImmediateRead );
+ if (Fresult == FR_OK)
+ {
+ readbBytes += ImmediateRead;
+ if (BrushStopPtr)
+ my_free(BrushStopPtr);
+
+ 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);
+ }//brushstop malloc ok
+ else
+ {
+ LOG_ERROR (Fresult, "f_read error");
+ status = ERROR;
+ }
+ my_free(BrushStopPtr);
+ }//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);
+}
+/************************************************************************************************************************************/
+/* this function is for development initial stages. it analyses the hardware configuration to determine which modules are operational
* according to the configuration map
*/
@@ -233,8 +402,8 @@ uint32_t SegmentReady(int ModuleId, ModuleStateEnum result)
assert (ModuleId<MAX_SYSTEM_MODULES);
assert (result<=ModuleFail);
- REPORT_MSG (ModuleId, "SegmentReady");
- Report("IDSSegmentState",__FILE__,__LINE__,(int)ModuleId,RpWarning,(int)result,0);
+ //REPORT_MSG (ModuleId, "SegmentReady");
+ Report("SegmentReady",__FILE__,__LINE__,(int)ModuleId,RpWarning,(int)result,0);
if (SegmentWaiting[ModuleId] != ModuleWaiting)
{
@@ -410,6 +579,7 @@ uint32_t EndState(void *JobDetails, char *Message)
//EndWaiting[Module_Thread] = ModuleWaiting;
ThreadEndState();
}
+ CloseJobFile();
//ROM_IntMasterEnable();
SendJobProgress(0.0,0,true,Message);
@@ -436,16 +606,18 @@ void StartPrinting(void)
//********************************************************************************************************************
//********************************************************************************************************************
-void StopPrinting(void)
-{
-}
int SegmentId = 0;
+JobDescriptionFileSegment *Segment;
+JobSegment SSegment;
+
+//********************************************************************************************************************
+//********************************************************************************************************************
void PrintSTMMsgHandler(void * msg)
{
JobMessageStruc *Message = msg;
PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message->messageData;
- Report("PrintSTMMsgHandler",__FILE__,__LINE__, RpMessage,0x1000,Message->messageId,PrtMessage->messageId);
+ Report("PrintSTMMsgHandler",__FILE__,__LINE__, 1000,RpMessage,Message->messageId,PrtMessage->messageId);
if ((Message->messageId != PrintMessage)&&(Message->messageId != Abort))
{
@@ -456,10 +628,28 @@ void PrintSTMMsgHandler(void * msg)
{
case PrintRequest:
SegmentId = 0;
- PreSegmentState(CurrentJob->segments[SegmentId],SegmentId);
+ 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);
+ }
+ else
+ {
+ PreSegmentState(CurrentJob->segments[SegmentId],SegmentId);
+ }
break;
case PreSegmentResultsOk:
- SegmentState(CurrentJob->segments[SegmentId],SegmentId);
+ if (CurrentJob->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile)
+ {
+ SegmentState(&SSegment,SegmentId);
+ }
+ else
+ {
+ SegmentState(CurrentJob->segments[SegmentId],SegmentId);
+ }
break;
case PreSegmentResultsFail:
EndState(CurrentJob, "PreSegment Failed");
@@ -467,8 +657,9 @@ void PrintSTMMsgHandler(void * msg)
break;
case SegmentResultsOk:
SegmentId++;
- LOG_ERROR(SegmentId, "SegmentResultsOk segmentId");
- if (SegmentId >= CurrentJob->n_segments)
+ //REPORT_MSG(SegmentId, "SegmentResultsOk segmentId");
+ Report("SegmentResultsOk segmentId",__FILE__,__LINE__, SegmentId,RpMessage,n_segments,0);
+ if (SegmentId >= n_segments)
{
if (dryerbufferlength == 0)
EndState(CurrentJob, "Job Ended");
@@ -477,7 +668,21 @@ void PrintSTMMsgHandler(void * msg)
}
else
{
- PreSegmentState(CurrentJob->segments[SegmentId],SegmentId);
+ if (CurrentJob->uploadstrategy == JOB_UPLOAD_STRATEGY__JobDescriptionFile)
+ {
+ if (Segment)
+ FreeSegmentFileData(Segment);
+
+ Segment = GetNextSegmentFromJobFile();
+ SSegment.length = Segment->length;
+ SSegment.has_length = Segment->has_length;
+ SSegment.n_brushstops = Segment->brushstopscount;
+ PreSegmentState(&SSegment,SegmentId);
+ }
+ else
+ {
+ PreSegmentState(CurrentJob->segments[SegmentId],SegmentId);
+ }
}
break;
case SegmentResultsFail: