Handle LoRa Basic Function
Diff: Parking.cpp
- Revision:
- 0:f8af47d9f0cd
diff -r 000000000000 -r f8af47d9f0cd Parking.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Parking.cpp Wed Mar 08 18:54:32 2017 +0000 @@ -0,0 +1,80 @@ +#include "Lora.h" +#include "mbed.h" +#include "mDot.h" +#include "MTSLog.h" +#include <string> +#include <vector> +#include <sstream> +#include <iostream> +#include "Parking.h" + +const string Parking::SATAE_TITLE = "DISTANCE="; +//const string Parking::EXIST = "QWE"; +//const string Parking::DISAPPEAR = "ZXC"; + + + + +//ADC + + + +bool Parking::init() +{ + loraNode1.joinNetwork(); + return true; +} + + + +bool Parking::capture_sent() +{ + static int i=0; + stringstream command; + command <<"num: "<<i; + string result; + command >> result; + // char buf[10]; + // sprintf(buf,"%d;\0",sensor1.sample()); + //result =SATAE_TITLE+(string)buf; + loraNode1.sendData_string(result); +// loraNode1.useDot()->openRxWindow(5000,2); + return true; +} + +bool Parking::recevie_set_sleeptime() +{ + string sleepTimeString; + loraNode1.receiveData_string(sleepTimeString); + logInfo("receive: %s",sleepTimeString.c_str()); + uint32_t sleeptime = (uint32_t)atoi(findKeyWord(sleepTimeString,"SLEEP").c_str()); + logInfo("sleepTime: %d",sleeptime); + if( 0<sleeptime && sleeptime<1000) + { + uint32_t sleep_time = std::max(sleeptime*1000, (uint32_t)useDot()->getNextTxMs()) / 1000; + logInfo("SettingSleeping..."); + useDot()->sleep(sleep_time, mDot::RTC_ALARM,false); + } + return true; +} + +std::string +Parking::findKeyWord(std::string in_string, std::string keyWord) +{ + int title; + int begin; + int end; + + title = in_string.find(keyWord); + begin = in_string.find("=",title)+1; + if(in_string.find("{",begin)==begin) + { + begin++; + end = in_string.find("}",begin); + } + else end = in_string.find(";",begin); + + return in_string.substr (begin, end-begin); +} + +