package com.ruoyi.monitorInterface.chenganshengbang.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.monitorInterface.chenganshengbang.service.WaterPressureService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/WaterPressure")
public class WaterPressureController {

    @Resource
    private WaterPressureService waterPressureService;

    /**
     * 水压传感器上报数据
     * */
    @PostMapping("/waterPressureMessageReceiver")
    public byte[] waterPressureMessageReceiver(@RequestBody String data){
        waterPressureService.waterPressureMessageReceiver(data);
        return responseData();
    }

    /**
     * 水压传感器指令下发
     * */
    @PostMapping("/command")
    public String command(@RequestBody String data){
        return waterPressureService.command(data);
    }

    public static byte[] responseData(){
        int xiangyingma = 200;
        byte[] xiangyingbytes = new byte[4];
        xiangyingbytes[3] = (byte) (xiangyingma & 0xff);
        xiangyingbytes[2] = (byte) (xiangyingma >> 8 & 0xff);
        xiangyingbytes[1] = (byte) (xiangyingma >> 16 & 0xff);
        xiangyingbytes[0] = (byte) (xiangyingma >> 24 & 0xff);
        return xiangyingbytes;
    }
}
