/*************************************************************************** * Copyright (C) 2004 by Johan Maes - ON4QZ * * on4qz@telenet.be * * http://users.telenet.be/on4qz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "txfunctions.h" #include "qsstvglobal.h" #include "dspfunctions.h" #include "modebase.h" #include "txmainwindow.h" #include "rxmainwindow.h" #include "galerymainwindow.h" #include "imageview.h" #include "configdialog.h" #include #include "mcanvas.h" #include "utils.h" txFunctions::txFunctions(QProgressBar *pb,QObject *parent, const char *name) : rxtxFunctions(parent,name) { busy=FALSE; thumbImPtr=NULL; orgImage=NULL; txTimer=new QTimer(this); connect(txTimer,SIGNAL(timeout()),SLOT(slotTransmit())); resultImage=NULL; pbPtr=pb; } txFunctions::~txFunctions() { } void txFunctions::setModeIndex(sstvMode mi) { selectedMode=mi; if(!startSelectedMode(txMW->getImagePtr(),TRUE)) return; setExistingImage(); debug("setModeIndex"); } void txFunctions::process() { if(orgImage==NULL) { QMessageBox::warning(0,"No image loaded","Load an image in the TX window",QMessageBox::Ok,0 ); busy=FALSE; return; } busy=TRUE; dsp->startTransmit(); if(!startSelectedMode(txMW->getImagePtr(),TRUE)) return; // QFrame *xxx=new QFrame(); // xxx->setBackgroundPixmap(*resultImage); // xxx->show(); // debug("resultimage pr show %x",resultImage); txMW->getImagePtr()->showImage(resultImage); // applyTemplate(); done=FALSE; rxtxDisplay->initTX(pbPtr); txPhase=HEADER; singleTone=FALSE; multiTone=FALSE; disconnect(txTimer,0,0,0); connect(txTimer,SIGNAL(timeout()),SLOT(slotTransmit())); txTimer->start(1,TRUE); } void txFunctions::slotTransmit() { etxState res; if(rxtxDisplay==NULL) { logfile.add("slotTransmit called with txDiplay==NULL"); return; } if(singleTone) { if((res=rxtxDisplay->txSingleTone(txFreq,txDur))==TXDONE) return; } else if(multiTone) { rxtxDisplay->txMultiTone(txFreq,txDur,txFreqb,txDurb); } else { do { switch(txPhase) { case HEADER: if((res=rxtxDisplay->txHeader())==TXDONE) { txPhase=VISCODE; emit statusMessage("Sending VIS Code"); } break; case VISCODE: if((res=rxtxDisplay->txVisCode())==TXDONE) { txPhase=LINE; emit statusMessage("Sending Image"); } break; case LINE: if((res=rxtxDisplay->txLine())==TXDONE) txPhase=TAIL; break; case TAIL: if((res=rxtxDisplay->txTail())==TXDONE) { if(useCW) { emit statusMessage("Sending CW"); txPhase=CW; rxtxDisplay->initCW(cwText); } else { txPhase=DELSTOP; emit statusMessage("Waiting for end of transmission"); } } break; case CW: if((res=rxtxDisplay->txCW())==TXDONE) { txPhase=DELSTOP; emit statusMessage("Waiting for end of transmission"); } break; case DELSTOP: if((res=rxtxDisplay->txDELAYEDSTOP())==TXDONE) txPhase=STOP; break; case STOP: if((res=rxtxDisplay->txWAITSTOP())==TXDONE) txPhase=END; break; case END: emit statusMessage("End of transmission"); done=TRUE; busy=FALSE; rxMW->slotStartRX(); pbPtr->reset(); return; break; default: break; } } while(res!=TXWAIT); } txTimer->start(10,TRUE); } void txFunctions::sendCW(QString st) { dsp->startTransmit(); if(!startSelectedMode(txMW->getImagePtr(),TRUE)) return; // create dummy modbase rxtxDisplay->initCW(st); singleTone=FALSE; multiTone=TRUE; txPhase=DELAY; done=FALSE; disconnect(txTimer,0,0,0); connect(txTimer,SIGNAL(timeout()),SLOT(slotSendCW())); txTimer->start(1,TRUE); } void txFunctions::slotSendCW() { etxState res; do { switch(txPhase) { case DELAY: { txTimer->start(1000,TRUE); txPhase=CW; return; } case CW: if((res=rxtxDisplay->txCW())==TXDONE) { txPhase=DELSTOP; emit statusMessage("Waiting for end of transmission"); } break; case DELSTOP: if((res=rxtxDisplay->txDELAYEDSTOP())==TXDONE) txPhase=STOP; break; case STOP: if((res=rxtxDisplay->txWAITSTOP())==TXDONE) txPhase=END; break; case END: emit statusMessage("End of transmission"); done=TRUE; busy=FALSE; rxMW->restartAfterAck(); return; break; default: break; } } while(res!=TXWAIT); txTimer->start(10,TRUE); } void txFunctions::sendAlignement() { dsp->startTransmit(); if(!startSelectedMode(txMW->getImagePtr(),TRUE)) return; singleTone=FALSE; multiTone=TRUE; txPhase=HEADER; done=FALSE; rxtxDisplay->initTX(pbPtr); txFreq=1200; txDur=0.150*txClock; txFreqb=2300; txDurb=0.850*txClock; txTimer->start(100,TRUE); } void txFunctions::addTemplate(int t) { templateIndex=t; applyTemplate(); } void txFunctions::applyTemplate() { mcanvas mCanvas(activeSSTVParam.numberOfPixels,activeSSTVParam.numberOfLines); if (orgImage==NULL)return; if(resultImage) delete resultImage; if(repeaterEnable) { resultImage=new QImage(mCanvas.overlay(orgImage,repeaterTemplate)->copy()); } else if(useTemplate) { resultImage=new QImage(mCanvas.overlay(orgImage,templateIndex-1)->copy()); } else { resultImage=new QImage(orgImage->copy()); } txMW->getImagePtr()->showImage(resultImage); } void txFunctions::setImage(QImage *ima) { logfile.add("txfunctions setImage"); if(orgImage) delete orgImage; orgImage= new QImage (ima->copy()); applyTemplate(); } void txFunctions::setExistingImage() { debug("txfunctions set Existing Image"); if(orgImage) applyTemplate(); } void txFunctions::stop() { singleTone=FALSE; multiTone=FALSE; txPhase=DELSTOP; txTimer->start(10,TRUE); } void txFunctions::sendTone(float freq,float duration) { // create a dummy mode dsp->startTransmit(); if(!startSelectedMode(txMW->getImagePtr(),TRUE)) return ; singleTone=TRUE; multiTone=FALSE; done=FALSE; rxtxDisplay->initTX(pbPtr); txTimer->start(1,TRUE); txFreq=freq; txDur=duration*txClock; }