+void SendCommand(UsbCommand* txcmd) {
+// printf("send: ");
+// cmd_debug(txcmd);
+ if (!uart_send(sp,(byte_t*)txcmd,sizeof(UsbCommand))) {
+ printf("Sending bytes to proxmark failed\n");
+ exit(1);
+ }
+}
+
+void ReceiveCommand(UsbCommand* rxcmd) {
+ byte_t* prxcmd = (byte_t*)rxcmd;
+ byte_t* prx = prxcmd;
+ size_t rxlen;
+ while (true) {
+ if (uart_receive(sp, prx, sizeof(UsbCommand) - (prx-prxcmd), &rxlen)) {
+ prx += rxlen;
+ if ((prx-prxcmd) >= sizeof(UsbCommand)) {
+ return;
+ }
+ }
+ }
+}
+
+void CloseProxmark() {
+ // Clean up the port
+ uart_close(sp);
+ // Fix for linux, it seems that it is extremely slow to release the serial port file descriptor /dev/*
+ unlink(serial_port_name);
+}
+
+int OpenProxmark(size_t i) {
+ sp = uart_open(serial_port_name);
+ if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT) {
+ //poll once a second
+ return 0;
+ }
+ return 1;
+}
+