diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2016-03-05 09:57:11 +0100 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2016-03-13 09:12:19 +0100 |
commit | 287b914b56d67760f6a056d065754dab0911574e (patch) | |
tree | 6727f8df4c6eefe57fcebb5a0282908174c3f6b6 /src/bnetz | |
parent | d21be383a6515760a38f403100a9d142633bf616 (diff) |
bnetz: Simplifying 'telegramm' handling
Diffstat (limited to 'src/bnetz')
-rw-r--r-- | src/bnetz/bnetz.c | 23 | ||||
-rw-r--r-- | src/bnetz/bnetz.h | 4 | ||||
-rw-r--r-- | src/bnetz/dsp.c | 18 | ||||
-rw-r--r-- | src/bnetz/dsp.h | 1 |
4 files changed, 28 insertions, 18 deletions
diff --git a/src/bnetz/bnetz.c b/src/bnetz/bnetz.c index 23a6a9c..cbe0a00 100644 --- a/src/bnetz/bnetz.c +++ b/src/bnetz/bnetz.c @@ -350,7 +350,7 @@ static void bnetz_go_idle(bnetz_t *bnetz) PDEBUG(DBNETZ, DEBUG_INFO, "Entering IDLE state, sending 'Gruppenfreisignal' %d.\n", bnetz->gfs); bnetz->state = BNETZ_FREI; - bnetz->dsp_mode = DSP_MODE_TELEGRAMM; + bnetz_set_dsp_mode(bnetz, DSP_MODE_TELEGRAMM); switch_channel_19(bnetz, 0); bnetz->station_id[0] = '\0'; } @@ -362,7 +362,7 @@ static void bnetz_release(bnetz_t *bnetz) PDEBUG(DBNETZ, DEBUG_INFO, "Entering release state, sending 'Trennsignal'.\n"); bnetz->state = BNETZ_TRENNEN; - bnetz->dsp_mode = DSP_MODE_TELEGRAMM; + bnetz_set_dsp_mode(bnetz, DSP_MODE_TELEGRAMM); switch_channel_19(bnetz, 0); bnetz->trenn_count = 0; bnetz->station_id[0] = '\0'; @@ -373,7 +373,7 @@ static void bnetz_page(bnetz_t *bnetz, const char *dial_string, int try) { PDEBUG(DBNETZ, DEBUG_INFO, "Entering paging state (try %d), sending 'Selektivruf' to '%s'.\n", try, dial_string); bnetz->state = BNETZ_SELEKTIVRUF; - bnetz->dsp_mode = DSP_MODE_0; + bnetz_set_dsp_mode(bnetz, DSP_MODE_0); bnetz->page_mode = PAGE_MODE_NUMBER; bnetz->page_try = try; strcpy(bnetz->station_id, dial_string); @@ -400,7 +400,7 @@ const char *bnetz_get_telegramm(bnetz_t *bnetz) break; case BNETZ_WAHLABRUF: if (bnetz->station_id_pos == 5) { - bnetz->dsp_mode = DSP_MODE_1; + bnetz_set_dsp_mode(bnetz, DSP_MODE_1); return NULL; } it = bnetz_telegramm(bnetz->station_id[bnetz->station_id_pos++]); @@ -409,7 +409,7 @@ const char *bnetz_get_telegramm(bnetz_t *bnetz) if (bnetz->page_mode == PAGE_MODE_KANALBEFEHL) { PDEBUG(DBNETZ, DEBUG_INFO, "Paging mobile station %s complete, waiting for answer.\n", bnetz->station_id); bnetz->state = BNETZ_RUFBESTAETIGUNG; - bnetz->dsp_mode = DSP_MODE_SILENCE; + bnetz_set_dsp_mode(bnetz, DSP_MODE_SILENCE); switch_channel_19(bnetz, 0); timer_start(&bnetz->timer, PAGING_TO); return NULL; @@ -470,8 +470,7 @@ void bnetz_receive_tone(bnetz_t *bnetz, int bit) PDEBUG(DBNETZ, DEBUG_INFO, "Received signal 'Kanalbelegung' from mobile station, sending signal 'Wahlabruf'.\n"); bnetz->state = BNETZ_WAHLABRUF; bnetz->dial_mode = DIAL_MODE_START; - bnetz->telegramm = NULL; - bnetz->dsp_mode = DSP_MODE_1; + bnetz_set_dsp_mode(bnetz, DSP_MODE_1); timer_start(&bnetz->timer, DIALING_TO); break; } @@ -481,7 +480,7 @@ void bnetz_receive_tone(bnetz_t *bnetz, int bit) PDEBUG(DBNETZ, DEBUG_INFO, "Received signal 'Rufbestaetigung' from mobile station, call is ringing.\n"); timer_stop(&bnetz->timer); bnetz->state = BNETZ_RUFHALTUNG; - bnetz->dsp_mode = DSP_MODE_1; + bnetz_set_dsp_mode(bnetz, DSP_MODE_1); call_in_alerting(bnetz->sender.callref); timer_start(&bnetz->timer, ALERTING_TO); break; @@ -492,7 +491,7 @@ void bnetz_receive_tone(bnetz_t *bnetz, int bit) PDEBUG(DBNETZ, DEBUG_INFO, "Received signal 'Beginnsignal' from mobile station, call establised.\n"); timer_stop(&bnetz->timer); bnetz->state = BNETZ_GESPRAECH; - bnetz->dsp_mode = DSP_MODE_AUDIO; + bnetz_set_dsp_mode(bnetz, DSP_MODE_AUDIO); call_in_answer(bnetz->sender.callref, bnetz->station_id); break; } @@ -568,7 +567,7 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm, double quality, PDEBUG(DBNETZ, DEBUG_INFO, "Received number from mobile phone: %s\n", bnetz->dial_number); bnetz->dial_mode = DIAL_MODE_START2; PDEBUG(DBNETZ, DEBUG_INFO, "Sending station id back to phone: %s.\n", bnetz->station_id); - bnetz->dsp_mode = DSP_MODE_TELEGRAMM; + bnetz_set_dsp_mode(bnetz, DSP_MODE_TELEGRAMM); bnetz->station_id_pos = 0; break; } @@ -629,7 +628,7 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm, double quality, } PDEBUG(DBNETZ, DEBUG_INFO, "Dialing complete %s->%s, call established.\n", bnetz->station_id, dialing); timer_stop(&bnetz->timer); - bnetz->dsp_mode = DSP_MODE_AUDIO; + bnetz_set_dsp_mode(bnetz, DSP_MODE_AUDIO); bnetz->state = BNETZ_GESPRAECH; /* setup call */ @@ -689,7 +688,7 @@ static void bnetz_timeout(struct timer *timer) break; case BNETZ_SELEKTIVRUF: PDEBUG(DBNETZ, DEBUG_DEBUG, "Transmitter switched to channel 19, starting paging telegramms.\n"); - bnetz->dsp_mode = DSP_MODE_TELEGRAMM; + bnetz_set_dsp_mode(bnetz, DSP_MODE_TELEGRAMM); break; case BNETZ_RUFBESTAETIGUNG: if (bnetz->page_try == PAGE_TRIES) { diff --git a/src/bnetz/bnetz.h b/src/bnetz/bnetz.h index 2064e63..3eed7c8 100644 --- a/src/bnetz/bnetz.h +++ b/src/bnetz/bnetz.h @@ -70,7 +70,7 @@ typedef struct bnetz { int fsk_filter_pos; /* current sample position in filter_spl */ int fsk_filter_step; /* number of samples for each analyzation */ int fsk_filter_bit; /* last bit, so we detect a bit change */ - int fsk_filter_sample; /* sample counter for shifting receive bits */ + int fsk_filter_sample; /* count until it is time to sample bit */ uint16_t fsk_filter_telegramm; /* rx shift register for receiveing telegramm */ double fsk_filter_quality[16]; /* quality of each bit in telegramm */ double fsk_filter_level[16]; /* level of each bit in telegramm */ @@ -79,7 +79,7 @@ typedef struct bnetz { int tone_count; /* how long has that tone been detected */ double phaseshift256[2]; /* how much the phase of sine wave changes per sample */ double phase256; /* current phase */ - const char *telegramm; /* current telegramm sequence */ + int telegramm; /* set, if there is a valid telegram */ int16_t *telegramm_spl; /* 16 * samples_per_bit */ int telegramm_pos; /* current sample position in telegramm_spl */ diff --git a/src/bnetz/dsp.c b/src/bnetz/dsp.c index 8a98981..fb352aa 100644 --- a/src/bnetz/dsp.c +++ b/src/bnetz/dsp.c @@ -331,6 +331,7 @@ static void fsk_tone(bnetz_t *bnetz, int16_t *samples, int length, int tone) static int fsk_telegramm(bnetz_t *bnetz, int16_t *samples, int length) { int16_t *spl; + const char *telegramm; int i, j; double phaseshift, phase; int count, max; @@ -339,17 +340,18 @@ next_telegramm: if (!bnetz->telegramm) { /* request telegramm */ // PDEBUG(DFSK, DEBUG_DEBUG, "Request new 'Telegramm'.\n"); - bnetz->telegramm = bnetz_get_telegramm(bnetz); - if (!bnetz->telegramm) { + telegramm = bnetz_get_telegramm(bnetz); + if (!telegramm) { PDEBUG(DFSK, DEBUG_DEBUG, "Stop sending 'Telegramm'.\n"); return length; } + bnetz->telegramm = 1; bnetz->telegramm_pos = 0; spl = bnetz->telegramm_spl; /* render telegramm */ phase = bnetz->phase256; for (i = 0; i < 16; i++) { - phaseshift = bnetz->phaseshift256[bnetz->telegramm[i] == '1']; + phaseshift = bnetz->phaseshift256[telegramm[i] == '1']; for (j = 0; j < bnetz->samples_per_bit; j++) { *spl++ = dsp_sine[((uint8_t)phase) & 0xff]; phase += phaseshift; @@ -372,7 +374,7 @@ next_telegramm: bnetz->telegramm_pos += count; /* check for end of telegramm */ if (bnetz->telegramm_pos == max) { - bnetz->telegramm = NULL; + bnetz->telegramm = 0; /* we need more ? */ if (length) goto next_telegramm; @@ -414,3 +416,11 @@ again: } } +void bnetz_set_dsp_mode(bnetz_t *bnetz, enum dsp_mode mode) +{ + /* reset telegramm */ + if (mode == DSP_MODE_TELEGRAMM && bnetz->dsp_mode != mode) + bnetz->telegramm = 0; + bnetz->dsp_mode = mode; +} + diff --git a/src/bnetz/dsp.h b/src/bnetz/dsp.h index 6d249c5..1114799 100644 --- a/src/bnetz/dsp.h +++ b/src/bnetz/dsp.h @@ -2,4 +2,5 @@ void dsp_init(void); int dsp_init_sender(bnetz_t *bnetz); void dsp_cleanup_sender(bnetz_t *bnetz); +void bnetz_set_dsp_mode(bnetz_t *bnetz, enum dsp_mode mode); |