Download NHK English news podcast automatically. XML Parser "spxml" is used. This application requires mpod mother board. See also http://mbed.org/users/geodenx/notebook/mpod/
Dependencies: BlinkLed HTTPClient EthernetInterface FatFileSystemCpp MSCFileSystem spxml mbed-rtos mbed
Fork of mpod_nhk_english by
Download NHK English news podcast automatically.
XML Parser "spxml" is used.
This application requires mpod mother board.
See also http://mbed.org/users/geodenx/notebook/mpod/
Diff: main.cpp
- Revision:
- 1:1637e625b21b
- Parent:
- 0:1855a008f28e
- Child:
- 2:0da3a4508b46
--- a/main.cpp Thu Aug 16 15:49:19 2012 +0000 +++ b/main.cpp Fri Aug 17 12:49:12 2012 +0000 @@ -28,16 +28,15 @@ printf("================================\n\n"); // FSUSB30 switches to HSD1 (mbed) - printf("USB host was switched to HSD1.\n"); - fsusb30s = 0; + printf("USB host was switched to HSD1(mbed).\n\n"); + fsusb30s = 0; // HSD1 // Network setup printf("Setup EtherNet with DHCP.\n"); eth.init(); //Use DHCP eth.connect(); - - // Obtain lastBuildDate + // Obtain original lastBuildDate const char* lastBuildDateOriginal; XMLDocument docOriginal; if(XML_SUCCESS != docOriginal.LoadFile(rssPath)) @@ -53,11 +52,11 @@ { lastBuildDateOriginal = lastBuildDateOriginalElement->GetText(); } - printf("lastBuildDate (original): %s\n", lastBuildDateOriginal); - - // RSS download and parse + // Download RSS GetFile(rssPath, rssUrl); + + // Obtain current lastBuildDate const char* lastBuildDateCurrent; XMLDocument docCurrent; if(XML_SUCCESS != docCurrent.LoadFile(rssPath)) @@ -73,9 +72,12 @@ { lastBuildDateCurrent = lastBuildDateCurrentElement->GetText(); } - printf("lastBuildDate (Current) : %s\n", lastBuildDateCurrent); + printf("\n"); + printf("lastBuildDate (original): %s\n", lastBuildDateOriginal); + printf("lastBuildDate (current) : %s\n", lastBuildDateCurrent); + // Download new MP3 if (strcmp(lastBuildDateOriginal, lastBuildDateCurrent) == 0) { printf("lastBuildDate (original) == lastBuildDate (current)\n"); @@ -91,24 +93,22 @@ } else { - const char* mp3Url; + printf("lastBuildDate (original) != lastBuildDate (current)\n"); XMLElement* enclosureElement = docCurrent.FirstChildElement("rss")->FirstChildElement("channel")->FirstChildElement("item")->FirstChildElement("enclosure"); if(NULL == enclosureElement) { - while(1){}; + printf("No \"enclosure\" element in RSS"); } else { - mp3Url = enclosureElement->Attribute( "url" ); + const char* mp3Url = enclosureElement->Attribute( "url" ); + GetFile(mp3Path, mp3Url); } - printf("mp3Url : %s\n", mp3Url); - GetFile(mp3Path, mp3Url); } - - // Switch USB host from mbed to KWD - printf("USB host was switched to HSD2.\n"); - fsusb30s = 1; // HSD2 (KWD) + // FSUSB30 switches to HSD2 (External Device) + printf("\nUSB host was switched to HSD2(External Device).\n"); + fsusb30s = 1; // HSD2 // blink LED led1.startBlink(); @@ -119,7 +119,7 @@ int GetFile(const char *path, const char *url) { HTTPFile file(path); - printf("Getting %s\n", url); + printf("\nGetting %s\n", url); timer.stop(); timer.reset(); @@ -127,6 +127,9 @@ HTTPResult retGet = http.get(url, &file); if (retGet != HTTP_OK) { + // FSUSB30 switches to HSD2 (External Device) + printf("USB host was switched to HSD2(External Device).\n"); + fsusb30s = 1; // HSD2 error("Error in http.get in GetFile(): %d\n", retGet); } file.clear();