|
@@ -0,0 +1,213 @@
|
|
|
+#include "DevicePlayerV5.hpp"
|
|
|
+
|
|
|
+namespace gsd
|
|
|
+{
|
|
|
+ uint8_t DevicePlayerV5::getPressure(){
|
|
|
+ return pressure;
|
|
|
+ }
|
|
|
+ uint8_t DevicePlayerV5::getCommamd(){
|
|
|
+ return commamd;
|
|
|
+ }
|
|
|
+ int16_t DevicePlayerV5::getCurrent(){
|
|
|
+ return current;
|
|
|
+ }
|
|
|
+ uint16_t DevicePlayerV5::getVoltage(){
|
|
|
+ return voltage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 序列化
|
|
|
+ * @param {ControlerMsg} gasControl
|
|
|
+ * @param {char*} data
|
|
|
+ * @param {bool} status
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ void DevicePlayerV5::serialization(const ControlerMsg gasControl, char* data, bool status){
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 反序列化
|
|
|
+ * @param {uint8_t} *data
|
|
|
+ * @param {int} len
|
|
|
+ * @param {int} &msg_id
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool DevicePlayerV5::deserialization(const uint8_t *data, int len, int &msg_id){
|
|
|
+ if(data[0] != 0xff){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // uint8_t dataCheckSum = 0;
|
|
|
+ // for(int i = 0; i < len - 1; i++){
|
|
|
+ // dataCheckSum += data[i];
|
|
|
+ // }
|
|
|
+ // if(dataCheckSum != data[len - 1]){
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ msg_id = data[1];
|
|
|
+ if(msg_id == 0x01){
|
|
|
+ this->setDeviceId(to_string(data[0]));
|
|
|
+ // this->pressure = (data[9]&0x80) >> 7;
|
|
|
+ // this->commamd = (data[4]);
|
|
|
+ // this->current = (int16_t)(data[8]<<8 || data[7]);
|
|
|
+ // this->voltage = uint16_t(data[6]<<8 || data[5]);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 消费数据
|
|
|
+ * @param {uint8_t} *data
|
|
|
+ * @param {int} len
|
|
|
+ * @param {int} &msg_id
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool DevicePlayerV5::Consumer(uint8_t *data, int len, int &msg_id){
|
|
|
+ bool ReceiveSuccessful = false;
|
|
|
+ for(int i = 0; i < len; i++){
|
|
|
+ switch(_comm.step){
|
|
|
+ case STEP_HEAD:
|
|
|
+ if(data[i] == 0xff){
|
|
|
+ _comm.data[0] = 0xff;
|
|
|
+ _comm.step = STEP_CMD;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case STEP_CMD:
|
|
|
+ _comm.data[1] = data[i];
|
|
|
+ if(data[i] == 0x05)
|
|
|
+ {
|
|
|
+ _comm.step = STEP_DATA;
|
|
|
+ _comm.dataCount = 2;
|
|
|
+ _comm.dataLength = 8;
|
|
|
+ }
|
|
|
+ else if(data[i] == 0x01)
|
|
|
+ {
|
|
|
+ _comm.step = STEP_LEN;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ _comm.step = STEP_HEAD;
|
|
|
+ break;
|
|
|
+ case STEP_LEN:
|
|
|
+ if (data[i] == 0x01) {
|
|
|
+ _comm.data[2] = 0x01;
|
|
|
+ _comm.dataLength = 6;
|
|
|
+ _comm.dataCount = 3;
|
|
|
+ _comm.step = STEP_DATA;
|
|
|
+ } else {
|
|
|
+ _comm.step = STEP_HEAD;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case STEP_DATA:
|
|
|
+ _comm.data[_comm.dataCount++] = data[i];
|
|
|
+ if(_comm.dataCount == _comm.dataLength){
|
|
|
+ ReceiveSuccessful = true;
|
|
|
+ _comm.step = STEP_HEAD;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ _comm.step = STEP_HEAD;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!ReceiveSuccessful) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return deserialization(_comm.data, _comm.dataLength, msg_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 打开
|
|
|
+ * @param {int} deivceId
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ int8_t DevicePlayerV5::Open(std::string DeviceId, uint8_t* data, int& length){
|
|
|
+ data[0] = 0xff;
|
|
|
+ data[1] = 0x05;
|
|
|
+ data[2] = 0x00;
|
|
|
+ data[3] = 0x00;
|
|
|
+ data[4] = 0xff;
|
|
|
+ data[5] = 0x00;
|
|
|
+ data[6] = 0x99;
|
|
|
+ data[7] = 0xe4;
|
|
|
+ length = 8;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 关闭
|
|
|
+ * @param {int} deivceId
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ int8_t DevicePlayerV5::Close(std::string DeviceId, uint8_t* data, int& length){
|
|
|
+ data[0] = 0xff;
|
|
|
+ data[1] = 0x05;
|
|
|
+ data[2] = 0x00;
|
|
|
+ data[3] = 0x00;
|
|
|
+ data[4] = 0x00;
|
|
|
+ data[5] = 0x00;
|
|
|
+ data[6] = 0xd8;
|
|
|
+ data[7] = 0x14;
|
|
|
+ length = 8;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 开炮
|
|
|
+ * @param {int} deivceId
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ int8_t DevicePlayerV5::Fire(std::string DeviceId, uint8_t* data, int& length){
|
|
|
+ return Open(DeviceId, data, length);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 状态
|
|
|
+ * @param {int} deivceId
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ int8_t DevicePlayerV5::Status(std::string DeviceId, uint8_t* data, int& length){
|
|
|
+ data[0] = 0xff;
|
|
|
+ data[1] = 0x01;
|
|
|
+ data[2] = 0x00;
|
|
|
+ data[3] = 0x00;
|
|
|
+ data[4] = 0x00;
|
|
|
+ data[5] = 0x08;
|
|
|
+ data[6] = 0x28;
|
|
|
+ data[7] = 0x12;
|
|
|
+ length = 8;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 判定msg是否为status
|
|
|
+ * @param {int} &msg_id
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool DevicePlayerV5::getStatusMsg(int &msg_id){
|
|
|
+ if(msg_id != 1) return false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 构建设备信息
|
|
|
+ * @param {SendDevice&} sendDevice
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ void DevicePlayerV5::BuildDeviceInfo(SendDevice& sendDevice){
|
|
|
+ sendDevice.deviceId = atoi(this->getDeviceId().c_str());
|
|
|
+ sendDevice.commandCode = "1";
|
|
|
+ sendDevice.status = 1;
|
|
|
+ sendDevice.workStatus = 1;
|
|
|
+ sendDevice.powerStatus = 1;
|
|
|
+ sendDevice.batteryStatus = 1;
|
|
|
+ sendDevice.num = 0;
|
|
|
+ sendDevice.oxyPressure = 0;
|
|
|
+ sendDevice.gasPressure = 0;
|
|
|
+ sendDevice.remark = "";
|
|
|
+ // sendDevice.attr1 = std::to_string(this->getVoltage()); // 电压
|
|
|
+ // sendDevice.attr2 = std::to_string(this->getCurrent()); // 电流
|
|
|
+ // sendDevice.attr3 = std::to_string(this->getPressure()); // 声压
|
|
|
+ }
|
|
|
+
|
|
|
+} // namespace gsd
|
|
|
+
|