| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- /* This file contains the implementation of the CDummyRoboDriver class. */
- #include "DummyDriver.h"
- #include "CCOMSerial.h"
- #include "AbstractUserDialog.h"
- /** Synchronize access to common GUI interface since it is access from our print thread too. */
- #define CN_LOCK if (m_pRoboMutex != NULL) m_pRoboMutex->Lock()
- #define CN_UNLOCK if (m_pRoboMutex != NULL) m_pRoboMutex->Unlock()
- CDummyRoboDriver::CDummyRoboDriver(IRoboCommNode *commnode)
- {
- /** Initialize our members. */
- m_pCommNode = commnode;
- m_pRoboMutex = (m_pCommNode != NULL) ? m_pCommNode->CreateMutex() : NULL;
- m_pPrintThread = NULL;
- m_pCommInterface = (m_pCommNode != NULL) ? m_pCommNode->GetSerialInterface() : NULL;
- m_eCurrentDiscPos = IRoboCommNode::ERLN_INPUT;
- m_bShowInfoMessage = TRUE;
- m_bPrintBeforeBurn = (m_pCommNode != NULL) ? m_pCommNode->GetConfigurationValueBOOL(CONFIG_PRINTBEFOREBURN, DEFAULTCONFIG_PRINTBEFOREBURN) : DEFAULTCONFIG_PRINTBEFOREBURN;
- m_bParallelizePrinting = (m_pCommNode != NULL) ? m_pCommNode->GetConfigurationValueBOOL(CONFIG_PARALLELIZE, DEFAULTCONFIG_PARALLELIZE) : DEFAULTCONFIG_PARALLELIZE;
- m_bIsTesting = FALSE;
- /** Configure the COM interface, although we don't use it here. */
- if((m_pCommInterface != NULL) && (m_pCommInterface->GetPortType() == PORT_SERIAL))
- static_cast<CCOMSerial*>(m_pCommInterface)->SetConfiguration(14400, 8, CCOMSerial::CPARITY_NO, CCOMSerial::STOPBITS_ONE);
- /** Up interface version 4 we can use some new communication node methods. */
- m_bHasNewInterface = (NERO_PLUGIN_GetInterfaceVersion() >= 4);
- /** We just don't paralllelize if printing should be done before burning. */
- if(m_bPrintBeforeBurn)
- m_bParallelizePrinting = FALSE;
- }
- CDummyRoboDriver::~CDummyRoboDriver()
- {
- /** Wait for print thread before we destroy our driver, to be sure the robo is idle. */
- WaitForPrintThread();
- if(m_pRoboMutex != NULL)
- delete m_pRoboMutex, m_pRoboMutex = NULL;
- }
- BOOL CDummyRoboDriver::InitBurn()
- {
- BOOL bResult = TRUE;
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "InitBurn is called.\n" \
- "Do some INITIALIZATION like RESETING robot here.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- return bResult;
- }
- BOOL CDummyRoboDriver::PreBurn()
- {
- BOOL bResult = TRUE;
- if((m_pCommNode != NULL) && (m_bShowInfoMessage))
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "PreBurn is called.\n" \
- "Now you can PRINT label before burning it.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- return bResult;
- }
- BOOL CDummyRoboDriver::InsertCD()
- {
- BOOL bResult = TRUE;
- if(m_pCommNode != NULL)
- {
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "InsertCD is called.\n" \
- "Send move command to your robot.\n" \
- "MOVE the disc to RECORDER or PRINT it before\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- CUserDialogHandle *pDialog = NULL;
- /** Check if printing label is possible. */
- if(m_bPrintBeforeBurn && m_pCommNode->LabelPrintEnabled())
- {
- WaitForPrintThread();
- CN_LOCK;
- pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_INPUT, IRoboCommNode::ERLN_PRINTER);
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
-
- m_eCurrentDiscPos = IRoboCommNode::ERLN_PRINTER;
- if(m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE)
- {
- CN_LOCK;
- pDialog = m_pCommNode->CreatePrintCoverDialog();
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
-
- if(m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE)
- pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_PRINTER, IRoboCommNode::ERLN_RECORDER);
- else
- bResult = FALSE;
- }
- else
- bResult = FALSE;
- }
- else
- {
- CN_LOCK;
- pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_INPUT, IRoboCommNode::ERLN_RECORDER);
- CN_UNLOCK;
- }
- if(bResult)
- {
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- m_eCurrentDiscPos = IRoboCommNode::ERLN_RECORDER;
- bResult = m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE;
- }
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- }
- else
- bResult = FALSE;
- return bResult;
- }
- BOOL CDummyRoboDriver::RemoveNonWriteableCD()
- {
- BOOL bResult = TRUE;
- if(m_pCommNode != NULL)
- {
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "RemoveNonWriteableCD is called.\n" \
- "Send move command to your robot.\n" \
- "MOVE the disc to WASTE bin because it can not be burned.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- CN_LOCK;
- CUserDialogHandle *pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_RECORDER, IRoboCommNode::ERLN_WASTEBIN);
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- m_eCurrentDiscPos = IRoboCommNode::ERLN_WASTEBIN;
- bResult = m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE;
- }
- return bResult;
- }
- BOOL CDummyRoboDriver::RemoveUntouchedCD()
- {
- BOOL bResult = TRUE;
- if(m_pCommNode != NULL)
- {
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "RemoveUntouchedCD is called.\n" \
- "Send move command to your robot.\n" \
- "MOVE the disc back to INPUT bin because it was not burned.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- CN_LOCK;
- CUserDialogHandle *pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_RECORDER, IRoboCommNode::ERLN_INPUT);
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- m_eCurrentDiscPos = IRoboCommNode::ERLN_INPUT;
- bResult = m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE;
- }
- return bResult;
- }
- BOOL CDummyRoboDriver::PostBurnOK()
- {
- BOOL bResult = TRUE;
- if(m_pCommNode != NULL)
- {
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "PostBurnOK is called.\n" \
- "Send move command to your robot.\n" \
- "MOVE the disc to OUTPUT bin or PRINT it before.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- CUserDialogHandle *pDialog = NULL;
- if(!m_bPrintBeforeBurn && m_pCommNode->LabelPrintEnabled())
- {
- WaitForPrintThread();
- CN_LOCK;
- pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_RECORDER, IRoboCommNode::ERLN_PRINTER);
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- m_eCurrentDiscPos = IRoboCommNode::ERLN_PRINTER;
- /** Create separate print thread, so the driver can do another tasks (e.g. insert new disc in the recorder)
- * during Printing. */
- if(m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE)
- m_pPrintThread = m_pCommNode->CreateThread(PrintThreadEntry, (void*)this);
- else
- bResult = FALSE;
- if(!m_bParallelizePrinting /*|| m_bIsTesting*/)
- WaitForPrintThread();
- }
- else
- {
- CN_LOCK;
- pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_RECORDER, IRoboCommNode::ERLN_OUTPUT);
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- m_eCurrentDiscPos = IRoboCommNode::ERLN_OUTPUT;
- }
- if(bResult)
- bResult = m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE;
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- }
- return bResult;
- }
- BOOL CDummyRoboDriver::PostBurnFAILURE()
- {
- BOOL bResult = TRUE;
- if(m_pCommNode != NULL)
- {
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "PostBurnFAILURE is called.\n" \
- "Send move command to your robot.\n" \
- "MOVE the disc to WASTE bin because burning failed.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- CN_LOCK;
- CUserDialogHandle *pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_RECORDER, IRoboCommNode::ERLN_WASTEBIN);
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- m_eCurrentDiscPos = IRoboCommNode::ERLN_WASTEBIN;
- bResult = m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE;
- }
- return bResult;
- }
- BOOL CDummyRoboDriver::CleanUp()
- {
- BOOL bResult = TRUE;
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "CleanUp is called.\n" \
- "REMOVE remaining discs from PRINTER and RECORDER.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- WaitForPrintThread();
- if((m_eCurrentDiscPos == IRoboCommNode::ERLN_RECORDER) || (m_eCurrentDiscPos == IRoboCommNode::ERLN_PRINTER))
- {
- CN_LOCK;
- CUserDialogHandle *pDialog = m_pCommNode->CreateMoveCDDialog(m_eCurrentDiscPos, IRoboCommNode::ERLN_WASTEBIN);
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- m_eCurrentDiscPos = IRoboCommNode::ERLN_WASTEBIN;
- bResult = m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE;
- }
- return bResult;
- }
- BOOL CDummyRoboDriver::StartPrintLabel()
- {
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "StartPrintLabel is called.\n" \
- "PRINT the LABEL if not already done.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- return TRUE;
- }
- BOOL CDummyRoboDriver::StartRoboTest()
- {
- BOOL bResult = TRUE;
- m_bIsTesting = TRUE;
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "StartRoboTest is called.\n" \
- "MOVE the disc USUAL WAY to check the setting.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- bResult = InsertCD() ? PostBurnOK() : FALSE;
- m_bIsTesting = FALSE;
- return bResult;
- }
- BOOL CDummyRoboDriver::ExitBurn()
- {
- if(m_bShowInfoMessage)
- {
- CUserDialogHandle *pErrorMessage = m_pCommNode->CreateMessage( "ExitBurn is called.\n" \
- "CLEANUP because burning could be aborted.\n" \
- "Press Cancel, so these messages will not be displayed anymore.",
- ROBOCOMMNODE_MSG_HINT);
- if(pErrorMessage != NULL)
- pErrorMessage->WaitForUserFeedback();
-
- m_bShowInfoMessage = (pErrorMessage->GetFeedback() != CUserDialogHandle::DLGRESULT_CANCEL);
- if(pErrorMessage != NULL)
- delete pErrorMessage, pErrorMessage = NULL;
- }
- return WaitForPrintThread() ? CleanUp() : FALSE;
- }
- UINT CDummyRoboDriver::PrintThreadEntry(void *pData)
- {
- UINT uiResult = 1;
- CDummyRoboDriver *pThis = (CDummyRoboDriver*)pData;
- if(pThis != NULL)
- uiResult = pThis->PrintThread();
-
- return uiResult;
- }
- UINT CDummyRoboDriver::PrintThread()
- {
- BOOL bResult = FALSE;
- if(m_pCommNode != NULL)
- {
- /** Add this thread to our list, so Nero will know to wait for it. */
- if(m_bHasNewInterface)
- m_pCommNode->AddMyPrintThread();
-
- CUserDialogHandle *pDialog = NULL;
- CN_LOCK;
- pDialog = m_pCommNode->CreatePrintCoverDialog();
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- if(m_bHasNewInterface ? !m_pCommNode->IsAbortedImmediate() : TRUE)
- {
- CN_LOCK;
- pDialog = m_pCommNode->CreateMoveCDDialog(IRoboCommNode::ERLN_PRINTER, IRoboCommNode::ERLN_OUTPUT);
- CN_UNLOCK;
- m_pCommNode->SuspendThread(SIMULATEROBOMOVEMENT_TIMEOUT);
- CN_LOCK;
- if(pDialog != NULL)
- delete pDialog, pDialog = NULL;
- CN_UNLOCK;
- }
- else
- bResult = FALSE;
- if(m_bHasNewInterface)
- m_pCommNode->RemoveMyPrintThread();
- }
-
- return bResult ? 0 : 1; /* Return 0 on success */
- }
- BOOL CDummyRoboDriver::WaitForPrintThread()
- {
- DWORD dwResult = 1;
-
- /* Wait for the print thread to exit */
- if((m_pPrintThread != NULL) && (m_pCommNode != NULL))
- {
- while(!m_pPrintThread->GetExitCodeThread(&dwResult))
- m_pCommNode->SuspendThread(100);
-
- delete m_pPrintThread; m_pPrintThread = NULL;
- }
- return (dwResult == 0); // Everything went ok
- };
|