From c4e8b78518093973e769e9ed3072b1300c6d61be Mon Sep 17 00:00:00 2001 From: Steven Franke Date: Thu, 4 Jun 2015 21:07:45 +0000 Subject: [PATCH] Actually add the files this time. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5532 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- WsprTxScheduler.cpp | 199 ++++++++++++++++++++++++++++++++++++++++++++ WsprTxScheduler.h | 19 +++++ 2 files changed, 218 insertions(+) create mode 100644 WsprTxScheduler.cpp create mode 100644 WsprTxScheduler.h diff --git a/WsprTxScheduler.cpp b/WsprTxScheduler.cpp new file mode 100644 index 000000000..1d0d10dec --- /dev/null +++ b/WsprTxScheduler.cpp @@ -0,0 +1,199 @@ +#include "WsprTxScheduler.h" +/*#include +#include +#include +#include +#include + +using namespace std; + +char tx[6][10]; +int pctx, tx_table_2hr_slot; +*/ +int tx_band_sum(char bsum[10]) +{ + int i,j; + + for (j=0; j<10; j++) { + bsum[j]=0; + for (i=0; i<6; i++) { + bsum[j]=bsum[j]+tx[i][j]; + } + } + return 1; +} + +int tx_add_to_band(int band) +{ + // add tx cycle to a band without regard to ntxlim + int i,islot; + for ( i=0; i<10; i++) { + islot=rand()%6; + if( tx[islot][band] != 1 ) { + tx[islot][band]=1; + return 1; + } + } + return 0; +} + +int tx_sum() +{ + int i,j,sum=0; + for (i=0; i<6; i++) { + for (j=0; j<10; j++) { + sum=sum+tx[i][j]; + } + } + return sum; +} + +int tx_add_one(char* tx) +{ + int i; + for (i=1; i<59; i++) { + if( tx[i-1]==0 && tx[i]==0 && tx[i+1]==0 ) { + tx[i]=1; + return 1; + } + } + return 0; +} + +int tx_trim(char* tx, int ntxlim) +{ + // trim array to that ntxlim is not exceeded + int i,nrun,sum; + nrun=0; + for (i=0; i<60; i++) { + if( tx[i]==1 ) { + nrun++; + if( nrun > ntxlim ) { + tx[i]=0; + nrun=0; + } + } else { + nrun=0; + } + } + sum=0; + for (i=0; i<60; i++) { + sum=sum+tx[i]; + } + return sum; +} + +void tx_print() +{ + int i,j; + for (i=0; i<6; i++) { + for (j=0; j<10; j++) { + if( (i*10+j)%10 == 0 && i>=0 ) printf("\n"); + printf("%d ",tx[i][j]); + } + } + printf("\n"); +} + +int create_tx_schedule() +{ + char bsum[10]; + int i, j, k, sum, ntxlim, ntxbandmin, needed; + int iflag; + + needed=60*(pctx/100.0)+0.5; + + srand(time(NULL)); + memset(tx,0,sizeof(char)*60); + + if( pctx < 17 ) { + needed=pctx*60/100; + for (i=0; i= 17 && pctx < 33 ) { + ntxlim=1; + ntxbandmin=1; + } else if( pctx >= 33 && pctx < 50 ) { + ntxlim=1; + ntxbandmin=2; + } else if( pctx >= 50 && pctx < 60 ) { + ntxlim=2; + ntxbandmin=3; + } else { + ntxlim=3; + ntxbandmin=4; + } + + // start by filling each band slot with ntxbandmin tx's + for (i=0; itm_hour; + int minute = ltm->tm_min; + + int tx_2hr_slot = hour/2; + int tx_20min_slot = (hour-tx_2hr_slot*2)*3 + minute/20; + int tx_2min_slot = (minute%20)/2; + + if( tx_2hr_slot != tx_table_2hr_slot ) { + create_tx_schedule(); + tx_table_2hr_slot = tx_2hr_slot; + } + + cout << "Hour " << hour << " Minute " << minute << endl; + cout << "tx_2hr_slot " << tx_2hr_slot << endl; + cout << "tx_20min_slot " << tx_20min_slot << endl; + cout << "tx_2min_slot " << tx_2min_slot << endl; + cout << "tx_table_2hr_slot " << tx_table_2hr_slot << endl; + return tx[tx_20min_slot][tx_2min_slot]; +} +/* +int main(int argc, char *argv[]) +{ + + if( argc == 2 ) { + pctx = atoi(argv[1]); + } else { + pctx = 25; + } + tx_table_2hr_slot = 0; + cout << "Next TX state: " << next_tx_state() << endl; + cout << "Requested % " << pctx << " Actual % " << 100*tx_sum()/60 << endl; + tx_print(); +} +*/ diff --git a/WsprTxScheduler.h b/WsprTxScheduler.h new file mode 100644 index 000000000..6fa2dd66c --- /dev/null +++ b/WsprTxScheduler.h @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include + +using namespace std; + +char tx[6][10]; +int pctx, tx_table_2hr_slot; + +int tx_band_sum(char bsum[10]); +int tx_add_to_band(int band); +int tx_sum(); +int tx_add_one(char* tx); +int tx_trim(char* tx, int ntxlim); +void tx_print(); +int create_tx_schedule(); +int next_tx_state();