aboutsummaryrefslogtreecommitdiff
path: root/flow-native/shared/include
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2013-06-30 12:02:12 +0200
committerJakob Odersky <jodersky@gmail.com>2013-06-30 12:02:12 +0200
commitee9073054c9f42d24067a02e8810597dabd9a550 (patch)
tree24522c6d1a0da228fe2df6fb826b50fe50aa9ae2 /flow-native/shared/include
parentc68bedee9717853a4e07b9b7000966ee9e9cca09 (diff)
downloadakka-serial-ee9073054c9f42d24067a02e8810597dabd9a550.tar.gz
akka-serial-ee9073054c9f42d24067a02e8810597dabd9a550.tar.bz2
akka-serial-ee9073054c9f42d24067a02e8810597dabd9a550.zip
refactor native source directory layout
Diffstat (limited to 'flow-native/shared/include')
-rw-r--r--flow-native/shared/include/flow.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/flow-native/shared/include/flow.h b/flow-native/shared/include/flow.h
new file mode 100644
index 0000000..eacc783
--- /dev/null
+++ b/flow-native/shared/include/flow.h
@@ -0,0 +1,67 @@
+#ifndef FLOW_H
+#define FLOW_H
+
+#include <stdbool.h>
+
+//general error codes that are meant to be communicated to user
+#define E_IO -1 //I/O error (port should be closed)
+#define E_ACCESS_DENIED -2 //access denied
+#define E_BUSY -3 // port is busy
+#define E_INVALID_BAUD -4 // baud rate is not valid
+#define E_INTERRUPT -5 // not really an error, function call aborted because port is closed
+#define E_NO_PORT -6
+
+/** Represents an open serial port. */
+struct serial_config;
+
+/**Opens a serial port and allocates memory for storing configuration. Note: if this function fails,
+ * any internally allocated resources will be freed.
+ * @param port_name name of port
+ * @param baud baud rate
+ * @param serial pointer to memory that will be allocated with a serial structure
+ * @return 0 on success
+ * @return E_NO_PORT if the given port does not exist
+ * @return E_ACCESS_DENIED if permissions are not sufficient to open port
+ * @return E_BUSY if port is already in use
+ * @return E_INVALID_BAUD if specified baudrate is non-standard
+ * @return E_IO on other error */
+int serial_open(const char* port_name, int baud, struct serial_config** serial);
+
+/**Closes a previously opened serial port and frees memory containing the configuration. Note: after a call to
+ * this function, the 'serial' pointer will become invalid, make sure you only call it once. This function is NOT
+ * thread safe, make sure no read or write is in prgress when this function is called (the reason is that per
+ * close manual page, close should not be called on a file descriptor that is in use by another thread).
+ * @param serial pointer to serial configuration that is to be closed (and freed)
+ * @return 0 on success
+ * @return E_IO on error */
+int serial_close(struct serial_config* serial);
+
+/**Starts a read from a previously opened serial port. The read is blocking, however it may be
+ * interrupted by calling 'serial_interrupt' on the given serial port.
+ * @param serial pointer to serial configuration from which to read
+ * @param buffer buffer into which data is read
+ * @param size maximum buffer size
+ * @return n>0 the number of bytes read into buffer
+ * @return E_INTERRUPT if the call to this function was interrupted
+ * @return E_IO on IO error */
+int serial_read(struct serial_config* serial, unsigned char* buffer, size_t size);
+
+/**Interrupts a blocked read call.
+ * @param serial_config the serial port to interrupt
+ * @return 0 on success
+ * @return E_IO on error */
+int serial_interrupt(struct serial_config* serial);
+
+/**Writes data to a previously opened serial port. Non bocking.
+ * @param serial pointer to serial configuration to which to write
+ * @param data data to write
+ * @param size number of bytes to write from data
+ * @return n>0 the number of bytes written
+ * @return E_IO on IO error */
+int serial_write(struct serial_config* serial, unsigned char* data, size_t size);
+
+/**Sets debugging option. If debugging is enabled, detailed error message are printed from method calls. */
+void serial_debug(bool value);
+
+
+#endif /* FLOW_H */