SmartApp_Miun

Dependents:   Light

Files at this revision

API Documentation at this revision

Comitter:
biwa1400
Date:
Mon Oct 02 16:09:25 2017 +0000
Parent:
1:5b29579a065e
Commit message:
201710002;

Changed in this revision

SmartApp.cpp Show annotated file Show diff for this revision Revisions of this file
SmartApp.h Show annotated file Show diff for this revision Revisions of this file
SmartAppSingle.cpp Show annotated file Show diff for this revision Revisions of this file
SmartAppSingle.h Show annotated file Show diff for this revision Revisions of this file
--- a/SmartApp.cpp	Thu Apr 20 07:02:56 2017 +0000
+++ b/SmartApp.cpp	Mon Oct 02 16:09:25 2017 +0000
@@ -12,31 +12,16 @@
 {
 }
 
-
-void MIUN::SmartApp::initializeSettings()
-{
-    std::string network_name         = "MiunLora";
-    std::string network_passphrase   = "MiunLora";
-    uint8_t     ack                  = 3;  //Times
-    uint8_t     joinDelay            = 1;  //Seconds
-    bool        ADR                  = true;
-    uint8_t     sf                   = 5;  //SF
-    uint32_t    defaultSleepTime_s   = 10;  //s
-    
-    // Handle ReConfing Network
-    lora.networkConfig(network_name, network_passphrase,ack, joinDelay, ADR, sf, defaultSleepTime_s);
-}
-
 /*** Running Thread ***/
 void MIUN::SmartApp::startRunning()
 {
     while(true)
     {
-        lora.joinNetwork();
-        heartBeat();
-        triggerApp();
+        //lora.joinNetwork();
+       // heartBeat();
+       // triggerApp();
         checkInterrupt();
-        lora.setBatteryLevel(measuredBattery());
+        //lora.setBatteryLevel(measuredBattery());
         lora.sleep();
     }
 }
--- a/SmartApp.h	Thu Apr 20 07:02:56 2017 +0000
+++ b/SmartApp.h	Mon Oct 02 16:09:25 2017 +0000
@@ -9,7 +9,7 @@
 #define SMART_APP_H
 
 #include "mDot.h"
-#include "LoRa.h"
+#include "MIUN.LoRa.h"
 #include "AppUnit.h"
 
 
@@ -34,7 +34,6 @@
     std::map <uint8_t, AppUnit&> appMap;
     
 public:
-    void initializeSettings();
     void addApp(AppUnit& app);
     void setSleepTime(uint32_t inSleepTime);
     void startRunning();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SmartAppSingle.cpp	Mon Oct 02 16:09:25 2017 +0000
@@ -0,0 +1,60 @@
+#include "SmartAppSingle.h"
+#include "mbed.h"
+#include "mDot.h"
+#include <map>
+#include <string>
+#include <iostream>
+
+const std::string MIUN::SmartAppSingle::emptyPayload = "";
+const int MIUN::SmartAppSingle::defaultPort =  0;
+
+MIUN::SmartAppSingle::SmartAppSingle()
+{
+}
+
+
+/*** Running Thread ***/
+void MIUN::SmartAppSingle::startRunning()
+{
+    while(true)
+    {
+       if(lora.joinNetwork()==true)
+       {
+            execute(); 
+       }
+       lora.sleep();
+    }
+}
+
+
+/*** public Functions ***/
+
+std::string MIUN::SmartAppSingle::sendReceive(std::string payload, int port, int* receivePort)
+{
+    if(lora.send(payload,port))
+    {
+        return lora.receive(receivePort);
+    }
+    else
+    {
+        return emptyPayload;
+    }
+}
+
+
+void MIUN::SmartAppSingle::setSleepTime(uint32_t inSleepTime)
+{
+    lora.setSleepTime(inSleepTime);
+}
+
+/*** virtual function ***/
+
+uint8_t MIUN::SmartAppSingle::measuredBattery()
+{
+    return 255;
+}
+
+void MIUN::SmartAppSingle::execute()
+{
+    logInfo("Please overwrite the execute function.");
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SmartAppSingle.h	Mon Oct 02 16:09:25 2017 +0000
@@ -0,0 +1,52 @@
+/**
+ * @file    SmartApp.h
+ * @brief   Application call
+ * @author  Bin Wang
+ * @version 1.0
+ */
+ 
+#ifndef SMART_APP_SINGLE_H
+#define SMART_APP_SINGLE_H
+
+#include "mDot.h"
+#include "MIUN.LoRa.h"
+
+
+namespace MIUN
+{
+    
+class SmartAppSingle
+{
+/*** Parameters ***/
+private:
+    static const std::string emptyPayload;
+    static const int defaultPort; 
+
+
+/*** constructor ***/
+public:
+    SmartAppSingle();
+
+/*** Components ***/
+private:
+    MIUN::LoRa lora;
+
+/*** Functions ***/
+public:
+    void setSleepTime(uint32_t inSleepTime);
+    void startRunning();
+
+protected:
+    std::string sendReceive(std::string payload, int port, int* receivePort);
+    
+/*** Virtual Function ***/
+public:
+     virtual uint8_t measuredBattery();
+     virtual void    execute();
+
+
+};
+
+} // End of namespace
+
+#endif
\ No newline at end of file