Example of using file interfaces for mDot

Dependencies:   libmDot-mbed5

Fork of BackupRegisterExample by Jason Reiss

Committer:
jreiss
Date:
Wed Feb 07 19:44:15 2018 +0000
Revision:
27:0bc6554f0bad
Parent:
26:99458ed6fd31
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jreiss 26:99458ed6fd31 1 #include "mbed.h"
jreiss 26:99458ed6fd31 2 #include "mDot.h"
jreiss 26:99458ed6fd31 3 #include "ChannelPlans.h"
jreiss 26:99458ed6fd31 4
jreiss 26:99458ed6fd31 5 static bool deep_sleep = false;
jreiss 26:99458ed6fd31 6
jreiss 26:99458ed6fd31 7 #define CHANNEL_PLAN CP_US915
jreiss 26:99458ed6fd31 8
jreiss 26:99458ed6fd31 9 mDot* dot = NULL;
jreiss 26:99458ed6fd31 10 lora::ChannelPlan* plan = NULL;
jreiss 26:99458ed6fd31 11
jreiss 26:99458ed6fd31 12 Serial pc(USBTX, USBRX);
jreiss 26:99458ed6fd31 13
jreiss 26:99458ed6fd31 14 #if defined(TARGET_XDOT_L151CC)
jreiss 26:99458ed6fd31 15 I2C i2c(I2C_SDA, I2C_SCL);
jreiss 26:99458ed6fd31 16 ISL29011 lux(i2c);
jreiss 26:99458ed6fd31 17 #else
jreiss 26:99458ed6fd31 18 AnalogIn lux(XBEE_AD0);
jreiss 26:99458ed6fd31 19 #endif
jreiss 26:99458ed6fd31 20
jreiss 26:99458ed6fd31 21 int main() {
jreiss 26:99458ed6fd31 22
jreiss 26:99458ed6fd31 23 pc.baud(115200);
jreiss 26:99458ed6fd31 24
jreiss 26:99458ed6fd31 25 mts::MTSLog::setLogLevel(0);
jreiss 26:99458ed6fd31 26
jreiss 26:99458ed6fd31 27 #if CHANNEL_PLAN == CP_US915
jreiss 26:99458ed6fd31 28 plan = new lora::ChannelPlan_US915();
jreiss 26:99458ed6fd31 29 #elif CHANNEL_PLAN == CP_AU915
jreiss 26:99458ed6fd31 30 plan = new lora::ChannelPlan_AU915();
jreiss 26:99458ed6fd31 31 #elif CHANNEL_PLAN == CP_EU868
jreiss 26:99458ed6fd31 32 plan = new lora::ChannelPlan_EU868();
jreiss 26:99458ed6fd31 33 #elif CHANNEL_PLAN == CP_KR920
jreiss 26:99458ed6fd31 34 plan = new lora::ChannelPlan_KR920();
jreiss 26:99458ed6fd31 35 #elif CHANNEL_PLAN == CP_AS923
jreiss 26:99458ed6fd31 36 plan = new lora::ChannelPlan_AS923();
jreiss 26:99458ed6fd31 37 #elif CHANNEL_PLAN == CP_AS923_JAPAN
jreiss 26:99458ed6fd31 38 plan = new lora::ChannelPlan_AS923_Japan();
jreiss 26:99458ed6fd31 39 #elif CHANNEL_PLAN == CP_IN865
jreiss 26:99458ed6fd31 40 plan = new lora::ChannelPlan_IN865();
jreiss 26:99458ed6fd31 41 #endif
jreiss 26:99458ed6fd31 42 assert(plan);
jreiss 26:99458ed6fd31 43
jreiss 26:99458ed6fd31 44 dot = mDot::getInstance(plan);
jreiss 26:99458ed6fd31 45 assert(dot);
jreiss 26:99458ed6fd31 46
jreiss 26:99458ed6fd31 47
jreiss 27:0bc6554f0bad 48 printf("\r\nCreate a file\r\n");
jreiss 27:0bc6554f0bad 49
jreiss 27:0bc6554f0bad 50 uint8_t buffer[20];
jreiss 27:0bc6554f0bad 51
jreiss 27:0bc6554f0bad 52 memset(buffer, 0x23, 20);
jreiss 27:0bc6554f0bad 53
jreiss 27:0bc6554f0bad 54 dot->saveUserFile("Test", buffer, 20);
jreiss 27:0bc6554f0bad 55
jreiss 27:0bc6554f0bad 56 uint8_t new_buffer[20];
jreiss 27:0bc6554f0bad 57
jreiss 27:0bc6554f0bad 58 memset(new_buffer, 0, 20);
jreiss 27:0bc6554f0bad 59
jreiss 27:0bc6554f0bad 60 dot->readUserFile("Test", new_buffer, 20);
jreiss 27:0bc6554f0bad 61
jreiss 27:0bc6554f0bad 62 printf("Read from file: %02x %02x %02x\r\n", new_buffer[0], new_buffer[1], new_buffer[2]);
jreiss 27:0bc6554f0bad 63
jreiss 27:0bc6554f0bad 64
jreiss 27:0bc6554f0bad 65 memset(buffer, 0x78, 20);
jreiss 27:0bc6554f0bad 66
jreiss 27:0bc6554f0bad 67
jreiss 27:0bc6554f0bad 68 // Similar to C open interface
jreiss 27:0bc6554f0bad 69 // see http://codewiki.wikidot.com/c:system-calls:open
jreiss 27:0bc6554f0bad 70 mDot::mdot_file my_file = dot->openUserFile("Test2", mDot::FM_CREAT | mDot::FM_WRONLY | mDot::FM_APPEND);
jreiss 27:0bc6554f0bad 71
jreiss 27:0bc6554f0bad 72 dot->writeUserFile(my_file, buffer, 20);
jreiss 27:0bc6554f0bad 73
jreiss 27:0bc6554f0bad 74 dot->closeUserFile(my_file);
jreiss 27:0bc6554f0bad 75
jreiss 27:0bc6554f0bad 76 memset(new_buffer, 0, 20);
jreiss 27:0bc6554f0bad 77
jreiss 27:0bc6554f0bad 78 dot->readUserFile("Test2", new_buffer, 20);
jreiss 27:0bc6554f0bad 79
jreiss 27:0bc6554f0bad 80 printf("Read from file: %02x %02x %02x\r\n", new_buffer[0], new_buffer[1], new_buffer[2]);
jreiss 26:99458ed6fd31 81
jreiss 26:99458ed6fd31 82 while (true) {
jreiss 27:0bc6554f0bad 83 osDelay(5000);
jreiss 26:99458ed6fd31 84 }
jreiss 26:99458ed6fd31 85
jreiss 26:99458ed6fd31 86 return 0;
jreiss 26:99458ed6fd31 87 }
jreiss 26:99458ed6fd31 88