⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 QAM module to use in Java with an easy interface and powerful performance
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void __fastcall TQAMForm::CMGotTextDataBlock(TMessage &Msg)
{
        criticalsection->Acquire();
        while(tstrings->Count>0)
        {
                AppendTextToRxConsole(tstrings->Strings[0].c_str(),tstrings->Strings[0].Length());
                tstrings->Delete(0);
        }
        criticalsection->Release();
}

void __fastcall TQAMForm::AppendTextToRxConsole(unsigned char * ch,int clen)
{
        for(int i=0;i<clen;i++)
        {
                if(ch[i]=='\r')ch[i]=0;
        }
        for(int i=0;i<clen;i++)
        {
                if(ch[i]==0)
                {
                ConsoleForm->RxConsole->Lines->Append("");
                i++;
                if(i<clen)ConsoleForm->RxConsole->Lines->Strings[ConsoleForm->RxConsole->Lines->Count-1]=ConsoleForm->RxConsole->Lines->Strings[ConsoleForm->RxConsole->Lines->Count-1]+(AnsiString) (char*)&ch[i];
                for(i=i;i<clen;i++)if(ch[i]==0){i--;break;}
                }
                 else
                 {
                      ConsoleForm->RxConsole->Lines->Strings[ConsoleForm->RxConsole->Lines->Count-1]=ConsoleForm->RxConsole->Lines->Strings[ConsoleForm->RxConsole->Lines->Count-1]+(AnsiString) (char*)&ch[i];
                      for(i=i;i<clen;i++)if(ch[i]==0){i--;break;}
                 }
        }
}


void __fastcall TQAMForm::CiaComPort1DataAvailable(TObject *Sender)
{
        if(!gSettings.ModMajor.Active)return;
        int space=mod->dataformatter->GetCountOfFreeSpaceInCharBuf();
        if (space<=0){Sleep(half_a_buffer_delay);return;}
        unsigned count=CiaComPort1->Receive(rs232incharbuf,space);
        mod->dataformatter->LoadNextBufferPacket(rs232incharbuf,(int)count,ptRs232);
}
//---------------------------------------------------------------------------




void __fastcall TQAMForm::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if(busy)
{
        CanClose=false;
        return;
}
if((gSettings.ModMajor.Active)||(gSettings.DemodMajor.Active))Stop1Click(this);

CritDestroy->Acquire();

        if(pDirMonThread)pDirMonThread->Terminate ();
        pDirMonThread = NULL;
        if(mod)delete mod;mod=0;
        if(demod)delete demod;demod=0;
        if(tstrings)delete tstrings;tstrings=0;


        if(criticalsection)delete criticalsection;criticalsection=0;
CritDestroy->Release();
        if(CritDestroy)delete CritDestroy;CritDestroy=0;
        if(rs232criticalsection)delete rs232criticalsection;rs232criticalsection=0;
        if(udpinbuffer)delete [] udpinbuffer;udpinbuffer=0;
        if(StationID)delete [] StationID;StationID=0;
        if(webfile>=0)FileClose(webfile);webfile=-2;
        if(webmetfilerec>=0)FileClose(webmetfilerec);webmetfilerec=-2;
        if(webfilfilerec>=0)
        {
                FileWrite(webfilfilerec,&fil_data[0],4*fil_data.size());
                FileClose(webfilfilerec);
        }
        webfilfilerec=-2;

        FtpServer1->Stop();
        FtpServer1->DisconnectAll();

        HttpServer1->Stop();

}
//---------------------------------------------------------------------------



void __fastcall TQAMForm::Exit1Click(TObject *Sender)
{
        Close();
}
//---------------------------------------------------------------------------





void __fastcall TQAMForm::FormHide(TObject *Sender)
{
        Timer1->Enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall TQAMForm::FormShow(TObject *Sender)
{
        if(gSettings.ModMajor.Active||gSettings.DemodMajor.Active)Timer1->Enabled=true;
}
//---------------------------------------------------------------------------


void __fastcall TQAMForm::About1Click(TObject *Sender)
{
       AboutBox->ShowModal();
}
//---------------------------------------------------------------------------


void __fastcall TQAMForm::WSocketListnerDataAvailable(TObject *Sender,
      WORD ErrCode)
{
        int len=WSocketListner->Receive(udpinbuffer,UDPBufferInSize);
        if((gSettings.ModMajor.Active)&&(len>=0)) mod->dataformatter->LoadNextBufferPacket(udpinbuffer,len,ptUdp);
}
//---------------------------------------------------------------------------


void __fastcall TQAMForm::WSocketSenderSessionConnected(TObject *Sender,
      WORD ErrCode)
{
        udp_sender_conneted=true;
}
//---------------------------------------------------------------------------

void __fastcall TQAMForm::WSocketSenderSessionClosed(TObject *Sender,
      WORD ErrCode)
{
        udp_sender_conneted=false;
}
//---------------------------------------------------------------------------

void __fastcall TQAMForm::SocketUnRealTCPClientSessionConnected(
      TObject *Sender, WORD ErrCode)
{
        UnRealHeaderGotIt=false;
        UnRealClientLED->Status=false;
        UnRealClientLED->Active=true;
        SocketUnRealTCPClient->SendStr("live-alias:"+SettingsForm->JvEditUnRealAlias->Text);
}
//---------------------------------------------------------------------------

void __fastcall TQAMForm::SocketUnRealTCPClientDataAvailable(
      TObject *Sender, WORD ErrCode)
{
        int Len;
        int i;
        unsigned char Buf[4098];
        unsigned long crc32;
        FastCrc fastCrc (0x04c11db7);
        if(!UnRealHeaderGotIt)
        {

                UnRealHeadersize=SocketUnRealTCPClient->Receive(UnRealHeader,sizeof(UnRealHeader)-4);
                UnRealClientLED->Active=false;
                UnRealClientLED->Status=true;
                UnRealHeaderGotIt=true;
                AddCRC32(UnRealHeader,&UnRealHeadersize);

        }
         else
         {
                Len=SocketUnRealTCPClient->Receive(Buf,sizeof(Buf));
                if(gSettings.ModMajor.Active&&(Len>=0))mod->dataformatter->LoadNextBufferPacket(Buf,Len,ptUnReal);
         }

}
//---------------------------------------------------------------------------

void __fastcall TQAMForm::SocketUnRealTCPClientSessionClosed(
      TObject *Sender, WORD ErrCode)
{
        UnRealHeaderGotIt=false;
        UnRealClientLED->Active=false;
        UnRealClientLED->Status=false;
        if(ModLED->Status)UnRealClientLED->ColorOff=clRed;
        if(ErrCode==10057)
        {
                ShowMessage("UnReal Media server is needed and can't be found.\nIf it's installed, check your settings are correct.\nElse download it from http://www.umediaserver.net\n");
        } else if(ModLED->Status)ShowMessage("UnReal media server connection has closed.\nThis is probably because the Alais link was not found on the server.");

}
//---------------------------------------------------------------------------


void __fastcall TQAMForm::SecondTimerTimer(TObject *Sender)
{

        if((gSettings.DemodMajor.Active)&&(gSettings.DemodMinor.Acquisitionstage!=WaitingForLossOfLock))
        {
                //this is for if the station has changed
                RXStationIDText->Caption="Unknown Station";
                RXStationIDText->Cursor=crDefault;
                //StatusBar1->Panels->Items[1]->Text="";
                StationIDRec="";
                QAMUnRealHeaderGotIt=false;
        }
        if(UnRealHeaderTimerEnabled)
        {
                UnRealHeaderTimerCounter--;
                if(UnRealHeaderTimerCounter<0)
                {
                        UnRealHeaderTimerCounter=UnRealHeaderTimerInterval;
                        //Display("URH Sent\r");
                        if(UnRealHeaderGotIt&&gSettings.ModMajor.Active)mod->dataformatter->LoadNextBufferPacket(UnRealHeader,UnRealHeadersize,ptUnRealHeader);
                }
        }
        if(StationIDTimerEnabled)
        {
                StationIDTimerCounter--;
                if(StationIDTimerCounter<0)
                {
                        StationIDTimerCounter=StationIDTimerInterval;
                        if(gSettings.ModMajor.Active)mod->dataformatter->LoadNextBufferPacket(StationID,StationIDSize,ptStationID);
                }
        }
}
//---------------------------------------------------------------------------

void __fastcall TQAMForm::ProgramLoaded(void)
{
        mod=new Modulator();
        demod=new Demodulator(&PacketCallBackFunc);
        JvgGroupBox12->Visible=false;
        JvgGroupBox13->Visible=false;
        Start1->Visible=true;
        Stop1->Visible=true;
        JvStandardPageNone->Show();
        Stop1Click(this);
        UpdateGuiPages();

        if(SettingsForm->JvXPShowWindowOnstartup->Checked)JvTrayIcon1->ShowApplication();
         else JvTrayIcon1->HideApplication();
        if(SettingsForm->JvXPStartOnLoading->Checked)Start1Click(this);
}

void __fastcall TQAMForm::SettingsFinished(void)
{

        HttpServer1->Stop();
        FtpServer1->Stop();
        FtpServer1->DisconnectAll();

        UpdateTXWindow();
        UpdateGuiPages();

        FileListBoxApplyPath(SettingsForm->JvDirectoryEditWebDir->Text);
        LoadSendingFileNames();

        HttpServer1->DocDir=Trim(ExtractFilePath(Application->ExeName));
        HttpServer1->DefaultDoc="index.html";
        HttpServer1->Port=Trim(SettingsForm->JvValidateEditHTTPServerPort->Text);
        HttpServer1->ClientClass = __classid(TMyHttpConnection);
        try
        {
                HttpServer1->Start();
        }
        catch (Exception &e )
        {
                ShowMessage((AnsiString)"HTTP Server statup failed\n"+e.Message);
        }



        if(SettingsForm->JvXPCheckboxModOn->Checked)
        {
                FtpServer1->Port=SettingsForm->JvEditFtpPort->Text;
                try
                {
                        FtpServer1->Start();
                }
                catch (Exception &e )
                {
                        ShowMessage((AnsiString)"FTP Server statup failed\n"+e.Message);//"FTP Server statup failed");
                }
        }


}

void __fastcall TQAMForm::SocketUnRealTCPServerListnerSessionAvailable(
      TObject *Sender, WORD ErrCode)
{
        TWSocket *NewClient;
       // Display("Client connected\r");
        NewClient = new TWSocket(NULL);
        FClients->Add(NewClient);
 //   NewClient->LingerOnOff=wsLingerNoSet;
 //   NewClient->KeepAliveInterval=10;
 //   NewClient->KeepAliveOnOff=wsKeepAliveOff;
        NewClient->MultiCast=false;
        NewClient->KeepAliveOnOff=wsKeepAliveOnSystem;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -