static void raw_tt_data_to_app (int chan, char *msg) { #if TT_MAIN return ; #else char src[10], dest[10]; char raw_tt_msg[200]; packet_t pp; char *c, *s; int i; int err; alevel_t alevel; // Set source and dest to something valid to keep rest of processing happy. // For lack of a better idea, make source "DTMF" to indicate where it came from. // Application version might be useful in case we end up using different // message formats in later versions. strcpy (src, "DTMF"); sprintf (dest, "%s%d%d", APP_TOCALL, MAJOR_VERSION, MINOR_VERSION); sprintf (raw_tt_msg, "%s>%s:t%s", src, dest, msg); pp = ax25_from_text (raw_tt_msg, 1); /* * Process like a normal received frame. * NOTE: This goes directly to application rather than * thru the multi modem duplicate processing. * * Should we use a different type so it can be easily * distinguished later? * * We try to capture an overall audio level here. * Mark and space do not apply in this case. * This currently doesn't get displayed but we might want it someday. */ if (pp != NULL) { alevel = demod_get_audio_level (chan, 0); alevel.mark = -2; alevel.space = -2; dlq_append (DLQ_REC_FRAME, chan, -1, pp, alevel, RETRY_NONE, "tt"); } else { text_color_set(DW_COLOR_ERROR); dw_printf ("Could not convert \"%s\" into APRS packet.\n", raw_tt_msg); } #endif }
static void send_packet (char *str) { packet_t pp; unsigned char fbuf[AX25_MAX_PACKET_LEN+2]; int flen; int c; pp = ax25_from_text (str, 1); flen = ax25_pack (pp, fbuf); for (c=0; c<modem.adev[0].num_channels; c++) { hdlc_send_flags (c, 8, 0); hdlc_send_frame (c, fbuf, flen); hdlc_send_flags (c, 2, 1); } ax25_delete (pp); }
static void pftest (int test_num, char *filter, char *monitor, int expected) { int result; packet_t pp; text_color_set (DW_COLOR_DEBUG); dw_printf ("test number %d\n", test_num); pp = ax25_from_text (monitor, 1); assert (pp != NULL); result = pfilter (0, 0, filter, pp); if (result != expected) { text_color_set (DW_COLOR_ERROR); dw_printf ("Unexpected result for test number %d\n", test_num); error_count++; } ax25_delete (pp); }
static void test (char *in, char *out) { packet_t pp, result; //int should_repeat; char rec[256]; char xmit[256]; unsigned char *pinfo; int info_len; unsigned char frame[AX25_MAX_PACKET_LEN]; int frame_len; alevel_t alevel; dw_printf ("\n"); /* * As an extra test, change text to internal format back to * text again to make sure it comes out the same. */ pp = ax25_from_text (in, 1); assert (pp != NULL); ax25_format_addrs (pp, rec); info_len = ax25_get_info (pp, &pinfo); strlcat (rec, (char*)pinfo, sizeof(rec)); if (strcmp(in, rec) != 0) { text_color_set(DW_COLOR_ERROR); dw_printf ("Text/internal/text error-1 %s -> %s\n", in, rec); } /* * Just for more fun, write as the frame format, read it back * again, and make sure it is still the same. */ frame_len = ax25_pack (pp, frame); ax25_delete (pp); alevel.rec = 50; alevel.mark = 50; alevel.space = 50; pp = ax25_from_frame (frame, frame_len, alevel); assert (pp != NULL); ax25_format_addrs (pp, rec); info_len = ax25_get_info (pp, &pinfo); strlcat (rec, (char*)pinfo, sizeof(rec)); if (strcmp(in, rec) != 0) { text_color_set(DW_COLOR_ERROR); dw_printf ("internal/frame/internal/text error-2 %s -> %s\n", in, rec); } /* * On with the digipeater test. */ text_color_set(DW_COLOR_REC); dw_printf ("Rec\t%s\n", rec); //TODO: Add filtering to test. // V result = digipeat_match (0, pp, mycall, mycall, &alias_re, &wide_re, 0, preempt, NULL); if (result != NULL) { dedupe_remember (result, 0); ax25_format_addrs (result, xmit); info_len = ax25_get_info (result, &pinfo); strlcat (xmit, (char*)pinfo, sizeof(xmit)); ax25_delete (result); } else { strlcpy (xmit, "", sizeof(xmit)); } text_color_set(DW_COLOR_XMIT); dw_printf ("Xmit\t%s\n", xmit); if (strcmp(xmit, out) == 0) { text_color_set(DW_COLOR_INFO); dw_printf ("OK\n"); } else { text_color_set(DW_COLOR_ERROR); dw_printf ("Expect\t%s\n", out); failed++; } dw_printf ("\n"); }
static void * beacon_thread (void *arg) #endif { int j; time_t earliest; time_t now; /* * Information from GPS. */ int fix = 0; /* 0 = none, 2 = 2D, 3 = 3D */ double my_lat = 0; /* degrees */ double my_lon = 0; float my_course = 0; /* degrees */ float my_speed_knots = 0; float my_speed_mph = 0; float my_alt = 0; /* meters */ /* * SmartBeaconing state. */ time_t sb_prev_time = 0; /* Time of most recent transmission. */ float sb_prev_course = 0; /* Most recent course reported. */ //float sb_prev_speed_mph; /* Most recent speed reported. */ int sb_every; /* Calculated time between transmissions. */ #if DEBUG struct tm tm; char hms[20]; now = time(NULL); localtime_r (&now, &tm); strftime (hms, sizeof(hms), "%H:%M:%S", &tm); text_color_set(DW_COLOR_DEBUG); dw_printf ("beacon_thread: started %s\n", hms); #endif now = time(NULL); while (1) { assert (g_misc_config_p->num_beacons >= 1); /* * Sleep until time for the earliest scheduled or * the soonest we could transmit due to corner pegging. */ earliest = g_misc_config_p->beacon[0].next; for (j=1; j<g_misc_config_p->num_beacons; j++) { if (g_misc_config_p->beacon[j].btype == BEACON_IGNORE) continue; earliest = MIN(g_misc_config_p->beacon[j].next, earliest); } if (g_misc_config_p->sb_configured && g_using_gps) { earliest = MIN(now + g_misc_config_p->sb_turn_time, earliest); earliest = MIN(now + g_misc_config_p->sb_fast_rate, earliest); } if (earliest > now) { SLEEP_SEC (earliest - now); } /* * Woke up. See what needs to be done. */ now = time(NULL); #if DEBUG localtime_r (&now, &tm); strftime (hms, sizeof(hms), "%H:%M:%S", &tm); text_color_set(DW_COLOR_DEBUG); dw_printf ("beacon_thread: woke up %s\n", hms); #endif /* * Get information from GPS if being used. * This needs to be done before the next scheduled tracker * beacon because corner pegging make it sooner. */ #if DEBUG_SIM FILE *fp; char cs[40]; fp = fopen ("c:\\cygwin\\tmp\\cs", "r"); if (fp != NULL) { fscanf (fp, "%f %f", &my_course, &my_speed_knots); fclose (fp); } else { fprintf (stderr, "Can't read /tmp/cs.\n"); } fix = 3; my_speed_mph = KNOTS_TO_MPH * my_speed_knots; my_lat = 42.99; my_lon = 71.99; my_alt = 100; #else if (g_using_gps) { fix = dwgps_read (&my_lat, &my_lon, &my_speed_knots, &my_course, &my_alt); my_speed_mph = KNOTS_TO_MPH * my_speed_knots; /* Don't complain here for no fix. */ /* Possibly at the point where about to transmit. */ } #endif /* * Run SmartBeaconing calculation if configured and GPS data available. */ if (g_misc_config_p->sb_configured && g_using_gps && fix >= 2) { if (my_speed_mph > g_misc_config_p->sb_fast_speed) { sb_every = g_misc_config_p->sb_fast_rate; } else if (my_speed_mph < g_misc_config_p->sb_slow_speed) { sb_every = g_misc_config_p->sb_slow_rate; } else { /* Can't divide by 0 assuming sb_slow_speed > 0. */ sb_every = ( g_misc_config_p->sb_fast_rate * g_misc_config_p->sb_fast_speed ) / my_speed_mph; } #if DEBUG_SIM text_color_set(DW_COLOR_DEBUG); dw_printf ("SB: fast %d %d slow %d %d speed=%.1f every=%d\n", g_misc_config_p->sb_fast_speed, g_misc_config_p->sb_fast_rate, g_misc_config_p->sb_slow_speed, g_misc_config_p->sb_slow_rate, my_speed_mph, sb_every); #endif /* * Test for "Corner Pegging" if moving. */ if (my_speed_mph >= 1.0) { int turn_threshold = g_misc_config_p->sb_turn_angle + g_misc_config_p->sb_turn_slope / my_speed_mph; #if DEBUG_SIM text_color_set(DW_COLOR_DEBUG); dw_printf ("SB-moving: course %.0f prev %.0f thresh %d\n", my_course, sb_prev_course, turn_threshold); #endif if (heading_change(my_course, sb_prev_course) > turn_threshold && now >= sb_prev_time + g_misc_config_p->sb_turn_time) { /* Send it now. */ for (j=0; j<g_misc_config_p->num_beacons; j++) { if (g_misc_config_p->beacon[j].btype == BEACON_TRACKER) { g_misc_config_p->beacon[j].next = now; } } } /* significant change in direction */ } /* is moving */ } /* apply SmartBeaconing */ for (j=0; j<g_misc_config_p->num_beacons; j++) { if (g_misc_config_p->beacon[j].btype == BEACON_IGNORE) continue; if (g_misc_config_p->beacon[j].next <= now) { int strict = 1; /* Strict packet checking because they will go over air. */ char stemp[20]; char info[AX25_MAX_INFO_LEN]; char beacon_text[AX25_MAX_PACKET_LEN]; packet_t pp = NULL; char mycall[AX25_MAX_ADDR_LEN]; /* * Obtain source call for the beacon. * This could potentially be different on different channels. * When sending to IGate server, use call from first radio channel. * * Check added in version 1.0a. Previously used index of -1. */ strcpy (mycall, "NOCALL"); if (g_misc_config_p->beacon[j].chan == -1) { strcpy (mycall, g_digi_config_p->mycall[0]); } else { strcpy (mycall, g_digi_config_p->mycall[g_misc_config_p->beacon[j].chan]); } if (strlen(mycall) == 0 || strcmp(mycall, "NOCALL") == 0) { text_color_set(DW_COLOR_ERROR); dw_printf ("MYCALL not set for beacon in config file line %d.\n", g_misc_config_p->beacon[j].lineno); continue; } /* * Prepare the monitor format header. */ strcpy (beacon_text, mycall); strcat (beacon_text, ">"); sprintf (stemp, "%s%1d%1d", APP_TOCALL, MAJOR_VERSION, MINOR_VERSION); strcat (beacon_text, stemp); if (g_misc_config_p->beacon[j].via) { strcat (beacon_text, ","); strcat (beacon_text, g_misc_config_p->beacon[j].via); } strcat (beacon_text, ":"); /* * Add the info part depending on beacon type. */ switch (g_misc_config_p->beacon[j].btype) { case BEACON_POSITION: encode_position (g_misc_config_p->beacon[j].compress, g_misc_config_p->beacon[j].lat, g_misc_config_p->beacon[j].lon, g_misc_config_p->beacon[j].symtab, g_misc_config_p->beacon[j].symbol, g_misc_config_p->beacon[j].power, g_misc_config_p->beacon[j].height, g_misc_config_p->beacon[j].gain, g_misc_config_p->beacon[j].dir, 0, 0, /* course, speed */ g_misc_config_p->beacon[j].freq, g_misc_config_p->beacon[j].tone, g_misc_config_p->beacon[j].offset, g_misc_config_p->beacon[j].comment, info); strcat (beacon_text, info); g_misc_config_p->beacon[j].next = now + g_misc_config_p->beacon[j].every; break; case BEACON_OBJECT: encode_object (g_misc_config_p->beacon[j].objname, g_misc_config_p->beacon[j].compress, 0, g_misc_config_p->beacon[j].lat, g_misc_config_p->beacon[j].lon, g_misc_config_p->beacon[j].symtab, g_misc_config_p->beacon[j].symbol, g_misc_config_p->beacon[j].power, g_misc_config_p->beacon[j].height, g_misc_config_p->beacon[j].gain, g_misc_config_p->beacon[j].dir, 0, 0, /* course, speed */ g_misc_config_p->beacon[j].freq, g_misc_config_p->beacon[j].tone, g_misc_config_p->beacon[j].offset, g_misc_config_p->beacon[j].comment, info); strcat (beacon_text, info); g_misc_config_p->beacon[j].next = now + g_misc_config_p->beacon[j].every; break; case BEACON_TRACKER: if (fix >= 2) { int coarse; /* APRS encoder wants 1 - 360. */ /* 0 means none or unknown. */ coarse = (int)roundf(my_course); if (coarse == 0) { coarse = 360; } encode_position (g_misc_config_p->beacon[j].compress, my_lat, my_lon, g_misc_config_p->beacon[j].symtab, g_misc_config_p->beacon[j].symbol, g_misc_config_p->beacon[j].power, g_misc_config_p->beacon[j].height, g_misc_config_p->beacon[j].gain, g_misc_config_p->beacon[j].dir, coarse, (int)roundf(my_speed_knots), g_misc_config_p->beacon[j].freq, g_misc_config_p->beacon[j].tone, g_misc_config_p->beacon[j].offset, g_misc_config_p->beacon[j].comment, info); strcat (beacon_text, info); /* Remember most recent tracker beacon. */ sb_prev_time = now; sb_prev_course = my_course; //sb_prev_speed_mph = my_speed_mph; /* Calculate time for next transmission. */ if (g_misc_config_p->sb_configured) { g_misc_config_p->beacon[j].next = now + sb_every; } else { g_misc_config_p->beacon[j].next = now + g_misc_config_p->beacon[j].every; } } else { g_misc_config_p->beacon[j].next = now + 2; continue; /* No fix. Try again in a couple seconds. */ } break; case BEACON_CUSTOM: if (g_misc_config_p->beacon[j].custom_info != NULL) { strcat (beacon_text, g_misc_config_p->beacon[j].custom_info); } else { text_color_set(DW_COLOR_ERROR); dw_printf ("Internal error. custom_info is null. %s %d\n", __FILE__, __LINE__); continue; } g_misc_config_p->beacon[j].next = now + g_misc_config_p->beacon[j].every; break; case BEACON_IGNORE: default: break; } /* switch beacon type. */ /* * Parse monitor format into form for transmission. */ pp = ax25_from_text (beacon_text, strict); if (pp != NULL) { /* Send to IGate server or radio. */ if (g_misc_config_p->beacon[j].chan == -1) { #if 1 text_color_set(DW_COLOR_XMIT); dw_printf ("[ig] %s\n", beacon_text); #endif igate_send_rec_packet (0, pp); ax25_delete (pp); } else { tq_append (g_misc_config_p->beacon[j].chan, TQ_PRIO_1_LO, pp); } } else { text_color_set(DW_COLOR_ERROR); dw_printf ("Config file: Failed to parse packet constructed from line %d.\n", g_misc_config_p->beacon[j].lineno); dw_printf ("%s\n", beacon_text); } } /* if time to send it */ } /* for each configured beacon */ } /* do forever */ } /* end beacon_thread */