Skip to content
Snippets Groups Projects
Commit e642bcf1 authored by jkerdreu's avatar jkerdreu
Browse files

- Added support for Golang

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3229 b32b6428-25c9-4566-ad07-03861ab6144f
parent 4491786c
No related branches found
No related tags found
No related merge requests found
......@@ -19,20 +19,20 @@ BLACK_LIST=['application-layer.cddl',
]
def name_to_method(name):
def name_snake_case(name):
if name.endswith('.basic'):
return name.split('.basic')[0]
else:
return name.replace('.','_')
def name_to_class(name):
def name_to_camel_case(name):
if name.endswith('.basic'):
tmp = name.split('.basic')[0]
else:
tmp = name.replace('.','_')
return tmp[0].upper() + tmp[1:]
tmp = name
tmp = tmp.title()
return tmp.replace('.','')
def dump(jsonDict):
......@@ -172,8 +172,8 @@ class DeviceBuilder:
datamodel.update({k:dict_})
args = {}
args['name'] = name_to_method(name)
args['Name'] = name_to_class(name)
args['name'] = name_snake_case(name)
args['Name'] = name_to_camel_case(name)
args['doc'] = data['description']
args['devtype'] = name
args['attributes'] = attributes
......@@ -198,7 +198,12 @@ class DeviceBuilder:
print(head)
self.build_all('devices_js.mako')
def build_go(self):
head = open('./head_go.txt','r').read()
print(head)
self.build_all('devices_go.mako')
db = DeviceBuilder()
db.build_py()
# db.build_py()
# db.build_js()
db.build_go()
//=====================================================================
func New${Name}(addr uuid.UUID) *xaal.Device {
dev := xaal.NewDevice("${devtype}")
dev.Address = addr
% if (len(attributes) !=0):
// -------- Attributes --------
% for attr in attributes:
<%
dm = datamodel[attributes[attr]]
desc = dm.get('description','no-desc ?')
type_ = dm.get('type')
unit = dm.get('unit')
comment = desc
if type_:
comment = comment +' | type: ' + type_
if unit:
comment = comment +' | unit: ' + unit
%> // ${comment}
<%
type_ = dm.get('type')
value = 'nil'
if type_ == 'data = bool':
value = 'false'
elif type_ in ['data = uint','data = number']:
value = 0
elif unit in ['K']:
value = 0
elif unit in ['%','%EL','%RH','°']:
value = 0.0
%> dev.AddAttribute("${attr}",${value})
% endfor
% endif
% if (len(methods) !=0):
// -------- Methods --------
% for meth in methods:
<%
keys = list(methods[meth].get('in',{}).keys())
print_keys = ', '.join(keys)
camel_meth = "default"+ f"{meth}".replace('_','.').title().replace('.','')
%> // ${methods[meth]['description']}
% if len(keys) != 0 :
${camel_meth} := func(args xaal.MessageBody) *xaal.MessageBody {
// Arguments: ${print_keys}
fmt.Printf("default ${meth}: %v\n", args)
% else:
${camel_meth} := func(xaal.MessageBody) *xaal.MessageBody {
fmt.Printf("default ${meth}\n")
% endif
return nil
}
% endfor
% for meth in methods:
<%
camel_meth = "default"+f"{meth}".replace('_','.').title().replace('.','')
%> dev.AddMethod("${meth}", ${camel_meth})
% endfor
% endif
return dev
}
package xaalschemas
import (
"fmt"
xaal "xAAL/xaal"
"github.com/google/uuid"
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment