-+ while ((enc[0] + 2) < (rxfifo_cnt - 1)) { // Wait for more data
-+ my_delay_ms(1);
-+ rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f) + 1;
+- if (enc[0]>=MAX_ASKSIN_MSG)
+- enc[0] = MAX_ASKSIN_MSG-1;
+-
++ if (enc[0] >= MAX_ASKSIN_MSG) {
++ // Something went horribly wrong, out of sync?
++ rf_asksin_reset_rx();
++ return;
++ }
++
++ if ((enc[0] + 2) > rxfifo_cnt) {
++ timeout = RX_TIMEOUT_MS * ((enc[0] + 2) - rxfifo_cnt);
++ while (timeout-- && ((enc[0] + 2) > rxfifo_cnt)) { // Wait for more data
++ my_delay_ms(1);
++ rxfifo_cnt = read_cc1100_rxbytes();
++
++ if (rxfifo_cnt & 0x80) { // Overflow
++ rf_asksin_reset_rx();
++ return;
++ }
++
++ rxfifo_cnt &= 0x7f;
++ }
++
++ if (!timeout) {
++ // Not enough data received, out of sync?
++ rf_asksin_reset_rx();
++ return;
++ }