module.exports = function(app, logger, io, db) {
    var fs = require("fs");
    var fpga = require('.././build/Release/openfpgaduino');
    var express = require('express');
    var router = express.Router();

    logger.debug("Initial fpga module");
    router.get('/', function(req, res) {
        res.json({
            message: 'hooray! welcome to our fpga api!'
        });
    });

    router.get('/device', function(req, res) {
        res.json({
            message: 'hooray! welcome to our api!'
        });
    });

    router.post('/device', function(req, res) {
        res.json({
            message: 'hooray! welcome to our api!'
        });
    });


    router.get('/memory', function(req, res) {
        res.json({
            message: 'hooray! welcome to our api!'
        });
    });

    router.post('/memory', function(req, res) {
        res.json({
            message: 'hooray! welcome to our api!'
        });
    });

    router.get('/config', function(req, res) {
        res.json({
            message: 'hooray! welcome to our api!'
        });
    });

    router.post('/config', function(req, res) {
        logger.debug(req);
        var uploadfile = req.files.uploadfile;
        var path = uploadfile.path;
        var filename = uploadfile.originalname;
        var extention = uploadfile.extension;
        var fullname = filename + extention;
        logger.debug(filename + extention);
        var ret = fs.renameSync(path, "./uploads/" + fullname);
        p.exec("cat ./uploads/" + fullname + " > /sys/kernel/debug/fpga/data;" +
            " echo 1 > /sys/kernel/debug/fpga/download",
            function(error, stdout, stderr) {
                if (error !== null) {
                    logger.error("Download config error");
                }
            });
        if (!ret)
            res.json({
                message: 'Write file success'
            });
    });
    
    router.post('/config/list', function(req, res) {
        var filelist = [];
        fs.readdirSync("./uploads/").forEach(function(filename) {
            if (!/\.rbf$/.test(filename)) {
                return;
            }
            filelist.push(filename);
        });
        res.json(
            filelist
        );
    });

    router.get('/api/list/', function(req, res) {
        var method = [];
        for (m in fpga) {
            method.push(m.toString);
        }
        req.json({
            "method": method
        });
    });

    router.get('/api/list/:method', function(req, res) {
        var method = req.params.method;
        if (fpga[method]) {
            req.json({
                "method": fpga[method]
            });
        }
    });

    router.post('/api/call/:method', function(req, res) {
        var method = req.params.method;
        var paramter = req.body;
        var ret;
        fpga.fpga_open();
        switch (paramter.length) {
            case 0:
                ret = fpga[method]();
                break;
            case 1:
                ret = fpga[method](paramter[0]);
                break;
            case 2:
                ret = fpga[method](paramter[0], paramter[1]);
                break;
            case 3:
                ret = fpga[method](paramter[0], paramter[1], paramter[2]);
                break;
            case 4:
                ret = fpga[method](paramter[0], paramter[1], paramter[2], paramter[3]);
                break;
            case 5:
                ret = fpga[method](paramter[0], paramter[1], paramter[2], paramter[3], paramter[4]);
                break;
            case 6:
                ret = fpga[method](paramter[0], paramter[1], paramter[2], paramter[3], paramter[4], paramter[5]);
                break;
            case 7:
                ret = fpga[method](paramter[0], paramter[1], paramter[2], paramter[3], paramter[4], paramter[5], paramter[6]);
                break;
            case 8:
                ret = fpga[method](paramter[0], paramter[1], paramter[2], paramter[3], paramter[4], paramter[5], paramter[6], paramter[7]);
                break;
            default:
                logger.error("too manay arguments");
        }
        logger.info("method is " + method);
        res.json(ret);
        fpga.fpga_close();
    });


    io.sockets.on('connection', function(socket) {
        socket.emit('news', {
            hello: 'world'
        });
        socket.on('my other event', function(data) {
            console.log(data);
        });
    });

    app.use('/fpga', router);

}
@@ -1089,24 +1089,30 @@
 uter.post('/
+upload
 config', fun
@@ -1121,32 +1121,32 @@
 ion(req, res) %7B%0A
-
         logger.d
@@ -1872,9 +1872,20 @@
 e: '
-W
+Upload and w
 rite
@@ -2244,16 +2244,16 @@
 ilelist%0A
-
         
@@ -2256,32 +2256,544 @@
     );%0A    %7D);%0A%0A
+    router.post('/config', function(req, res) %7B%0A        var filename = req.filename;%0A        p.exec(%22cat ./uploads/%22 + filename + %22 %3E /sys/kernel/debug/fpga/data;%22 +%0A            %22 echo 1 %3E /sys/kernel/debug/fpga/download%22,%0A            function(error, stdout, stderr) %7B%0A                if (error !== null) %7B%0A                    logger.error(%22Download config error%22);%0A                %7D%0A            %7D);%0A        if (!ret)%0A            res.json(%7B%0A                message: 'Write file success'%0A            %7D);%0A    %7D);%0A%0A
     router.get('

add config