#ifdef BSDSOUND #include BSDSOUND #endif #include #include #include static gint isalpha_ui(guint c); static gint isdigit_ui(guint c); static gint isprint_ui(guint c); static gint isupper_ui(guint c); static guint toupper_ui(guint c); static void new_pen(gint ipen); static gint kp_snooper(GtkWidget *widget, GdkEventKey *event, gpointer da); static void cursor_control(gpointer widget, gint iadd, gint cursor_type, gint cursor_row, gint cursor_col, gint cursor_fg, gint cursor_bg); static void play_bells(int isound); static void get_kb_time(void); static void fill_kb_dt(void); static gint idelta_time(const gchar *day1, const gchar *day2, const gchar *time1, const gchar *time2); static void concat(gchar *s1, const gchar *s2, gint is2, gint js2, gint nullout_s1); static gint kb_index(const gchar *s1, const gchar *s2); static void left_zero_pad(gchar *s1, gint ss1); static void left_blank_pad(gchar *s1, gint ss1); static void left_blank_unpad(gchar *s1); static void right_blank_pad(gchar *s1, gint ss1); static void right_blank_unpad(gchar *s1); static gint int_to_char(gint in, gchar *s1); static gint int_to_comma(gint in, gchar *s1); static gint real_to_char(gdouble rin, gchar *s1, gint ndp); static gint nint(gdouble rin); static gint inquire(const gchar *filnam); static void set_keyer_port(gint set_kp); static void make_cw_line(guint ikey); static gint send_cw_line(gpointer widget); static void process_cw_message(guint ikey, gpointer widget); static gint get_cw_eom(gpointer widget); static gint repeat_cw_message(gpointer widget); static gint open_dvk(gpointer widget); static void close_dvk(void); static void send_dvk_msg(guint ikey); static void repeat_dvk_msg(void); static gint delay_dvk_msg(gpointer data); static gint mount_floppy(void); static gint isalpha_ui(guint c) { gint cout=FALSE; if(c<256) cout = isalpha(c); return cout; } static gint isdigit_ui(guint c) { gint cout=FALSE; if(c<256) cout = isdigit(c); return cout; } static gint isprint_ui(guint c) { gint cout=FALSE; if(c<256) cout = isprint(c); return cout; } static gint isupper_ui(guint c) { gint cout=FALSE; if(c<256) cout = isupper(c); return cout; } static guint toupper_ui(guint c) { guint cout; if(c<256) cout = toupper(c); else cout = c; return cout; } static void new_pen(gint ipen) { GdkColor color; static gint saved_color = -1; gint red[17] = {0,0,0,0, 43690,43690,43690,43690, 16383,0,0,0, 65535,65535,65535,65535, 21845}; gint green[17] = {0,0,43690,43690, 0,0,21845,43690, 16383,0,65535,65535, 0,0,65535,65535, 21845}; gint blue[17] = {0,43690,0,43690, 0,43690,0,43690, 16383,65535,0,65535, 0,65535,0,65535, 21845}; if(ipen != saved_color) { color.red = red[ipen]; color.green = green[ipen]; color.blue = blue[ipen]; gdk_gc_set_rgb_fg_color (gc, &color); saved_color = ipen; } } static gint kp_snooper(GtkWidget *widget, GdkEventKey *event, gpointer da) { if(event->keyval==65479) event->keyval=65482; return FALSE; } static void cursor_control(gpointer widget, gint iadd, gint cursor_type, gint cursor_row, gint cursor_col, gint cursor_fg, gint cursor_bg) { if(iadd%2 && cursor_type) new_pen (cursor_fg); else new_pen (cursor_bg); pango_layout_set_text (layout, "_", 1); gdk_draw_layout (main_drawing_area->window, gc, (cursor_col-1)*wcol, (cursor_row-1)*hrow+cursor_offset, layout); } #ifdef BSDSOUND #include "bsd_bells.c" #endif static void play_bells(int isound) { if(fd_bells<0) return; if(strcmp(set_screen_choices[3], "") !=0) return; #ifdef BSD #ifdef BSDSOUND bsd_play_bells(isound); #endif #else ioctl(fd_bells, _IO(KB_BELLS_IOCTL_BASE, isound)); #endif } static void get_kb_time(void) { time_t tsec; int lday_array[12] = {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; tsec = time(NULL); kb_time = *gmtime(&tsec); if(kb_time.tm_year%4) lday_array[1] = 28; else lday_array[1] = 29; kb_time.tm_hour += utc_offset; if(kb_time.tm_hour>23) { kb_time.tm_hour -= 24; kb_time.tm_wday++; if(kb_time.tm_wday>6) kb_time.tm_wday = 0; kb_time.tm_mday++; if(kb_time.tm_mday>lday_array[kb_time.tm_mon]) { kb_time.tm_mday = 1; kb_time.tm_mon++; if(kb_time.tm_mon>11) { kb_time.tm_mon = 0; kb_time.tm_year++; } } } if(kb_time.tm_mon==1 && kb_time.tm_mday==lday_array[1]) { kb_time.tm_mday = 0; kb_time.tm_mon = 2; } } static void fill_kb_dt(void) { strftime(kb_dt.date, sizeof(kb_dt.date), "%m%d%g", &kb_time); strftime(kb_dt.time, sizeof(kb_dt.time), "%H%M%S", &kb_time); } static gint idelta_time(const gchar *day1, const gchar *day2, const gchar *time1, const gchar *time2) { gint id1, id2, ih1, ih2, im1, im2, is1, is2, dsecs; gchar d1[3], d2[3], h1[3], h2[3], m1[3], m2[3], s1[3], s2[3]; concat(d1, day1, 2, 3, COPY); concat(d2, day2, 2, 3, COPY); concat(h1, time1, 0, 1, COPY); concat(h2, time2, 0, 1, COPY); concat(m1, time1, 2, 3, COPY); concat(m2, time2, 2, 3, COPY); concat(s1, time1, 4, 5, COPY); concat(s2, time2, 4, 5, COPY); id1 = atoi(d1); id2 = atoi(d2); ih1 = atoi(h1); ih2 = atoi(h2); im1 = atoi(m1); im2 = atoi(m2); is1 = atoi(s1); is2 = atoi(s2); if(is2-1; i--) s1[i+nblanks] = s1[i]; for(i=0; i-1; i--) s1[i+nblanks] = s1[i]; for(i=0; i-1) while(s1[i]==' ') { s1[i] = '\0'; i--; if(i<0) break; } } static gint int_to_char(gint in, gchar *s1) { gint i; gint nout=1; while(in > pow(10, nout)-1) nout++; for(i=nout; i>0; i--) s1[nout-i] = ((in%(gint)pow(10, i))/(gint)pow(10, i-1))+48; s1[nout] = '\0'; return nout; } static gint int_to_comma(gint in, gchar *s1) { gint nout; gchar s1_hold[12]; nout = int_to_char (in, s1); if(nout>3) { strcpy(s1_hold, s1); if(nout<7) { concat(s1, s1_hold, 0, nout-4, COPY); strcat(s1, ","); concat(s1, s1_hold, nout-3, nout-1, !COPY); nout++; } else if(nout<10) { concat(s1, s1_hold, 0, nout-7, COPY); strcat(s1, ","); concat(s1, s1_hold, nout-6, nout-4, !COPY); strcat(s1, ","); concat(s1, s1_hold, nout-3, nout-1, !COPY); nout += 2; } } return nout; } static gint real_to_char(gdouble rin, gchar *s1, gint ndp) { gint lod, rod, nl, nr, nout; gchar s1_hold[20]; const gchar *zeros = "000000"; lod = (gint) rin; nl = int_to_char (lod, s1_hold); concat(s1, s1_hold, 0, nl-1, COPY); strcat(s1, "."); rod = (gint) ((rin-((gdouble) lod))*pow(10, ndp)); nr = int_to_char (rod, s1_hold); if(nr")) { strcpy(port_name, "/dev/"); concat(port_name, init_screen_choices[16], 1, strlen(init_screen_choices[16])-2, !COPY); fp_keyer = fopen(port_name, "r+"); if(fp_keyer) { printf("port %s opened\n", port_name); tcgetattr(fileno(fp_keyer), &settings_keyer); settings_save = settings_keyer; cfsetispeed(&settings_keyer, B2400); cfsetospeed(&settings_keyer, B2400); settings_keyer.c_cflag &= ~CSTOPB; settings_keyer.c_lflag |= ICANON; tcsetattr(fileno(fp_keyer), TCSANOW, &settings_keyer); printf("c_cflag = %d\n", settings_save.c_cflag); printf("c_cflag = %d\n", settings_keyer.c_cflag); //file=termbits.h //c_cflag=CLOCAL+HUPCL+CREAD+CS8+B2400 //3259 =2048 +1024 +128 +48 +11 } else printf("cannot open port %s \n", port_name); } } } static void make_cw_line(guint ikey) { gint ihat, ipnd; gchar ksc_hold[63], qso_hold[5]; if(ikey==65299) { ikey = atoi(set_screen_choices[5])+65469; if(ikey==65479) ikey=65482; } switch (ikey) { case 65482 : /*F10*/ strcpy(cw_line, cr_array[icall_count].call); break; case 65480 : /*F11*/ strcpy(cw_line, "?"); break; case 65481 : /*F12*/ strcpy(cw_line, "TU"); break; case 65470 : /*F1*/ case 65471 : /*F2*/ case 65472 : /*F3*/ case 65473 : /*F4*/ case 65474 : /*F5*/ case 65475 : /*F6*/ case 65476 : /*F7*/ case 65477 : /*F8*/ case 65478 : /*F9*/ strcpy(ksc_hold, keyer_screen_choices[ikey-65468]); ihat = kb_index (ksc_hold, "^"); ipnd = kb_index (ksc_hold, "#"); if(ihat==-1 && ipnd==-1) strcpy(cw_line, ksc_hold); else if(ihat>-1 && ipnd==-1) { concat(cw_line, ksc_hold, 0, ihat-1, COPY); strcat(cw_line, cr_array[iscroll_log+1].call); concat(cw_line, ksc_hold, ihat+1, strlen(ksc_hold)-1, !COPY); } else if(ipnd>-1 && ihat==-1) { strcpy(qso_hold, cr_array[iscroll_log+1].qso); left_blank_unpad (qso_hold); concat(cw_line, ksc_hold, 0, ipnd-1, COPY); strcat(cw_line, qso_hold); concat(cw_line, ksc_hold, ipnd+1, strlen(ksc_hold)-1, !COPY); } else { concat(cw_line, ksc_hold, 0, ihat-1, COPY); strcat(cw_line, cr_array[iscroll_log+1].call); concat(cw_line, ksc_hold, ihat+1, strlen(ksc_hold)-1, !COPY); strcpy(ksc_hold, cw_line); ipnd = kb_index (ksc_hold, "#"); strcpy(qso_hold, cr_array[iscroll_log+1].qso); left_blank_unpad (qso_hold); concat(cw_line, ksc_hold, 0, ipnd-1, COPY); strcat(cw_line, qso_hold); concat(cw_line, ksc_hold, ipnd+1, strlen(ksc_hold)-1, !COPY); } break; } } static gint send_cw_line(gpointer widget) { gint i, iunit, dit, dah, esp, csp, sp; gchar ksc0[5]; static gint j = 0; static gint jbytes = 24; concat(ksc0, keyer_screen_choices[0], 1, 4, COPY); iunit = (gint) (288.*cw_speed_adj/atof(ksc0)+.5); if(iunit<4) iunit = 4; if(iunit>24) iunit = 24; dit = iunit; dah = iunit*3; esp = iunit; csp = iunit*3; sp = iunit*2; if(fp_keyer) { if(cw_line[j]) { jbytes -= 24; if(jbytes>240) return TRUE; switch (cw_line[j]) { case 'A' : for(i=0; i0) g_source_remove (source_tag); memset(cw_line, '\0', sizeof(cw_line)); send_cw_line (widget); tcflush(fileno(fp_keyer), TCOFLUSH); cw_speed_adj = 1.0; sending_cw = TRUE; make_cw_line (ikey); send_cw_line (widget); source_tag = g_timeout_add (100, send_cw_line, widget); if(repeat_message) g_timeout_add (100, get_cw_eom, widget); } static gint get_cw_eom(gpointer widget) { static guint source_tag = 0; if(repeat_message) { if(!sending_cw) { if(source_tag>0) g_source_remove (source_tag); sending_cw = TRUE; source_tag = g_timeout_add (atoi(set_screen_choices[6])+500, repeat_cw_message, widget); } return TRUE; } else { sending_cw = FALSE; return FALSE; } } static gint repeat_cw_message(gpointer widget) { static guint source_tag = 0; if(repeat_message) { if(source_tag>0) g_source_remove (source_tag); source_tag = g_timeout_add (100, send_cw_line, widget); } return FALSE; } static gint open_dvk(gpointer widget) { gint fd_gsc; const char *host = "localhost"; gnome_sound_init (host); fd_gsc = gnome_sound_connection_get (); if(fd_gsc==-1) gnome_sound_init (host); return FALSE; } static void close_dvk(void) { gnome_sound_shutdown (); } static void send_dvk_msg(guint ikey) { guint key_num; gchar dvk_sound_file[13], dvk_key[3], emsg[40]; const gchar *sound_file_base = "DVKMSG"; const gchar *sound_file_ext = ".WAV"; key_num = ikey; if(key_num==65482) key_num = 65479; int_to_char (key_num-65469, dvk_key); strcpy(dvk_sound_file, sound_file_base); strcat(dvk_sound_file, dvk_key); strcat(dvk_sound_file, sound_file_ext); if(inquire(dvk_sound_file)) gnome_sound_play (dvk_sound_file); else { play_bells (MESSAGE_SOUND); strcpy(emsg, "Cannot find sound file: "); strcat(emsg, dvk_sound_file); message_box (main_drawing_area, emsg, !REDRAW, CLEAR); } } static void repeat_dvk_msg(void) { FILE *fp; gint wav[8], delay; gchar emsg[40]; static gchar dvk_sound_file[13]; const gchar *sound_file_base = "DVKMSG"; const gchar *sound_file_ext = ".WAV"; strcpy(dvk_sound_file, sound_file_base); strcat(dvk_sound_file, set_screen_choices[5]); strcat(dvk_sound_file, sound_file_ext); if(!repeat_message) { if(inquire(dvk_sound_file)) { gnome_sound_play (dvk_sound_file); repeat_message = TRUE; fp = fopen(dvk_sound_file, "r"); fread(wav, 4, 8, fp); fclose(fp); delay = (gint) (1000.*((gdouble) wav[1]/(gdouble) wav[7])) +atoi(set_screen_choices[6]); g_timeout_add (delay, delay_dvk_msg, dvk_sound_file); } else { play_bells (MESSAGE_SOUND); strcpy(emsg, "Cannot find sound file: "); strcat(emsg, dvk_sound_file); message_box (main_drawing_area, emsg, !REDRAW, CLEAR); } } else play_bells (BELL_SOUND); } static gint delay_dvk_msg(gpointer data) { gint rm; gchar *dvk_sound_file; dvk_sound_file = (gchar*)data; rm = repeat_message; if(rm) gnome_sound_play (dvk_sound_file); return rm; } static gint mount_floppy(void) { gint i; gchar rhold[3]; struct utsname uts; gint mf=FALSE, kv=0, j=0, idot[5] = {-1, 0, 0, 0, 0}; gint MOUNT_NUM = 20617; uname(&uts); idot[4] = kb_index (uts.release, "-"); idot[3] = idot[4]; for(i=0; iMOUNT_NUM) mf = TRUE; return mf; }