Emulation of LocalFileSystem with virtual COM.

Dependencies:   USBDevice

Dependents:   KL46Z-lpc81isp lpcterm2

#include "USBLocalFileSystem.h"

int main() {
    USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB)

    while(1) {
        usb_local->lock(true);
        usb_local->remount();
        char filename[32];
        if (usb_local->find(filename, sizeof(filename), "*.TXT")) {
            FILE* fp = fopen(filename, "r");
            if (fp) {
                int c;
                while((c = fgetc(fp)) != EOF) {
                    usb_local->putc(c);
                }
                fclose(fp);
            }
        }    
        usb_local->lock(false);

        wait_ms(1000*5);
    }
}



Sample application:

Import programKL46Z-lpc81isp

ISP example program.

Import programlpcterm2

semihost server example program

src/mymap.h

Committer:
va009039
Date:
2014-06-21
Revision:
6:528036abfb02
Parent:
0:39eb4d5b97df

File content as of revision 6:528036abfb02:

#pragma once

template<class K,class T>
class mymap {
    struct mypair {
        K first;
        T second;
    };
public:
    mymap() {
        m_size = 0;
    }
    T& operator[](const K& key) {
        int it;
        if (count(key) == 0) {
            it = insert(key, 0);
        } else {
            it = find(key);
        }
        return m_buf[it].second;
    }
    bool empty() { return m_size == 0 ? true : false; }
    int size() { return m_size; }
    void clear() { m_size = 0; }
    int count(K key) {
        for(int i = 0; i < m_size; i++) {
            if (m_buf[i].first == key) {
                return 1;
            }
        }
        return 0;
    }
    K getKey(int index) {
        return m_buf[index].first;
    }

private:
    int find(K key) {
        for(int i = 0; i < m_size; i++) {
            if (m_buf[i].first == key) {
                return i;
            }
        }
        return -1;
    }
    int insert(K key, T value) {
        int it = find(key);
        if (it != -1) {
            m_buf[it].second = value;
            return it;
        }
        mypair* new_buf = new mypair[m_size+1];
        if (m_size > 0) {
            for(int i = 0; i < m_size; i++) {
                new_buf[i] = m_buf[i];
            }
            delete[] m_buf;
        }
        m_buf = new_buf;
        it = m_size++;
        m_buf[it].first = key;
        m_buf[it].second = value;
        return it;
    }

    int m_size;
    mypair *m_buf;
};