1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/usr/bin/env python
- # -*- coding:utf-8 -*-
- from sanic import Sanic
- from sanic_cors import CORS, cross_origin
- from sanic import response
- from event_storage import EventStorage
- from utility import Utility
- from api_context import ApiContext
- app = Sanic(__name__)
- CORS(app)
- gateway_storage = EventStorage()
- @app.route('/readRealText', methods=['POST'])
- async def read_point_data_text(request):
- list = request.json['pointList']
- dict = gateway_storage.get_real_data(list)
- point_list = gateway_storage.get_point_info(list)
- data_list = {}
- for info in point_list:
- data_list[info['io_point_name']] = str(dict["c"+str(info['serial_number'])]) + " " +str(info['unit'])
- return response.json(data_list)
- @app.route('/readReal', methods=['POST'])
- async def read_point_data(request):
- list = request.json['pointList']
- dict = gateway_storage.get_real_data(list)
- '''
- data_list = gateway_storage.get_point_info(list)
- for info in data_list:
- info['value'] = dict["c"+str(info['serial_number'])]
- '''
- return response.json(dict)
- @app.route('/api', methods=['POST'])
- async def read_statistics_data(request):
- if len(request.json) > 0:
- list = []
- for index in range(len(request.json)):
- api_object = request.json[index]['apiObject']
- parameter = request.json[index]['parameter']
- api = ApiContext()
- api.set_api_object(api_object)
- result = api.operation(parameter)
- list.append(result)
- data_json = Utility.data_encoder(list)
- return response.text(data_json)
- @app.route('/write',methods=['POST'])
- async def write_data(request):
- station_name = request.json["station_name"]
- command = request.json["command"]
- try:
- result = Utility.available_connectors[station_name].send_command(command)
- return response.json({'message': result})
- except Exception as e:
- print(station_name+"write[ERROR]:" + str(e))
- return response.json({'message': result})
- @app.route('/s7/getState', methods=['POST'])
- async def read_point_data(request):
- point_list = ["c577", "c578", "c569", "c570", "c571", "c572", "c573", "c574", "c575",
- "c402", "c423", "c411", "c815", "c432", "c817"]
- dict = gateway_storage.get_real_data(point_list)
- return response.json(dict)
- if __name__ == "__main__":
- app.run(host="0.0.0.0", port=8080, workers=8)
|