#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <keycodes.h>
#include "mfjterm.h"
#include "misc.h"
#include "inout.h"
#include "qso.h"
#include "timefuncs.h"


void send_cq(void)
{
       int i;
       char cq_tail[50];

       switch(opmode) {
               case AMTOR :
               case PACTOR:
                       switch_fec(ON);
                       zleep(10);
                       break;
               case ASCII:
               case RTTY:
                       write_tnc(K_CTL_T);
                       write_tnc(0x0A);
                       send_ry();
       }

       strcpy(cq_tail, callsign);
       strcat(cq_tail, " ");
       strcat(cq_tail, callsign);
       strcat(cq_tail, " ");
       strcat(cq_tail, callsign);

       if (opmode == AMTOR) {
               strcat(cq_tail, " SELCALL ");
               strcat(cq_tail, my_selcall);
       }

       for (i = 0; i < 2; i++) {
               send_string(cq_str, 0);
               send_string(cq_tail, 1);
       }
       send_string(cq_str, 0);
       send_string(cq_tail, 0);
       send_string(over_str[2],1);

       waitfor_string("K K\012");

       if ((opmode == AMTOR) || (opmode == PACTOR))
               switch_fec(OFF);
       else
               write_tnc(K_CTL_R);
}