Now that we're in cpp land, remove the mrf_ prefixes from all methods.

Also, add a proper set_channel method, and a method for promiscuous mode.
This commit is contained in:
Karl Palsson
2011-03-13 18:35:18 +00:00
parent 0a2c207146
commit fd58b93767
3 changed files with 98 additions and 88 deletions

View File

@@ -20,10 +20,10 @@ long tx_interval = 1000;
void setup() {
Serial.begin(9600);
Serial.println("Starting to reset and startup...");
mrf.mrf_pan_write(0xcafe);
mrf.mrf_address16_write(0x6001);
mrf.set_pan(0xcafe);
// This is _our_ address
mrf.address16_write(0x6001);
attachInterrupt(0, interrupt_routine, CHANGE);
last_time = millis();
}
@@ -34,7 +34,7 @@ volatile uint8_t last_interrupt;
void interrupt_routine() {
// read and clear from the radio
last_interrupt = mrf.mrf_read_short(MRF_INTSTAT);
last_interrupt = mrf.read_short(MRF_INTSTAT);
if (last_interrupt & MRF_I_RXIF) {
gotrx = 1;
}
@@ -44,19 +44,19 @@ void interrupt_routine() {
}
void loop() {
//mrf.mrf_write_short(MRF_RXMCR, 0x01); // promiscuous!
//mrf.set_promiscuous(true);
int tmp;
interrupts();
unsigned long current_time = millis();
if (current_time - last_time > tx_interval) {
last_time = current_time;
Serial.println("txxxing...");
mrf.mrf_send16(0x4202, 4, "abcd");
mrf.send16(0x4202, 4, "abcd");
}
if (txok) {
txok = 0;
Serial.print("tx went ok:");
tmp = mrf.mrf_read_short(MRF_TXSTAT);
tmp = mrf.read_short(MRF_TXSTAT);
Serial.print(tmp);
if (!(tmp & ~(1<<TXNSTAT))) { // 1 = failed
Serial.print("...And we got an ACK");
@@ -69,22 +69,22 @@ void loop() {
if (gotrx) {
gotrx = 0;
noInterrupts();
mrf.mrf_write_short(MRF_BBREG1, 0x04); // RXDECINV - disable receiver
mrf.write_short(MRF_BBREG1, 0x04); // RXDECINV - disable receiver
byte frame_length = mrf.mrf_read_long(0x300); // read start of rxfifo
byte frame_length = mrf.read_long(0x300); // read start of rxfifo
Serial.print("received a packet ");Serial.print(frame_length, DEC);Serial.println(" bytes long");
Serial.println("Packet data:");
for (int i = 1; i <= frame_length; i++) {
tmp = mrf.mrf_read_long(0x300 + i);
tmp = mrf.read_long(0x300 + i);
Serial.print(tmp, HEX);
}
Serial.print("\r\nLQI/RSSI=");
byte lqi = mrf.mrf_read_long(0x300 + frame_length + 1);
byte rssi = mrf.mrf_read_long(0x300 + frame_length + 2);
byte lqi = mrf.read_long(0x300 + frame_length + 1);
byte rssi = mrf.read_long(0x300 + frame_length + 2);
Serial.print(lqi, HEX);
Serial.println(rssi, HEX);
mrf.mrf_write_short(MRF_BBREG1, 0x00); // RXDECINV - enable receiver
mrf.write_short(MRF_BBREG1, 0x00); // RXDECINV - enable receiver
interrupts();
}