summaryrefslogtreecommitdiffstats
path: root/src/host/osmocon/osmocon.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-03-07 02:59:55 +0100
committerHarald Welte <laforge@gnumonks.org>2010-03-07 02:59:55 +0100
commit8dba2a85c80782a5805acb5cc91b4395c1f25334 (patch)
tree48ea8ff55790b299028dcc62219dbdc4aad1970e /src/host/osmocon/osmocon.c
parentf216bb3024f1b557d73af459c999f53feb483baf (diff)
osmocon: drain the hdlc sercomm queue through select
Diffstat (limited to 'src/host/osmocon/osmocon.c')
-rw-r--r--src/host/osmocon/osmocon.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c
index e3575414..25e2cf07 100644
--- a/src/host/osmocon/osmocon.c
+++ b/src/host/osmocon/osmocon.c
@@ -262,7 +262,7 @@ static void hexdump(const uint8_t *data, unsigned int len)
#define WRITE_BLOCK 4096
-static int handle_write(void)
+static int handle_write_dnload(void)
{
int bytes_left, write_len, rc;
@@ -301,6 +301,24 @@ static int handle_write(void)
return 0;
}
+static int handle_write(void)
+{
+ uint8_t c;
+
+ switch (dnload.state) {
+ case DOWNLOADING:
+ return handle_write_dnload();
+ default:
+ if (sercomm_drv_pull(&c) != 0) {
+ if (write(dnload.serial_fd.fd, &c, 1) != 1)
+ perror("short write");
+ } else
+ dnload.serial_fd.when &= ~BSC_FD_WRITE;
+ }
+
+ return 0;
+}
+
static uint8_t buffer[sizeof(phone_prompt1)];
static uint8_t *bufptr = buffer;
@@ -309,6 +327,9 @@ static void hdlc_send_to_phone(uint8_t dlci, uint8_t *data, int len)
struct msgb *msg;
uint8_t c, *dest;
+ printf("hdlc_send_to_phone(dlci=%u): ", dlci);
+ hexdump(data, len);
+
if (len > 512) {
fprintf(stderr, "Too much data to send. %u\n", len);
return;
@@ -327,10 +348,7 @@ static void hdlc_send_to_phone(uint8_t dlci, uint8_t *data, int len)
sercomm_sendmsg(dlci, msg);
- /* drain the queue: TODO: do this through the select */
- while (sercomm_drv_pull(&c) != 0)
- if (write(dnload.serial_fd.fd, &c, 1) != 1)
- perror("short write");
+ dnload.serial_fd.when |= BSC_FD_WRITE;
}
static void hdlc_console_cb(uint8_t dlci, struct msgb *msg)