Example of using file interfaces for mDot
Fork of BackupRegisterExample by
main.cpp
00001 #include "mbed.h" 00002 #include "mDot.h" 00003 #include "ChannelPlans.h" 00004 00005 static bool deep_sleep = false; 00006 00007 #define CHANNEL_PLAN CP_US915 00008 00009 mDot* dot = NULL; 00010 lora::ChannelPlan* plan = NULL; 00011 00012 Serial pc(USBTX, USBRX); 00013 00014 #if defined(TARGET_XDOT_L151CC) 00015 I2C i2c(I2C_SDA, I2C_SCL); 00016 ISL29011 lux(i2c); 00017 #else 00018 AnalogIn lux(XBEE_AD0); 00019 #endif 00020 00021 int main() { 00022 00023 pc.baud(115200); 00024 00025 mts::MTSLog::setLogLevel(0); 00026 00027 #if CHANNEL_PLAN == CP_US915 00028 plan = new lora::ChannelPlan_US915(); 00029 #elif CHANNEL_PLAN == CP_AU915 00030 plan = new lora::ChannelPlan_AU915(); 00031 #elif CHANNEL_PLAN == CP_EU868 00032 plan = new lora::ChannelPlan_EU868(); 00033 #elif CHANNEL_PLAN == CP_KR920 00034 plan = new lora::ChannelPlan_KR920(); 00035 #elif CHANNEL_PLAN == CP_AS923 00036 plan = new lora::ChannelPlan_AS923(); 00037 #elif CHANNEL_PLAN == CP_AS923_JAPAN 00038 plan = new lora::ChannelPlan_AS923_Japan(); 00039 #elif CHANNEL_PLAN == CP_IN865 00040 plan = new lora::ChannelPlan_IN865(); 00041 #endif 00042 assert(plan); 00043 00044 dot = mDot::getInstance(plan); 00045 assert(dot); 00046 00047 00048 printf("\r\nCreate a file\r\n"); 00049 00050 uint8_t buffer[20]; 00051 00052 memset(buffer, 0x23, 20); 00053 00054 dot->saveUserFile("Test", buffer, 20); 00055 00056 uint8_t new_buffer[20]; 00057 00058 memset(new_buffer, 0, 20); 00059 00060 dot->readUserFile("Test", new_buffer, 20); 00061 00062 printf("Read from file: %02x %02x %02x\r\n", new_buffer[0], new_buffer[1], new_buffer[2]); 00063 00064 00065 memset(buffer, 0x78, 20); 00066 00067 00068 // Similar to C open interface 00069 // see http://codewiki.wikidot.com/c:system-calls:open 00070 mDot::mdot_file my_file = dot->openUserFile("Test2", mDot::FM_CREAT | mDot::FM_WRONLY | mDot::FM_APPEND); 00071 00072 dot->writeUserFile(my_file, buffer, 20); 00073 00074 dot->closeUserFile(my_file); 00075 00076 memset(new_buffer, 0, 20); 00077 00078 dot->readUserFile("Test2", new_buffer, 20); 00079 00080 printf("Read from file: %02x %02x %02x\r\n", new_buffer[0], new_buffer[1], new_buffer[2]); 00081 00082 while (true) { 00083 osDelay(5000); 00084 } 00085 00086 return 0; 00087 } 00088
Generated on Wed Jul 13 2022 15:28:39 by 1.7.2