Handle LoRa Basic Function

Dependents:   lora_example_miun

Committer:
biwa1400
Date:
Wed Mar 08 18:54:32 2017 +0000
Revision:
0:f8af47d9f0cd
20170308

Who changed what in which revision?

UserRevisionLine numberNew contents of line
biwa1400 0:f8af47d9f0cd 1 #include "Lora.h"
biwa1400 0:f8af47d9f0cd 2 #include "mbed.h"
biwa1400 0:f8af47d9f0cd 3 #include "mDot.h"
biwa1400 0:f8af47d9f0cd 4 #include "MTSLog.h"
biwa1400 0:f8af47d9f0cd 5 #include <string>
biwa1400 0:f8af47d9f0cd 6 #include <vector>
biwa1400 0:f8af47d9f0cd 7 #include <sstream>
biwa1400 0:f8af47d9f0cd 8 #include <iostream>
biwa1400 0:f8af47d9f0cd 9 #include "Parking.h"
biwa1400 0:f8af47d9f0cd 10
biwa1400 0:f8af47d9f0cd 11 const string Parking::SATAE_TITLE = "DISTANCE=";
biwa1400 0:f8af47d9f0cd 12 //const string Parking::EXIST = "QWE";
biwa1400 0:f8af47d9f0cd 13 //const string Parking::DISAPPEAR = "ZXC";
biwa1400 0:f8af47d9f0cd 14
biwa1400 0:f8af47d9f0cd 15
biwa1400 0:f8af47d9f0cd 16
biwa1400 0:f8af47d9f0cd 17
biwa1400 0:f8af47d9f0cd 18 //ADC
biwa1400 0:f8af47d9f0cd 19
biwa1400 0:f8af47d9f0cd 20
biwa1400 0:f8af47d9f0cd 21
biwa1400 0:f8af47d9f0cd 22 bool Parking::init()
biwa1400 0:f8af47d9f0cd 23 {
biwa1400 0:f8af47d9f0cd 24 loraNode1.joinNetwork();
biwa1400 0:f8af47d9f0cd 25 return true;
biwa1400 0:f8af47d9f0cd 26 }
biwa1400 0:f8af47d9f0cd 27
biwa1400 0:f8af47d9f0cd 28
biwa1400 0:f8af47d9f0cd 29
biwa1400 0:f8af47d9f0cd 30 bool Parking::capture_sent()
biwa1400 0:f8af47d9f0cd 31 {
biwa1400 0:f8af47d9f0cd 32 static int i=0;
biwa1400 0:f8af47d9f0cd 33 stringstream command;
biwa1400 0:f8af47d9f0cd 34 command <<"num: "<<i;
biwa1400 0:f8af47d9f0cd 35 string result;
biwa1400 0:f8af47d9f0cd 36 command >> result;
biwa1400 0:f8af47d9f0cd 37 // char buf[10];
biwa1400 0:f8af47d9f0cd 38 // sprintf(buf,"%d;\0",sensor1.sample());
biwa1400 0:f8af47d9f0cd 39 //result =SATAE_TITLE+(string)buf;
biwa1400 0:f8af47d9f0cd 40 loraNode1.sendData_string(result);
biwa1400 0:f8af47d9f0cd 41 // loraNode1.useDot()->openRxWindow(5000,2);
biwa1400 0:f8af47d9f0cd 42 return true;
biwa1400 0:f8af47d9f0cd 43 }
biwa1400 0:f8af47d9f0cd 44
biwa1400 0:f8af47d9f0cd 45 bool Parking::recevie_set_sleeptime()
biwa1400 0:f8af47d9f0cd 46 {
biwa1400 0:f8af47d9f0cd 47 string sleepTimeString;
biwa1400 0:f8af47d9f0cd 48 loraNode1.receiveData_string(sleepTimeString);
biwa1400 0:f8af47d9f0cd 49 logInfo("receive: %s",sleepTimeString.c_str());
biwa1400 0:f8af47d9f0cd 50 uint32_t sleeptime = (uint32_t)atoi(findKeyWord(sleepTimeString,"SLEEP").c_str());
biwa1400 0:f8af47d9f0cd 51 logInfo("sleepTime: %d",sleeptime);
biwa1400 0:f8af47d9f0cd 52 if( 0<sleeptime && sleeptime<1000)
biwa1400 0:f8af47d9f0cd 53 {
biwa1400 0:f8af47d9f0cd 54 uint32_t sleep_time = std::max(sleeptime*1000, (uint32_t)useDot()->getNextTxMs()) / 1000;
biwa1400 0:f8af47d9f0cd 55 logInfo("SettingSleeping...");
biwa1400 0:f8af47d9f0cd 56 useDot()->sleep(sleep_time, mDot::RTC_ALARM,false);
biwa1400 0:f8af47d9f0cd 57 }
biwa1400 0:f8af47d9f0cd 58 return true;
biwa1400 0:f8af47d9f0cd 59 }
biwa1400 0:f8af47d9f0cd 60
biwa1400 0:f8af47d9f0cd 61 std::string
biwa1400 0:f8af47d9f0cd 62 Parking::findKeyWord(std::string in_string, std::string keyWord)
biwa1400 0:f8af47d9f0cd 63 {
biwa1400 0:f8af47d9f0cd 64 int title;
biwa1400 0:f8af47d9f0cd 65 int begin;
biwa1400 0:f8af47d9f0cd 66 int end;
biwa1400 0:f8af47d9f0cd 67
biwa1400 0:f8af47d9f0cd 68 title = in_string.find(keyWord);
biwa1400 0:f8af47d9f0cd 69 begin = in_string.find("=",title)+1;
biwa1400 0:f8af47d9f0cd 70 if(in_string.find("{",begin)==begin)
biwa1400 0:f8af47d9f0cd 71 {
biwa1400 0:f8af47d9f0cd 72 begin++;
biwa1400 0:f8af47d9f0cd 73 end = in_string.find("}",begin);
biwa1400 0:f8af47d9f0cd 74 }
biwa1400 0:f8af47d9f0cd 75 else end = in_string.find(";",begin);
biwa1400 0:f8af47d9f0cd 76
biwa1400 0:f8af47d9f0cd 77 return in_string.substr (begin, end-begin);
biwa1400 0:f8af47d9f0cd 78 }
biwa1400 0:f8af47d9f0cd 79
biwa1400 0:f8af47d9f0cd 80