git.ucc.asn.au
/
tpg
/
opendispense2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed door for direct serial
[tpg/opendispense2.git]
/
src
/
server
/
handler_door.c
diff --git
a/src/server/handler_door.c
b/src/server/handler_door.c
index
3359ed1
..
163ed3c
100644
(file)
--- a/
src/server/handler_door.c
+++ b/
src/server/handler_door.c
@@
-29,6
+29,7
@@
int Door_InitHandler();
int Door_CanDispense(int User, int Item);
int Door_DoDispense(int User, int Item);
int Door_InitHandler();
int Door_CanDispense(int User, int Item);
int Door_DoDispense(int User, int Item);
+ int writes(int fd, const char *str);
// === GLOBALS ===
tHandler gDoor_Handler = {
// === GLOBALS ===
tHandler gDoor_Handler = {
@@
-94,8
+95,20
@@
int Door_DoDispense(int User, int Item)
}
door_serial_handle = InitSerial(gsDoor_SerialPort, 1200);
}
door_serial_handle = InitSerial(gsDoor_SerialPort, 1200);
+ if(door_serial_handle < 0) {
+ fprintf(stderr, "Unable to open door serial '%s'\n", gsDoor_SerialPort);
+ perror("Opening door port");
+ return -1;
+ }
- if( write(door_serial_handle, "ATH1\n", 5) != 5 ) {
+ {
+ struct termios info;
+ tcgetattr(door_serial_handle, &info);
+ info.c_iflag &= ~IGNCR; // Ignore \r
+ tcsetattr(door_serial_handle, TCSANOW, &info);
+ }
+
+ if( writes(door_serial_handle, "\r\nATH1\r\n") ) {
fprintf(stderr, "Unable to open door (sending ATH1)\n");
perror("Sending ATH1");
return -1;
fprintf(stderr, "Unable to open door (sending ATH1)\n");
perror("Sending ATH1");
return -1;
@@
-104,7
+117,7
@@
int Door_DoDispense(int User, int Item)
// Wait before re-locking
sleep(DOOR_UNLOCKED_DELAY);
// Wait before re-locking
sleep(DOOR_UNLOCKED_DELAY);
- if( write
(door_serial_handle, "ATH0\n", 5) != 5
) {
+ if( write
s(door_serial_handle, "\r\nATH0\r\n")
) {
fprintf(stderr, "Oh, hell! Door not re-locking, big error (sending ATH0 failed)\n");
perror("Sending ATH0");
return -1;
fprintf(stderr, "Oh, hell! Door not re-locking, big error (sending ATH0 failed)\n");
perror("Sending ATH0");
return -1;
@@
-119,3
+132,14
@@
int Door_DoDispense(int User, int Item)
return 0;
}
return 0;
}
+int writes(int fd, const char *str)
+{
+ int len = strlen(str);
+
+ if( len != write(fd, str, len) )
+ {
+ return 1;
+ }
+ return 0;
+}
+
UCC
git Repository :: git.ucc.asn.au