Joe Sobchuk
/
RFtrans_full
The transmitter's code for Home Security with RF
main.cpp@0:47380c5f575d, 2014-12-08 (annotated)
- Committer:
- jsobchuk3
- Date:
- Mon Dec 08 22:43:22 2014 +0000
- Revision:
- 0:47380c5f575d
ECE 4180 Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jsobchuk3 | 0:47380c5f575d | 1 | #include "mbed.h" |
jsobchuk3 | 0:47380c5f575d | 2 | #include "hmac_md5.h" |
jsobchuk3 | 0:47380c5f575d | 3 | #include <stdio.h> |
jsobchuk3 | 0:47380c5f575d | 4 | #include <string.h> |
jsobchuk3 | 0:47380c5f575d | 5 | |
jsobchuk3 | 0:47380c5f575d | 6 | DigitalOut myled1(LED1); |
jsobchuk3 | 0:47380c5f575d | 7 | DigitalOut myled2(LED2); |
jsobchuk3 | 0:47380c5f575d | 8 | |
jsobchuk3 | 0:47380c5f575d | 9 | DigitalIn pb(p20); |
jsobchuk3 | 0:47380c5f575d | 10 | Serial rf(p9,p10); |
jsobchuk3 | 0:47380c5f575d | 11 | |
jsobchuk3 | 0:47380c5f575d | 12 | |
jsobchuk3 | 0:47380c5f575d | 13 | int main() { |
jsobchuk3 | 0:47380c5f575d | 14 | pb.mode(PullUp); |
jsobchuk3 | 0:47380c5f575d | 15 | // Delay for initial pullup to take effect |
jsobchuk3 | 0:47380c5f575d | 16 | wait(.01); |
jsobchuk3 | 0:47380c5f575d | 17 | |
jsobchuk3 | 0:47380c5f575d | 18 | rf.baud(1200); |
jsobchuk3 | 0:47380c5f575d | 19 | int old_pb=0; |
jsobchuk3 | 0:47380c5f575d | 20 | int new_pb; |
jsobchuk3 | 0:47380c5f575d | 21 | |
jsobchuk3 | 0:47380c5f575d | 22 | /*const char * key = "Dhruvin"; |
jsobchuk3 | 0:47380c5f575d | 23 | const char * text = "open"; |
jsobchuk3 | 0:47380c5f575d | 24 | char output[26]; |
jsobchuk3 | 0:47380c5f575d | 25 | char output2[3]; |
jsobchuk3 | 0:47380c5f575d | 26 | */ |
jsobchuk3 | 0:47380c5f575d | 27 | |
jsobchuk3 | 0:47380c5f575d | 28 | int i = 0; |
jsobchuk3 | 0:47380c5f575d | 29 | /*HMAC_MD5(key, text, output); |
jsobchuk3 | 0:47380c5f575d | 30 | output2[0] = output[0]; |
jsobchuk3 | 0:47380c5f575d | 31 | output2[1] = output[1]; |
jsobchuk3 | 0:47380c5f575d | 32 | output2[2] = output[2]; |
jsobchuk3 | 0:47380c5f575d | 33 | */ |
jsobchuk3 | 0:47380c5f575d | 34 | char key[4] = "Dhr"; |
jsobchuk3 | 0:47380c5f575d | 35 | for (i = 0; i < 4; i++) { |
jsobchuk3 | 0:47380c5f575d | 36 | key[i] = (key[i] + 5); |
jsobchuk3 | 0:47380c5f575d | 37 | } |
jsobchuk3 | 0:47380c5f575d | 38 | while (1) { |
jsobchuk3 | 0:47380c5f575d | 39 | new_pb = pb; |
jsobchuk3 | 0:47380c5f575d | 40 | if( (new_pb==0) && (old_pb==1) ) { |
jsobchuk3 | 0:47380c5f575d | 41 | //Send out the real data whenever the button is pressed |
jsobchuk3 | 0:47380c5f575d | 42 | rf.putc(key[0]); |
jsobchuk3 | 0:47380c5f575d | 43 | rf.putc(key[1]); |
jsobchuk3 | 0:47380c5f575d | 44 | rf.putc(key[2]); |
jsobchuk3 | 0:47380c5f575d | 45 | |
jsobchuk3 | 0:47380c5f575d | 46 | //HMAC_MD5(output2, text, output2); |
jsobchuk3 | 0:47380c5f575d | 47 | for (i = 0; i < 4; i++) { |
jsobchuk3 | 0:47380c5f575d | 48 | key[i] = (key[i] + 5); |
jsobchuk3 | 0:47380c5f575d | 49 | } |
jsobchuk3 | 0:47380c5f575d | 50 | |
jsobchuk3 | 0:47380c5f575d | 51 | } |
jsobchuk3 | 0:47380c5f575d | 52 | |
jsobchuk3 | 0:47380c5f575d | 53 | else { |
jsobchuk3 | 0:47380c5f575d | 54 | //RF Transmit Code |
jsobchuk3 | 0:47380c5f575d | 55 | myled1 = 0; |
jsobchuk3 | 0:47380c5f575d | 56 | //Send 10101010 pattern when idle to keep receivers AGC gain locked to transmitters signal |
jsobchuk3 | 0:47380c5f575d | 57 | //When receiver loses the signal lock (Around 10-30MS with no data change seen) it starts sending out noise |
jsobchuk3 | 0:47380c5f575d | 58 | rf.putc(0xAA); |
jsobchuk3 | 0:47380c5f575d | 59 | myled1 = 0; |
jsobchuk3 | 0:47380c5f575d | 60 | |
jsobchuk3 | 0:47380c5f575d | 61 | } |
jsobchuk3 | 0:47380c5f575d | 62 | old_pb = new_pb; |
jsobchuk3 | 0:47380c5f575d | 63 | |
jsobchuk3 | 0:47380c5f575d | 64 | } |
jsobchuk3 | 0:47380c5f575d | 65 | } |