mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-25 17:27:18 +00:00
added dvt class
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"module": {
|
||||
"bb_current": {
|
||||
"sys_path": "/sys/bb_sensor",
|
||||
"sys_path": "/home/oc/sys/bb_sensor",
|
||||
"get_vars": {
|
||||
"bb_shunt_voltage": {
|
||||
"unit": "mV"
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
},
|
||||
"bb_temp": {
|
||||
"sys_path": "/sys/bb_temp",
|
||||
"sys_path": "/home/oc/sys/bb_temp",
|
||||
"get_vars": {
|
||||
"bb_input_temp": {
|
||||
"unit": "Celcius"
|
||||
|
||||
@@ -3,58 +3,89 @@ import sys
|
||||
import json
|
||||
|
||||
DB_FILE = "data.json"
|
||||
db = '';
|
||||
module = ''
|
||||
operation = ''
|
||||
param = ''
|
||||
value = ''
|
||||
|
||||
def check_args(args):
|
||||
global module
|
||||
global operation
|
||||
global param
|
||||
global value
|
||||
class dvt():
|
||||
|
||||
def __init__(self, dbfile):
|
||||
self.module = ''
|
||||
self.operation = ''
|
||||
self.param = ''
|
||||
self.value = ''
|
||||
self.dbfile = dbfile
|
||||
self.db = ''
|
||||
|
||||
def get(self):
|
||||
pass
|
||||
|
||||
def set(self):
|
||||
pass
|
||||
|
||||
def print_vars(self):
|
||||
print("module_name: %s" %(self.module))
|
||||
print("operation: %s" %(self.operation))
|
||||
print("param: %s" %(self.param))
|
||||
print("value: %s" %(self.value))
|
||||
print("DB file: %s" %(self.dbfile))
|
||||
|
||||
def load_db(self):
|
||||
try:
|
||||
f = open(self.dbfile)
|
||||
self.db = json.load(f)
|
||||
f.close()
|
||||
except:
|
||||
print "File error %s" %(self.dbfile)
|
||||
sys.exit(-1);
|
||||
|
||||
return 0
|
||||
|
||||
def print_cmds(self):
|
||||
pass;
|
||||
|
||||
def check_args(args, a):
|
||||
|
||||
# check for module name
|
||||
if((len(args) < 2) or (args[1] == 'help')):
|
||||
return -1
|
||||
try:
|
||||
if((len(args) < 1) or (args[1] == 'help')):
|
||||
return -1
|
||||
|
||||
for x in db['module']:
|
||||
if(x == args[1]):
|
||||
module = x
|
||||
for x in a.db['module']:
|
||||
if(x == args[1]):
|
||||
a.module = x
|
||||
break
|
||||
|
||||
if a.module == '':
|
||||
return -1
|
||||
else:
|
||||
# Check for get/set
|
||||
if(len(args) < 3 and (args[2] == 'get' or args[2] == 'set')):
|
||||
if(len(args) < 2 and (args[2] == 'get' or args[2] == 'set')):
|
||||
return -1
|
||||
else:
|
||||
operation = args[2]
|
||||
if(operation == 'set'):
|
||||
if(len(args) < 5):
|
||||
return -1
|
||||
else:
|
||||
param = args[3]
|
||||
value = args[4]
|
||||
else: # get
|
||||
a.operation = args[2]
|
||||
if(a.operation == 'set'):
|
||||
if(len(args) < 4):
|
||||
return -1
|
||||
else:
|
||||
param = args[3]
|
||||
|
||||
return 0
|
||||
a.param = args[3]
|
||||
a.value = args[4]
|
||||
else: # get
|
||||
if(len(args) < 3):
|
||||
return -1
|
||||
else:
|
||||
a.param = args[3]
|
||||
return 0
|
||||
|
||||
def load_database():
|
||||
global db
|
||||
with open(DB_FILE) as json_data:
|
||||
db = json.load(json_data)
|
||||
return 0
|
||||
except:
|
||||
return -1
|
||||
|
||||
def main():
|
||||
load_database()
|
||||
if(check_args(sys.argv)):
|
||||
print db['module']['help']
|
||||
a = dvt(DB_FILE)
|
||||
a.load_db()
|
||||
if(check_args(sys.argv, a)):
|
||||
print a.db['module']['help']
|
||||
sys.exit(-1)
|
||||
|
||||
# We have a valid request request process it
|
||||
print "Request valid"
|
||||
a.print_vars()
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user