summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-02-14 23:41:42 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-02-14 23:41:42 +0100
commit8ce50ba2f70b3dda8045d3807abf0c72c2d623b4 (patch)
treeafa388c85c4acef90ebc093de178c92b4da68b3f
parent3f9b6a6539d487140f6d7e49e8cf9dc06bf040c6 (diff)
rf: Delay execution of commandson-waves/0.3.99.21
Delay executing RF commands up to a second. If many commands arrive within a second then just execute the last command.
-rw-r--r--openbsc/include/openbsc/osmo_bsc_rf.h4
-rw-r--r--openbsc/src/osmo_bsc_rf.c53
2 files changed, 39 insertions, 18 deletions
diff --git a/openbsc/include/openbsc/osmo_bsc_rf.h b/openbsc/include/openbsc/osmo_bsc_rf.h
index 4c8c65e36..e00d9c63c 100644
--- a/openbsc/include/openbsc/osmo_bsc_rf.h
+++ b/openbsc/include/openbsc/osmo_bsc_rf.h
@@ -14,6 +14,10 @@ struct osmo_bsc_rf {
const char *last_state_command;
+ /* delay the command */
+ char last_request;
+ struct timer_list delay_cmd;
+
/* verify that RF is up as it should be */
struct timer_list rf_check;
diff --git a/openbsc/src/osmo_bsc_rf.c b/openbsc/src/osmo_bsc_rf.c
index b748cc9e7..8878f7dbb 100644
--- a/openbsc/src/osmo_bsc_rf.c
+++ b/openbsc/src/osmo_bsc_rf.c
@@ -156,20 +156,44 @@ static void grace_timeout(void *_data)
switch_rf_off(rf);
}
-static int enter_grace(struct osmo_bsc_rf_conn *conn)
+static int enter_grace(struct osmo_bsc_rf *rf)
{
- struct osmo_bsc_rf *rf = conn->rf;
-
rf->grace_timeout.cb = grace_timeout;
rf->grace_timeout.data = rf;
bsc_schedule_timer(&rf->grace_timeout, rf->gsm_network->mid_call_timeout, 0);
LOGP(DINP, LOGL_NOTICE, "Going to switch RF off in %d seconds.\n",
rf->gsm_network->mid_call_timeout);
- send_signal(conn->rf, S_RF_GRACE);
+ send_signal(rf, S_RF_GRACE);
return 0;
}
+static void rf_delay_cmd_cb(void *data)
+{
+ struct osmo_bsc_rf *rf = data;
+
+ switch (rf->last_request) {
+ case RF_CMD_D_OFF:
+ rf->last_state_command = "RF Direct Off";
+ bsc_del_timer(&rf->rf_check);
+ bsc_del_timer(&rf->grace_timeout);
+ switch_rf_off(rf);
+ break;
+ case RF_CMD_ON:
+ rf->last_state_command = "RF Direct On";
+ bsc_del_timer(&rf->grace_timeout);
+ lock_each_trx(rf->gsm_network, 0);
+ send_signal(rf, S_RF_ON);
+ bsc_schedule_timer(&rf->rf_check, 3, 0);
+ break;
+ case RF_CMD_OFF:
+ rf->last_state_command = "RF Scheduled Off";
+ bsc_del_timer(&rf->rf_check);
+ enter_grace(rf);
+ break;
+ }
+}
+
static int rf_read_cmd(struct bsc_fd *fd)
{
struct osmo_bsc_rf_conn *conn = fd->data;
@@ -191,22 +215,11 @@ static int rf_read_cmd(struct bsc_fd *fd)
handle_query(conn);
break;
case RF_CMD_D_OFF:
- conn->rf->last_state_command = "RF Direct Off";
- bsc_del_timer(&conn->rf->rf_check);
- bsc_del_timer(&conn->rf->grace_timeout);
- switch_rf_off(conn->rf);
- break;
case RF_CMD_ON:
- conn->rf->last_state_command = "RF Direct On";
- bsc_del_timer(&conn->rf->grace_timeout);
- lock_each_trx(conn->rf->gsm_network, 0);
- send_signal(conn->rf, S_RF_ON);
- bsc_schedule_timer(&conn->rf->rf_check, 3, 0);
- break;
case RF_CMD_OFF:
- conn->rf->last_state_command = "RF Scheduled Off";
- bsc_del_timer(&conn->rf->rf_check);
- enter_grace(conn);
+ conn->rf->last_request = buf[0];
+ if (!bsc_timer_pending(&conn->rf->delay_cmd))
+ bsc_schedule_timer(&conn->rf->delay_cmd, 1, 0);
break;
default:
conn->rf->last_state_command = "Unknown command";
@@ -343,6 +356,10 @@ struct osmo_bsc_rf *osmo_bsc_rf_create(const char *path, struct gsm_network *net
rf->rf_check.data = rf;
rf->rf_check.cb = rf_check_cb;
+ /* delay cmd handling */
+ rf->delay_cmd.data = rf;
+ rf->delay_cmd.cb = rf_delay_cmd_cb;
+
return rf;
}