Uses Arduino to take signals from a Lidar Lite v3 to scan a room. Arduino picks up a change in distance. Sends a signal to the k64. That k64 sets off sounds connected to a speaker. Those sounds are prerecorded on a flash drive. The k64 also flashes and LED that will flash until a turn off signal UDP packet is sent to it. It also sends an alarm UDP packet to another K64 that has flashing LEDs.

Dependencies:   EthernetInterface LidarLitev2 SDFileSystem Servo mbed-rtos mbed wave_player

Need to use this program also.

https://developer.mbed.org/users/dereklstinson/code/Motion_Secure_Client_IUPUI/

Committer:
dereklstinson
Date:
Fri Dec 16 00:52:05 2016 +0000
Revision:
0:a76470827116
Version .01 Alpha had to use an Arduino to read the Lidar sensor.  Any sensor will work as long as you pass a signal to the K64.  It will play sounds that you have on your flash card.  I used wav files I made from various sources involving security

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dereklstinson 0:a76470827116 1 /*------------------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 2 /* Ethernet UDP Server (to be used with Ethernet_UDP_client) */
dereklstinson 0:a76470827116 3 /*------------------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 4
dereklstinson 0:a76470827116 5 /*--COMPANY-----AUTHOR------DATE------------REVISION----NOTES-------------------------*/
dereklstinson 0:a76470827116 6 /* NXP mareikeFSL 2015.12.23 rev 1.0 initial */
dereklstinson 0:a76470827116 7 /* */
dereklstinson 0:a76470827116 8 /*------------------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 9 /* This "Hello World" program is used in conjunction with the Ethernet_UDP_client */
dereklstinson 0:a76470827116 10 /* program. It communicates between two FRDM-K64F boards via the Ethernet protocol. */
dereklstinson 0:a76470827116 11 /* To use this program, you need to do the following: */
dereklstinson 0:a76470827116 12 /* - Connect an Ethernet cable between two FRDM-K64F boards (a crossover cable */
dereklstinson 0:a76470827116 13 /* is not required). */
dereklstinson 0:a76470827116 14 /* - Flash one board with Ethernet_UDP_client and the other with */
dereklstinson 0:a76470827116 15 /* Ethernet_UDP_server */
dereklstinson 0:a76470827116 16 /* - [optional] If you would like to see the "Hello World" output on your */
dereklstinson 0:a76470827116 17 /* monitor, install and open a terminal. Tera Term is used in the Wiki for */
dereklstinson 0:a76470827116 18 /* this program. */
dereklstinson 0:a76470827116 19 /*------------------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 20
dereklstinson 0:a76470827116 21
dereklstinson 0:a76470827116 22 /*--INCLUDES----------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 23 #include "mbed.h"
dereklstinson 0:a76470827116 24 #include "EthernetInterface.h"
dereklstinson 0:a76470827116 25 #include "SDFileSystem.h"
dereklstinson 0:a76470827116 26 #include "wave_player.h"
dereklstinson 0:a76470827116 27 #include "Servo.h"
dereklstinson 0:a76470827116 28 #include "LidarLitev2.h"
dereklstinson 0:a76470827116 29 #include "rtos.h"
dereklstinson 0:a76470827116 30 #include "eth_arch.h"
dereklstinson 0:a76470827116 31 /*--DEFINES-----------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 32 #define SWEEP_TIME .1
dereklstinson 0:a76470827116 33
dereklstinson 0:a76470827116 34
dereklstinson 0:a76470827116 35 /*--CONSTANTS---------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 36 Queue<uint32_t, 5> queue;
dereklstinson 0:a76470827116 37 const int PORT = 7; //arbitrary port
dereklstinson 0:a76470827116 38
dereklstinson 0:a76470827116 39 static const char* SERVER_IP = "192.168.1.101"; //IP of server board
dereklstinson 0:a76470827116 40 static const char* MASK = "255.255.255.0"; //mask
dereklstinson 0:a76470827116 41 static const char* GATEWAY = "192.168.1.1"; //gateway
dereklstinson 0:a76470827116 42
dereklstinson 0:a76470827116 43
dereklstinson 0:a76470827116 44 /*--INITS-------------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 45 Serial pc(USBTX, USBRX); //create PC interface
dereklstinson 0:a76470827116 46 EthernetInterface eth; //create ethernet
dereklstinson 0:a76470827116 47 UDPSocket server; //creat server
dereklstinson 0:a76470827116 48 Endpoint client; //create endpoint
dereklstinson 0:a76470827116 49
dereklstinson 0:a76470827116 50 DigitalOut alarmconfirm(PTD0);
dereklstinson 0:a76470827116 51 DigitalIn alarmcheckpin(PTD1);
dereklstinson 0:a76470827116 52 DigitalOut red(LED_RED); //debug led
dereklstinson 0:a76470827116 53 DigitalOut green(LED_GREEN); //debug led
dereklstinson 0:a76470827116 54 DigitalOut led(D12);
dereklstinson 0:a76470827116 55 SDFileSystem sd(PTE3,PTE1, PTE2, PTE4, "sd"); //SD card
dereklstinson 0:a76470827116 56
dereklstinson 0:a76470827116 57 AnalogOut DACout(DAC0_OUT);
dereklstinson 0:a76470827116 58
dereklstinson 0:a76470827116 59 wave_player waver(&DACout);
dereklstinson 0:a76470827116 60
dereklstinson 0:a76470827116 61
dereklstinson 0:a76470827116 62 Timer dt;
dereklstinson 0:a76470827116 63 /*--VARIABLES---------------------------------------------------------------------------*/
dereklstinson 0:a76470827116 64 int n; //size of received message
dereklstinson 0:a76470827116 65 char counter[1] = {0}; //sample receive/send buffer
dereklstinson 0:a76470827116 66 int i=0;
dereklstinson 0:a76470827116 67 int sweep_flag =0;
dereklstinson 0:a76470827116 68 int waiting_answer = 0;
dereklstinson 0:a76470827116 69 Ticker flashes;
dereklstinson 0:a76470827116 70 //Ticker IO;
dereklstinson 0:a76470827116 71
dereklstinson 0:a76470827116 72 int someflag=0;
dereklstinson 0:a76470827116 73 FILE *wave_file;
dereklstinson 0:a76470827116 74 /*--FUNCTION DECLARATIONS---------------------------------------------------------------*/
dereklstinson 0:a76470827116 75 int sensoralarmcheck(void);
dereklstinson 0:a76470827116 76 void alarmCheck(char x);
dereklstinson 0:a76470827116 77 void alarmLight(void);
dereklstinson 0:a76470827116 78 void alarmSound(void);
dereklstinson 0:a76470827116 79 void init_usb(void); //initializes pc.printf if required
dereklstinson 0:a76470827116 80 void init_eth(void); //initializes Ethernet
dereklstinson 0:a76470827116 81 void receive(void); //receives packets
dereklstinson 0:a76470827116 82 void queue_isr();
dereklstinson 0:a76470827116 83 int main(void); //main
dereklstinson 0:a76470827116 84 void flashingstuff();
dereklstinson 0:a76470827116 85
dereklstinson 0:a76470827116 86
dereklstinson 0:a76470827116 87 /*--FUNCTION DEFINITIONS----------------------------------------------------------------*/
dereklstinson 0:a76470827116 88 /****************************************************************************************/
dereklstinson 0:a76470827116 89 void flashingstuff(){
dereklstinson 0:a76470827116 90 if ((someflag==1) || (red==0)){
dereklstinson 0:a76470827116 91 red=!red;
dereklstinson 0:a76470827116 92 led=!led;
dereklstinson 0:a76470827116 93 }
dereklstinson 0:a76470827116 94 }
dereklstinson 0:a76470827116 95 /*queue_thread**************************************************************************/
dereklstinson 0:a76470827116 96
dereklstinson 0:a76470827116 97
dereklstinson 0:a76470827116 98 /*****************************************************************************INIT_USB***/
dereklstinson 0:a76470827116 99 void init_usb(void)
dereklstinson 0:a76470827116 100 {
dereklstinson 0:a76470827116 101 pc.baud(9600); //baud
dereklstinson 0:a76470827116 102
dereklstinson 0:a76470827116 103 } //end init_usb()
dereklstinson 0:a76470827116 104
dereklstinson 0:a76470827116 105 /*****************************************************************************INIT_ETH***/
dereklstinson 0:a76470827116 106 void init_eth(void)
dereklstinson 0:a76470827116 107 {
dereklstinson 0:a76470827116 108 pc.printf("Initializing Ethernet\r\n");
dereklstinson 0:a76470827116 109 eth.init(SERVER_IP, MASK, GATEWAY); //set up IP
dereklstinson 0:a76470827116 110 eth.connect(); //connect ethernet
dereklstinson 0:a76470827116 111 pc.printf("\nSERVER - Server IP Address is %s\r\n", eth.getIPAddress()); //get server IP address;
dereklstinson 0:a76470827116 112
dereklstinson 0:a76470827116 113 server.bind(PORT); //bind server
dereklstinson 0:a76470827116 114 pc.printf("Initialization Complete\n\r");
dereklstinson 0:a76470827116 115 } //end init_eth()
dereklstinson 0:a76470827116 116
dereklstinson 0:a76470827116 117 /******************************************************************************RECEIVE***/
dereklstinson 0:a76470827116 118 void receive(void)
dereklstinson 0:a76470827116 119 {
dereklstinson 0:a76470827116 120 int herewego=0;
dereklstinson 0:a76470827116 121
dereklstinson 0:a76470827116 122 pc.printf("\nSERVER - Waiting for UDP packet...\r\n"); //wait for packet
dereklstinson 0:a76470827116 123 n = server.receiveFrom(client, counter, sizeof(counter)); //receive message from client
dereklstinson 0:a76470827116 124 counter[n] = '\0'; //add \0 to end of message
dereklstinson 0:a76470827116 125
dereklstinson 0:a76470827116 126
dereklstinson 0:a76470827116 127 pc.printf("SERVER - Received '%i' from client %s\r\n", counter[0], client.get_address()); //print message and client
dereklstinson 0:a76470827116 128 alarmCheck(counter[0]);
dereklstinson 0:a76470827116 129 herewego = sensoralarmcheck();
dereklstinson 0:a76470827116 130
dereklstinson 0:a76470827116 131 if (herewego==1||waiting_answer==1){
dereklstinson 0:a76470827116 132 waiting_answer =1;
dereklstinson 0:a76470827116 133 printf("Lidar Caught something\r\n");
dereklstinson 0:a76470827116 134 counter[0]='z';
dereklstinson 0:a76470827116 135 }
dereklstinson 0:a76470827116 136 pc.printf("SERVER - Sending '%i' back to client %s\r\n", counter[0], client.get_address()); //print sending back
dereklstinson 0:a76470827116 137 wait(.5f);
dereklstinson 0:a76470827116 138
dereklstinson 0:a76470827116 139 server.sendTo(client, counter, n);
dereklstinson 0:a76470827116 140 //send message
dereklstinson 0:a76470827116 141 } //end receive()
dereklstinson 0:a76470827116 142
dereklstinson 0:a76470827116 143 /***Alarm Check***************************************************************************/
dereklstinson 0:a76470827116 144 void alarmCheck(char x){
dereklstinson 0:a76470827116 145 pc.printf("\n\rInto alarm check\r\n");
dereklstinson 0:a76470827116 146 if (x == 'x') {
dereklstinson 0:a76470827116 147 alarmconfirm =0;
dereklstinson 0:a76470827116 148 waiting_answer=0;
dereklstinson 0:a76470827116 149 someflag=0;
dereklstinson 0:a76470827116 150 }
dereklstinson 0:a76470827116 151 if (x!='b') return;
dereklstinson 0:a76470827116 152 alarmLight();
dereklstinson 0:a76470827116 153 alarmSound();
dereklstinson 0:a76470827116 154
dereklstinson 0:a76470827116 155 }
dereklstinson 0:a76470827116 156
dereklstinson 0:a76470827116 157
dereklstinson 0:a76470827116 158
dereklstinson 0:a76470827116 159
dereklstinson 0:a76470827116 160 /**Alarm_Sound****************************************************************************/
dereklstinson 0:a76470827116 161
dereklstinson 0:a76470827116 162 void alarmSound(void){
dereklstinson 0:a76470827116 163
dereklstinson 0:a76470827116 164 if (i==0){
dereklstinson 0:a76470827116 165 wave_file=fopen("/sd/intuder_detected.wav","r");
dereklstinson 0:a76470827116 166 }
dereklstinson 0:a76470827116 167 else if (i==1){
dereklstinson 0:a76470827116 168 wave_file=fopen("/sd/alarm.wav","r");
dereklstinson 0:a76470827116 169 }
dereklstinson 0:a76470827116 170 else if(i==2){
dereklstinson 0:a76470827116 171 wave_file=fopen("/sd/20seconds.wav","r");
dereklstinson 0:a76470827116 172 }
dereklstinson 0:a76470827116 173 else if (i==3){
dereklstinson 0:a76470827116 174 wave_file=fopen("/sd/dangerous.wav","r");
dereklstinson 0:a76470827116 175 }
dereklstinson 0:a76470827116 176 else if (i==4){
dereklstinson 0:a76470827116 177 wave_file=fopen("/sd/searching.wav","r");
dereklstinson 0:a76470827116 178 }
dereklstinson 0:a76470827116 179 else if (i==5){
dereklstinson 0:a76470827116 180 wave_file=fopen("/sd/scanning.wav","r");
dereklstinson 0:a76470827116 181 }
dereklstinson 0:a76470827116 182
dereklstinson 0:a76470827116 183
dereklstinson 0:a76470827116 184 waver.play(wave_file);
dereklstinson 0:a76470827116 185 fclose(wave_file);
dereklstinson 0:a76470827116 186 i++;
dereklstinson 0:a76470827116 187 if(i>=6){
dereklstinson 0:a76470827116 188 i=0;
dereklstinson 0:a76470827116 189 }
dereklstinson 0:a76470827116 190 }
dereklstinson 0:a76470827116 191
dereklstinson 0:a76470827116 192
dereklstinson 0:a76470827116 193 /**Alarm_lights**************************************************************************/
dereklstinson 0:a76470827116 194 void alarmLight(void){
dereklstinson 0:a76470827116 195
dereklstinson 0:a76470827116 196 someflag = 1;
dereklstinson 0:a76470827116 197 wait(0.1f);
dereklstinson 0:a76470827116 198 }
dereklstinson 0:a76470827116 199
dereklstinson 0:a76470827116 200 /***lidarSweep****************************************************************************/
dereklstinson 0:a76470827116 201 int sensoralarmcheck(void){
dereklstinson 0:a76470827116 202 if (alarmcheckpin){
dereklstinson 0:a76470827116 203 alarmLight();
dereklstinson 0:a76470827116 204 alarmSound();
dereklstinson 0:a76470827116 205 return 1;
dereklstinson 0:a76470827116 206 }
dereklstinson 0:a76470827116 207 return 0;
dereklstinson 0:a76470827116 208 }
dereklstinson 0:a76470827116 209 /*********************************************************************************MAIN***/
dereklstinson 0:a76470827116 210 int main(void)
dereklstinson 0:a76470827116 211 {
dereklstinson 0:a76470827116 212
dereklstinson 0:a76470827116 213 red = 1;
dereklstinson 0:a76470827116 214 green = 0; //server
dereklstinson 0:a76470827116 215
dereklstinson 0:a76470827116 216 init_usb(); //initialize the PC interface
dereklstinson 0:a76470827116 217 init_eth(); //initialize the Ethernet connection
dereklstinson 0:a76470827116 218 flashes.attach(&flashingstuff,.1);
dereklstinson 0:a76470827116 219
dereklstinson 0:a76470827116 220 while (true) //repeat forever
dereklstinson 0:a76470827116 221 {
dereklstinson 0:a76470827116 222
dereklstinson 0:a76470827116 223 receive(); //wait for message
dereklstinson 0:a76470827116 224
dereklstinson 0:a76470827116 225 }
dereklstinson 0:a76470827116 226
dereklstinson 0:a76470827116 227 } //end main()