This is code is part of a Technion course project in advanced IoT, implementing a device to receive and present sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

Dependencies:   mbed Buffer

Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by ST

This is code is part of a Technion course project in advanced IoT, implementing a device to receive sensors data from another L072CZ-LRWAN1 installed on a Formula racing car (built by students at Technion - Israel Institute of Technology), and sends it to a GUI presenting the data (GUI project: github.com/ward-mattar/TechnionFormulaGUI).

How to install

  • Create an account on Mbed: https://os.mbed.com/account/signup/
  • Import project into Compiler
  • In the Program Workspace select "Formula_Nucleo_Receiver"
  • Select a Platform like so:
  1. Click button at top-left
  2. Add Board
  3. Search "NUCLEO F103RB" and then "Add to your Mbed Compiler"
  • Finally click "Compile", if the build was successful, the binary would download automatically
  • To install it on device simply plug it in to a PC, open device drive and drag then drop binary file in it
Committer:
wardm
Date:
Sat May 19 15:42:38 2018 +0000
Revision:
12:046346a16ff4
V1.0.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wardm 12:046346a16ff4 1 /* mbed Microcontroller Library - MemFileSystem
wardm 12:046346a16ff4 2 * Copyright (c) 2008, sford
wardm 12:046346a16ff4 3 */
wardm 12:046346a16ff4 4
wardm 12:046346a16ff4 5
wardm 12:046346a16ff4 6 #ifndef MBED_MEMFILESYSTEM_H
wardm 12:046346a16ff4 7 #define MBED_MEMFILESYSTEM_H
wardm 12:046346a16ff4 8
wardm 12:046346a16ff4 9 #include "FATFileSystem.h"
wardm 12:046346a16ff4 10
wardm 12:046346a16ff4 11 namespace mbed
wardm 12:046346a16ff4 12 {
wardm 12:046346a16ff4 13
wardm 12:046346a16ff4 14 class MemFileSystem : public FATFileSystem
wardm 12:046346a16ff4 15 {
wardm 12:046346a16ff4 16 public:
wardm 12:046346a16ff4 17
wardm 12:046346a16ff4 18 // 2000 sectors, each 512 bytes (malloced as required)
wardm 12:046346a16ff4 19 char *sectors[2000];
wardm 12:046346a16ff4 20
wardm 12:046346a16ff4 21 MemFileSystem(const char* name) : FATFileSystem(name) {
wardm 12:046346a16ff4 22 memset(sectors, 0, sizeof(sectors));
wardm 12:046346a16ff4 23 }
wardm 12:046346a16ff4 24
wardm 12:046346a16ff4 25 virtual ~MemFileSystem() {
wardm 12:046346a16ff4 26 for(int i = 0; i < 2000; i++) {
wardm 12:046346a16ff4 27 if(sectors[i]) {
wardm 12:046346a16ff4 28 free(sectors[i]);
wardm 12:046346a16ff4 29 }
wardm 12:046346a16ff4 30 }
wardm 12:046346a16ff4 31 }
wardm 12:046346a16ff4 32
wardm 12:046346a16ff4 33 // read a sector in to the buffer, return 0 if ok
wardm 12:046346a16ff4 34 virtual int disk_read(char *buffer, int sector) {
wardm 12:046346a16ff4 35 if(sectors[sector] == 0) {
wardm 12:046346a16ff4 36 // nothing allocated means sector is empty
wardm 12:046346a16ff4 37 memset(buffer, 0, 512);
wardm 12:046346a16ff4 38 } else {
wardm 12:046346a16ff4 39 memcpy(buffer, sectors[sector], 512);
wardm 12:046346a16ff4 40 }
wardm 12:046346a16ff4 41 return 0;
wardm 12:046346a16ff4 42 }
wardm 12:046346a16ff4 43
wardm 12:046346a16ff4 44 // write a sector from the buffer, return 0 if ok
wardm 12:046346a16ff4 45 virtual int disk_write(const char *buffer, int sector) {
wardm 12:046346a16ff4 46 // if buffer is zero deallocate sector
wardm 12:046346a16ff4 47 char zero[512];
wardm 12:046346a16ff4 48 memset(zero, 0, 512);
wardm 12:046346a16ff4 49 if(memcmp(zero, buffer, 512)==0) {
wardm 12:046346a16ff4 50 if(sectors[sector] != 0) {
wardm 12:046346a16ff4 51 free(sectors[sector]);
wardm 12:046346a16ff4 52 sectors[sector] = 0;
wardm 12:046346a16ff4 53 }
wardm 12:046346a16ff4 54 return 0;
wardm 12:046346a16ff4 55 }
wardm 12:046346a16ff4 56 // else allocate a sector if needed, and write
wardm 12:046346a16ff4 57 if(sectors[sector] == 0) {
wardm 12:046346a16ff4 58 char *sec = (char*)malloc(512);
wardm 12:046346a16ff4 59 if(sec==0) {
wardm 12:046346a16ff4 60 return 1; // out of memory
wardm 12:046346a16ff4 61 }
wardm 12:046346a16ff4 62 sectors[sector] = sec;
wardm 12:046346a16ff4 63 }
wardm 12:046346a16ff4 64 memcpy(sectors[sector], buffer, 512);
wardm 12:046346a16ff4 65 return 0;
wardm 12:046346a16ff4 66 }
wardm 12:046346a16ff4 67
wardm 12:046346a16ff4 68 // return the number of sectors
wardm 12:046346a16ff4 69 virtual int disk_sectors() {
wardm 12:046346a16ff4 70 return sizeof(sectors)/sizeof(sectors[0]);
wardm 12:046346a16ff4 71 }
wardm 12:046346a16ff4 72
wardm 12:046346a16ff4 73 };
wardm 12:046346a16ff4 74
wardm 12:046346a16ff4 75 }
wardm 12:046346a16ff4 76
wardm 12:046346a16ff4 77 #endif