first commit
Dependencies: C12832_lcd DigiLogger XBeeLib mbed
Fork of XBee802_Receive_Data by
Revision 11:733adf81a578, committed 2016-12-16
- Comitter:
- kingkingyyk
- Date:
- Fri Dec 16 02:58:01 2016 +0000
- Parent:
- 10:b9dc1600c409
- Commit message:
- first commit
Changed in this revision
diff -r b9dc1600c409 -r 733adf81a578 C12832_lcd.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Fri Dec 16 02:58:01 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
diff -r b9dc1600c409 -r 733adf81a578 DigiLogger.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DigiLogger.lib Fri Dec 16 02:58:01 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Digi-International-Inc/code/DigiLogger/#58c5158b5120
diff -r b9dc1600c409 -r 733adf81a578 XBeeLib.lib --- a/XBeeLib.lib Fri Jul 29 12:11:23 2016 +0200 +++ b/XBeeLib.lib Fri Dec 16 02:58:01 2016 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/Digi-International-Inc/code/XBeeLib/#b5f4a0e92249 +https://developer.mbed.org/users/kingkingyyk/code/XBeeLib/#1da9c7e7e057
diff -r b9dc1600c409 -r 733adf81a578 config.h --- a/config.h Fri Jul 29 12:11:23 2016 +0200 +++ b/config.h Fri Dec 16 02:58:01 2016 +0000 @@ -14,22 +14,22 @@ #define __CONFIG_H_ /** Library configuration options */ -#define ENABLE_LOGGING +//#define ENABLE_LOGGING #define ENABLE_ASSERTIONS #define FRAME_BUFFER_SIZE 4 #define MAX_FRAME_PAYLOAD_LEN 128 #define SYNC_OPS_TIMEOUT_MS 2000 -//#define RADIO_TX NC /* TODO: specify your setup's Serial TX pin connected to the XBee module DIN pin */ -//#define RADIO_RX NC /* TODO: specify your setup's Serial RX pin connected to the XBee module DOUT pin */ +#define RADIO_TX p9 /* TODO: specify your setup's Serial TX pin connected to the XBee module DIN pin */ +#define RADIO_RX p10 /* TODO: specify your setup's Serial RX pin connected to the XBee module DOUT pin */ //#define RADIO_RTS NC /* TODO: specify your setup's Serial RTS# pin connected to the XBee module RTS# pin */ //#define RADIO_CTS NC /* TODO: specify your setup's Serial CTS# pin connected to the XBee module CTS# pin */ -//#define RADIO_RESET NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's reset pin */ +#define RADIO_RESET p30 /* TODO: specify your setup's GPIO (output) connected to the XBee module's reset pin */ //#define RADIO_SLEEP_REQ NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's SLEEP_RQ pin */ //#define RADIO_ON_SLEEP NC /* TODO: specify your setup's GPIO (input) connected to the XBee module's ON_SLEEP pin */ -//#define DEBUG_TX NC /* TODO: specify your setup's Serial TX for debugging */ -//#define DEBUG_RX NC /* TODO: specify your setup's Serial RX for debugging (optional) */ +#define DEBUG_TX USBTX /* TODO: specify your setup's Serial TX for debugging */ +#define DEBUG_RX USBRX /* TODO: specify your setup's Serial RX for debugging (optional) */ #if !defined(RADIO_TX) #error "Please define RADIO_TX pin"
diff -r b9dc1600c409 -r 733adf81a578 main.cpp --- a/main.cpp Fri Jul 29 12:11:23 2016 +0200 +++ b/main.cpp Fri Dec 16 02:58:01 2016 +0000 @@ -11,54 +11,88 @@ */ #include "mbed.h" +#include "string" #include "XBeeLib.h" -#if defined(ENABLE_LOGGING) -#include "DigiLoggerMbedSerial.h" -using namespace DigiLog; -#endif +#include "C12832_lcd.h" using namespace XBeeLib; -Serial *log_serial; +#define END_NODE ((uint16_t)0x0) +const char *field_delimiter=";"; +const char *controller_name="Toilet_Control"; +const char *procCommand_ON="ON"; +const char *procCommand_OFF="OFF"; +XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); +DigitalOut led[]={(LED1),(LED2),(LED3)}; +DigitalOut fan(p13); +char send_data [98]; +C12832_LCD lcd; + +const RemoteXBee802 remoteDevice16b = RemoteXBee802(END_NODE); + +void clear_send_data() { + for (int i=0;i<98;i++) send_data[i]=0; +} + +int calculate_send_data_size() { + for (int i=0;i<98;i++) if (send_data[i]==0) return i; + return 98; +} + +const char fan_status_format []="2;Toilet_Control;ToiletWater;%s"; +void send_fan_status (const RemoteXBee802& remote, const char* value) { + snprintf(send_data,98,fan_status_format,value); + + xbee.send_data(remote,(const uint8_t *)send_data,calculate_send_data_size()); + clear_send_data(); +} static void receive_cb(const RemoteXBee802& remote, bool broadcast, const uint8_t *const data, uint16_t len) -{ - if (remote.is_valid_addr16b()) { - log_serial->printf("\r\nGot a %s 16-bit RX packet [%04x], len %d\r\nData: ", broadcast ? "BROADCAST" : "UNICAST", remote.get_addr16(), len); - } else { - log_serial->printf("\r\nGot a %s 64-bit RX packet [%08x:%08x], len %d\r\nData: ", broadcast ? "BROADCAST" : "UNICAST", remote.get_addr64(), len); +{ + led[1]=1; + char* read_data = new char [len]; + for (int i = 0; i < len; i++) + read_data[i]=data[i]; + lcd.cls(); + lcd.printf("%s",read_data); + + string tempCmd (strtok(read_data,field_delimiter)); + string commandId = tempCmd.substr(tempCmd.length()-1,tempCmd.length()); + string ctrl (strtok(NULL,field_delimiter)); + string act (strtok(NULL,field_delimiter)); + string status (strtok(NULL,field_delimiter)); + + if (!ctrl.find(controller_name)) { + if (!commandId.compare("1")) { + if (!act.compare("ToiletWater")) { + int statusInt=(status.find(procCommand_ON) != std::string::npos); + fan=statusInt; + led[2]=statusInt; + + if (statusInt) send_fan_status(remote,procCommand_ON); + else send_fan_status(remote,procCommand_OFF); + } + } } - - for (int i = 0; i < len; i++) - log_serial->printf("%02x ", data[i]); - - log_serial->printf("\r\n"); + + led[1]=0; } int main() { - log_serial = new Serial(DEBUG_TX, DEBUG_RX); - log_serial->baud(9600); - log_serial->printf("Sample application to demo how to receive unicast and broadcast data with the XBee802\r\n\r\n"); - log_serial->printf(XB_LIB_BANNER); - -#if defined(ENABLE_LOGGING) - new DigiLoggerMbedSerial(log_serial, LogLevelInfo); -#endif - - XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); - - /* Register callback */ + send_fan_status(remoteDevice16b,"ON"); xbee.register_receive_cb(&receive_cb); RadioStatus const radioStatus = xbee.init(); MBED_ASSERT(radioStatus == Success); - + + led[0]=1; + lcd.printf("Ready"); + + fan=1; + led[2]=1; while (true) { xbee.process_rx_frames(); wait_ms(100); - log_serial->printf("."); } - - delete(log_serial); }
diff -r b9dc1600c409 -r 733adf81a578 mbed.bld --- a/mbed.bld Fri Jul 29 12:11:23 2016 +0200 +++ b/mbed.bld Fri Dec 16 02:58:01 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf \ No newline at end of file