Merge pull request #41 from ucloud/feature_dev_model_gen_inc_file
dev model gen inc file
This commit is contained in:
commit
85f5e82890
|
@ -22,93 +22,10 @@
|
|||
#include "uiot_export.h"
|
||||
#include "uiot_import.h"
|
||||
#include "uiot_export_dm.h"
|
||||
#include "dm_property.h"
|
||||
#include "dm_event.h"
|
||||
#include "dm_command.h"
|
||||
|
||||
DM_Property_t property_humidity;
|
||||
DM_Node_t node_property_humidity;
|
||||
|
||||
DM_Property_t property_temperature;
|
||||
DM_Node_t node_property_temperature;
|
||||
|
||||
static void _init_data_template(){
|
||||
node_property_humidity.base_type = TYPE_FLOAT;
|
||||
node_property_humidity.key = "humidity";
|
||||
node_property_humidity.value.float32_value = 0.0;
|
||||
property_humidity.parse_type = TYPE_NODE;
|
||||
property_humidity.value.dm_node = &node_property_humidity;
|
||||
|
||||
node_property_temperature.base_type = TYPE_FLOAT;
|
||||
node_property_temperature.key = "temperature";
|
||||
node_property_temperature.value.float32_value = 0.0;
|
||||
property_temperature.parse_type = TYPE_NODE;
|
||||
property_temperature.value.dm_node = &node_property_temperature;
|
||||
|
||||
}
|
||||
|
||||
DM_Property_t event_high_temp_temperature;
|
||||
DM_Node_t node_event_high_temp_temperature;
|
||||
|
||||
static void _init_event_property_template(){
|
||||
node_event_high_temp_temperature.base_type = TYPE_FLOAT;
|
||||
node_event_high_temp_temperature.key = "temperature";
|
||||
node_event_high_temp_temperature.value.float32_value = 0.0;
|
||||
event_high_temp_temperature.parse_type = TYPE_NODE;
|
||||
event_high_temp_temperature.value.dm_node = &node_event_high_temp_temperature;
|
||||
|
||||
}
|
||||
DM_Event_t event_high_temp_warning;
|
||||
DM_Property_t high_temp[1];
|
||||
|
||||
static void _init_event_template(){
|
||||
_init_event_property_template();
|
||||
high_temp[0] = event_high_temp_temperature;
|
||||
event_high_temp_warning.event_identy = "high_temp";
|
||||
event_high_temp_warning.dm_property = high_temp;
|
||||
event_high_temp_warning.property_num = 1;
|
||||
|
||||
}
|
||||
|
||||
DM_Property_t cmd_input_set_temp_correction_temp_correction;
|
||||
DM_Node_t node_cmd_input_set_temp_correction_temp_correction;
|
||||
|
||||
static void _init_command_input_template(){
|
||||
node_cmd_input_set_temp_correction_temp_correction.base_type = TYPE_INT;
|
||||
node_cmd_input_set_temp_correction_temp_correction.key = "temp_correction";
|
||||
node_cmd_input_set_temp_correction_temp_correction.value.int32_value = 0;
|
||||
cmd_input_set_temp_correction_temp_correction.parse_type = TYPE_NODE;
|
||||
cmd_input_set_temp_correction_temp_correction.value.dm_node = &node_cmd_input_set_temp_correction_temp_correction;
|
||||
|
||||
}
|
||||
static void _input_parse_config(const char *cmd_id, const char *input){
|
||||
if((strlen(cmd_id) == strlen("set_temp_correction")) && (0 == strncmp(cmd_id, "set_temp_correction", strlen("set_temp_correction"))))
|
||||
{
|
||||
char *set_temp_correction_temp_correction = NULL;
|
||||
set_temp_correction_temp_correction = LITE_json_value_of((char *)"temp_correction", (char *)input);
|
||||
node_cmd_input_set_temp_correction_temp_correction.value.int32_value = atoi(set_temp_correction_temp_correction);
|
||||
HAL_Free(set_temp_correction_temp_correction);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
DM_Property_t cmd_output_set_temp_correction_correction_result;
|
||||
DM_Node_t node_cmd_output_set_temp_correction_correction_result;
|
||||
|
||||
DM_Property_t cmd_output_set_temp_correction_effect_temp_correction;
|
||||
DM_Node_t node_cmd_output_set_temp_correction_effect_temp_correction;
|
||||
|
||||
static void _init_command_output_template(){
|
||||
node_cmd_output_set_temp_correction_correction_result.base_type = TYPE_BOOL;
|
||||
node_cmd_output_set_temp_correction_correction_result.key = "correction_result";
|
||||
node_cmd_output_set_temp_correction_correction_result.value.bool_value = 0;
|
||||
cmd_output_set_temp_correction_correction_result.parse_type = TYPE_NODE;
|
||||
cmd_output_set_temp_correction_correction_result.value.dm_node = &node_cmd_output_set_temp_correction_correction_result;
|
||||
|
||||
node_cmd_output_set_temp_correction_effect_temp_correction.base_type = TYPE_INT;
|
||||
node_cmd_output_set_temp_correction_effect_temp_correction.key = "effect_temp_correction";
|
||||
node_cmd_output_set_temp_correction_effect_temp_correction.value.int32_value = 0;
|
||||
cmd_output_set_temp_correction_effect_temp_correction.parse_type = TYPE_NODE;
|
||||
cmd_output_set_temp_correction_effect_temp_correction.value.dm_node = &node_cmd_output_set_temp_correction_effect_temp_correction;
|
||||
|
||||
}
|
||||
//用实际设备四元组替换
|
||||
#define UIOT_MY_PRODUCT_SN "PRODUCT_SN"
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#include "uiot_internal.h"
|
||||
#include "dm_internal.h"
|
||||
|
||||
extern DM_Property_t cmd_input_set_temp_correction_temp_correction;
|
||||
extern DM_Node_t node_cmd_input_set_temp_correction_temp_correction;
|
||||
|
||||
void _init_command_input_template();
|
||||
extern DM_Property_t cmd_output_set_temp_correction_correction_result;
|
||||
extern DM_Node_t node_cmd_output_set_temp_correction_correction_result;
|
||||
|
||||
extern DM_Property_t cmd_output_set_temp_correction_effect_temp_correction;
|
||||
extern DM_Node_t node_cmd_output_set_temp_correction_effect_temp_correction;
|
||||
|
||||
void _init_command_output_template();
|
||||
void _input_parse_config(const char *cmd_id, const char *input);
|
|
@ -0,0 +1,11 @@
|
|||
#include "uiot_internal.h"
|
||||
#include "dm_internal.h"
|
||||
|
||||
extern DM_Property_t event_high_temp_temperature;
|
||||
extern DM_Node_t node_event_high_temp_temperature;
|
||||
|
||||
void _init_event_property_template();
|
||||
extern DM_Event_t event_high_temp_warning;
|
||||
extern DM_Property_t high_temp[1];
|
||||
|
||||
void _init_event_template();
|
|
@ -0,0 +1,10 @@
|
|||
#include "uiot_internal.h"
|
||||
#include "dm_internal.h"
|
||||
|
||||
extern DM_Property_t property_humidity;
|
||||
extern DM_Node_t node_property_humidity;
|
||||
|
||||
extern DM_Property_t property_temperature;
|
||||
extern DM_Node_t node_property_temperature;
|
||||
|
||||
void _init_data_template();
|
|
@ -1,7 +1,8 @@
|
|||
#include "dm_command.h"
|
||||
DM_Property_t cmd_input_set_temp_correction_temp_correction;
|
||||
DM_Node_t node_cmd_input_set_temp_correction_temp_correction;
|
||||
|
||||
static void _init_command_input_template(){
|
||||
void _init_command_input_template(){
|
||||
node_cmd_input_set_temp_correction_temp_correction.base_type = TYPE_INT;
|
||||
node_cmd_input_set_temp_correction_temp_correction.key = "temp_correction";
|
||||
node_cmd_input_set_temp_correction_temp_correction.value.int32_value = 0;
|
||||
|
@ -9,7 +10,7 @@ static void _init_command_input_template(){
|
|||
cmd_input_set_temp_correction_temp_correction.value.dm_node = &node_cmd_input_set_temp_correction_temp_correction;
|
||||
|
||||
}
|
||||
static void _input_parse_config(const char *cmd_id, const char *input){
|
||||
void _input_parse_config(const char *cmd_id, const char *input){
|
||||
if((strlen(cmd_id) == strlen("set_temp_correction")) && (0 == strncmp(cmd_id, "set_temp_correction", strlen("set_temp_correction"))))
|
||||
{
|
||||
char *set_temp_correction_temp_correction = NULL;
|
||||
|
@ -26,7 +27,7 @@ DM_Node_t node_cmd_output_set_temp_correction_correction_result;
|
|||
DM_Property_t cmd_output_set_temp_correction_effect_temp_correction;
|
||||
DM_Node_t node_cmd_output_set_temp_correction_effect_temp_correction;
|
||||
|
||||
static void _init_command_output_template(){
|
||||
void _init_command_output_template(){
|
||||
node_cmd_output_set_temp_correction_correction_result.base_type = TYPE_BOOL;
|
||||
node_cmd_output_set_temp_correction_correction_result.key = "correction_result";
|
||||
node_cmd_output_set_temp_correction_correction_result.value.bool_value = 0;
|
|
@ -1,7 +1,8 @@
|
|||
#include "dm_event.h"
|
||||
DM_Property_t event_high_temp_temperature;
|
||||
DM_Node_t node_event_high_temp_temperature;
|
||||
|
||||
static void _init_event_property_template(){
|
||||
void _init_event_property_template(){
|
||||
node_event_high_temp_temperature.base_type = TYPE_FLOAT;
|
||||
node_event_high_temp_temperature.key = "temperature";
|
||||
node_event_high_temp_temperature.value.float32_value = 0.0;
|
||||
|
@ -12,7 +13,7 @@ static void _init_event_property_template(){
|
|||
DM_Event_t event_high_temp_warning;
|
||||
DM_Property_t high_temp[1];
|
||||
|
||||
static void _init_event_template(){
|
||||
void _init_event_template(){
|
||||
_init_event_property_template();
|
||||
high_temp[0] = event_high_temp_temperature;
|
||||
event_high_temp_warning.event_identy = "high_temp";
|
|
@ -1,10 +1,11 @@
|
|||
#include "dm_property.h"
|
||||
DM_Property_t property_humidity;
|
||||
DM_Node_t node_property_humidity;
|
||||
|
||||
DM_Property_t property_temperature;
|
||||
DM_Node_t node_property_temperature;
|
||||
|
||||
static void _init_data_template(){
|
||||
void _init_data_template(){
|
||||
node_property_humidity.base_type = TYPE_FLOAT;
|
||||
node_property_humidity.key = "humidity";
|
||||
node_property_humidity.value.float32_value = 0.0;
|
|
@ -97,6 +97,30 @@ class iot_filed:
|
|||
declar_info += "DM_Node_t node_{};\n".format("{}_".format(self.prefix) + self.id)
|
||||
return declar_info
|
||||
|
||||
def get_property_extern_declar_name(self):
|
||||
extern_declar_info = ""
|
||||
if self.type_name == "struct":
|
||||
extern_declar_info += "extern DM_Property_t {};\n".format("{}_".format(self.prefix) + self.id)
|
||||
extern_declar_info += "extern DM_Type_Struct_t st_{};\n".format("{}_".format(self.prefix) + self.id)
|
||||
extern_declar_info += "extern DM_Node_t node_{}[{}];\n".format("{}_".format(self.prefix) + self.id, self.struct_member_num)
|
||||
return extern_declar_info
|
||||
elif self.type_name == "array":
|
||||
if self.item_type == "struct":
|
||||
extern_declar_info += "extern DM_Property_t {};\n".format("{}_".format(self.prefix) + self.id)
|
||||
extern_declar_info += "extern DM_Array_Struct_t arr_st_{};\n".format("{}_".format(self.prefix) + self.id)
|
||||
extern_declar_info += "extern DM_Type_Struct_t st_{}[{}];\n".format("{}_".format(self.prefix) + self.id, self.array_num)
|
||||
extern_declar_info += "extern DM_Node_t node_{}[{}][{}];\n".format("{}_".format(self.prefix) + self.id, self.array_num, self.item_member_num)
|
||||
return extern_declar_info
|
||||
else:
|
||||
extern_declar_info += "extern DM_Property_t {};\n".format("{}_".format(self.prefix) + self.id)
|
||||
extern_declar_info += "extern DM_Array_Base_t arr_base_{};\n".format("{}_".format(self.prefix) + self.id)
|
||||
extern_declar_info += "extern DM_Node_t node_{}[{}];\n".format("{}_".format(self.prefix) + self.id, self.array_num)
|
||||
return extern_declar_info
|
||||
else:
|
||||
extern_declar_info += "extern DM_Property_t {};\n".format("{}_".format(self.prefix) + self.id)
|
||||
extern_declar_info += "extern DM_Node_t node_{};\n".format("{}_".format(self.prefix) + self.id)
|
||||
return extern_declar_info
|
||||
|
||||
def get_property_config_member(self):
|
||||
config_info = ""
|
||||
loop = 0
|
||||
|
@ -206,6 +230,12 @@ class iot_event:
|
|||
declar_info += "DM_Property_t {}[{}];\n".format(self.id, self.output_num)
|
||||
return declar_info
|
||||
|
||||
def get_event_extern_declar_name(self):
|
||||
extern_declar_info = ""
|
||||
extern_declar_info += "extern DM_Event_t event_{}_{};\n".format(self.id, self.type_name)
|
||||
extern_declar_info += "extern DM_Property_t {}[{}];\n".format(self.id, self.output_num)
|
||||
return extern_declar_info
|
||||
|
||||
def get_event_config_member(self):
|
||||
config_info = ""
|
||||
loop = 0
|
||||
|
@ -349,8 +379,9 @@ class iot_json_parse:
|
|||
|
||||
def gen_data_config(self):
|
||||
declar = ""
|
||||
declar += "#include \"dm_property.h\"\n"
|
||||
config = ""
|
||||
config += "static void _init_data_template(){\n"
|
||||
config += "void _init_data_template(){\n"
|
||||
for field in self.fields:
|
||||
declar += "{}\n".format(field.get_property_declar_name())
|
||||
config += "{}\n".format(field.get_property_config_member())
|
||||
|
@ -358,10 +389,20 @@ class iot_json_parse:
|
|||
result = declar + config
|
||||
return result
|
||||
|
||||
def gen_data_inc(self):
|
||||
extern_data_inc = ""
|
||||
extern_data_inc += "#include \"uiot_internal.h\"\n"
|
||||
extern_data_inc += "#include \"dm_internal.h\"\n\n"
|
||||
for field in self.fields:
|
||||
extern_data_inc += "{}\n".format(field.get_property_extern_declar_name())
|
||||
extern_data_inc += "void _init_data_template();\n"
|
||||
return extern_data_inc
|
||||
|
||||
def gen_event_config(self):
|
||||
properties_declar = ""
|
||||
properties_declar += "#include \"dm_event.h\"\n"
|
||||
properties_config = ""
|
||||
properties_config += "static void _init_event_property_template(){\n"
|
||||
properties_config += "void _init_event_property_template(){\n"
|
||||
for event_properties in self.events_properties:
|
||||
properties_declar += "{}\n".format(event_properties.get_property_declar_name())
|
||||
properties_config += "{}\n".format(event_properties.get_property_config_member())
|
||||
|
@ -369,7 +410,7 @@ class iot_json_parse:
|
|||
|
||||
event_declar = ""
|
||||
event_config = ""
|
||||
event_config += "static void _init_event_template(){\n"
|
||||
event_config += "void _init_event_template(){\n"
|
||||
event_config += " _init_event_property_template();\n"
|
||||
for event_obj in self.events:
|
||||
event_declar += "{}\n".format(event_obj.get_event_declar_name())
|
||||
|
@ -378,24 +419,40 @@ class iot_json_parse:
|
|||
result = properties_declar + properties_config + event_declar + event_config
|
||||
return result
|
||||
|
||||
def gen_event_inc(self):
|
||||
properties_extern_inc = ""
|
||||
properties_extern_inc += "#include \"uiot_internal.h\"\n"
|
||||
properties_extern_inc += "#include \"dm_internal.h\"\n\n"
|
||||
for event_properties in self.events_properties:
|
||||
properties_extern_inc += "{}\n".format(event_properties.get_property_extern_declar_name())
|
||||
properties_extern_inc += "void _init_event_property_template();\n"
|
||||
|
||||
event_extern_inc = ""
|
||||
for event_obj in self.events:
|
||||
event_extern_inc += "{}\n".format(event_obj.get_event_extern_declar_name())
|
||||
event_extern_inc += "void _init_event_template();\n"
|
||||
result = properties_extern_inc + event_extern_inc
|
||||
return result
|
||||
|
||||
def gen_command_config(self):
|
||||
cmd_input_declar = ""
|
||||
cmd_input_declar += "#include \"dm_command.h\"\n"
|
||||
cmd_input_config = ""
|
||||
cmd_input_config += "static void _init_command_input_template(){\n"
|
||||
cmd_input_config += "void _init_command_input_template(){\n"
|
||||
for command_input_property in self.input:
|
||||
cmd_input_declar += "{}\n".format(command_input_property.get_property_declar_name())
|
||||
cmd_input_config += "{}\n".format(command_input_property.get_property_config_member())
|
||||
cmd_input_config += "}\n"
|
||||
|
||||
cmd_input_parse = ""
|
||||
cmd_input_parse += "static void _input_parse_config(const char *cmd_id, const char *input){\n"
|
||||
cmd_input_parse += "void _input_parse_config(const char *cmd_id, const char *input){\n"
|
||||
for cmd_input_parse_item in self.input_parse:
|
||||
cmd_input_parse += "{}\n".format(cmd_input_parse_item.get_input_config())
|
||||
cmd_input_parse += "}\n"
|
||||
|
||||
cmd_output_declar = ""
|
||||
cmd_output_config = ""
|
||||
cmd_output_config += "static void _init_command_output_template(){\n"
|
||||
cmd_output_config += "void _init_command_output_template(){\n"
|
||||
for command_output_property in self.output:
|
||||
cmd_output_declar += "{}\n".format(command_output_property.get_property_declar_name())
|
||||
cmd_output_config += "{}\n".format(command_output_property.get_property_config_member())
|
||||
|
@ -403,6 +460,22 @@ class iot_json_parse:
|
|||
result = cmd_input_declar + cmd_input_config + cmd_input_parse + cmd_output_declar + cmd_output_config
|
||||
return result
|
||||
|
||||
def gen_command_inc(self):
|
||||
cmd_input_extern_inc = ""
|
||||
cmd_input_extern_inc += "#include \"uiot_internal.h\"\n"
|
||||
cmd_input_extern_inc += "#include \"dm_internal.h\"\n\n"
|
||||
for command_input_property in self.input:
|
||||
cmd_input_extern_inc += "{}\n".format(command_input_property.get_property_extern_declar_name())
|
||||
cmd_input_extern_inc += "void _init_command_input_template();\n"
|
||||
|
||||
cmd_output_extern_inc = ""
|
||||
for command_output_property in self.output:
|
||||
cmd_output_extern_inc += "{}\n".format(command_output_property.get_property_extern_declar_name())
|
||||
cmd_output_extern_inc += "void _init_command_output_template();\n"
|
||||
cmd_output_extern_inc += "void _input_parse_config(const char *cmd_id, const char *input);\n"
|
||||
result = cmd_input_extern_inc + cmd_output_extern_inc
|
||||
return result
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Iothub datatemplate events and command config code generator.', usage='use "./codegen.py -c xx/config.json" gen config code')
|
||||
parser.add_argument('-c', '--config', dest='config', metavar='xxx.json', required=False, default='xxx.json',
|
||||
|
@ -441,25 +514,42 @@ def main():
|
|||
try:
|
||||
snippet = iot_json_parse(thingmodel)
|
||||
|
||||
output_data_config_file_name = args.dest + "/property_config.c"
|
||||
output_data_config_file_name = args.dest + "/dm_property_config.c"
|
||||
output_file = open(output_data_config_file_name, "w")
|
||||
output_file.write("{}".format(snippet.gen_data_config()))
|
||||
output_file.close()
|
||||
|
||||
output_event_config_file_name = args.dest + "/event_config.c"
|
||||
output_data_inc_file_name = args.dest + "/dm_property.h"
|
||||
output_file = open(output_data_inc_file_name, "w")
|
||||
output_file.write("{}".format(snippet.gen_data_inc()))
|
||||
output_file.close()
|
||||
|
||||
output_event_config_file_name = args.dest + "/dm_event_config.c"
|
||||
output_file = open(output_event_config_file_name, "w")
|
||||
output_file.write("{}".format(snippet.gen_event_config()))
|
||||
output_file.close()
|
||||
|
||||
output_command_config_file_name = args.dest + "/command_config.c"
|
||||
output_event_inc_file_name = args.dest + "/dm_event.h"
|
||||
output_file = open(output_event_inc_file_name, "w")
|
||||
output_file.write("{}".format(snippet.gen_event_inc()))
|
||||
output_file.close()
|
||||
|
||||
output_command_config_file_name = args.dest + "/dm_command_config.c"
|
||||
output_file = open(output_command_config_file_name, "w")
|
||||
output_file.write("{}".format(snippet.gen_command_config()))
|
||||
output_file.close()
|
||||
|
||||
print(u"file {} release successful".format(output_data_config_file_name))
|
||||
print(u"file {} release successful".format(output_event_config_file_name))
|
||||
print(u"file {} release successful".format(output_command_config_file_name))
|
||||
output_command_inc_file_name = args.dest + "/dm_command.h"
|
||||
output_file = open(output_command_inc_file_name, "w")
|
||||
output_file.write("{}".format(snippet.gen_command_inc()))
|
||||
output_file.close()
|
||||
|
||||
print(u"file {} release successful".format(output_data_config_file_name))
|
||||
print(u"file {} release successful".format(output_data_inc_file_name))
|
||||
print(u"file {} release successful".format(output_event_config_file_name))
|
||||
print(u"file {} release successful".format(output_event_inc_file_name))
|
||||
print(u"file {} release successful".format(output_command_config_file_name))
|
||||
print(u"file {} release successful".format(output_command_inc_file_name))
|
||||
return 0
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
|
|
Loading…
Reference in New Issue