demo project
Dependencies: AX-12A Dynamixel mbed iothub_client EthernetInterface NTPClient ConfigFile SDFileSystem iothub_amqp_transport mbed-rtos proton-c-mbed wolfSSL
main.cpp
- Committer:
- henryrawas
- Date:
- 2015-12-29
- Revision:
- 7:6723f6887d00
- Parent:
- 5:36916b1c5a06
- Child:
- 8:d98e2dec0f40
File content as of revision 7:6723f6887d00:
#include "mbed.h" #include "rtos.h" #include "EthernetInterface.h" #include "mbed/logging.h" #include "mbed/mbedtime.h" #include <NTPClient.h> #include <Terminal.h> using namespace std; DigitalOut myled(LED_GREEN); Terminal pc(USBTX, USBRX); extern void RunController(); extern bool StartIothubThread(); int setupRealTime(void) { int result; (void)printf("setupRealTime begin\r\n"); if (EthernetInterface::connect()) { (void)printf("Error initializing EthernetInterface.\r\n"); result = __LINE__; } else { (void)printf("setupRealTime NTP begin\r\n"); NTPClient ntp; if (ntp.setTime("0.pool.ntp.org") != 0) { (void)printf("Failed setting time.\r\n"); result = __LINE__; } else { (void)printf("set time correctly!\r\n"); result = 0; } (void)printf("setupRealTime NTP end\r\n"); EthernetInterface::disconnect(); } (void)printf("setupRealTime end\r\n"); return result; } int InitEthernet() { (void)printf("Initializing mbed specific things...\r\n"); /* These are needed in order to initialize the time provider for Proton-C */ mbed_log_init(); mbedtime_init(); if (EthernetInterface::init()) { (void)printf("Error initializing EthernetInterface.\r\n"); return -1; } if (setupRealTime() != 0) { (void)printf("Failed setting up real time clock\r\n"); return -1; } if (EthernetInterface::connect()) { (void)printf("Error connecting EthernetInterface.\r\n"); return -1; } return 0; } int main() { pc.baud(115200); pc.cls(); pc.foreground(Yellow); pc.background(Black); pc.locate( 0, 0 ); pc.printf("**********************\r\n"); pc.printf("RobotArmDemo start\r\n"); pc.printf("**********************\r\n"); pc.foreground(Teal); pc.background(Black); InitEthernet(); // start IotHub connection StartIothubThread(); // time delay is to allow the position encoders to come online after initial power supply event ~ 5 secs // and to allow IoTHub SSL connection established // TODO: test for connection established Thread::wait(15000); pc.printf( "Initialization done. Ready to run. \r\n"); RunController(); }