+ if ((sci_rx_buf[1] < '0') || (sci_rx_buf[1] > '9') ||
+ (sci_rx_buf[2] < '0') || (sci_rx_buf[2] > '9') ||
+ (sci_rx_buf[3] < '0') || (sci_rx_buf[3] > '9') ||
+ (sci_rx_buf[4] < '0') || (sci_rx_buf[4] > '9') ||
+ (sci_rx_buf[5] < '0') || (sci_rx_buf[5] > '9')) {
+ send_nack();
+ }
+ cost = sci_rx_buf[1] - '0';
+ cost *= 10; cost = sci_rx_buf[2] - '0';
+ cost *= 10; cost = sci_rx_buf[3] - '0';
+ cost *= 10; cost = sci_rx_buf[4] - '0';
+ cost *= 10; cost = sci_rx_buf[5] - '0';
+
+ coin_cost(cost);
+ send_ack();
+}
+
+void send_keypress(u8 key) {
+ /* send a packet of the form KX with X being the key, or R for reset */
+ wait_for_tx_free();
+ sci_tx_buf[0] = 'K';
+ if (key == KEY_RESET)
+ sci_tx_buf[1] = 'R';
+ else
+ sci_tx_buf[1] = (key%10)+'0';
+ sci_tx_buf[2] = '\n';
+ sci_tx_buf[3] = 0;
+ send_packet();
+}
+
+void send_door_msg(bool open) {
+ wait_for_tx_free();
+ sci_tx_buf[0] = 'D';
+ sci_tx_buf[1] = open?'1':'0';
+ sci_tx_buf[2] = '\n';
+ sci_tx_buf[3] = 0;
+ send_packet();
+}
+
+void do_chime() {
+ chime_start();
+ send_ack();
+}
+
+void ping_pong() {
+ /* make sure it's really a ping */
+ if (sci_rx_buf[1] != 'I' ||
+ sci_rx_buf[2] != 'N' ||
+ sci_rx_buf[3] != 'G') {
+ send_nack();
+ return;
+ }
+ /* respond with ack & pong */
+ wait_for_tx_free();
+ sci_tx_buf[0] = 'P';
+ sci_tx_buf[1] = 'O';
+ sci_tx_buf[2] = 'N';
+ sci_tx_buf[3] = 'G';
+ sci_tx_buf[4] = '\n';
+ sci_tx_buf[5] = 0;
+ send_packet();