Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
8ee7b4f
修改了json里的数据,增加了按钮时输出的数据,并且把Opreation改为IoOpration,由于操作把所有的数据一起加入了,无法进行…
Jan 3, 2019
727e33b
增加IoOpreation的父类Opreation
Jan 3, 2019
0cf12a8
增加IoOpreation的父类Opreation
Jan 3, 2019
c246035
智能电表的定义
Jan 4, 2019
43c7e80
智能电表方法的实现
Jan 4, 2019
211149f
配置文件更改
Jan 4, 2019
2d8b367
增加了采集参数参数定义
Jan 5, 2019
d93788e
多了空格
Jan 5, 2019
f732abb
把父类里的共用的参数和方法拿回
Jan 5, 2019
077fba7
增加SmartMeterMessager类
Jan 5, 2019
fc42272
实现SmartMeterMessager类
Jan 5, 2019
bce92ca
增加type_类型字段,基本属性留着备用
Jan 5, 2019
b1b2e3f
对update方法进行增加参数,并实现该方法
Jan 5, 2019
10497ea
增加次数让采集电表频率减少
Jan 5, 2019
9841957
对notify方法采用多个参数重载
Jan 5, 2019
5616eb7
采集数据修改
Jan 5, 2019
d2a4de3
增加notfys_字段的定义,用于存放读出的数据
Jan 5, 2019
e84c28b
把电表和io模块的数据统一为一种数据类型
Jan 5, 2019
be7caa8
重新定义update方法的参数类型使之统一
Jan 5, 2019
aef27e9
重新定义update方法的参数类型使之统一,并修改其中的实现
Jan 5, 2019
067ec2f
重新定义notify方法的参数类型使之统一
Jan 5, 2019
ff9cbb5
重新定义notify方法的参数类型使之统一
Jan 5, 2019
32de6e8
在topic里添加设备id
Jan 5, 2019
6bbee31
把创建的IoOpreation改为由Opration创建
Jan 7, 2019
97c09b4
把创建的IoOpreation改为由Opration创建
Jan 7, 2019
4fb67c1
给IoOpration添加父类Opration
Jan 7, 2019
25e4dba
给IoOpration添加父类Opration
Jan 7, 2019
94b25cc
重载execute方法,并加入SmOperation类
Jan 7, 2019
10c36e0
实现execute方法,并实现SmOperation类
Jan 7, 2019
3e52413
去掉数据中的time
Jan 7, 2019
b1fa11e
更改update里的方法
Jan 7, 2019
30afcbe
去掉重载的update方法
Jan 7, 2019
a62105e
重写modbus的写入方法;
Jan 9, 2019
c5492e3
modbus写入的方法修改
Jan 9, 2019
ee5e193
修改写错的函数名称
Jan 9, 2019
4743019
增加io模块的modbusWrite,和write方法
Jan 14, 2019
c75760d
io模块对modbusWrite和write的实现
Jan 14, 2019
f04f135
把IOopration改成readopration,增加writeopration
Jan 14, 2019
5fd910d
把IOopration改成readopration,增加writeopration
Jan 14, 2019
463a067
增加设置设备的server
Jan 14, 2019
83afd1b
增加setServer和update方法
Jan 14, 2019
b5f3bb4
对增加的update方法的引用和实现
Jan 14, 2019
d5c9b58
更改了部分数据
Jan 14, 2019
7aeceaa
删除deviceid,增加type属性
Jan 17, 2019
0be5f62
修改属性之后代码的修改
Jan 17, 2019
0cdcbd8
继承出了AGVLight模块.并增加了relationship属性
Jan 17, 2019
cd849dc
继承之后代码的实现
Jan 17, 2019
883bc21
修改结构,把电表字段去掉,在oprate里添加type字段
Jan 17, 2019
2fd86ac
增加读取失败时的报错信息
Jan 18, 2019
3ce3771
增加isRead() 方法
Jan 18, 2019
0427b05
删除不要模块
Jan 18, 2019
d9db2bc
删除不要模块
Jan 18, 2019
375456a
增加isread的调用
Jan 18, 2019
525d4a9
去掉一些无用提示
Jan 21, 2019
74f5dd3
增加灯的三个开,关,闪烁操作
Jan 21, 2019
06cda73
对定义的实现
Jan 21, 2019
5ba96e3
增加电表和按钮的继承类定义
Jan 21, 2019
938dcbb
对定义的实现
Jan 21, 2019
e9fb205
对配置内容的修改
Jan 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Connection.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "Connection.h"

#include <syslog.h>
#include <cassert>

Connection::Connection() {

times=0;
}

void Connection::attach(Device *device) {
Expand All @@ -16,7 +16,7 @@ void Connection::detach(Device *device) {
}

void Connection::notify(const std::string &ip, int id,
const std::vector<char> &buf) {
const uint16_t buf[]) {
for(Device *dev : devices_) {
if(dev->equalIP(ip))
dev->update(id, buf);
Expand Down
4 changes: 2 additions & 2 deletions Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class Connection {
private:
std::vector<Device*> devices_;
int times;
public:
Connection();
void attach(Device *device);
void detach(Device *device);
void notify(const std::string &ip, int id,
const std::vector<char> &buf);
void notify(const std::string &ip, int id,const uint16_t buf[]);
};

#endif
107 changes: 92 additions & 15 deletions Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,32 @@
#include <sstream>
#include <string>
#include <cassert>
#include <sys/time.h>
#include "json.hpp"
#include "ZLServer.h"
#include <iostream>
using json = nlohmann::json;
Device::Device(const char ip[], const char id[]):ip_(ip), id_(id) {
Device::Device(const char ip[], const char id[],const char type[],const char relationship[]):ip_(ip), id_(id),type_(type),relationship_(relationship) {

}

Device::~Device() {
clearOpers();
}

void Device::update(int sid, const std::vector<char> &stats) {
int idx = 0;
void Device::update(int sid,const uint16_t stats[]) {
if(equalType("controllableDevice")) syslog(LOG_INFO,"是按钮灯的函数哦%d",sid);
bool newst = false;
for(char s : stats) {
for(Operation *oper : opers_) {
if(oper->equalPort(sid) && oper->equalAddr(idx)) {
newst |= oper->execute(s);
break; //TODO one state for one operation
int idx = 0;
for(int i=0;i<sizeof(stats);i++) {
for(Operation *oper : opers_) {
if(oper->equalPort(sid) && oper->equalAddr(idx)&&oper->isRead()) {
newst |= oper->execute(stats[i]);
break; //TODO one state for one operation
}
}
idx += 1;
}
idx += 1;
}
if(newst) {
for(Messager *mes : messagers_) {
if(mes != nullptr) {
Expand Down Expand Up @@ -68,6 +71,26 @@ std::string Device::stateStr(Messager *mes) {
assert(oper != nullptr);
oper->stateStr(mes);
}
mes->setDID(relationship_);
gchar *time_str = NULL;
GDateTime *time = NULL;
time = g_date_time_new_now_local();
time_str = g_date_time_format(time, "%Y/%m/%d %H:%M:%S");
mes->setTime(time_str);
g_free(time_str);
g_date_time_unref(time);

mes->dump();
return "";
}

std::string Device::stateStrSmartMeter(Messager *mes) {
mes->setID(id_);
mes->setDID(relationship_);
for(Operation* oper : opers_) {
assert(oper != nullptr);
oper->stateStr(mes);
}

gchar *time_str = NULL;
GDateTime *time = NULL;
Expand All @@ -86,6 +109,54 @@ void Device::clearOpers() {
delete oper;
opers_.clear();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

AGVLight::AGVLight(const char ip[], const char id[],const char type[],const char relationship[]):Device(ip,id,type,relationship) {
syslog(LOG_INFO,"现在创建可操控设备:%s",id);
}

AGVLight::~AGVLight() {

}
void AGVLight::update(int sid,const uint16_t stats[])
{
// syslog(LOG_INFO,"现在调用的是按钮灯的函数哦%d",sid);
for(Operation *oper : opers_) {
if(oper->equalName("lightflashing")) {
oper->execute(server_,ip_,"light1","off");
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SmartMeter::SmartMeter(const char ip[], const char id[],const char type[],const char relationship[]):Device(ip,id,type,relationship) {
syslog(LOG_INFO,"现在创建电表设备:%s",id);
}
SmartMeter::~SmartMeter(){

}
void SmartMeter::update(int sid,const uint16_t stats[])
{
//syslog(LOG_INFO,"现在调用的是电表的函数哦%d",sid);
bool newst = false;
for(Operation *oper : opers_) {
if(oper->equalPort(sid)&&oper->isRead()) {
if(oper->execute(stats))
newst=true;
}
}
if(newst) {
for(Messager *mes : messagers_) {
if(mes != nullptr) {
stateStr(mes);
for(Broker *bk : brokers_) {
if(bk != nullptr) {
mes->send(bk);
}
}
}
}
}
}

///////////////////////////////////////////////////////////////////////
DeviceFactory::DeviceFactory() {
Expand All @@ -106,21 +177,28 @@ std::vector<Device*> DeviceFactory::createDevices() {
syslog(LOG_CRIT, "Device configure fail!");
return devs; //TODO sth will do
}
else
else
{
syslog(LOG_CRIT, "Device configure success!");
}
OperationDefine opdef;
for (auto& element : js_["devices"]){
for (auto& element : js_["devices"]){
std::string str_id=element["id"];
char* id=(char*)str_id.c_str();
syslog(LOG_CRIT,"Device has loded !!! id: %s",id);
std::string str_ip=element["ip"];
char* ip=(char*)str_ip.c_str();
std::string str_type=element["type"];
char* type=(char*)str_type.c_str();

Device *dev = new Device(ip, id);
std::string str_relationship=element["relationship"].dump();
char* relationship=(char*)str_relationship.c_str();
Device *dev;
if(strcmp(type,"controllableDevice")==0)
dev = new AGVLight(ip, id,type,relationship);
else if(strcmp(type,"electricMeter")==0)
dev = new SmartMeter(ip, id,type,relationship);
else
dev = new Device(ip, id,type,relationship);
Broker *bro = kafDef_->getBroker(id);
dev->attach(bro);
Messager *mes = kafDef_->getMessager(id);
Expand All @@ -131,4 +209,3 @@ std::vector<Device*> DeviceFactory::createDevices() {
}
return devs;
}

44 changes: 39 additions & 5 deletions Device.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#ifndef _DEVICE_H_
#define _DEVICE_H_

class Connection;
#include <string>
#include <vector>
#include <glib.h>
#include "Operation.h"
#include "Broker.h"
#include "Messager.hpp"

class ZLServer;
class Device {
private:
protected:
const std::string ip_;
const std::string id_;
const std::string type_;
const std::string relationship_;
std::vector<Operation*> opers_;
std::vector<Broker*> brokers_;
std::vector<Messager*> messagers_;
ZLServer* server_;
public:
Device(const char ip[], const char id[]);
Device(const char ip[], const char id[],const char type[],const char relationship[]);
~Device();
////////////////////////////////////////////
Device* equalIP(const std::string &ip) {
Expand All @@ -25,6 +28,13 @@ class Device {
Device* equalID(const std::string &id) {
return id_ == id ? this : nullptr;
}

Device* equalType(const std::string &type) {
return type_ == type ? this : nullptr;
}
void setServer(ZLServer* server) {
server_=server;
}
void setOpers(std::vector<Operation*> &opers) {
clearOpers();
opers_ = opers;
Expand All @@ -37,13 +47,37 @@ class Device {
if(mes != nullptr)
messagers_.push_back(mes);
}

//////////////////////////////////////////////////////
void update(int sid, const std::vector<char> &stats);
virtual void update(int sid, const uint16_t stats[]);

std::string stateStr();
std::string stateStr(Messager *mes);
std::string stateStrSmartMeter(Messager *mes);
private:
void clearOpers();
};
///////////////////////////////////////////下面是闪烁灯的创建////////////////////////////////////////////////////////////////////////////////

class AGVLight:public Device{
private:

public:
AGVLight(const char ip[], const char id[],const char type[],const char relationship[]);
~AGVLight();
virtual void update(int sid, const uint16_t stats[]);
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class SmartMeter:public Device{
private:
public:
SmartMeter(const char ip[], const char id[],const char type[],const char relationship[]);
~SmartMeter();
virtual void update(int sid, const uint16_t stats[]);
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class DeviceFactory {
private:
Expand Down
Loading