rabin 5 lat temu
rodzic
commit
aff4e6b043

+ 68 - 71
admin/page/device.py

@@ -10,7 +10,7 @@ class gateway_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'网关'
 			,path = 'gateway'
 			,width = '600'
@@ -23,7 +23,7 @@ class gateway_path(Load):
 			,state = False
 		)
 		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
-		self.commonList('device_gateway')
+		self.list('device_gateway')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
 				farm = self.service('common').one('farm', id=value['farm_id'])
@@ -41,7 +41,7 @@ class gateway_path(Load):
 							elif v['hardware_type'] == 4 and v['value']:
 								self.data['list'][key]['power_status'] = '连接'
 								self.data['list'][key]['power_num'] = v['value']
-		self.commonView('list')
+		self.show('list')
 
 class gateway_update_path(Load):
 	@Web.auth
@@ -53,24 +53,24 @@ class gateway_update_path(Load):
 			hardware_id = 'hardware_id-input-required'
 		else:
 			hardware_id = 'hardware_id-input-required'
-		self.common(
+		self.set(
 			path = 'gateway'
 			,label = (u'所属农场', u'网关名称', u'设备id', u'设备分布图纸')
 			,update = ('farm_id-select-required', 'name-input-required',hardware_id, 'pic-pic-')
 			,update_farm_id = Demeter.config['setting']['farmList']
 		)
-		self.commonOne('device_gateway')
-		self.commonView('update')
+		self.one('device_gateway')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		id = self.commonUpdate('device_gateway')
+		id = self.update('device_gateway')
 		self.device(id)
 
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('device_gateway')
+		self.drop('device_gateway')
 
 	@Web.auth
 	@Web.setting
@@ -83,7 +83,7 @@ class info_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'设备'
 			,path = 'info'
 			,width = '600'
@@ -91,12 +91,11 @@ class info_path(Load):
 			,button = ({'name':'添加摄像机','link':'/device/camera_update'},{'name':'添加摄像头','link':'/device/camera_pic_update'})
 			,add = False
 			#,edit = False
-			,search = (('farm_id-select--gateway_id', 'hardware_type-select-','type_id-select-','name-input-mlike', 'status-hidden-'), (u'选择农场',u'硬件类型',u'设备类型',u'设备名称', '设备状态'))
-			,thead = (u'所属农场', u'设备名称', u'设备id', u'当前值', u'设备类型', u'网关',u'硬件类型')
-			,tbody = ('farm','name', 'hardware_id', 'value', 'type', 'gateway', 'hardware_type')
+			,search = (('hardware_type-select-','type_id-select-','name-input-mlike', 'status-hidden-'), (u'硬件类型',u'设备类型',u'设备名称', '设备状态'))
+			,thead = (u'设备名称', u'设备id', u'当前值', u'设备类型', u'网关',u'硬件类型')
+			,tbody = ('name', 'hardware_id', 'value', 'type', 'gateway', 'hardware_type')
 			,state = True
 		)
-		self.data['common']['search_farm_id-select--gateway_id'] = Demeter.config['setting']['farmList']
 		self.data['common']['search_type_id-select-'] = self.service('common').list('device_type')
 		self.data['common']['search_gateway_id-select---farm_id'] = self.service('common').list('device_gateway')
 		self.data['common']['search_hardware_type-select-'] = self.service('common').list('hardware_type')
@@ -108,11 +107,9 @@ class info_path(Load):
 		if status:
 			self.data['search']['status'] = False
 
-		self.commonList('device_info', order='inorder asc, type_id asc,udate asc,hardware_id asc')
+		self.list('device_info', order='inorder asc, type_id asc,udate asc,hardware_id asc')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
-				farm = self.service('common').one('farm', id=value['farm_id'])
-				self.data['list'][key]['farm'] = farm['name']
 				self.data['list'][key]['type'] = '无'
 				if value['type_id'] > 0:
 					type_info = self.service('common').one('device_type', id=value['type_id'])
@@ -155,7 +152,7 @@ class info_path(Load):
 				self.data['list'][key]['hardware_type'] = hardware_type['name']
 
 
-		self.commonView('list')
+		self.show('list')
 
 	@Web.auth
 	@Web.setting
@@ -172,20 +169,20 @@ class info_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.commonOne('device_info')
+		self.one('device_info')
 		if self.data['info']['hardware_type'] == 7:
-			self.common(
+			self.set(
 				path = 'camera'
 				#,label = (u'摄像机名称', u'摄像机id', u'所属农场', u'选择网关', u'选择硬件类型', u'摄像机地址')
 				#,update = ('name-input-required','hardware_id-show-','farm_id-select-required','gateway_id-select-required','hardware_type-select-required','value-text-required')
-				,label = (u'摄像机名称', u'摄像机id', u'所属农场', u'选择网关', u'摄像机地址', u'排序')
-				,update = ('name-input-required','hardware_id-show-','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
+				,label = (u'摄像机名称', u'摄像机id', u'选择网关', u'摄像机地址', u'排序')
+				,update = ('name-input-required','hardware_id-show-','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
 				,update_farm_id = Demeter.config['setting']['farmList']
 				,update_gateway_id = self.service('common').list('device_gateway')
 				#,update_hardware_type = self.service('common').list('hardware_type')
 			)
 		elif self.data['info']['hardware_type'] == 6:
-			self.common(
+			self.set(
 				path = 'camera_pic'
 				,label = (u'摄像头名称', u'摄像头id', u'所属农场', u'选择网关', u'摄像头地址', u'排序')
 				,update = ('name-input-required','hardware_id-show-','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
@@ -193,7 +190,7 @@ class info_update_path(Load):
 				,update_gateway_id = self.service('common').list('device_gateway')
 			)
 		elif self.data['info']['hardware_type'] in (2,4):
-			self.common(
+			self.set(
 				path = 'info'
 				#,label = (u'设备名称', u'设备id', u'计算公式', u'实时计算公式')
 				#,update = ('name-input-required','hardware_id-show-',u'exp-text--{n}为当前数据,只处理最新数据',u'out_exp-text--处理所有数据,比较消耗服务器资源')
@@ -201,24 +198,24 @@ class info_update_path(Load):
 				,update = ('name-input-required','hardware_id-show-',u'exp-text--{n}为当前数据,只处理最新数据','inorder-text-')
 			)
 		else:
-			self.common(
+			self.set(
 				path = 'info'
 				,label = (u'设备名称', u'设备id', u'排序')
 				,update = ('name-input-required','hardware_id-show-','inorder-text-')
 			)
-		self.commonView('update')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('device_info')
+		self.update('device_info')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('device_info')
+		self.drop('device_info')
 		"""
-		self.commonOne('device_info')
+		self.one('device_info')
 		if self.input('state') == 'True' or (self.data['info'] and 'hardware_type' in self.data['info'] and self.data['info']['hardware_type'] == 7):
-			self.commonDelete('device_info')
+			self.drop('device_info')
 		else:
 			#除摄像机之外,其余设备不允许删除
 			self.out('no')
@@ -234,25 +231,25 @@ class camera_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = 'camera'
 			,label = (u'摄像机名称', u'摄像机id', u'所属农场', u'选择网关', u'摄像机地址',u'排序')
 			,update = ('name-input-required','hardware_id-input-required','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
 			,update_farm_id = Demeter.config['setting']['farmList']
 			,update_gateway_id = self.service('common').list('device_gateway')
 		)
-		self.commonOne('device_info')
-		self.commonView('update')
+		self.one('device_info')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
 		self.data['update']['hardware_type'] = 7
 		self.data['update']['type_id'] = 0
-		self.commonUpdate('device_info')
+		self.update('device_info')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('device_info')
+		self.drop('device_info')
 
 class camera_pic_path(Load):
 	@Web.auth
@@ -264,31 +261,31 @@ class camera_pic_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = 'camera_pic'
 			,label = (u'摄像头名称', u'摄像头id', u'所属农场', u'选择网关', u'摄像头地址',u'排序')
 			,update = ('name-input-required','hardware_id-input-required','farm_id-select-required-gateway_id','gateway_id-select-required--farm_id','value-text-required','inorder-text-')
 			,update_farm_id = Demeter.config['setting']['farmList']
 			,update_gateway_id = self.service('common').list('device_gateway')
 		)
-		self.commonOne('device_info')
-		self.commonView('update')
+		self.one('device_info')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
 		self.data['update']['hardware_type'] = 6
 		self.data['update']['type_id'] = 0
-		self.commonUpdate('device_info')
+		self.update('device_info')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('device_info')
+		self.drop('device_info')
 
 class pic_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'摄像头图片'
 			,path = 'pic'
 			,width = '600'
@@ -301,11 +298,11 @@ class pic_path(Load):
 			,state = False
 		)
 
-		self.commonList('device_pic', order='sdate desc')
+		self.list('device_pic', order='sdate desc')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
 				self.data['list'][key]['pic'] = '<img src="'+value['pic']+'" width="200px" />'
-		self.commonView('list')
+		self.show('list')
 
 class stat_path(Load):
 	@Web.auth
@@ -313,7 +310,7 @@ class stat_path(Load):
 	def get(self):
 		method = self.input('method', 'avg')
 		id = self.input('id')
-		self.common(
+		self.set(
 			name = u'设备统计'
 			,path = 'stat'
 			,search = (('label-1','cdate-time-start','cdate-time-end', 'date-select-'), (u'日期范围',u'开始时间',u'截止时间',u'周期选择'))
@@ -337,14 +334,14 @@ class stat_path(Load):
 			search['group'] = self.data['search']['date-select-']
 		self.data['list'] = model.getData(method, search, data)
 
-		self.commonView('stat')
+		self.show('stat')
 
 
 class type_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'类型'
 			,path = 'type'
 			,width = '600'
@@ -354,37 +351,37 @@ class type_path(Load):
 			,tbody = ('id', 'name', 'key', 'unit', 'cdate')
 			,state = True
 		)
-		self.commonList('device_type')
-		self.commonView('list')
+		self.list('device_type')
+		self.show('list')
 
 class type_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = 'type'
 			#,label = (u'类型名称', u'类型标识',u'类型单位',u'表达式')
 			#,update = ('name-input-required','key-input-required','unit-input-',u'exp-text--请输入表达式,{n}代表当前数据')
 			,label = (u'类型名称', u'类型标识',u'类型单位')
 			,update = ('name-input-required','key-input-required','unit-input-')
 		)
-		self.commonOne('device_type')
-		self.commonView('update')
+		self.one('device_type')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('device_type')
+		self.update('device_type')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('device_type')
+		self.drop('device_type')
 
 
 class printer_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'打印机'
 			,path = 'printer'
 			,width = '600'
@@ -395,40 +392,40 @@ class printer_path(Load):
 			,state = True
 		)
 		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
-		self.commonList('device_printer')
+		self.list('device_printer')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
 				farm = self.service('common').one('farm', id=value['farm_id'])
 				self.data['list'][key]['farm'] = farm['name']
-		self.commonView('list')
+		self.show('list')
 
 class printer_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = 'printer'
 			,label = (u'所属农场', u'打印机名称', u'打印机地址')
 			,update = ('farm_id-select-required', 'name-input-required','host-input-required')
 			,update_farm_id = Demeter.config['setting']['farmList']
 		)
-		self.commonOne('device_printer')
-		self.commonView('update')
+		self.one('device_printer')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('device_printer')
+		self.update('device_printer')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('device_printer')
+		self.drop('device_printer')
 
 
 class notice_type_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'错误码设置'
 			,path = '/device/notice_type'
 			,width = '600'
@@ -438,34 +435,34 @@ class notice_type_path(Load):
 			,tbody = ('id', 'name', 'key', 'cdate')
 			,state = False
 		)
-		self.commonList('notice_type')
-		self.commonView('list')
+		self.list('notice_type')
+		self.show('list')
 
 class notice_type_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/device/notice_type'
 			,label = (u'错误码描述', u'错误码key')
 			,update = ('name-input-required', 'key-input-required')
 		)
-		self.commonOne('notice_type')
-		self.commonView('update')
+		self.one('notice_type')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('notice_type')
+		self.update('notice_type')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('notice_type')
+		self.drop('notice_type')
 
 class log_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'网关日志'
 			,path = '/device/log'
 			,width = '600'
@@ -478,11 +475,11 @@ class log_path(Load):
 			,state = False
 		)
 		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
-		self.commonList('log')
+		self.list('log')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
 				farm = self.service('common').one('farm', id=value['farm_id'])
 				self.data['list'][key]['farm'] = farm['name']
 				gateway = self.service('common').one('device_gateway', id=value['gateway_id'])
 				self.data['list'][key]['gateway'] = gateway['name']
-		self.commonView('list')
+		self.show('list')

+ 2 - 2
admin/page/farm.py

@@ -7,14 +7,14 @@
 from .__load__ import *
 
 farm = {
-	'id' : Demeter.config['setting']['farm']
+	'id' : int(Demeter.config['setting']['farm'])
 }
 class info_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
 		id = str(farm['id'])
-		param = '?farm=' + id + '&search_farm_id-select-=' + id
+		param = '?farm=' + id
 		self.set(
 			path = '/farm/info' + param
 			,label = (u'农场名称',u'农场图片',u'农场位置',u'联系电话',u'联系地址',u'农场主姓名',u'农场主照片',u'欢迎语',u'农场介绍')

+ 16 - 16
admin/page/hardware.py

@@ -10,7 +10,7 @@ class hardware_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'硬件设备'
 			,path = '/hardware/hardware'
 			,width = '600'
@@ -24,7 +24,7 @@ class hardware_path(Load):
 		)
 		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
 		self.data['common']['search_hardware_type-select-'] = self.service('common').list('hardware_type')
-		self.commonList('hardware')
+		self.list('hardware')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
 				farm = self.service('common').one('farm', id=value['farm_id'])
@@ -42,34 +42,34 @@ class hardware_path(Load):
 					if device:
 						self.data['list'][key]['device'] = device['name']
 					
-		self.commonView('list')
+		self.show('list')
 
 class hardware_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/hardware/hardware'
 			,label = (u'硬件类型',u'硬件id')
 			,update = ('hardware_type-select-required','hardware_id-input-required')
 			,update_hardware_type = self.service('common').list('hardware_type')
 		)
-		self.commonOne('hardware')
-		self.commonView('update')
+		self.one('hardware')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('hardware')
+		self.update('hardware')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('hardware')
+		self.drop('hardware')
 
 class type_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'硬件类型'
 			,path = '/hardware/type'
 			,button = ({'name':'重启守护进程','link':'/hardware/restart_cron','ajax':True,'icon':'&#xe631;'},{'name':'重启mqtt订阅服务','link':'/hardware/restart_sub','ajax':True,'icon':'&#xe631;'},{'name':'重启园区服务','link':'/hardware/restart_front','ajax':True,'icon':'&#xe631;'},{'name':'重启后台服务','link':'/hardware/restart_admin','ajax':True,'icon':'&#xe631;'},{'name':'重启网站服务','link':'/hardware/restart_web','ajax':True,'icon':'&#xe631;'})
@@ -80,28 +80,28 @@ class type_path(Load):
 			,tbody = ('id', 'name', 'key', 'cdate')
 			,state = False
 		)
-		self.commonList('hardware_type')
-		self.commonView('list')
+		self.list('hardware_type')
+		self.show('list')
 
 class type_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/hardware/type'
 			,label = (u'类型名称', u'类型key')
 			,update = ('name-input-required', 'key-input-required')
 		)
-		self.commonOne('hardware_type')
-		self.commonView('update')
+		self.one('hardware_type')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('hardware_type')
+		self.update('hardware_type')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('hardware_type')
+		self.drop('hardware_type')
 
 class restart_cron_path(Load):
 	@Web.auth

+ 21 - 25
admin/page/msg.py

@@ -12,7 +12,7 @@ class msg_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'消息'
 			,path = '/msg/msg'
 			,width = '600'
@@ -20,18 +20,15 @@ class msg_path(Load):
 			,add = False
 			,edit = False
 			,full = True
-			,search = (('farm_id-select-','type_id-select-','content-input-mlike'), (u'选择农场',u'硬件类型', u'消息内容'))
-			,thead = (u'所属农场', u'消息类型', u'消息内容', u'是否已读',u'发送时间')
-			,tbody = ('farm','type', 'content', 'status', 'cdate')
+			,search = (('type_id-select-','content-input-mlike'), (u'硬件类型', u'消息内容'))
+			,thead = ( u'消息类型', u'消息内容', u'是否已读',u'发送时间')
+			,tbody = ('type', 'content', 'status', 'cdate')
 			,state = False
 		)
-		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
 		self.data['common']['search_type_id-select-'] = self.service('common').list('msg_type')
-		self.commonList('msg')
+		self.list('msg')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
-				farm = self.service('common').one('farm', id=value['farm_id'])
-				self.data['list'][key]['farm'] = farm['name']
 				htype = self.service('common').one('msg_type', id=value['type_id'])
 				self.data['list'][key]['type'] = htype['name']
 
@@ -45,38 +42,37 @@ class msg_path(Load):
 					self.data['list'][key]['status'] = '已读'
 				else:
 					self.data['list'][key]['status'] = '未读'
-		self.commonView('list')
+		self.show('list')
 
 class msg_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/msg/msg'
-			,label = (u'所属农场',u'发送用户',u'消息类型',u'消息内容',u'消息链接',u'推送')
-			,update = ('farm_id-select--uid','uid-checkbox--farm_id','msg_type-select-required','content-editor-required','link-input-','push-checkbox-')
+			,label = (u'发送用户',u'消息类型',u'消息内容',u'消息链接',u'推送')
+			,update = ('uid-checkbox--farm_id','msg_type-select-required','content-editor-required','link-input-','push-checkbox-')
 			,update_msg_type = self.service('common').list('msg_type')
-			,update_farm_id = Demeter.config['setting']['farmList']
 			,update_uid = self.service('common').list('farm_user')
 			,update_push = push
 		)
-		self.commonOne('msg')
-		self.commonView('update')
+		self.one('msg')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
 		# 发消息
-		self.commonUpdate('msg')
+		self.update('msg')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('msg')
+		self.drop('msg')
 
 class type_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'消息类型'
 			,path = '/msg/type'
 			,width = '600'
@@ -86,14 +82,14 @@ class type_path(Load):
 			,tbody = ('id', 'name', 'key', 'cdate')
 			,state = False
 		)
-		self.commonList('msg_type')
-		self.commonView('list')
+		self.list('msg_type')
+		self.show('list')
 
 class type_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/msg/type'
 			#,label = (u'类型名称', u'类型key',u'推送')
 			#,update = ('name-input-required', 'key-input-required','push-checkbox-')
@@ -101,13 +97,13 @@ class type_update_path(Load):
 			,update = ('name-input-required', 'key-input-required')
 			,update_push = push
 		)
-		self.commonOne('msg_type')
-		self.commonView('update')
+		self.one('msg_type')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('msg_type')
+		self.update('msg_type')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('msg_type')
+		self.drop('msg_type')

+ 13 - 17
admin/page/origin.py

@@ -10,48 +10,44 @@ class batch_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'溯源批次'
 			,path = '/origin/batch'
 			,width = '600'
 			,height = '600'
 			,add = False
 			,edit = False
-			,search = (('farm_id-select-','land_id-select-'), (u'选择农场',u'地块'))
-			,thead = (u'所属农场', u'产品名称', u'种植时间', u'采收时间', u'地块')
-			,tbody = ('farm','name', 'zzdate', 'csdate', 'land')
+			,search = (('land_id-select-'), (u'地块'))
+			,thead = (u'产品名称', u'种植时间', u'采收时间', u'地块')
+			,tbody = ('name', 'zzdate', 'csdate', 'land')
 			,state = False
 		)
-		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
 		self.data['common']['search_land_id-select-'] = self.service('common').list('farm_work_land')
-		self.commonList('origin_batch')
+		self.list('origin_batch')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
-				farm = self.service('common').one('farm', id=value['farm_id'])
-				self.data['list'][key]['farm'] = farm['name']
 				land = self.service('common').one('farm_work_land', id=value['land_id'])
 				self.data['list'][key]['land'] = land['name']
-		self.commonView('list')
+		self.show('list')
 
 class batch_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/origin/batch'
-			,label = (u'所属农场',u'产品名称', u'种植时间',u'采收时间',u'设备网关',u'地块',u'图像记录')
-			,update = ('farm_id-select-required','name-input-required', 'zzdate-date-required', 'csdate-date-required','gateway_id-select-required','land_id-select-required','pic-pic-required')
+			,label = (u'产品名称', u'种植时间',u'采收时间',u'设备网关',u'地块',u'图像记录')
+			,update = ('name-input-required', 'zzdate-date-required', 'csdate-date-required','gateway_id-select-required','land_id-select-required','pic-pic-required')
 			,update_gateway_id = self.service('common').list('device_gateway')
 			,update_land_id = self.service('common').list('farm_work_land')
-			,update_farm_id = Demeter.config['setting']['farmList']
 		)
-		self.commonOne('origin_batch')
-		self.commonView('update')
+		self.one('origin_batch')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('origin_batch')
+		self.update('origin_batch')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('origin_batch')
+		self.drop('origin_batch')

+ 16 - 16
admin/page/package.py

@@ -10,7 +10,7 @@ class version_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'版本'
 			,path = '/package/version'
 			,width = '600'
@@ -21,39 +21,39 @@ class version_path(Load):
 			,state = False
 		)
 		self.data['common']['search_package-select-'] = self.service('common').list('package')
-		self.commonList('package_version')
+		self.list('package_version')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
 				package = self.service('common').one('package', id=value['package_id'])
 				self.data['list'][key]['package'] = package['name']
-		self.commonView('list')
+		self.show('list')
 
 class version_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/package/version'
 			,label = (u'所属Package',u'版本名称',u'版本号')
 			,update = ('package_id-select','name-input-required','name-input-required')
 			,update_package_id = self.service('common').list('package')
 		)
-		self.commonOne('package_version')
-		self.commonView('update')
+		self.one('package_version')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('package_version')
+		self.update('package_version')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('package_version')
+		self.drop('package_version')
 
 class package_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'Package'
 			,path = '/package/package'
 			,width = '600'
@@ -63,25 +63,25 @@ class package_path(Load):
 			,tbody = ('id', 'name', 'url', 'cdate')
 			,state = False
 		)
-		self.commonList('package')
-		self.commonView('list')
+		self.list('package')
+		self.show('list')
 
 class package_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/package/package'
 			,label = (u'名称', u'地址')
 			,update = ('name-input-required', 'url-input-required')
 		)
-		self.commonOne('package')
-		self.commonView('update')
+		self.one('package')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('package')
+		self.update('package')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('package')
+		self.drop('package')

+ 0 - 32
admin/page/user.py

@@ -1,32 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-    demeter web page
-    name:user.py
-    author:rabin
-"""
-from .__load__ import *
-
-class login_path(Load):
-	def get(self):
-		self.view("login.html")
-	def post(self):
-		mobile = self.input('username')
-		password = self.input('password')
-		if mobile and password:
-			admin = self.service('common').one('manage_admin', mobile=mobile)
-			if admin:
-				temp = admin['password'].split('_')
-				if Demeter.md5(password, temp[1]) == admin['password']:
-					self.set_secure_cookie('admin', str(admin['id']))
-					#self.redirect('/')
-					self.out('yes', {'id':admin['id']})
-					return
-		self.out('手机号或密码错误,登录失败')
-
-		
-
-
-class loginout_path(Load):
-	def get(self):
-		self.set_secure_cookie('admin', '')
-		self.redirect('/user/login')

+ 53 - 74
admin/page/work.py

@@ -10,196 +10,175 @@ class work_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'农事'
 			,path = '/work/work'
 			,width = '600'
 			,height = '600'
 			,add = False
 			,edit = False
-			,search = (('label-1','workdate-time-start','workdate-time-end','farm_id-select-','category_id-select-'), (u'日期范围',u'开始时间',u'截止时间',u'选择农场',u'劳作分类'))
-			,thead = (u'所属农场', u'劳作时间', u'劳作分类', u'劳作方式', u'劳作地块', u'劳作用量', u'更新时间')
-			,tbody = ('farm','workdate', 'category', 'method', 'land', 'amount', 'cdate')
+			,search = (('label-1','workdate-time-start','workdate-time-end','category_id-select-'), (u'日期范围',u'开始时间',u'截止时间',u'劳作分类'))
+			,thead = (u'劳作时间', u'劳作分类', u'劳作方式', u'劳作地块', u'劳作用量', u'更新时间')
+			,tbody = ('workdate', 'category', 'method', 'land', 'amount', 'cdate')
 			,state = False
 		)
-		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
-		self.commonList('device_gateway')
+		self.list('device_gateway')
 
 		self.data['common']['search_category_id-select-'] = self.service('common').list('farm_work_category')
-		self.commonList('farm_work')
+		self.list('farm_work')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
-				farm = self.service('common').one('farm', id=value['farm_id'])
-				#self.data['list'][key]['workdate'] = Demeter.date(value['workdate'])
-				self.data['list'][key]['farm'] = farm['name']
 				category = self.service('common').one('farm_work_category', id=value['category_id'])
 				self.data['list'][key]['category'] = category['name']
 				method = self.service('common').one('farm_work_method', id=value['method_id'])
 				self.data['list'][key]['method'] = method['name']
 				land = self.service('common').one('farm_work_land', id=value['land_id'])
 				self.data['list'][key]['land'] = land['name']
-		self.commonView('list')
+		self.show('list')
 
 class work_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/work/work'
-			,label = (u'所属农场',u'劳作时间',u'劳作类别',u'劳作方式',u'劳作用量',u'劳作地块',u'图像记录')
-			,update = ('farm_id-select-required', 'workdate-date-required','category_id-select-required-method_id','method_id-select-required--category_id','amount-input-required','land_id-select-required','pic-pic-required')
+			,label = (u'劳作时间',u'劳作类别',u'劳作方式',u'劳作用量',u'劳作地块',u'图像记录')
+			,update = ('workdate-date-required','category_id-select-required-method_id','method_id-select-required--category_id','amount-input-required','land_id-select-required','pic-pic-required')
 			,update_category_id = self.service('common').list('farm_work_category')
 			,update_method_id = self.service('common').list('farm_work_method')
 			,update_land_id = self.service('common').list('farm_work_land')
-			,update_farm_id = Demeter.config['setting']['farmList']
 		)
-		self.commonOne('farm_work')
-		self.commonView('update')
+		self.one('farm_work')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('farm_work')
+		self.update('farm_work')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('farm_work')
+		self.drop('farm_work')
 
 class method_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'劳作方法'
 			,path = '/work/method'
 			,width = '800'
 			,height = '300'
 			,add = False
 			,edit = False
-			,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','category_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'选择农场',u'劳作分类',u'劳作内容'))
-			,thead = (u'所属农场',u'劳作内容', u'劳作分类', u'更新时间')
-			,tbody = ('farm','name', 'category', 'cdate')
+			,search = (('label-1','cdate-time-start','cdate-time-end','category_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'劳作分类',u'劳作内容'))
+			,thead = (u'劳作内容', u'劳作分类', u'更新时间')
+			,tbody = ('name', 'category', 'cdate')
 			,state = False
 		)
-		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
 		self.data['common']['search_category_id-select-'] = self.service('common').list('farm_work_category')
-		self.commonList('farm_work_method')
+		self.list('farm_work_method')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):
-				farm = self.service('common').one('farm', id=value['farm_id'])
-				self.data['list'][key]['farm'] = farm['name']
 				category = self.service('common').one('farm_work_category', id=value['category_id'])
 				self.data['list'][key]['category'] = category['name']
-		self.commonView('list')
+		self.show('list')
 
 class method_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/work/method'
-			,label = (u'所属农场', u'劳作内容',u'劳作分类')
-			,update = ('farm_id-select-required', 'name-input-required','category_id-select-required')
+			,label = (u'劳作内容',u'劳作分类')
+			,update = ('name-input-required','category_id-select-required')
 			,update_category_id = self.service('common').list('farm_work_category')
-			,update_farm_id = Demeter.config['setting']['farmList']
 		)
-		self.commonOne('farm_work_method')
-		self.commonView('update')
+		self.one('farm_work_method')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('farm_work_method')
+		self.update('farm_work_method')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('farm_work_method')
+		self.drop('farm_work_method')
 
 class category_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'劳作分类'
 			,path = '/work/category'
 			,width = '600'
 			,height = '300'
 			,add = False
 			,edit = False
-			,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'选择农场',u'分类名称'))
-			,thead = (u'所属农场',u'分类名称', u'更新时间')
-			,tbody = ('farm', 'name', 'cdate')
+			,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'选择农场',u'分类名称'))
+			,thead = (u'分类名称', u'更新时间')
+			,tbody = ('name', 'cdate')
 			,state = False
 		)
-		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
-		self.commonList('farm_work_category')
-		if self.data['list']:
-			for key, value in enumerate(self.data['list']):
-				farm = self.service('common').one('farm', id=value['farm_id'])
-				self.data['list'][key]['farm'] = farm['name']
-		self.commonView('list')
+		self.list('farm_work_category')
+		self.show('list')
 
 class category_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/work/category'
-			,label = (u'所属农场', u'分类名称')
-			,update = ('farm_id-select-required', 'name-input-required')
-			,update_farm_id = Demeter.config['setting']['farmList']
+			,label = (u'分类名称')
+			,update = ('name-input-required')
 		)
-		self.commonOne('farm_work_category')
-		self.commonView('update')
+		self.one('farm_work_category')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('farm_work_category')
+		self.update('farm_work_category')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('farm_work_category')
+		self.drop('farm_work_category')
 
 
 class land_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			name = u'地块'
 			,path = '/work/land'
 			,width = '600'
 			,height = '300'
 			,add = False
 			,edit = False
-			,search = (('label-1','cdate-time-start','cdate-time-end','farm_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'选择农场',u'地块名称'))
-			,thead = (u'所属农场',u'地块名称', u'更新时间')
-			,tbody = ('farm', 'name', 'cdate')
+			,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'地块名称'))
+			,thead = (u'地块名称', u'更新时间')
+			,tbody = ('name', 'cdate')
 			,state = False
 		)
-		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
-		self.commonList('farm_work_land')
-		if self.data['list']:
-			for key, value in enumerate(self.data['list']):
-				farm = self.service('common').one('farm', id=value['farm_id'])
-				self.data['list'][key]['farm'] = farm['name']
-		self.commonView('list')
+		self.list('farm_work_land')
+		self.show('list')
 
 class land_update_path(Load):
 	@Web.auth
 	@Web.setting
 	def get(self):
-		self.common(
+		self.set(
 			path = '/work/land'
-			,label = (u'所属农场', u'地块名称')
-			,update = ('farm_id-select-required','name-input-required')
-			,update_farm_id = Demeter.config['setting']['farmList']
+			,label = (u'地块名称',)
+			,update = ('name-input-required',)
 		)
-		self.commonOne('farm_work_land')
-		self.commonView('update')
+		self.one('farm_work_land')
+		self.show('update')
 	@Web.auth
 	@Web.setting
 	def post(self):
-		self.commonUpdate('farm_work_land')
+		self.update('farm_work_land')
 	@Web.auth
 	@Web.setting
 	def delete(self):
-		self.commonDelete('farm_work_land')
+		self.drop('farm_work_land')

+ 9 - 0
client.py

@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+"""
+    demeter web
+    name:admin.py
+    author:rabin
+"""
+from demeter.core import *
+
+Demeter.service('tcp', 'modbus').client()

+ 1 - 1
conf/dev.conf

@@ -60,7 +60,7 @@ process				= 0
 ;定义后台父级菜单
 menu_parent			= 农场管理:&#xe62e;,设备管理:&#xe62a;
 ;定义后台子级菜单
-menu_child			= 基础资料:/farm/info,用户管理:/farm/user,产品管理:/farm/product,地块管理:/work/land,农事管理:/work/work;设备列表:/device/info,设备分组:/device/group
+menu_child			= 基础资料:/farm/info?id=1,用户管理:/farm/user,产品管理:/farm/product,地块管理:/work/land,农事管理:/work/work;设备列表:/device/info,设备分组:/device/group
 
 ;cookie
 cookie_secret       = 61oETzKXQAGaYekL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=

+ 19 - 0
model/modbus.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+"""
+    demeter database
+    name:hardware.py
+    author:rabin
+"""
+from .__load__ import *
+
+class Modbus(Model):
+	__table__ = 'modbus'
+	__comment__ = 'modbus配置表'
+	id = Fields(type='uuid', primaryKey=True, comment='硬件设备表ID', uuid='farm_id')
+	farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
+	hardware_id = Fields(type='bigint', comment='硬件id', unique=True)
+	hardware_type = Fields(type='int', comment='硬件类型')
+	device_id = Fields(type='uuid', comment='设备id')
+	gateway_id = Fields(type='uuid', comment='网关id')
+	state = Fields(type='boolean', default='True', comment='数据存在状态')
+	cdate = Fields(type='int', default='time', comment='创建时间')

+ 23 - 0
model/modbus_device.py

@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+"""
+    demeter database
+    name:hardware.py
+    author:rabin
+"""
+from .__load__ import *
+
+class Modbus_device(Model):
+	__table__ = 'modbus_device'
+	__comment__ = 'modbus设备表'
+	id = Fields(type='uuid', primaryKey=True, comment='设备表ID', uuid='farm_id')
+	farm_id = Fields(type='int', default='setting.farm', comment='园区ID', match='not')
+	modbus_id = Fields(type='uuid', comment='modbusid')
+	slave_id = Fields(type='int', comment='从机id', unique=True)
+	slave_type = Fields(type='int', comment='1读取2写入')
+	register_type = Fields(type='int', comment='寄存器类型')
+	register_address = Fields(type='varchar(50)', comment='寄存器地址')
+	register_length = Fields(type='varchar(50)', comment='寄存器长度')
+	exp = Fields(type='varchar(50)', comment='计算公式')
+	unit = Fields(type='varchar(10)', comment='单位')
+	state = Fields(type='boolean', default='True', comment='数据存在状态')
+	cdate = Fields(type='int', default='time', comment='创建时间')

+ 1 - 0
runtime/postgresql/device_gateway

@@ -0,0 +1 @@
+[["cdate", 1], ["stat", 1], ["farm_id", 1], ["camera", 1], ["pic", 1], ["id", 1], ["hardware_id", 1], ["state", 1], ["name", 1]]

+ 1 - 0
runtime/postgresql/device_info

@@ -0,0 +1 @@
+[["value", 1], ["operdate", 1], ["cxtype", 1], ["gateway_id", 1], ["udate", 1], ["id", 1], ["cdate", 1], ["cxdate", 1], ["hardware_type", 1], ["cxnum", 1], ["status", 1], ["state", 1], ["name", 1], ["type_id", 1], ["oper", 1], ["exp", 1], ["max", 1], ["hardware_id", 1], ["min", 1], ["inorder", 1], ["farm_id", 1]]

+ 1 - 1
runtime/postgresql/device_type

@@ -1 +1 @@
-[["cdate", 1], ["unit", 1], ["state", 1], ["name", 1], ["id", 1], ["exp", 1], ["key", 1]]
+[["state", 1], ["unit", 1], ["cdate", 1], ["key", 1], ["id", 1], ["exp", 1], ["name", 1]]

+ 1 - 1
runtime/postgresql/farm

@@ -1 +1 @@
-[["cdate", 1], ["pic", 1], ["name", 1], ["id", 1], ["gateway", 1], ["welcome", 1], ["master_pic", 1], ["info", 1], ["state", 1], ["address", 1], ["master_name", 1], ["location", 1], ["tel", 1]]
+[["tel", 1], ["master_name", 1], ["pic", 1], ["name", 1], ["address", 1], ["cdate", 1], ["master_pic", 1], ["info", 1], ["welcome", 1], ["location", 1], ["state", 1], ["gateway", 1], ["id", 1]]

+ 1 - 0
runtime/postgresql/farm_product

@@ -0,0 +1 @@
+[["yields", 1], ["pic", 1], ["id", 1], ["state", 1], ["name", 1], ["charact", 1], ["notice", 1], ["area", 1], ["status", 1], ["cdate", 1], ["farm_id", 1]]

+ 1 - 0
runtime/postgresql/farm_user

@@ -0,0 +1 @@
+[["id", 1], ["state", 1], ["password", 1], ["username", 1], ["farm_id", 1], ["cdate", 1], ["mobile", 1]]

+ 1 - 0
runtime/postgresql/farm_work

@@ -0,0 +1 @@
+[["cdate", 1], ["land_id", 1], ["workdate", 1], ["pic", 1], ["amount", 1], ["id", 1], ["category_id", 1], ["farm_id", 1], ["state", 1], ["method_id", 1]]

+ 1 - 0
runtime/postgresql/farm_work_category

@@ -0,0 +1 @@
+[["cdate", 1], ["id", 1], ["farm_id", 1], ["name", 1], ["state", 1]]

+ 1 - 0
runtime/postgresql/farm_work_land

@@ -0,0 +1 @@
+[["id", 1], ["state", 1], ["cdate", 1], ["name", 1], ["farm_id", 1]]

+ 1 - 1
runtime/postgresql/hardware_type

@@ -1 +1 @@
-[["cdate", 1], ["id", 1], ["state", 1], ["name", 1], ["key", 1]]
+[["state", 1], ["id", 1], ["cdate", 1], ["name", 1], ["key", 1]]

+ 1 - 1
runtime/postgresql/manage_admin

@@ -1 +1 @@
-[["cdate", 1], ["id", 1], ["state", 1], ["role_id", 1], ["username", 1], ["password", 1], ["mobile", 1]]
+[["mobile", 1], ["state", 1], ["cdate", 1], ["role_id", 1], ["password", 1], ["id", 1], ["username", 1]]

+ 1 - 0
runtime/postgresql/manage_log

@@ -0,0 +1 @@
+[["method", 1], ["state", 1], ["admin_id", 1], ["cdate", 1], ["data", 1], ["id", 1], ["model", 1]]

+ 1 - 1
runtime/postgresql/manage_role

@@ -1 +1 @@
-[["cdate", 1], ["state", 1], ["name", 1], ["oper", 1], ["id", 1], ["top", 1], ["auth", 1]]
+[["top", 1], ["state", 1], ["name", 1], ["cdate", 1], ["auth", 1], ["id", 1], ["oper", 1]]

+ 1 - 1
runtime/postgresql/msg_type

@@ -1 +1 @@
-[["cdate", 1], ["push", 1], ["state", 1], ["name", 1], ["id", 1], ["key", 1]]
+[["state", 1], ["cdate", 1], ["push", 1], ["key", 1], ["id", 1], ["name", 1]]

+ 1 - 1
runtime/postgresql/notice_type

@@ -1 +1 @@
-[["cdate", 1], ["id", 1], ["state", 1], ["name", 1], ["key", 1]]
+[["state", 1], ["id", 1], ["cdate", 1], ["name", 1], ["key", 1]]

+ 21 - 0
service/modbus/rtu.py

@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter service
+    name:record_log.py 记录网关日志
+    author:rabin
+    key:log/hw/gateway/gateway
+"""
+from demeter.core import *
+class Record_log(object):
+
+	def handle(self, record, config, value):
+		model = Demeter.model('device_gateway')
+		model.hardware_id = config['parent']
+		data = model.select(type='fetchone')
+		if data:
+			logModel = Demeter.model('log')
+			logModel.farm_id = data['farm_id']
+			logModel.gateway_id = data['id']
+			logModel.content = value
+			logModel.insert()

+ 76 - 0
service/modbus/tcp.py

@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+from demeter.core import *
+import modbus_tk
+import modbus_tk.modbus_tcp as modbus_tcp
+import modbus_tk.defines as mdef
+import time
+import random
+import struct
+
+class Tcp(object):
+
+	def server(self):
+		server = modbus_tcp.TcpServer(port=1152)
+		server.start()
+		slave_1 = server.add_slave(1)
+		slave_1.add_block('block1', modbus_tk.defines.ANALOG_INPUTS, 0, 2)
+
+		while 1:
+			bb = random.random()
+			aa = struct.unpack('>HH', struct.pack('>f', bb))
+			Demeter.echo('bb:' + str(bb))
+			Demeter.echo('aa:' + str(aa))
+			slave_1.set_values('block1', 0, aa)
+			Demeter.echo('=========')
+			time.sleep(3)
+
+
+	def client(self):
+		# slave id
+		master = modbus_tcp.TcpMaster(host="192.168.33.10", port=1152)
+		master.set_timeout(3)  #timeout表示若超过3秒没有连接上slave就会自动断开
+		aa = master.execute(1, modbus_tk.defines.ANALOG_INPUTS, 0, 2)
+		#(slave id,只读,block地址,长度:即字节乘个数)
+		Demeter.echo('aa:' + str(aa) + 'size:' + str(len(aa)))
+		bb = struct.unpack('>f', struct.pack('>HH', aa[0], aa[1]))
+		#在slave中,是先打包成'>f'在以'>HH'解包的,在master中刚好相反
+		#struct.unpack里解出来的是一个元组,可以用bb, = 或者输出bb[0]
+		Demeter.echo('bb:' + str(bb[0]))
+		time.sleep(3)
+
+		slave = 1
+
+		# 读线圈寄存器
+		master.execute(slave, mdef.READ_COILS, 0, 16)
+
+		# 读离散输入寄存器
+		master.execute(slave, mdef.READ_DISCRETE_INPUTS, 0, 16)
+
+		# 读保持寄存器
+		master.execute(slave, mdef.READ_HOLDING_REGISTERS, 0, 16)
+
+		# 读输入寄存器
+		master.execute(slave, mdef.READ_INPUT_REGISTERS, 0, 16)
+
+		# 单个读写寄存器操作
+
+		# 写单个线圈 写寄存器地址为0的线圈寄存器,写入内容为0(位操作)
+		master.execute(slave, mdef.WRITE_SINGLE_COIL, 0, output_value=0)
+		master.execute(slave, mdef.READ_COILS, 0, 1)
+
+		# 写单个保持寄存器 写寄存器地址为0的保持寄存器
+		master.execute(slave, mdef.WRITE_SINGLE_REGISTER, 0, output_value=21)
+		master.execute(slave, mdef.READ_HOLDING_REGISTERS, 0, 1)
+
+
+		# 多个寄存器读写操作
+
+		# 写多个保持寄存器 写寄存器起始地址为0的保持寄存器,操作寄存器个数为4
+		master.execute(slave, mdef.WRITE_MULTIPLE_REGISTERS, 0, output_value=[20,21,22,23])
+		master.execute(slave, mdef.READ_HOLDING_REGISTERS, 0, 4)
+
+		# 写寄存器起始地址为0的线圈寄存器
+		master.execute(slave, mdef.WRITE_MULTIPLE_COILS, 0, output_value=[0,0,0,0])
+		master.execute(slave, mdef.READ_COILS, 0, 4)
+
+		# slave_id,类型,地址,长度(或者值)、读取还是写入、计算公式

+ 9 - 0
test.py

@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+"""
+    demeter web
+    name:admin.py
+    author:rabin
+"""
+from demeter.core import *
+
+Demeter.service('tcp', 'modbus').server()