コード例 #1
0
ファイル: keyer.c プロジェクト: patlc/tlf
int keyer(void)
{

    extern char mode[20];
    extern int bufloc;
    extern char buffer[];
    extern char termbuf[];
    extern char message[15][80];
    extern char wkeyerbuffer[];
    extern int data_ready;
    extern int keyerport;
    extern int weight;

    int x = 0, i = 0, j = 0;
    int cury, curx;
    char nkbuffer[2];
    char keyerstring[30] = "                              ";
    char weightbuf[15];
    const char txcontrolstring[2] = { 20, '\0' };
    const char rxcontrolstring[2] = { 18, '\0' };
    const char crcontrolstring[2] = { 13, '\0' };
    const char ctl_c_controlstring[2] = { 92, '\0' };

    strcpy(mode, "Keyboard");
    clear_display();
    attron(COLOR_PAIR(C_LOG) | A_STANDOUT);

    if (keyerport == NO_KEYER)	/* no keyer present */
	return (1);

    if (keyerport == MFJ1278_KEYER) {
	buffer[0] = 20;		// 1 char at the time !
	buffer[1] = '\0';
	if (data_ready != 1) {
	    strcat(wkeyerbuffer, buffer);
	    data_ready = 1;
	}
	buffer[0] = '\0';
    }

    while (1) {
	x = onechar();

	if (x == 34) {		/* bug fix */// "
	    x = 32;
	}

	if (x == '\n')
	    x = 32;

	if (x == 27 || x == 11 || x == 235) {	//      esc, ctrl-k,  alt-k
	    if (keyerport == MFJ1278_KEYER) {
		buffer[0] = 18;	// 1 char at the time !
		buffer[1] = '\0';
		if (data_ready != 1) {
		    strcat(wkeyerbuffer, buffer);
		    data_ready = 1;
		}
	    } else {
		stoptx();
	    }

	    buffer[0] = '\0';
	    break;
	}

	if (x >= 32 && x <= 125) {	// display              space ... }
	    addch(x);
	    refreshp();
	    i++;
	    if ((i >= 40)) {
		i = 0;
		mvprintw(4, 0, "                            ");
		mvprintw(4, 0, "");
		refreshp();
		displayit();

	    }

	    refreshp();
	}

	if (x == 127 && (strlen(buffer) >= 1)) {	/* erase  */

	    getyx(stdscr, cury, curx);
	    mvprintw(5, curx - 1, " ");
	    mvprintw(5, curx - 1, "");
	    buffer[strlen(buffer) - 1] = '\0';
	    bufloc--;
	}

	if (x > 96 && x < 123)	/* upper case only */
	    x = x - 32;

	if (x > 9 && x < 91) {

	    if (bufloc >= 38)	// maximum buffer = 39
	    {
		bufloc = 38;
		printw("\nBuffer overflow !, bufloc = %d\n", bufloc);
		refreshp();
	    } else {
		if (x > 31 || x == 10) {
		    if (keyerport == MFJ1278_KEYER) {
			mfj1278_control(x);
		    } else if (keyerport == NET_KEYER) {
			nkbuffer[0] = x;	// 1 char at the time !
			nkbuffer[1] = '\0';
			netkeyer(K_MESSAGE, nkbuffer);
			nkbuffer[0] = '\0';
			for (j = 0; j < 29; j++) {
			    keyerstring[j] = keyerstring[j + 1];
			}
			keyerstring[28] = x;
			keyerstring[29] = '\0';

			attron(COLOR_PAIR(C_LOG) | A_STANDOUT);
			mvprintw(5, 0, "%s", keyerstring);
			refreshp();
		    } else if (keyerport == ORION_KEYER) {
			nkbuffer[0] = x;
			nkbuffer[1] = '\0';
			strcat(wkeyerbuffer, nkbuffer);
			sendbuf();
			nkbuffer[0] = '\0';
			for (j = 0; j < 29; j++) {
			    keyerstring[j] = keyerstring[j + 1];
			}
			keyerstring[28] = x;
			keyerstring[29] = '\0';

			attron(COLOR_PAIR(C_LOG) | A_STANDOUT);
			mvprintw(5, 0, "%s", keyerstring);
			refreshp();

		    }
		} else		// control char...
		{

		    if (data_ready != 1) {
			strcat(wkeyerbuffer, buffer);
			data_ready = 1;
		    } else
			buffer[0] = '\0';

		    getyx(stdscr, cury, curx);
		    attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
		    mvaddstr(0, 0, "  ");
		    attron(COLOR_PAIR(C_LOG));
		    mvaddstr(cury, curx, "");
		    refreshp();

		    strcat(termbuf, buffer);
		    strcat(termbuf, " ");
		    mvprintw(5, 0, termbuf);
		    refreshp();

		    if ((strlen(buffer) + strlen(termbuf) > 39)
			|| x == '=') {
			i = 0;
			mvprintw(5, 0, "                         ");
			mvprintw(5, 0, "");
			refreshp();
			displayit();
		    }

		    bufloc = 0;
		    buffer[bufloc] = '\0';
		}
	    }
	} else {

	    switch (x) {
	    case 9:
		{
		    bufloc = 0;
		    buffer[bufloc] = '\0';
		    strcpy(mode, "Log     ");
		    clear_display();
		    return (2);
		}
	    case '\n':
	    case 13:
		{
		    if (keyerport == MFJ1278_KEYER && strlen(buffer) < 39) {
			strcat(buffer, crcontrolstring);
			sendbuf();
			bufloc = 0;
		    }
		    break;
		}

	    case 27:
	    case 11:
		{
		    stoptx();
		    bufloc = 0;
		    buffer[bufloc] = '\0';
		    strcpy(mode, "Log     ");
		    clear_display();
		    return (2);
		}
	    case 123:
		{
		    if (keyerport == MFJ1278_KEYER) {
			strcat(buffer, txcontrolstring);
			sendbuf();
		    }
		    break;
		}
	    case 125:
		{
		    if (keyerport == MFJ1278_KEYER) {
			strcat(buffer, rxcontrolstring);
			sendbuf();
		    }
		    break;
		}
	    case 92:
		{
		    if (keyerport == MFJ1278_KEYER) {
			strcat(buffer, ctl_c_controlstring);
			sendbuf();
		    }
		    break;
		}

	    case 247:		// Alt-w, set weight
		{
		    mvprintw(1, 0, "Weight=   ");
		    mvprintw(1, 7, "");
		    refreshp();
		    echo();
		    getnstr(weightbuf, 2);
		    noecho();

		    weight = atoi(weightbuf);
		    netkeyer(K_WEIGHT, weightbuf);
		    break;
		}
	    case 156:
		{
		    speedup();
		    clear_display();
		    break;
		}
	    case 157:
		{
		    speeddown();
		    clear_display();
		    break;
		}

	    case 129:
		{
		    strcat(buffer, message[0]);	/* F1 */
		    getyx(stdscr, cury, curx);
		    mvprintw(5, 0, "");
		    sendbuf();
		    mvprintw(cury, curx, "");
		    break;
		}
	    case 130:
		{
		    strcat(buffer, message[1]);	/* F2 */
		    sendbuf();
		    break;
		}
	    case 131:
		{
		    strcat(buffer, message[2]);	/* F3 */
		    sendbuf();
		    break;
		}
	    case 132:
		{
		    strcat(buffer, message[3]);	/* F4 */
		    sendbuf();
		    break;
		}
	    case 133:
		{
		    strcat(buffer, message[4]);	/* F5 */
		    sendbuf();
		    break;
		}
	    case 134:
		{
		    strcat(buffer, message[5]);	/* F6 */
		    sendbuf();
		    break;
		}
	    case 135:
		{
		    strcat(buffer, message[6]);	/* F7 */
		    sendbuf();
		    break;
		}
	    case 136:
		{
		    strcat(buffer, message[7]);	/* F8 */
		    sendbuf();
		    break;
		}
	    case 137:
		{
		    strcat(buffer, message[8]);	/* F9 */
		    sendbuf();
		    break;
		}
	    case 138:
		{
		    strcat(buffer, message[9]);	/* F10 */
		    sendbuf();
		    break;
		}

	    case 140:
		{
		    strcat(buffer, message[10]);	/* F11 */
		    sendbuf();
		    break;
		}
	    case 141:
		{

		    strcat(buffer, message[11]);	/* F12 */
		    sendbuf();
		    break;
		}

	    default:
		x = x;
	    }

	}
    }

    strcpy(mode, "Log     ");
    clear_display();

    return (2);			/* show end of keyer  routine */
}
コード例 #2
0
int keyer(void)
{

    extern int cqmode;
    extern char mode[20];
    extern char message[][80];
    extern char wkeyerbuffer[];
    extern int data_ready;
    extern int keyerport;
    extern int weight;

    WINDOW *win = NULL;
    PANEL *panel = NULL;

    int x = 0, j = 0;
    int cury, curx;
    char nkbuffer[2];
    char keyerstring[KEYER_LINE_WIDTH+1] = "";
    int keyerstringpos = 0;
    char weightbuf[15];
    const char txcontrolstring[2] = { 20, '\0' };	// ^t
    const char rxcontrolstring[2] = { 18, '\0' };	// ^r
    const char crcontrolstring[2] = { 13, '\0' };	// cr
    const char ctl_c_controlstring[2] = { 92, '\0' };	// '\'

    if (keyerport == NO_KEYER)	/* no keyer present */
	return 1;

    strcpy(mode, "Keyboard");
    clear_display();
    attron(COLOR_PAIR(C_LOG) | A_STANDOUT);

    if (panel == NULL) {
	win = newwin(KEYER_WIN_HEIGHT, KEYER_WIN_WIDTH, KEYER_Y, KEYER_Y );
	if (win == NULL)
	    return 1;
	panel = new_panel(win);
	if (panel == NULL) {
	    delwin(win);
	    return 1;
	}
    }

    show_panel(panel);
    werase(win);
    wnicebox(win, 0, 0, 1, KEYER_LINE_WIDTH, "CW Keyer");

    if (keyerport == MFJ1278_KEYER) {
	if (data_ready != 1) { 		/* switch to tx */
	    strcat(wkeyerbuffer, txcontrolstring);
	    data_ready = 1;
	}
    }

    while (1) {
	wattron(win, COLOR_PAIR(C_LOG) | A_STANDOUT);
	wmove (win, 1, 1);
	for (j = 0; j < KEYER_LINE_WIDTH; j++) {
	    waddch (win, ' ');
	}
	mvwprintw(win, 1, 1, "%s", keyerstring);
	refreshp();

	x = key_get();

	// Send space instead of double quote.
	if (x == 34) {
	    x = 32;
	}

	// Send space instead of newline or return.
	if (x == '\n' || x == KEY_ENTER)
	    x = 32;

	// <Escape>, Ctrl-K (^K), Alt-k (M-k)
	if (x == 27 || x == 11 || x == 235) {
	    if (keyerport == MFJ1278_KEYER) {
		if (data_ready != 1) { 	/* switch back to rx */
		    strcat(wkeyerbuffer, rxcontrolstring);
		    data_ready = 1;
		}
	    } else {
		stoptx();
	    }

	    break;
	}

	// Promote lower case to upper case.
	if (x > 96 && x < 123)
	    x = x - 32;

	if (x > 9 && x < 91) { 	/* drop all other control char... */
	    if (x > 31 || x == 10) {
		if (keyerport == MFJ1278_KEYER) {
		    mfj1278_control(x);
		} else if (keyerport == NET_KEYER) {
		    nkbuffer[0] = x;	// 1 char at the time !
		    nkbuffer[1] = '\0';
		    netkeyer(K_MESSAGE, nkbuffer);
		}

		/* if display field is full move text one left */
		if (keyerstringpos == KEYER_LINE_WIDTH - 1) {
		    for (j = 0; j < KEYER_LINE_WIDTH - 1; j++) {
		    	keyerstring[j] = keyerstring[j + 1];
		    }
		    keyerstringpos--;
		}
		/* add new character for display */
		keyerstring[keyerstringpos++] = x;
		keyerstring[keyerstringpos] = '\0';
	    }
	} else {

	    switch (x) {
	    case '\n':
	    case 13:
	    case KEY_ENTER:
		{
		    if (keyerport == MFJ1278_KEYER) {
			sendmessage(crcontrolstring);
		    }
		    break;
		}

	    case 123:		/* { */
		{
		    if (keyerport == MFJ1278_KEYER) {
			sendmessage(txcontrolstring);
		    }
		    break;
		}
	    case 125:		/* } */
		{
		    if (keyerport == MFJ1278_KEYER) {
			sendmessage(rxcontrolstring);
		    }
		    break;
		}
	    case 92:		/* \ */
		{
		    if (keyerport == MFJ1278_KEYER) {
			sendmessage(ctl_c_controlstring);
		    }
		    break;
		}

	    case 247:		// Alt-w, set weight
		{
		    mvprintw(1, 0, "Weight=   ");
		    mvprintw(1, 7, "");
		    refreshp();
		    echo();
		    getnstr(weightbuf, 2);
		    noecho();

		    weight = atoi(weightbuf);
		    netkeyer(K_WEIGHT, weightbuf);
		    break;
		}

	    // <Page-Up>, increase CW speed.
	    case KEY_PPAGE:
		{
		    speedup();
		    clear_display();
		    break;
		}

	    // <Page-Down>, decrease CW speed.
	    case KEY_NPAGE:
		{
		    speeddown();
		    clear_display();
		    break;
		}

	    case KEY_F(1):
		{
		    getyx(stdscr, cury, curx);
		    mvprintw(5, 0, "");
		    sendmessage(message[0]);	/* F1 */
		    mvprintw(cury, curx, "");
		    break;
		}
	    case KEY_F(2):
		{
		    sendmessage(message[1]);	/* F2 */
		    break;
		}
	    case KEY_F(3):
		{
		    sendmessage(message[2]);	/* F3 */
		    break;
		}
	    case KEY_F(4):
		{
		    sendmessage(message[3]);	/* F4 */
		    break;
		}
	    case KEY_F(5):
		{
		    sendmessage(message[4]);	/* F5 */
		    break;
		}
	    case KEY_F(6):
		{
		    sendmessage(message[5]);	/* F6 */
		    break;
		}
	    case KEY_F(7):
		{
		    sendmessage(message[6]);	/* F7 */
		    break;
		}
	    case KEY_F(8):
		{
		    sendmessage(message[7]);	/* F8 */
		    break;
		}
	    case KEY_F(9):
		{
		    sendmessage(message[8]);	/* F9 */
		    break;
		}
	    case KEY_F(10):
		{
		    sendmessage(message[9]);	/* F10 */
		    break;
		}

	    case KEY_F(11):
		{
		    sendmessage(message[10]);	/* F11 */
		    break;
		}
	    case KEY_F(12):
		{

		    sendmessage(message[11]);	/* F12 */
		    break;
		}

	    default:
		x = x;
	    }

	}
    }
    hide_panel(panel);

    if (cqmode == CQ)
        strcpy(mode, "Log     ");
    else
        strcpy(mode, "S&P     ");

    clear_display();

    return 0;			/* show end of keyer  routine */
}