| | |
| | | import { ALL, Body, Get, Inject, Post, Provide, Query } from '@midwayjs/decorator'; |
| | | import { CoolController, BaseController } from '@cool-midway/core'; |
| | | import { Taskimmediately } from '../../entity/taskimmediately'; |
| | | // import { TaskimmediatelyService } from '../../service/taskimmediately'; |
| | | import { TaskimmediatelyService } from '../../../business/service/taskimmediately'; |
| | | import { DataController } from '../../../base/controller/dataController'; |
| | | import { SocketHandler } from '../../../../../socket/socketHandle'; |
| | | import { RpcService } from '../../../base/service/dataapi/rpcservice'; |
| | | import { randomUUID } from 'crypto'; |
| | | |
| | | const ProtoBufJs = require("protobufjs"); |
| | | const root = ProtoBufJs.loadSync("D:/21-dljc/road-env-server/server/models/aerial.proto"); |
| | | const CommandMessage = root.lookupType("CommandMessage"); |
| | | const command_req = CommandMessage.create(); |
| | | // const SYScommand = root.lookupType("SysCommand"); |
| | | // const SUBcommand = root.lookupType("SubCommand"); |
| | | |
| | | /** |
| | | * 即时任务记录 |
| | | */ |
| | | @Provide() |
| | | @CoolController({ |
| | | api: ['add', 'delete', 'update', 'list', 'page', 'info'], |
| | | api: ['delete', 'update', 'list', 'page', 'info'], |
| | | entity: Taskimmediately, |
| | | // service: TaskimmediatelyService, |
| | | // service: TaskimmediatelyService, |
| | | }) |
| | | export class TaskimmediatelyController extends DataController { |
| | | // @Inject() |
| | | // taskimmediatelyService: TaskimmediatelyService; |
| | | |
| | | @Inject() |
| | | taskimmediatelyService: TaskimmediatelyService; |
| | | |
| | | @Inject() |
| | | socketHandler: SocketHandler |
| | | |
| | | @Inject() |
| | | rpcService: RpcService |
| | | |
| | | private colletServiceUrl = "http://192.168.1.4:5000/api"; |
| | | |
| | | /** |
| | | * 下发设备指令消息 |
| | | */ |
| | | @Post('/sendMsgToDevice', { summary: '下发设备指令消息' }) |
| | | async sendMsgToDevice(@Query(ALL) params: any) { |
| | | |
| | | console.log(params); |
| | | return this.ok(await this.rpcService.remoteCall(this.colletServiceUrl, this.createCommand(params))) |
| | | } |
| | | |
| | | /** |
| | | * 下发设备指令消息 |
| | | */ |
| | | @Get('/sendMsgToDevice', { summary: '下发设备指令消息' }) |
| | | async sendMsg2Device(@Query(ALL) params: any) { |
| | | // this.socketHandler.connection |
| | | console.log(params); |
| | | return this.ok(await this.rpcService.remoteCall(this.colletServiceUrl, this.createCommand(params))) |
| | | // this.rpcService.remoteCall("http://192.168.1.4:5000/api", params); |
| | | } |
| | | |
| | | /** |
| | | * 获得数据 |
| | |
| | | async postData(@Query(ALL) params: any) { |
| | | return this.ok(await this.dataService.getData(params)); |
| | | } |
| | | |
| | | createCommand(params: any) { |
| | | |
| | | command_req.source = "testcommand" |
| | | command_req.generatetime = "2" |
| | | command_req.syscommand = root.SysCommand.CAMERA_COMMAND |
| | | command_req.subcommand = root.SubCommand.ONE_TIME_CAPTURE |
| | | command_req.targetclient = "bunker0.block0.device0" |
| | | command_req.returnserver = "server0" |
| | | command_req.taskuuid = randomUUID() |
| | | console.log(JSON.stringify(command_req)) |
| | | |
| | | // Verify the payload if necessary (i.e. when possibly incomplete or invalid) |
| | | let errMsg = CommandMessage.verify(command_req); |
| | | if (errMsg) |
| | | throw Error(errMsg); |
| | | |
| | | // let buffer = Buffer.from(command_req) |
| | | let buffer_ = CommandMessage.encode(command_req).finish(); |
| | | // let msg_ = CommandMessage.decode(buffer_); |
| | | return buffer_; |
| | | |
| | | } |
| | | |
| | | |
| | | } |