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 Satoshi Togawa

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/

Files at this revision

API Documentation at this revision

Comitter:
togayan
Date:
Sun Aug 19 15:57:55 2012 +0000
Parent:
2:0da3a4508b46
Child:
4:7dae52cf560f
Commit message:
Remove iostream and Use printf().; Change the BlinkLed class.

Changed in this revision

BlinkLed.cpp Show annotated file Show diff for this revision Revisions of this file
BlinkLed.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/BlinkLed.cpp	Sat Aug 18 16:46:40 2012 +0000
+++ b/BlinkLed.cpp	Sun Aug 19 15:57:55 2012 +0000
@@ -1,8 +1,8 @@
 #include "BlinkLed.h"
     
-BlinkLed::BlinkLed(PinName pin, uint32_t millisecWait, const char* name) :
+BlinkLed::BlinkLed(PinName pin, float dutyChangeStep, const char* name) :
 led(pin, name),
-millisecWait(millisecWait),
+dutyChangeStep(dutyChangeStep),
 thread(0)
 {
 }
@@ -48,14 +48,15 @@
         } else {
             error("LED PWM error\n");
         }
-
+        
+        float dutyChangeStep = blinkLed->dutyChangeStep;
         if (up == 1) {
-            brightness += 0.01;
+            brightness += dutyChangeStep;
         } else {
-            brightness -= 0.01;
+            brightness -= dutyChangeStep;
         }
         blinkLed->led = brightness;
         
-        Thread::wait(blinkLed->millisecWait);
+        Thread::wait(20);
     }
 }
--- a/BlinkLed.h	Sat Aug 18 16:46:40 2012 +0000
+++ b/BlinkLed.h	Sun Aug 19 15:57:55 2012 +0000
@@ -1,59 +1,59 @@
-/* BlinkLed.h */
-#ifndef BLINKLED_H_
-#define BLINKLED_H_
-
-#include "mbed.h"
-#include "rtos.h"
-
-/** LED which blinks automatically with RTOS
-*/
-class BlinkLed
-{
-public:
-    /** Constructor
-     */
-    BlinkLed(PinName pin, uint32_t millisecWait, const char* name = NULL);
-    
-    /** Destructor
-     */
-    ~BlinkLed();
-    
-    /** Start biinking
-     */
-    void startBlink();
-    
-    /** Finish biinking
-     */
-    void finishBlink();
-      
-private:
-    /** Copy constructor
-     *  Disable because it is only declaration
-     */
-    BlinkLed(const BlinkLed&);
-    
-    /** Copy assignment operators
-     *  Disable because it is only declaration
-     */
-    BlinkLed& operator=(const BlinkLed&);
-    
-    /** Function for blinking
-     *  This function will be bind to new thread
-     */
-    static void blink(void const *argument);
-    
-    /** Target Led
-     */
-    PwmOut led;
-    
-    /** Waiting time for making the cycle to change brightness
-     */
-    uint32_t millisecWait;
-    
-    /** Pointer to thread for blinking
-     */
-    Thread* thread;
-};
-
-
-#endif /* BLINKLED_H_ */
+/* BlinkLed.h */
+#ifndef BLINKLED_H_
+#define BLINKLED_H_
+
+#include "mbed.h"
+#include "rtos.h"
+
+/** LED which blinks automatically with RTOS
+*/
+class BlinkLed
+{
+public:
+    /** Constructor
+     */
+    BlinkLed(PinName pin, float dutyChangeStep, const char* name = NULL);
+    
+    /** Destructor
+     */
+    ~BlinkLed();
+    
+    /** Start biinking
+     */
+    void startBlink();
+    
+    /** Finish biinking
+     */
+    void finishBlink();
+      
+private:
+    /** Copy constructor
+     *  Disable because it is only declaration
+     */
+    BlinkLed(const BlinkLed&);
+    
+    /** Copy assignment operators
+     *  Disable because it is only declaration
+     */
+    BlinkLed& operator=(const BlinkLed&);
+    
+    /** Function for blinking
+     *  This function will be bind to new thread
+     */
+    static void blink(void const *argument);
+    
+    /** Target Led
+     */
+    PwmOut led;
+    
+    /** Duty ratio step of changing every 20ms
+     */
+    float dutyChangeStep;
+    
+    /** Pointer to thread for blinking
+     */
+    Thread* thread;
+};
+
+
+#endif /* BLINKLED_H_ */
--- a/main.cpp	Sat Aug 18 16:46:40 2012 +0000
+++ b/main.cpp	Sun Aug 19 15:57:55 2012 +0000
@@ -5,12 +5,7 @@
 #include "HTTPFile.h"
 #include "BlinkLed.h"
 #include "tinyxml2.h"
-#include <string>
-#include <iostream>
 
-using std::string;
-using std::cout;
-using std::endl;
 using namespace tinyxml2;
 
 int GetFile(const char *path, const char *url);
@@ -18,8 +13,10 @@
 EthernetInterface eth;
 HTTPClient http;
 MSCFileSystem usb("usb");
-BlinkLed led1(LED1, 6);
-BlinkLed led2(LED2, 1);
+BlinkLed led1(LED1, 0.02);
+BlinkLed led2(LED2, 0.2);
+BlinkLed ethGreen(p26, 0.02);
+BlinkLed ethYellow(p25, 0.2);
 DigitalOut fsusb30s(p9);
 Timer timer;
 
@@ -43,35 +40,35 @@
     eth.connect();
     
     // Obtain original lastBuildDate
-    string lastBuildDateOriginal;
+    char lastBuildDateOriginal[128] = {0};
     {
         XMLDocument docOriginal;
         if(XML_SUCCESS != docOriginal.LoadFile(rssPath))
         {
-            lastBuildDateOriginal = "No original english.xml in USB memory";
+            strcpy(lastBuildDateOriginal, "No original english.xml in USB memory");
         }
         else
         {
             XMLElement* lastBuildDateOriginalElement = docOriginal.FirstChildElement("rss")->FirstChildElement("channel")->FirstChildElement("lastBuildDate");
             if(NULL == lastBuildDateOriginalElement)
             {
-                lastBuildDateOriginal = "No \"lastBuildDate\" element in original RSS";
+                strcpy(lastBuildDateOriginal, "No \"lastBuildDate\" element in original RSS");
             }
             else
             {
-                lastBuildDateOriginal = lastBuildDateOriginalElement->GetText();
+                strcpy(lastBuildDateOriginal, lastBuildDateOriginalElement->GetText());
             }
         }
     }
-    cout << endl << "lastBuildDate (original): " << lastBuildDateOriginal << endl;
+    printf("\nlastBuildDate (original): %s\n", lastBuildDateOriginal);
     
     // Download RSS
     GetFile(rssPath, rssUrl);
     
     // Obtain current lastBuildDate 
-    string lastBuildDateCurrent;
-    string mp3Url;
-    string mp3Length;
+    char lastBuildDateCurrent[128] = {0};
+    char mp3Url[256] = {0};
+    char mp3Length[32] = {0};
     {
         XMLDocument docCurrent;
         if(XML_SUCCESS != docCurrent.LoadFile(rssPath))
@@ -86,7 +83,7 @@
             fsusb30s = 1; // HSD2
             error("No \"lastBuildDate\" element in current RSS.\n");
         }
-        lastBuildDateCurrent = lastBuildDateCurrentElement->GetText();
+        strcpy(lastBuildDateCurrent, lastBuildDateCurrentElement->GetText());
         
         XMLElement* enclosureElement = docCurrent.FirstChildElement("rss")->FirstChildElement("channel")->FirstChildElement("item")->FirstChildElement("enclosure");
         if(NULL == enclosureElement)
@@ -94,54 +91,55 @@
             fsusb30s = 1; // HSD2
             error("No \"enclosure\" element in current RSS.\n");
         }
-        mp3Url = enclosureElement->Attribute( "url" );
-        mp3Length = enclosureElement->Attribute( "length" );
+        strcpy(mp3Url, enclosureElement->Attribute("url"));
+        strcpy(mp3Length, enclosureElement->Attribute("length"));
     }
-    cout << endl << "lastBuildDate (current) : " << lastBuildDateCurrent << endl;
+    printf("\nlastBuildDate (current) : %s\n", lastBuildDateCurrent);
     
     // Determine the necessity of downloading new MP3.
     bool flgDownloadMp3 = false;
-    if (lastBuildDateOriginal == lastBuildDateCurrent)
+    if ( strcmp(lastBuildDateOriginal, lastBuildDateCurrent) == 0 )
     {
-        cout << "lastBuildDate (original) == lastBuildDate (current)" << endl;
+        printf("lastBuildDate (original) == lastBuildDate (current)\n");
         FILE* mp3fp = fopen(mp3Path, "r"); // check an existance of english.mp3
         if (mp3fp != NULL)
         {
             fseek(mp3fp, 0, SEEK_END); // seek to end of file
-            if (ftell(mp3fp) != atol(mp3Length.c_str()))
+            if (ftell(mp3fp) != atol(mp3Length))
             {
-                cout << "MP3 file size is invalid." << endl;
+                printf("MP3 file size is invalid.\n");
                 flgDownloadMp3 = true;
             }
             fclose(mp3fp);
         }
         else
         {
-            cout << "However, no enlish.mp3 in USB memory" << endl;
+            printf("However, no enlish.mp3 in USB memory\n");
             flgDownloadMp3 = true;
         }
     }
     else
     {
-        cout << "lastBuildDate (original) != lastBuildDate (current)" << endl;
+        printf("lastBuildDate (original) != lastBuildDate (current)\n");
         flgDownloadMp3 = true;
     }
     
     // Download new MP3
     if(flgDownloadMp3 == true)
     {
-        GetFile(mp3Path, mp3Url.c_str());
+        GetFile(mp3Path, mp3Url);
     }
     
     // Wait for the completion of writing to USB Mass Storage Device.
     wait(1);
     
     // FSUSB30 switches to HSD2 (External Device)
-    cout << endl << "USB host was switched to HSD2(External Device)." << endl;
+    printf("\nUSB host was switched to HSD2(External Device).\n");
     fsusb30s = 1; // HSD2
 
     // blink LED
     led1.startBlink();
+    ethGreen.startBlink();
     
     while(true){}
 }
@@ -149,7 +147,8 @@
 int GetFile(const char *path, const char *url)
 {
     led2.startBlink();
-    cout << endl << "Getting " << url << endl;
+    ethYellow.startBlink();
+    printf("\nGetting %s\n", url);
     
     timer.stop();
     timer.reset();
@@ -159,16 +158,15 @@
     HTTPResult retGet = http.get(url, &file);
     if (retGet != HTTP_OK)
     {
-        // FSUSB30 switches to HSD2 (External Device)
-        cout << "USB host was switched to HSD2(External Device)." << endl;
         fsusb30s = 1; // HSD2
         error("Error in http.get in GetFile(): %d\n", retGet);
     }
     file.clear();
     
     timer.stop();
-    cout << "timer.read_ms(): " << timer.read_ms() << endl;
+    printf("timer.read_ms(): %d\n", timer.read_ms());
     
     led2.finishBlink();
+    ethYellow.finishBlink();
     return (0);
 }