The MCR20A Wireless UART application functions as an wireless UART bridge between two (one-to-one) or several (one to many) boards. The application can be used with both a TERM, or with software that is capable of opening a serial port and writing to or reading from it. The characters sent or received are not necessarily ASCII printable characters.

Dependencies:   fsl_phy_mcr20a fsl_smac mbed-rtos mbed

Fork of mcr20_wireless_uart by Freescale

By default, the application uses broadcast addresses for OTA communication. This way, the application can be directly downloaded and run without any user intervention. The following use case assumes no changes have been done to the project.

  • Two (or more) MCR20A platforms (plugged into the FRDM-K64F Freescale Freedom Development platform) have to be connected to the PC using the mini/micro-USB cables.
  • The code must be downloaded on the platforms via CMSIS-DAP (or other means).
  • After that, two or more TERM applications must be opened, and the serial ports must be configured with the same baud rate as the one in the project (default baud rate is 115200). Other necessary serial configurations are 8 bit, no parity, and 1 stop bit.
  • To start the setup, each platform must be reset, and one of the (user) push buttons found on the MCR20A platform must be pressed. The user can press any of the non-reset buttons on the FRDM-K64F Freescale Freedom Development platform as well. *This initiates the state machine of the application so user can start.

Documentation

SMAC Demo Applications User Guide

Revision:
3:a38ad504a18c
Parent:
2:3e7685cfb2a7
Child:
15:990a8b5664e1
--- a/main.cpp	Thu Mar 05 15:47:08 2015 +0000
+++ b/main.cpp	Thu Mar 05 16:37:54 2015 +0000
@@ -1,7 +1,6 @@
 #include "mbed.h"
 
 #include "driverDebug.h"
-
 #include "socket_api.h"
 #include "net_interface.h"
 #include "system_event.h"
@@ -16,19 +15,11 @@
 #include "common_functions.h"
 #include "driverRFPhy.h"
 #include "driverAtmelRFInterface.h"
-
 #include "nsdl_support.h"
 #include "node_cfg.h"
 
-#if NODE_SENSOR_STATION
-//  #include "DHT.h"
-  #include "BMP085.h"
-#endif
-
-
 /*** DEBUG ******/
 #define DEBUG       1
-
 #if DEBUG
 #define debug   printf
 #else
@@ -43,22 +34,6 @@
   InterruptIn TAP_INT(PTC6);  // INT1 from FXOS8700Q
 #endif
 
-#if NODE_HOME
-DigitalOut  light(D2);
-DigitalOut  fire(D3);
-DigitalOut  fan(D4);
-InterruptIn motion(D6);
-DigitalIn door(D8);
-#endif
-
-#if NODE_SENSOR_STATION
-//DHT sensor(D2, DHT11);
-BMP085 barometer(D14, D15);
-AnalogIn moisture(A0);
-AnalogIn HCHO(A1);
-AnalogIn UVsensor(A2);
-#endif
-
 /*******  Timers Definitions   ************/
 #define RETRY_TIMER             1
 #define NSP_REGISTRATION_TIMER  2
@@ -69,17 +44,14 @@
   #define DOOR_CHECK_TIMER        4
 #endif
 
-
 void app_heap_error_handler(heap_fail_t event);
 void tasklet_main(arm_event_s *event);
 void button_main(arm_event_s *event);
 
-
 #define APP_DEV_HEAP_SIZE 6000
 static uint8_t app_defined_stack_heap[APP_DEV_HEAP_SIZE];
 static int8_t main_tasklet_id = -1;
 
-
 static const uint8_t app_MAC_address[8] = NODE_MAC_ADDRESS;
 static int8_t rf_phy_device_register_id = -1;
 static int8_t net_6lowpan_id = -1;
@@ -87,12 +59,12 @@
 
 int8_t coap_udp_socket = -1;
 
-#define AUDP_SOCKET_PORT    61630
+#define AUDP_SOCKET_PORT     61630
 #define RECV_CTRL_UDP_PORT   1050    // receive
 #define SEND_CTRL_UDP_PORT   1060    // send
 
 /** Used for Receive Data source Address store*/
-static  ns_address_t app_src;
+static ns_address_t app_src;
 static sn_nsdl_addr_s sn_addr_s;
 
 static int access_point_status = 0;
@@ -116,19 +88,6 @@
 
 
 /* #defines, definitions and declarations according node profile  */
-#if NODE_HOME
-#define DOOR_CHECK_TIME     1000
-uint8_t door_last_state = 0;
-/* Since the PIR Motion detector throws a (false) trigger everytime the
-other sensors/actuators change (possibly an interference), we will need
-to disable it for 1s. So every time the sensors/actuators change, we set a variable
-which is reset in the DOOR_CHECK_TIMER. This variable needs to be cleared to
-consider a real motion detection */
-uint8_t motion_disable = 0;         
-int8_t ctrl_udp_socket = -1;
-void ctrl_udp_receive(void * cb);
-void ctrl_udp_send(uint8_t cmd);
-#endif
 
 #if NODE_CONTROLLER
 int8_t ctrl_udp_socket = -1;
@@ -362,20 +321,6 @@
 }
 #endif
 
-#if NODE_HOME
-void motion_handler(void)
-{
-  if (motion_disable)
-    return;
-  printf("***************Motion Detected!**********************\r\n");
-  if (door)
-    ctrl_udp_send('O');
-  else
-    ctrl_udp_send('C');
-}
-#endif
-
-
 int main()
 {
 #if NODE_CONTROLLER      
@@ -385,11 +330,6 @@
   TAP_INT.rise(&tap_detector_handler); 
 #endif
  
-#if NODE_HOME  
-  light = 0;
-  motion.rise(&motion_handler);
-#endif
-     
   debug("\r\nApplication Start\r\n");
   ns_dyn_mem_init(app_defined_stack_heap, APP_DEV_HEAP_SIZE, app_heap_error_handler,0);
   rf_set_mac_address(app_MAC_address);
@@ -594,13 +534,6 @@
         timer_sys_event(ACCELEROMETER_TIMER, ACCEL_SAMPLE_TIME);
 #endif  
         multicast_set_parameters(10,0,20,3,75 );
-                                       
-#if NODE_HOME
-        /* open a socket to support control from NODE_CONTROLLER */                                             
-        ctrl_udp_socket = socket_open(SOCKET_UDP, RECV_CTRL_UDP_PORT, ctrl_udp_receive);
-        /* init a timer to check door state  */
-        timer_sys_event(DOOR_CHECK_TIMER, DOOR_CHECK_TIME);
-#endif
 
 #if NODE_CONTROLLER
         /* open a socket to support control for REMOTE_NODE */                                             
@@ -693,19 +626,7 @@
           timer_sys_event(ACCELEROMETER_TIMER, ACCEL_SAMPLE_TIME);   
         }    
 #endif  
-#if NODE_HOME        
-        else if (event->event_id == DOOR_CHECK_TIMER)
-        {
-          uint8_t door_state = door.read();
-          if (door_state != door_last_state) 
-          {
-            door_last_state = door_state;
-            printf("Door state %d\r\n", door_state);
-          }            
-          motion_disable = 0;
-          timer_sys_event(DOOR_CHECK_TIMER, DOOR_CHECK_TIME);   
-        }    
-#endif       
+
         break;
                                 
       default:
@@ -773,112 +694,6 @@
 #endif   
 }
 
-#if NODE_HOME
-/******  Control UDP Socket Receive  *******/
-void ctrl_udp_receive(void * cb)
-{
-  socket_callback_t * cb_res =0;
-  int16_t length;
-  cb_res = (socket_callback_t *) cb;
-
-  if(cb_res->event_type == SOCKET_DATA)
-  {
-    uint8_t *payload = 0;
-    /*Read Data*/
-    if ( cb_res->d_len > 0)
-    {
-      /*Read data to the RX buffer*/
-      payload = (uint8_t *) ns_dyn_mem_alloc(cb_res->d_len);
-      if(payload)
-      {
-        /*Read data to the RX buffer*/
-        length = socket_read(cb_res->socket_id, &app_src, payload, cb_res->d_len);
-        if(length)
-        {
-          uint8_t * ptr = payload ;
-          /*Handles data received in UDP socket*/
-          debug("UDP Data From: ");
-          printf_ipv6_address(&(app_src.address[0]));        //REVIEW
-          
-          if(app_src.identifier == SEND_CTRL_UDP_PORT)       // check source port to avoid interference
-          {
-            debug("Data: ");
-            printf("%s\r\n",ptr);     
-            switch(payload[0]) {
-              case 'R':
-                fire = !fire;
-                fan = 0;
-                break;    
-              case 'G':
-                light = !light; 
-                break;              
-              case 'B':
-                fan = !fan;
-                fire = 0; 
-                break;              
-            } 
-            motion_disable = 1;
-          }  
-        }
-        ns_dyn_mem_free(payload);
-      }
-    }
-    else
-    {
-      debug("No Data\r\n");
-      socket_read(cb_res->socket_id, &app_src, NULL, 0);
-    }
-  }
-  else if(cb_res->event_type == SOCKET_TX_DONE)
-  {
-    debug("UDP TX Done\r\n");
-  }
-  /* No Route to Packet Destination Address */
-  else if(cb_res->event_type == SOCKET_NO_ROUTE) 
-  {
-    debug("ND/RPL not ready\r\n");
-  }
-  /* Link Layer TX Fail for socket packet */
-  else if(cb_res->event_type == SOCKET_TX_FAIL)
-  {
-    debug("Link Layer Tx fail\r\n");
-  }
-}
-
-void ctrl_udp_send(uint8_t cmd)
-{
-  uint8_t * payload = 0;
-  ns_address_t address;
-  /*SET UDP echo Port*/
-  address.identifier = ALARM_CTRL_UDP_PORT;  
-
-  uint8_t node_address[16] = ALARM_IP_ADDRESS;       
-    
-  payload = (uint8_t *) ns_dyn_mem_alloc(1);        
-  if(payload)
-  {
-    uint8_t *ptr = payload;
-     
-    memcpy(address.address,node_address,16); 
-    address.type = ADDRESS_IPV6;
-    *ptr = cmd;
-    if(socket_sendto(ctrl_udp_socket, &address, payload, (1)) != 0)
-    {
-      debug("Ctrl UDP Failed\r\n");
-    }
-    else
-    {
-      debug("Ctrl UDP Ok\r\n");
-    }
-    ns_dyn_mem_free(payload);
-  }
-  else
-  {
-    debug("No Heap for Ctrl UDP\r\n");
-  }
-}
-#endif
-
 #if NODE_CONTROLLER 
 void ctrl_udp_send(uint8_t cmd)
 {