Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADS1115 BME280 CronoDot SDFileSystem mbed
Fork of Outdoor_UPAS_v1_2_Tboard by
Revision 39:f1ebecfb32ca, committed 2016-05-03
- Comitter:
- jelord
- Date:
- Tue May 03 01:00:15 2016 +0000
- Parent:
- 38:65ae9771f1e3
- Child:
- 40:cac5bdffba44
- Commit message:
- sample name to 15, bt file transfer code
Changed in this revision
| Tb_SD_Reader.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Tb_SD_Reader.lib Fri Apr 29 20:28:05 2016 +0000 +++ b/Tb_SD_Reader.lib Tue May 03 01:00:15 2016 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/Vockens-Group-Sensors/code/Tb_SD_Reader/#09e2de3f3ad4 +http://developer.mbed.org/teams/Vockens-Group-Sensors/code/Tb_SD_Reader/#86a4ea42d5ef
--- a/main.cpp Fri Apr 29 20:28:05 2016 +0000
+++ b/main.cpp Tue May 03 01:00:15 2016 +0000
@@ -12,6 +12,7 @@
#include "Calibration.h"
#include "MAX_M8.h"
#include "DRV8830.h"
+#include "Tb_SD_Reader.h"
/////////////////////////////////////////////
@@ -93,7 +94,9 @@
/////////////////////////////////////////////
char filename[] = "/sd/XXXX0000LOG000000000000---------------.txt";
SDFileSystem sd(PB_5, PB_4, PB_3, PB_6, "sd");//(D4, D5, D3, D10, "sd"); // (MOSI, MISO, SCK, SEL)
+Tb_SD_Reader sdReader;
DigitalIn sdCD(PA_11, PullUp);
+char fileTest[] = "test.txt";
/////////////////////////////////////////////
//Callbacks
@@ -190,7 +193,7 @@
//*************************************************//
void sendData();
-
+void Read_File(char[]);
void pc_recv(){
while(pc.readable()){
@@ -206,6 +209,7 @@
static uint8_t dataLength = 0;
static int runReady = 0;
static uint8_t startAndEndTime[12] = {0,};
+static uint8_t fileTransferLock = 0;
//////////////////////////////////////////////////////////////
//BLE Functions
@@ -234,7 +238,7 @@
else if(rx_buf[0] == 0x0B)transmissionValue = 11; //GPS Coordinates (Second Set)
else if(rx_buf[0] == 0x0C)transmissionValue = 12; //Cartridge ID
else if(rx_buf[0] == 0x0D)transmissionValue = 13; //Duty Cycle
- //else if (rx_buf[0] == 0x0F)transmissionValue = 15; //BT TRANSFER TEST
+ else if (rx_buf[0] == 0x0F)transmissionValue = 15; //BT TRANSFER TEST
//else if(rx_buf[0] == 0x30)RGB_LED.set_led(1,0,0);
else transmissionValue = 100; //Not useful data
}
@@ -244,7 +248,14 @@
transmissionValue == 6 || transmissionValue == 7 || transmissionValue ==10 || transmissionValue ==11 || transmissionValue ==12) && rx_buf[rx_len-1] != 0xff)
{}else{
if(transmissionValue == 4 ) sendData();
- //if(transmissionValue == 15) sdReader.read_file(fileTest,0);
+ if(transmissionValue == 15){
+ if(fileTransferLock==0){
+ fileTransferLock=1;
+ Read_File(fileTest);
+ fileTransferLock=0;
+ RGB_LED.set_led(1,1,1);
+ }
+ }
if(transmissionValue == 8){
runReady = 1;
microChannel.attach(NULL,microChannel.RxIrq);
@@ -293,7 +304,7 @@
if(dataLength ==12)E2PROM.write(0x00015, writeData, 12);
}else if(transmissionValue ==3){ //process and store sample name
- if(dataLength ==8)E2PROM.write(0x00001,writeData,8);
+ if(dataLength ==15)E2PROM.write(0x00001,writeData,15);
}else if(transmissionValue ==5){ //process and store Log Interval
if(dataLength ==1)E2PROM.write(0x00014,writeData,1);
@@ -329,7 +340,7 @@
//First byte is designator for the App
uint8_t sampleTimePassValues[13] = {0x01,0x00,0x00,0x0A,0x01,0x01,0x10,0x00,0x00,0x0A,0x01,0x01,0x10};
- uint8_t subjectLabelOriginal[9] = {0x02,0x52,0x45,0x53,0x45,0x54,0x5F,0x5F,0x5f};
+ uint8_t subjectLabelOriginal[16] = {0x02,0x52,0x45,0x53,0x45,0x54,0x5F,0x5F,0x5f,0x5F,0x5F,0x5f,0x5F,0x5F,0x5f,0x0F};
uint8_t dataLogOriginal[2] = {0x03,0x0A,};
uint8_t flowRateOriginal[5] = {0x04,0x00,0x00,0x80,0x3F};
uint8_t serialBytes[3] = {0x07,0x00,0x00};
@@ -347,9 +358,9 @@
//NEW EEPROM Check bit = 0x75
E2PROM.read(0x00075,NEW_EEPROM_CHECK,1);
- if(NEW_EEPROM_CHECK[0] == 0x0C){
+ if(NEW_EEPROM_CHECK[0] == 0x0C){ //increment when you add a new parameter to pass to app
E2PROM.read(0x00015, sampleTimePassValues+1, 12);
- E2PROM.read(0x00001, subjectLabelOriginal+1,8);
+ E2PROM.read(0x00001, subjectLabelOriginal+1,15);
E2PROM.read(0x00014,dataLogOriginal+1,1);
E2PROM.read(0x00010,flowRateOriginal+1,4);
E2PROM.read(0x00034,serialBytes+1,2);
@@ -359,10 +370,10 @@
E2PROM.read(0x00076,dutyCycleOriginal+1,3);
}else{
- NEW_EEPROM_CHECK[0] = 0x0C;
+ NEW_EEPROM_CHECK[0] = 0x0C; //increment as well
E2PROM.write(0x00075,NEW_EEPROM_CHECK,1);
E2PROM.write(0x00015, sampleTimePassValues+1, 12);
- E2PROM.write(0x00001, subjectLabelOriginal+1,8);
+ E2PROM.write(0x00001, subjectLabelOriginal+1,15);
E2PROM.write(0x00014,dataLogOriginal+1,1);
E2PROM.write(0x00010,flowRateOriginal+1,4);
E2PROM.write(0x00034,serialBytes+1,2);
@@ -378,7 +389,7 @@
}
wait(.15);
- for(int i=0; i<9; i++){
+ for(int i=0; i<16; i++){
microChannel.putc(subjectLabelOriginal[i]);
}
wait(.15);
@@ -414,6 +425,33 @@
}
+void Read_File(char filename[]){
+ char new_str[] = "/sd/XXXX0000LOG000000000000---------------.txt";
+
+ sprintf(new_str, "/sd/%s", filename);
+ FILE *fp = fopen(new_str, "r");
+ if(fp == NULL) {
+ pc.printf("Could not open file, check disk.\r\n");
+ while(1) {};
+ } else {
+ pc.printf("file opened\r\n");
+ }
+ unsigned char c;
+ uint8_t sendMe[1] = {254};
+ RGB_LED.set_led(0,1,0);
+ //pc.printf("%s\r\n",fp.c_str());
+ microChannel.putc(sendMe[0]);
+ while (c != 255){ // while not end of file or forever
+ c=fgetc(fp); // get a character/byte from the file
+ //printf("%c",c); // and show it in hex format
+ microChannel.putc(c);
+ //wait(0.005);
+ }
+ //RGB_LED.set_led(1,0,0);
+ printf("\r\n");
+ fclose(fp); // close the file
+
+};
//////////////////////////////////////////////////////////////
// GPS: Calculate distance from target location
