Permalink
Browse files

New library tracking method

  • Loading branch information...
1 parent 02d9dfd commit d22167b42ab9977ce5d17e476397167e1eac69ff qmast committed Jan 20, 2013
Showing with 256 additions and 0 deletions.
  1. 0 PololuServo/pololu_servo.cpp
  2. +26 −0 PololuServo/pololu_servo.h
  3. +132 −0 SDCard/SDCard.cpp
  4. +67 −0 SDCard/SDCard.h
  5. +11 −0 Test/test.cpp
  6. +20 −0 Test/test.h
No changes.
@@ -0,0 +1,26 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ *
+ * Copyright (C) Stephen Cripps, 2013
+ */
+
+#include <Arduino.h>
+
+class PololuMSC {
+ private:
+ Stream* serialCom;
+ public:
+ PololuMSC(Stream*);
+}
View
@@ -0,0 +1,132 @@
+/*
+SDCard.c
+
+*/
+
+#include "SDCard.h"
+
+SDCard::SDCard(int pin)
+{
+ _list = NULL;
+
+ _pin = pin;
+ pinMode(_pin, OUTPUT);
+
+ _logfile = (char*) malloc(sizeof(char)*14);
+
+ if(DEBUG)
+ Serial.println("Initializing SD Card...");
+
+ if(!SD.begin(_pin))
+ {
+ Serial.println("Initialization Failed");
+ delay(5000);
+ return;
+ }
+
+ //Create a new file, with the proper filename
+ strcpy(_logfile, "MASTLOG00.txt");
+
+ for(int i=0; i<100; i++)
+ {
+ logfile[7] = '0' + i/10;
+ logfile[8] = '0' + i%10;
+ if(!SD.exists(_logfile))
+ break;
+ }
+
+ delay(2000);
+
+ File testFile = SD.open(_logfile, FILE_WRITE);
+ if(!testFile)
+ {
+ Serial.println("Couldn't Create File");
+ delay(5000);
+ return;
+ }
+ testFile.close();
+
+
+ delay(5000);
+}
+
+char* SDCard::getFilename()
+{
+ //Returns a copy of the filename as a C string
+ char* filename = (char*) malloc(sizeof(char)*14);
+ strcpy(filename, _logfile);
+ return filename;
+}
+
+
+/*
+Adds a DataSource to the list of sources.
+*/
+void SDCard::addDataSource(char* label, void* data, DataType type)
+{
+ DataSource* link = (DataSource*) malloc(sizeof(DataSource));
+ link->label = label;
+ link->data = data;
+ link->type = type;
+ link->head = _list;
+ _list = link;
+}
+
+/*
+Writes all the dataSources to the file, returning a 0 if successful.
+Error Codes:
+ 0 - File write successful
+ 1 - File failed to open
+
+Need to test to see if floats can be written to the file without issue.
+If not, will need to write a method to do this.
+*/
+int SDCard::writeLine()
+{
+
+ DataSource* link = _list;
+ int* idata;
+ double* ddata;
+ char* cdata;
+ float* fdata;
+
+ //Open the file
+ File f = SD.open(_logfile, FILE_WRITE);
+ if(!f)//File failed to open
+ return 1;
+
+
+ while(link!=NULL)
+ {
+ f.write("###");
+ f.flush();
+
+ f.write(link->label);
+ f.flush();
+ switch(link->type) {
+ case DataType.INT:
+ idata = (int *) link->data;
+ f.print(*idata, DEC);
+ break;
+ case DataType.DOUBLE:
+ ddata = (double *) link->data;
+ f.print(*ddata, DEC);
+ break;
+ case DataType.CHAR:
+ cdata = (char *) link->data;
+ f.write(cdata);
+ break;
+ case DataType.FLOAT:
+ fdata = (float *) link->data;
+ f.print(*fdata);
+ break;
+ }
+ f.flush();
+ f.write(",");
+ f.flush();
+ link=link->head;//Travel to the next link
+ }
+ //Close the file
+ f.write("***\n");
+ f.close();
+}
View
@@ -0,0 +1,67 @@
+/* SDCard.h
+
+ For interacting with the SD Card shield, used for datalogging. Eventually will
+ include GPS functionality as well, but as it is a back-up gps, it will be
+ programmed later, and merely use modified code from the main GPS
+
+
+ For the datalogging, the SD card needs to get information from the sensors, and
+ send it as a formatted string to the SD card. The information is organized as
+ ### LABEL1: DATA1, LABEL2: DATA2, .... LABELN: DATAN ### The organization of
+ this depends on how flexible we want the data logging to be. If we want to
+ simply hardcode in all the data sources, then it is easy, if cumbersome, to
+ write the logging function. If we want to make it more flexible, then we can
+ implement a linked list of structs containing the data label, and a pointer to
+ the data source variable. The data source variable could then be updated by other
+ functions which poll the hardware sources.
+ This would obviously be more intensive - both in implementation and in memory usage,
+ however, it would be a lot more flexible if more sources were added, or we wanted to
+ change anything regarding how they were formatted.
+
+ The issue with creating a list of values is that different sources have different data types - certain sources are doubles, others are longs, or ints. Would need to look carefully at this.
+
+ In the meantime, I will implement the basic read/write and initialization functions.
+*/
+#ifndef SDCard_h
+#define SDCard_h
+
+#include "Arduino.h"
+#include <SD.h>
+#define DEBUG 0
+
+//The different datatypes that are possible to be written to the file
+ enum DataType{
+ INT,
+ DOUBLE,
+ CHAR,
+ FLOAT
+};
+
+/*
+This structure is used to hold pieces of information which will be written to the SD card.
+Each piece of information has a string label, a pointer to the data, and a DataType telling what type of data it is.
+As well, there is a pointer to another DataSource. This allows the DataSources to be used as a linked list.
+When a line is logged, the list will be looped through, and each source will be written to a line in the log.
+*/
+typedef struct {
+ DataType type;
+ char* label;
+ void* data;
+ DataSource* head;
+} DataSource;
+
+class SDCard
+{
+public:
+ SDCard(int pin);
+ char* getFilename();
+ void addDataSource(char* label, void* data, DataType type);
+ int writeLine();
+private:
+ int _pin;
+ char* _logfile;
+ DataSource* _list;
+}
+
+
+#endif
View
@@ -0,0 +1,11 @@
+#include "test.h"
+
+test::test(Stream* initSerial) {
+ serialInstance = initSerial;
+}
+
+int test::printOut(char* inString) {
+ serialInstance->println(inString);
+
+ return 0;
+}
View
@@ -0,0 +1,20 @@
+/** Example Library
+ *
+ * Containing some of the basics, plus the use of a serial port instance
+ * within the library without hard coding the `Serial` code word for access.
+ */
+
+// Include guard
+#ifndef test_h
+#define test_h
+#include <Arduino.h>
+
+class test {
+ private:
+ Stream* serialInstance;
+ public:
+ // Function prototypes
+ test(Stream* initSerial);
+ int printOut(char* inString);
+};
+#endif

0 comments on commit d22167b

Please sign in to comment.