Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to acknowledge answers #12

Merged
merged 4 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions emulator/iSkipper/examples/capture/capture.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include <string.h>

/* UPDATE THESE FOR YOUR PARTICULAR BOARD */
#define IS_RFM69HW false //make true if using w version
#define IS_RFM69HW true //make true if using w version
ammaraskar marked this conversation as resolved.
Show resolved Hide resolved
#define IRQ_PIN 3 // This is 3 on adafruit feather
#define CSN 8 // This is 8 on adafruit feather
/* END THINGS YOU MUST UPDATE */


#define MAX_BUFFERED_PACKETS 20
#define SEND_ACKS false
#define SEND_ACKS true

iClickerEmulator clicker(CSN, IRQ_PIN, digitalPinToInterrupt(IRQ_PIN), IS_RFM69HW);
RingBufCPP<iClickerPacket, MAX_BUFFERED_PACKETS> recvBuf;
Expand All @@ -33,21 +33,13 @@ void loop()
iClickerPacket r;

//see if there is a pending packet, check if its an answer packet

while (recvBuf.pull(&r) && r.type == PACKET_ANSWER) {
uint8_t *id = r.packet.answerPacket.id;
char answer = iClickerEmulator::answerChar(r.packet.answerPacket.answer);
snprintf(tmp, sizeof(tmp), "Captured: %c (%02X, %02X, %02X, %02X) \n", answer, id[0], id[1], id[2], id[3]);
Serial.println(tmp);
}

// restore the frequency back to AA and go back
// to promiscous mode if we sent an ACK packet
if (SEND_ACKS) {
clicker.setChannel(iClickerChannels::AA);
clicker.startPromiscuous(CHANNEL_SEND, recvPacketHandler);
}

delay(100);
}

Expand All @@ -56,7 +48,10 @@ void recvPacketHandler(iClickerPacket *recvd)
{
if (SEND_ACKS && recvd->type == PACKET_ANSWER) {
Serial.println("Sending ACK");
ammaraskar marked this conversation as resolved.
Show resolved Hide resolved
clicker.acknowledgeAnswer(&recvd->packet.answerPacket);
clicker.acknowledgeAnswer(&recvd->packet.answerPacket, true);
// restore the frequency back to AA and go back to promiscous mode
clicker.setChannel(iClickerChannels::AA);
clicker.startPromiscuous(CHANNEL_SEND, recvPacketHandler);
}

recvBuf.add(*recvd);
Expand Down
28 changes: 17 additions & 11 deletions emulator/iSkipper/iClickerEmulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,30 @@ bool iClickerEmulator::submitAnswer(uint8_t id[ICLICKER_ID_LEN], iClickerAnswer
}

void iClickerEmulator::acknowledgeAnswer(iClickerAnswerPacket* packet, bool accept) {
uint8_t ack_payload[ACK_SIZE];
// ACKs are either 4 (accept) or 5 (reject) bytes
uint8_t ack_payload[5];
encodeId(packet->id, ack_payload);

ack_payload[2] = ~ack_payload[2];
configureRadio(CHANNEL_RECV, ACK_SEND_SYNC_ADDR);
ammaraskar marked this conversation as resolved.
Show resolved Hide resolved

if (accept) {
ack_payload[3] = (ack_payload[3] & 0xF0) | 0x2;
ack_payload[4] = 0x22;
// When accepting, we simply replay the encoded payload
// ack[0-2] = encodedId[0-2]
// ack[3] = (encodedId[3] & 0xF0) | answer_nibble
ack_payload[3] = (ack_payload[3] & 0xF0) | (0x0F & getAnswerOffset(packet->answer));

_radio.send(ack_payload, 4, false);
} else {
// ack[0-1] = encodedId[0-1]
// ack[2] = ~encodedId[2]
ack_payload[2] = ~ack_payload[2];
// ack[3] = (encodedId[3] & 0xF0) | 0x6
ack_payload[3] = (ack_payload[3] & 0xF0) | 0x6;
// ack[4] = 0x66
ack_payload[4] = 0x66;
}

_radio.setChannelType(CHANNEL_RECV);

_radio.setSyncAddr(ACK_SYNC_ADDR, ACK_HEADER_SIZE);
_radio.setPayloadLength(ACK_SIZE, false);

_radio.send(ack_payload, ACK_SIZE, false);
_radio.send(ack_payload, 5, false);
}
}


Expand Down
6 changes: 2 additions & 4 deletions emulator/iSkipper/iClickerEmulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#define SEND_SYNC_ADDR_LEN 3
#define RECV_SYNC_ADDR_LEN 2
ammaraskar marked this conversation as resolved.
Show resolved Hide resolved

#define ACK_HEADER_SIZE 3
#define ACK_SIZE 5

#define DEFAULT_ACK_TIMEOUT 1500

enum iClickerAnswer : uint8_t
Expand Down Expand Up @@ -49,7 +46,8 @@ const uint8_t answerOffsets[NUM_ANSWER_CHOICES] = {0x1, 0x5, 0xd, 0xe, 0xa, 0x2}
const uint8_t DEFAULT_SEND_SYNC_ADDR[SEND_SYNC_ADDR_LEN] =
{RF_SYNC_BYTE1_VALUE_IC, RF_SYNC_BYTE2_VALUE_IC , RF_SYNC_BYTE3_VALUE_IC };

const uint8_t ACK_SYNC_ADDR[ACK_HEADER_SIZE] = {0x55, 0x55, 0x55};
#define ACK_SEND_SYNC_ADDR_LEN 3
ammaraskar marked this conversation as resolved.
Show resolved Hide resolved
const uint8_t ACK_SEND_SYNC_ADDR[ACK_SEND_SYNC_ADDR_LEN] = {0x55, 0x55, 0x55};


// 5 bytes
Expand Down
3 changes: 2 additions & 1 deletion emulator/iSkipper/iClickerRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "RFM69.h"

// threshold for triggerins fifo transmit interrupt
ammaraskar marked this conversation as resolved.
Show resolved Hide resolved
#define RF_FIFOTHRESH_TXSTART_FIFOTHRESH_IC 0x04
// (should be the [smallest packet size - 1])
#define RF_FIFOTHRESH_TXSTART_FIFOTHRESH_IC 0x03


//RegSyncValue1-8 for sending is:
Expand Down