#!/usr/bin/python3

import datetime
from db import *
import json
import sqlite3
from globalSettings import *
import cgi
import cgitb
cgitb.enable()

device = DeviceName

form = cgi.FieldStorage()
request_Type = form.getvalue('requestType')


def read_SetupDefault():
    mockdata = {"currentControl": [0, 250, 300], "profiles": ["Custom", "Type A", "Type B"], "waveLength": [1500, 1600], "fsr": [200, 400, 500], "outPutPower": [5, 10, 15], "serialPort": ["Lab view", "Debug"], "baudRate": [2300, 2500, 2600],
                "IpAddress": "192.168.12.2", "subnetMask": "255.255.0.0", "defaultGateway": "10.0.15.2", "DNSServer": "103.12.15.11"}
    print(json.JSONEncoder().encode(mockdata))


print("Content-type:text/html\r\n\r\n")

try:
    if request_Type == 'read_SetupDefault':
        read_SetupDefault()
except BaseException as e:
    print(json.JSONEncoder().encode(
        {'status': 'fail', 'description': 'Eror occured, Please refer log file more info'}))
    # print e.message #Better to implement error logging
    #f.write(str(e.message)+ "\r\n")
    timeNow = datetime.datetime.now()
    f = open("./log.txt", "a+")
    f.write(str(timeNow)+" " + str(e.message) + "\r\n")
    f.close()
finally:
    conn.close()
