MBED code for Xbee unit running on chase car

Dependencies:   CUER_CAN XBeeLib mbed

Committer:
ItsJustZi
Date:
Tue Sep 26 12:09:13 2017 +0000
Revision:
15:6e5910216c39
Parent:
13:a6f0f8990842
Attempt to increase frequency of CAN packets sent to CANAlyzer by increasing time between xbee callbacks which are blocking functions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hbujanda 5:b4cf3c26e2ec 1 /**
hbujanda 5:b4cf3c26e2ec 2 * Copyright (c) 2015 Digi International Inc.,
hbujanda 5:b4cf3c26e2ec 3 * All rights not expressly granted are reserved.
hbujanda 5:b4cf3c26e2ec 4 *
hbujanda 5:b4cf3c26e2ec 5 * This Source Code Form is subject to the terms of the Mozilla Public
hbujanda 5:b4cf3c26e2ec 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
hbujanda 5:b4cf3c26e2ec 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
hbujanda 5:b4cf3c26e2ec 8 *
hbujanda 5:b4cf3c26e2ec 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
hbujanda 5:b4cf3c26e2ec 10 * =======================================================================
hbujanda 5:b4cf3c26e2ec 11 */
hbujanda 5:b4cf3c26e2ec 12
hbujanda 5:b4cf3c26e2ec 13 #include "mbed.h"
hbujanda 5:b4cf3c26e2ec 14 #include "XBeeLib.h"
ItsJustZi 12:c492d4bc45cd 15 #include "CAN_Parser_Telemetry.h"
hbujanda 5:b4cf3c26e2ec 16 #if defined(ENABLE_LOGGING)
hbujanda 5:b4cf3c26e2ec 17 #include "DigiLoggerMbedSerial.h"
hbujanda 5:b4cf3c26e2ec 18 using namespace DigiLog;
ItsJustZi 12:c492d4bc45cd 19 using namespace CAN_IDs;
hbujanda 5:b4cf3c26e2ec 20 #endif
hbujanda 5:b4cf3c26e2ec 21
ItsJustZi 15:6e5910216c39 22 #define DEBUG 0
ItsJustZi 12:c492d4bc45cd 23
hbujanda 5:b4cf3c26e2ec 24 using namespace XBeeLib;
hbujanda 5:b4cf3c26e2ec 25
hbujanda 5:b4cf3c26e2ec 26 Serial *log_serial;
ItsJustZi 11:c10bc0fb801a 27
hbujanda 5:b4cf3c26e2ec 28 static void receive_cb(const RemoteXBee802& remote, bool broadcast, const uint8_t *const data, uint16_t len)
hbujanda 5:b4cf3c26e2ec 29 {
ItsJustZi 12:c492d4bc45cd 30 /*if (remote.is_valid_addr16b()) {
hbujanda 5:b4cf3c26e2ec 31 log_serial->printf("\r\nGot a %s 16-bit RX packet [%04x], len %d\r\nData: ", broadcast ? "BROADCAST" : "UNICAST", remote.get_addr16(), len);
hbujanda 5:b4cf3c26e2ec 32 } else {
hbujanda 5:b4cf3c26e2ec 33 log_serial->printf("\r\nGot a %s 64-bit RX packet [%08x:%08x], len %d\r\nData: ", broadcast ? "BROADCAST" : "UNICAST", remote.get_addr64(), len);
hbujanda 5:b4cf3c26e2ec 34 }
hbujanda 5:b4cf3c26e2ec 35
hbujanda 5:b4cf3c26e2ec 36 for (int i = 0; i < len; i++)
ItsJustZi 11:c10bc0fb801a 37 log_serial->printf("%02x", data[i]);
hbujanda 5:b4cf3c26e2ec 38
ItsJustZi 12:c492d4bc45cd 39 log_serial->printf("\r\n");*/
ItsJustZi 12:c492d4bc45cd 40 if (DEBUG) log_serial->printf("Incoming Xbee packet received! \r\n");
ItsJustZi 12:c492d4bc45cd 41
ItsJustZi 12:c492d4bc45cd 42 can_send(generateCANPackets(data));
ItsJustZi 12:c492d4bc45cd 43 if (DEBUG) log_serial->printf("\r\n");
hbujanda 5:b4cf3c26e2ec 44 }
hbujanda 5:b4cf3c26e2ec 45
spastor 7:2e6ea668bc9e 46 int main()
hbujanda 5:b4cf3c26e2ec 47 {
DasSidG 13:a6f0f8990842 48 CAN_Init();
DasSidG 13:a6f0f8990842 49
hbujanda 5:b4cf3c26e2ec 50 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 5:b4cf3c26e2ec 51 log_serial->baud(9600);
hbujanda 5:b4cf3c26e2ec 52 log_serial->printf("Sample application to demo how to receive unicast and broadcast data with the XBee802\r\n\r\n");
hbujanda 5:b4cf3c26e2ec 53 log_serial->printf(XB_LIB_BANNER);
hbujanda 5:b4cf3c26e2ec 54
hbujanda 5:b4cf3c26e2ec 55 #if defined(ENABLE_LOGGING)
hbujanda 5:b4cf3c26e2ec 56 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 5:b4cf3c26e2ec 57 #endif
hbujanda 5:b4cf3c26e2ec 58
hbujanda 5:b4cf3c26e2ec 59 XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 5:b4cf3c26e2ec 60
hbujanda 5:b4cf3c26e2ec 61 /* Register callback */
hbujanda 5:b4cf3c26e2ec 62 xbee.register_receive_cb(&receive_cb);
hbujanda 5:b4cf3c26e2ec 63
hbujanda 5:b4cf3c26e2ec 64 RadioStatus const radioStatus = xbee.init();
hbujanda 5:b4cf3c26e2ec 65 MBED_ASSERT(radioStatus == Success);
hbujanda 5:b4cf3c26e2ec 66
hbujanda 5:b4cf3c26e2ec 67 while (true) {
hbujanda 5:b4cf3c26e2ec 68 xbee.process_rx_frames();
ItsJustZi 15:6e5910216c39 69 wait_ms(1000);
ItsJustZi 12:c492d4bc45cd 70 if (DEBUG) log_serial->printf(".");
hbujanda 5:b4cf3c26e2ec 71 }
hbujanda 5:b4cf3c26e2ec 72
hbujanda 5:b4cf3c26e2ec 73 delete(log_serial);
hbujanda 5:b4cf3c26e2ec 74 }