summaryrefslogtreecommitdiffstats
path: root/sahara.c
diff options
context:
space:
mode:
Diffstat (limited to 'sahara.c')
-rw-r--r--sahara.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/sahara.c b/sahara.c
index 271ee56..d41212c 100644
--- a/sahara.c
+++ b/sahara.c
@@ -21,9 +21,49 @@
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
+#include <termios.h>
+#include <errno.h>
-#include <sahara.h>
-#include <i9305.h>
+#include "sahara.h"
+#include "i9305.h"
+
+int configure_tty(int *tty_fd, time_t timeout_sec, long int timeout_usec)
+{
+ int tty_dev;
+ struct termios termios;
+ struct timeval timeout;
+ fd_set fds;
+ int rc;
+
+ tty_dev = open(TTY_DEVICE, O_RDWR | O_SYNC);
+ if (tty_dev < 0) {
+ printf("failed to open modem tty device\n");
+ return -1;
+ } else {
+ printf("opened modem tty device\n");
+ }
+
+ tcgetattr(tty_dev, &termios);
+ cfmakeraw(&termios);
+ cfsetispeed(&termios, B9600);
+ cfsetospeed(&termios, B9600);
+ tcsetattr(tty_dev, TCSANOW, &termios);
+
+ FD_ZERO(&fds);
+ FD_SET(tty_dev, &fds);
+ timeout.tv_sec = timeout_sec;
+ timeout.tv_usec = timeout_usec;
+
+ rc = select(tty_dev+1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0) {
+ printf("failed waiting to read\n");
+ return -1;
+ }
+
+ *tty_fd = tty_dev;
+
+ return 0;
+}
static int check_mode(int mode_recv, int mode_expected)
{
@@ -215,6 +255,7 @@ int send_file(int tty_fd, struct sah_data_end_ack *data_end_ack)
struct sah_header header;
struct sah_data_end_req data_end_req;
int rc;
+ char *filename = NULL;
rc = hello_handshake(tty_fd, SAH_MODE_TRANSFER_PENDING);
if (rc < 0) {
@@ -241,7 +282,8 @@ int send_file(int tty_fd, struct sah_data_end_ack *data_end_ack)
return -1;
}
- printf("id %d: file transfer complete\n", data_end_req.id);
+ file_for_id(data_end_req.id, &filename); // assume success because it succeeded before
+ printf("id %d file %s: file transfer complete\n", data_end_req.id, filename);
header.command = SAH_COMMAND_DATA_END_RESP;
header.packet_size = 8;