Browse Source

Started building major bricks and global algorithm

tags/v1.2.0
Bertrand Lemasle 7 years ago
parent
commit
a8b9d65327
19 changed files with 252 additions and 18 deletions
  1. +1
    -1
      .editorconfig
  2. +4
    -1
      .gitignore
  3. +14
    -0
      GpsTracker/Core.cpp
  4. +24
    -0
      GpsTracker/Core.h
  5. +13
    -5
      GpsTracker/Debug.cpp
  6. +11
    -4
      GpsTracker/Debug.h
  7. +27
    -1
      GpsTracker/Gps.cpp
  8. +18
    -1
      GpsTracker/Gps.h
  9. +6
    -2
      GpsTracker/GpsTracker.h
  10. +18
    -1
      GpsTracker/GpsTracker.ino
  11. +7
    -1
      GpsTracker/Network.cpp
  12. +5
    -0
      GpsTracker/Network.h
  13. +56
    -1
      GpsTracker/Rtc.cpp
  14. +10
    -0
      GpsTracker/Rtc.h
  15. +8
    -0
      GpsTracker/Storage.cpp
  16. +5
    -0
      GpsTracker/Storage.h
  17. +10
    -0
      GpsTracker/Time.h
  18. +8
    -0
      GpsTracker/Utils.cpp
  19. +7
    -0
      GpsTracker/Utils.h

+ 1
- 1
.editorconfig View File

@@ -1,6 +1,6 @@
root = true

[*]
end_of_line = lf
end_of_line = crlf
indent_style = tab
trim_trailing_whitespace = true

+ 4
- 1
.gitignore View File

@@ -261,4 +261,7 @@ __pycache__/
*.pyc

#VisualMicro
__vm/
__vm/

#Line endings unifier
.leu

+ 14
- 0
GpsTracker/Core.cpp View File

@@ -0,0 +1,14 @@
#include "Core.h"

#define LOGGER_NAME "Core"

namespace core {

GPS_TRACKER_STATES state;

void setCurrentState(GPS_TRACKER_STATES s) {
state = s;
VERBOSE_FORMAT("setCurrentState", "%d, Free RAM : %d", state debug::freeRam());
}

}

+ 24
- 0
GpsTracker/Core.h View File

@@ -0,0 +1,24 @@
#pragma once

#include <Arduino.h>

#include "Debug.h"

enum class GPS_TRACKER_STATES : uint8_t
{
SETUP = 0,
GET_POSITION = 1,
SAVE_POSITION = 2,
SEND_POSITION = 3,
SLEEP = 4
};



namespace core {

extern GPS_TRACKER_STATES state;

void setCurrentState(GPS_TRACKER_STATES s);

}

+ 13
- 5
GpsTracker/Debug.cpp View File

@@ -1,8 +1,16 @@
#include "Debug.h"

void waitForSerial() {
#ifdef _DEBUG
while (!Serial);
Serial.begin(115200);
#endif // _DEBUG
namespace debug {

void waitForSerial() {
while (!Serial);
Serial.begin(115200);
}

int freeRam() {
extern int __heap_start, *__brkval;
int v;
return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int)__brkval);
}

}

+ 11
- 4
GpsTracker/Debug.h View File

@@ -1,21 +1,28 @@
#pragma once

#include <Arduino.h>

#ifdef _DEBUG

#include <ArduinoLog.h>

#define VERBOSE(f) Log.verbose(F("[" LOGGER_NAME "::" f "]\n"))
#define VERBOSE_MSG(f, msg) Log.verbose(F("[" LOGGER_NAME "::" f "] " msg "\n"))
#define VERBOSE_FORMAT(f, msg, ...) Log.verbose(F["[" LOGGER_NAME "::" f "] " msg "\n"), __VA_ARGS__)
#define VERBOSE_FORMAT(f, msg, ...) Log.verbose(F("[" LOGGER_NAME "::" f "] " msg "\n"), __VA_ARGS__)

#else

#define DISABLE_LOGGING 1

#define VERBOSE(f)
#define VERBOSE(f, msg)
#define VERBOSE(f, msg, ...)
#define VERBOSE_MSG(f, msg)
#define VERBOSE_FORMAT(f, msg, ...)

#endif

void waitForSerial();
namespace debug {

void waitForSerial();
int freeRam();

}

+ 27
- 1
GpsTracker/Gps.cpp View File

@@ -1,3 +1,29 @@
#include "Gps.h"

#define LOGGER_NAME "Gps"
#define LOGGER_NAME "Gps"

namespace gps {

void powerOn() {

}

void powerOff() {

}

SIM808_GPS_STATUS acquireCurrentPosition() {
SIM808_GPS_STATUS currentStatus = SIM808_GPS_STATUS::OFF;

//TODO : do while (!timeout && < accurate_fix)
if (currentStatus > SIM808_GPS_STATUS::NO_FIX) {
lastStatus = currentStatus;
}

return currentStatus;
}

Time getTime() {
}
}

+ 18
- 1
GpsTracker/Gps.h View File

@@ -1 +1,18 @@
#pragma once
#pragma once

#include "Time.h"

#define GPS_POSITION_SIZE 128

namespace gps {

char lastPosition[GPS_POSITION_SIZE];
SIM808_GPS_STATUS lastStatus;

void powerOn();
void powerOff();

SIM808_GPS_STATUS acquireCurrentPosition();
Time getTime();

}

+ 6
- 2
GpsTracker/GpsTracker.h View File

@@ -5,9 +5,13 @@
#include <SIM808.h>

#include "Debug.h"
#include "Core.h"

#include "Gps.h"
#include "Network.h"
#include "Rtc.h"
#include "Storage.h"
#include "Utils.h"

#define LOGGER_NAME "GpsTracker"

@@ -16,9 +20,9 @@
#define SIM_PWR 9
#define SIM_STATUS 8

#define IC_PWR A0
#define RTC_PWR A0
#define EEPROM_PWR A0
#define SD_SS SS

#define SIM_RI 2
#define RTC_WAKE 3


+ 18
- 1
GpsTracker/GpsTracker.ino View File

@@ -1,12 +1,29 @@
#include "GpsTracker.h"


void setup() {
#ifdef _DEBUG
waitForSerial();
debug::waitForSerial();
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
#endif

core::setCurrentState(GPS_TRACKER_STATES::SETUP);

rtc::powerOn();
rtc::setup();
rtc::powerOff();
}

void loop() {

gps::powerOn();
SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition();
gps::powerOff();

if (gpsStatus > SIM808_GPS_STATUS::NO_FIX) {
Time time = utils::parseTime();
rtc::powerOn();
rtc::setTime(time);
rtc::powerOff();
}
}

+ 7
- 1
GpsTracker/Network.cpp View File

@@ -1,3 +1,9 @@
#include "Network.h"

#define LOGGER_NAME "Network"
#define LOGGER_NAME "Network"

namespace network {

void powerOn() {}
void powerOff() {}
}

+ 5
- 0
GpsTracker/Network.h View File

@@ -1 +1,6 @@
#pragma once

namespace network {
void powerOn();
void powerOff();
}

+ 56
- 1
GpsTracker/Rtc.cpp View File

@@ -1,3 +1,58 @@
#include "Rtc.h"

#define LOGGER_NAME "Rtc"
#include <Wire.h>
#include <MD_DS3231.h>

#define LOGGER_NAME "Rtc"

namespace rtc {

void powerOn() {
digitalWrite(RTC_PWR, HIGH);
pinMode(RTC_PWR, OUTPUT);

Wire.begin();
}

void powerOff() {
pinMode(RTC_PWR, INPUT);
digitalWrite(RTC_PWR, LOW);

//turn off i2c
TWCR &= ~(bit(TWEN) | bit(TWIE) | bit(TWEA));

//disable i2c internal pull ups
digitalWrite(A4, LOW);
digitalWrite(A5, LOW);
}

void setup() {
RTC.control(DS3231_12H, DS3231_OFF); //24 hours clock
RTC.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON
}

Time getTime() {
RTC.readTime();

return {
RTC.yyyy,
RTC.mm,
RTC.dd,
RTC.h,
RTC.m,
RTC.s
};
}

void setTime(Time time) {
RTC.yyyy = time.yyyy;
RTC.mm = time.mm;
RTC.dd = time.dd;
RTC.h = time.h;
RTC.m = time.m;
RTC.s = time.s;

RTC.writeTime();
}

}

+ 10
- 0
GpsTracker/Rtc.h View File

@@ -1 +1,11 @@
#pragma once

namespace rtc {
void powerOn();
void powerOff();

void setup();

Time getTime();
void setTime(Time time);
}

+ 8
- 0
GpsTracker/Storage.cpp View File

@@ -0,0 +1,8 @@
#include "Storage.h"

#define LOGGER_NAME "Storage"

namespace storage {
void powerOn() {}
void powerOff() {}
}

+ 5
- 0
GpsTracker/Storage.h View File

@@ -1 +1,6 @@
#pragma once

namespace storage {
void powerOn();
void powerOff();
}

+ 10
- 0
GpsTracker/Time.h View File

@@ -0,0 +1,10 @@
#pragma once

struct Time {
uint16_t yyyy;
uint8_t mm;
uint8_t dd;
uint8_t h;
uint8_t m;
uint8_t s;
};

+ 8
- 0
GpsTracker/Utils.cpp View File

@@ -0,0 +1,8 @@
#include "Utils.h"
#include "Gps.h"

namespace utils {

Time parseTime();

}

+ 7
- 0
GpsTracker/Utils.h View File

@@ -0,0 +1,7 @@
#pragma once

#include "Time.h"

namespace utils {
Time parseTime();
}

Loading…
Cancel
Save