📄 v8.c
字号:
static void cm_send(V8State *s, int mod_mask){ int val; sm_put_bits(&s->tx_fifo, V8_TEN_ONES, 10); sm_put_bits(&s->tx_fifo, V8_CM_SYNC, 10); /* data call */ v8_put_byte(s, V8_CALL_FUNC_DATA); /* supported modulations */ val = V8_MODN0; if (mod_mask & V8_MOD_V90) val |= V8_MODN0_V90; if (mod_mask & V8_MOD_V34) val |= V8_MODN0_V34; v8_put_byte(s, val); v8_put_byte(s, V8_EXT); val = V8_EXT; if (mod_mask & V8_MOD_V23) val |= V8_MODN2_V23; if (mod_mask & V8_MOD_V21) val |= V8_MODN2_V21; v8_put_byte(s, val); /* for now, no LAPM */ //v8_put_byte(s, V8_DATA_LAPM); /* We are not on celullar connection. What is that, anyway? GSM? Don't send this - we don't what it is for, anyway. */ //v8_put_byte(s, V8_DATA_NOCELULAR);}/* selection the modulation according to V8 priority from the bits in 'mask' */static int select_modulation(int mask){ int val; val = V8_MOD_HANGUP; /* use modulations in this order */ if (mask & V8_MOD_V21) val = V8_MOD_V21; if (mask & V8_MOD_V23) val = V8_MOD_V23; if (mask & V8_MOD_V34) val = V8_MOD_V34; if (mask & V8_MOD_V90) val = V8_MOD_V90; return val;}/* V8 protocol handler */int V8_process(V8State *s, s16 *output, s16 *input, int nb_samples){ int ret = 0; /* modulation part */ switch (s->state) { case V8_CI_SEND: case V8_CM_SEND: case V8_JM_SEND: case V8_CJ_SEND: /* modulate with V21 */ FSK_mod(&s->v21_tx, output, nb_samples); break; case V8_CM_WAIT: /* send ANSam modulation */ V8_mod(&s->v8_tx, output, nb_samples); break; default: /* output nothing */ memset(output, 0, nb_samples * sizeof(s16)); break; } /* demodulation part */ switch (s->state) { case V8_CI: case V8_CI_OFF: case V8_CI_SEND: /* detect ANSam */ V8_demod(&s->v8_rx, input, nb_samples); break; case V8_CM_WAIT: case V8_CM_SEND: case V8_JM_SEND: /* V21 receive */ FSK_demod(&s->v21_rx, input, nb_samples); break; default: break; } /* state machine */ if (lm_debug) { if (s->state != s->debug_laststate) { s->debug_laststate = s->state; printf("%s: V8: state: %s\n", s->calling ? "cal" : "ans", sm_states_str[s->state]); } } switch(s->state) { case V8_WAIT_1SECOND: { /* wait 1 second before sending the first CI packet */ if (sm_check_timer(&s->v8_start_timer)) { s->state = V8_CI; s->v8_ci_count = 0; V8_demod_init(&s->v8_rx); /* init ANSam detection */ V21_mod_init(&s->v21_tx, 1, get_bit, s); } } break; /* send the CI packets */ case V8_CI: { int i; /* send 4 CI packets (at least 3 must be sent) */ for(i=0;i<4;i++) { sm_put_bits(&s->tx_fifo, V8_TEN_ONES, 10); sm_put_bits(&s->tx_fifo, V8_CI_SYNC, 10); v8_put_byte(s, V8_CALL_FUNC_DATA); } s->state = V8_CI_SEND; } break; case V8_CI_SEND: { if (sm_size(&s->tx_fifo) == 0) { s->state = V8_CI_OFF; sm_set_timer(&s->v8_ci_timer, 500); /* 0.5 s off */ } } break; case V8_CI_OFF: { /* check if an ANSam tone is detected */ if (s->v8_rx.v8_ANSam_detected) { sm_set_timer(&s->v8_ci_timer, V8_TE); s->state = V8_GOT_ANSAM; } else if (sm_check_timer(&s->v8_ci_timer)) { if (++s->v8_ci_count == V8_MAX_CI_SEQ) { ret = V8_MOD_HANGUP; } else { s->state = V8_CI; } } } break; case V8_GOT_ANSAM: { if (sm_check_timer(&s->v8_ci_timer)) { v8_decode_init(s); s->state = V8_CM_SEND; } } break; case V8_CM_SEND: { if (s->got_cm) { /* if JM detected, we send CJ & wait for 75 ms before exiting V8 */ s->selected_mod_mask = s->modulation_mask & s->decoded_modulations; s->selected_modulation = select_modulation(s->selected_mod_mask); /* flush tx queue */ sm_flush(&s->tx_fifo); v8_put_byte(s, 0); v8_put_byte(s, 0); v8_put_byte(s, 0); /* a few more bytes to fill the time */ v8_put_byte(s, 0); v8_put_byte(s, 0); v8_put_byte(s, 0); v8_put_byte(s, 0); v8_put_byte(s, 0); v8_put_byte(s, 0); s->state = V8_CJ_SEND; } else if (sm_size(&s->tx_fifo) == 0) { /* send CM */ cm_send(s, s->modulation_mask); } } break; case V8_CJ_SEND: /* wait until CJ is sent */ if (sm_size(&s->tx_fifo) == 0) { sm_set_timer(&s->v8_start_timer, 75); s->state = V8_SIGC; } break; case V8_SIGC: if (sm_check_timer(&s->v8_start_timer)) { /* it's OK, let's start the wanted modulation */ ret = s->selected_modulation; } break; /* V8 answer */ case V8_WAIT: { if (sm_check_timer(&s->v8_connect_timer)) { /* send the ANSam tone */ s->v8_tx.tone_level = -3; /* XXX: fix it */ V8_mod_init(&s->v8_tx); /* prepare V21 to receive CI or CM */ v8_decode_init(s); /* wait at most 5 seconds */ sm_set_timer(&s->v8_connect_timer, 5000); s->state = V8_CM_WAIT; } } break; case V8_CM_WAIT: { if (sm_check_timer(&s->v8_connect_timer)) { /* timeout */ ret = V8_MOD_HANGUP; } else { if (s->got_cm) { /* stop sending ANSam & send JM */ V21_mod_init(&s->v21_tx, 0, get_bit, s); /* timeout for JM */ sm_set_timer(&s->v8_connect_timer, 5000); s->state = V8_JM_SEND; s->selected_mod_mask = s->modulation_mask & s->decoded_modulations; s->selected_modulation = select_modulation(s->selected_mod_mask); } } } break; case V8_JM_SEND: { if (sm_check_timer(&s->v8_connect_timer)) { /* timeout */ ret = V8_MOD_HANGUP; } else if (s->got_cj) { /* stop sending JM & wait 75 ms */ sm_set_timer(&s->v8_connect_timer, 75); s->state = V8_SIGA; } else if (sm_size(&s->tx_fifo) == 0) { /* Send JM */ cm_send(s, s->selected_mod_mask); } } break; case V8_SIGA: if (sm_check_timer(&s->v8_connect_timer)) { ret = s->selected_modulation; } break; } return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -