diff --git a/smart_home_client/airconditurepage.ui b/smart_home_client/airconditurepage.ui new file mode 100755 index 0000000000000000000000000000000000000000..edc266756ba521de6b4363e067b99be63a74b10a --- /dev/null +++ b/smart_home_client/airconditurepage.ui @@ -0,0 +1,19 @@ + + + airconditurePage + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/smart_home_client/camerapage.cpp b/smart_home_client/camerapage.cpp new file mode 100755 index 0000000000000000000000000000000000000000..3833fe6e7670481bd27ae6ebcc20d0844c515b65 --- /dev/null +++ b/smart_home_client/camerapage.cpp @@ -0,0 +1,14 @@ +#include "camerapage.h" +#include "ui_camerapage.h" + +cameraPage::cameraPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::cameraPage) +{ + ui->setupUi(this); +} + +cameraPage::~cameraPage() +{ + delete ui; +} diff --git a/smart_home_client/camerapage.ui b/smart_home_client/camerapage.ui new file mode 100755 index 0000000000000000000000000000000000000000..f4a92fa487f4c3b18ec6762afb62fed1166a976e --- /dev/null +++ b/smart_home_client/camerapage.ui @@ -0,0 +1,19 @@ + + + cameraPage + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/smart_home_client/client.cpp b/smart_home_client/client.cpp new file mode 100755 index 0000000000000000000000000000000000000000..90ada696f86f0daff53939646784e8a4421c84a0 --- /dev/null +++ b/smart_home_client/client.cpp @@ -0,0 +1,28 @@ +#include "client.h" + +#include + +client::client() +{ + socket = new QTcpSocket(this); +} + +//连接服务器 +void client::connect() +{ + socket->connectToHost("192.168.0.169", 8888); +} + +//发送消息 +void client::sendMessage() +{ + QString strLine = "hello world!"; + socket->write(strLine); +} + +//接收消息 +void client::recvMessage() +{ + QByteArray arr = socket->readAll(); + qDebug() << arr; +} diff --git a/smart_home_client/client.h b/smart_home_client/client.h new file mode 100755 index 0000000000000000000000000000000000000000..a1f0839cc6974c728be7edce0b89f821f60c5427 --- /dev/null +++ b/smart_home_client/client.h @@ -0,0 +1,23 @@ +#ifndef CLIENT_H +#define CLIENT_H + +#include + +class client +{ +public: + client(); + + //连接服务器 + void connect(); + + //发送消息 + void sendMessage(); + + //接收消息 + void recvMessage(); +private: + QTcpSocket * socket; +}; + +#endif // CLIENT_H diff --git a/smart_home_client/historydata.cpp b/smart_home_client/historydata.cpp new file mode 100755 index 0000000000000000000000000000000000000000..cbd2fa21c2ba041a6a20e97ba8698ab9031ffc92 --- /dev/null +++ b/smart_home_client/historydata.cpp @@ -0,0 +1,188 @@ +#include "historydata.h" +#include "ui_historydata.h" + +#include +#include + +historyData::historyData(QWidget *parent) : + QWidget(parent), + ui(new Ui::historyData) +{ + ui->setupUi(this); + + //设置窗口标题 + this->setWindowTitle("历史数据"); + this->setFixedSize(this->width(), this->height()); + + //实例化 + chart = new QChart; + chart->setAnimationOptions(QChart::SeriesAnimations); //在缩放窗口大小时可以用动画进行美化 + TemSeries = new QLineSeries(); + HumSeries = new QLineSeries(); + LightSeries = new QLineSeries(); + SmokeSeries = new QLineSeries(); + paintXY(); + + //创建套接字,和A9服务器取得连接 + historyDataSocket = new QTcpSocket(this); + historyDataSocket->connectToHost("192.168.200.105", 7777); + + connect(historyDataSocket, SIGNAL(readyRead()), this, SLOT(recvA9ServerSlot())); +} + +historyData::~historyData() +{ + delete ui; + historyDataSocket->close(); + historyDataSocket = NULL; +} + +void historyData::on_historyDataReturnBrn_clicked() +{ + TemSeries->clear(); + HumSeries->clear(); + LightSeries->clear(); + SmokeSeries->clear(); + emit historyDataToWidgetSignal(); +} + +void historyData::on_searchHistoryDataBtn_clicked() +{ + QString command = {"searchHistoryData"}; + QByteArray arr; + arr.clear(); + arr.append(command); + if(this->historyDataSocket->write(arr) == -1) + { + int ret = QMessageBox::question(this, "提交命令失败", "你提交的命令并没有上传到服务器!!!", QMessageBox::Yes); + } + else + { + int ret = QMessageBox::question(this, "提交成功", "恭喜你成功提交数据到服务器!!!", QMessageBox::Yes); + } + + //清空坐标里的内容 + TemSeries->clear(); + HumSeries->clear(); + LightSeries->clear(); + SmokeSeries->clear(); + + paintTemSeries(); + paintHumSeries(); + paintLightSeries(); + paintSmokeSeries(); + +} + +void historyData::recvA9ServerSlot() +{ + QByteArray recvServer = historyDataSocket->readAll(); + qDebug() << "history recv " << recvServer; +} + +//画坐标轴 +void historyData::paintXY() +{ + axisX = new QValueAxis; + //设置坐标轴的格式 + + axisX->setRange(0,12); //设置范围 + axisX->setLabelFormat("%d"); //设置刻度的格式 + axisX->setGridLineVisible(true); //网格线可见 + axisX->setTickCount(12); //设置多少格 + axisX->setMinorTickCount(5); //设置每格小刻度线的数目 + chart->addAxis(axisX, Qt::AlignBottom); //为chart设置x轴,并把轴附加到线上 + + axisY = new QValueAxis; + axisY->setRange(0,100); //设置范围 + axisY->setLabelFormat("%d"); //设置刻度的格式 + axisY->setGridLineVisible(true); //网格线可见 + axisY->setTickCount(11); //设置多少格 + axisY->setMinorTickCount(5); //设置每格小刻度线的数目 + chart->addAxis(axisY, Qt::AlignLeft); //为chart设置y轴,并把轴附加到线上 + + //用Qchart在QChartView上面 + ui->canvas->setChart(chart); + ui->canvas->setRenderHint(QPainter::Antialiasing); //抗锯齿 +} + +//画温度的折线统计图 +void historyData::paintTemSeries() +{ + //设置一个pen给线 + QPen TemPen; + TemPen.setWidth(2); + TemPen.setColor(Qt::red); + + //把笔交给线 + TemSeries->setPen(TemPen); + TemSeries->setName("温度"); + + *TemSeries << QPointF(0,24) << QPointF(1,23) << QPointF(2,25) << QPointF(3,27) << QPointF(4,29)<< QPointF(5,29) << QPointF(6,30) << QPointF(7,32) << QPointF(8,35)<< QPointF(9,37) << QPointF(10,35) << QPointF(11,33) << QPointF(12,30); + chart->addSeries(TemSeries); + + //把线绑定到坐标轴上 + TemSeries->attachAxis(axisX); + TemSeries->attachAxis(axisY); +} + +//画湿度的折线统计图 +void historyData::paintHumSeries() +{ + //设置一个pen给线 + QPen HumPen; + HumPen.setWidth(2); + HumPen.setColor(Qt::yellow); + + //把笔交给线 + HumSeries->setPen(HumPen); + HumSeries->setName("湿度"); + + *HumSeries << QPointF(0,65) << QPointF(1,67) << QPointF(2,64) << QPointF(3,64) << QPointF(4,62)<< QPointF(5,60) << QPointF(6,58) << QPointF(7,57) << QPointF(8,57)<< QPointF(9,55) << QPointF(10,56) << QPointF(11,58) << QPointF(12,62); + chart->addSeries(HumSeries); + + //把线绑定到坐标轴上 + HumSeries->attachAxis(axisX); + HumSeries->attachAxis(axisY); +} + +//画光照强度的折线统计图 +void historyData::paintLightSeries() +{ + //设置一个pen给线 + QPen LightPen; + LightPen.setWidth(2); + LightPen.setColor(Qt::green); + + //把笔交给线 + LightSeries->setPen(LightPen); + LightSeries->setName("光照强度"); + + *LightSeries << QPointF(0,48) << QPointF(1,53) << QPointF(2,52) << QPointF(3,51) << QPointF(4,53)<< QPointF(5,50) << QPointF(6,55) << QPointF(7,60) << QPointF(8,68)<< QPointF(9,69) << QPointF(10,75) << QPointF(11,62) << QPointF(12,55); + chart->addSeries(LightSeries); + + //把线绑定到坐标轴上 + LightSeries->attachAxis(axisX); + LightSeries->attachAxis(axisY); +} + +//画烟雾浓度的折线统计图 +void historyData::paintSmokeSeries() +{ + //设置一个pen给线 + QPen SmokePen; + SmokePen.setWidth(2); + SmokePen.setColor(Qt::blue); + + //把笔交给线 + SmokeSeries->setPen(SmokePen); + SmokeSeries->setName("烟雾浓度"); + + *SmokeSeries << QPointF(0,10) << QPointF(3,10) << QPointF(7,10) << QPointF(9,10) << QPointF(12,10); + chart->addSeries(SmokeSeries); + + //把线绑定到坐标轴上 + SmokeSeries->attachAxis(axisX); + SmokeSeries->attachAxis(axisY); + +} diff --git a/smart_home_client/historydata.cpp.autosave b/smart_home_client/historydata.cpp.autosave new file mode 100755 index 0000000000000000000000000000000000000000..157ade856067a4732ce051ff8f0c7b33c2ca78e1 --- /dev/null +++ b/smart_home_client/historydata.cpp.autosave @@ -0,0 +1,189 @@ +#include "historydata.h" +#include "ui_historydata.h" + +#include +#include + +historyData::historyData(QWidget *parent) : + QWidget(parent), + ui(new Ui::historyData) +{ + ui->setupUi(this); + + //设置窗口标题 + this->setWindowTitle("历史数据"); + this->setFixedSize(this->width(), this->height()); + + //实例化 + chart = new QChart; + chart->setAnimationOptions(QChart::SeriesAnimations); //在缩放窗口大小时可以用动画进行美化 + TemSeries = new QLineSeries(); + HumSeries = new QLineSeries(); + LightSeries = new QLineSeries(); + SmokeSeries = new QLineSeries(); + paintXY(); + + //创建套接字,和A9服务器取得连接 + historyDataSocket = new QTcpSocket(this); + historyDataSocket->connectToHost("192.168.200.105", 7777); + + connect(historyDataSocket, SIGNAL(readyRead()), this, SLOT(recvA9ServerSlot())); +} + +historyData::~historyData() +{ + delete ui; + historyDataSocket->close(); + historyDataSocket = NULL; +} + +void historyData::on_historyDataReturnBrn_clicked() +{ + TemSeries->clear(); + HumSeries->clear(); + LightSeries->clear(); + SmokeSeries->clear(); + emit historyDataToWidgetSignal(); +} + +void historyData::on_searchHistoryDataBtn_clicked() +{ + QString command = {"searchHistoryData"}; + QByteArray arr; + arr.clear(); + arr.append(command); + if(this->historyDataSocket->write(arr) == -1) + { + int ret = QMessageBox::question(this, "提交命令失败", "你提交的命令并没有上传到服务器!!!", QMessageBox::Yes); + } + else + { + int ret = QMessageBox::question(this, "提交成功", "恭喜你成功提交数据到服务器!!!", QMessageBox::Yes); + } + + //清空坐标里的内容 + TemSeries->clear(); + HumSeries->clear(); + LightSeries->clear(); + SmokeSeries->clear(); + + paintTemSeries(); + paintHumSeries(); + paintLightSeries(); + paintSmokeSeries(); + +} + +void historyData::recvA9ServerSlot() +{ + QString recvServer = historyDataSocket->readAll(); + qDebug() << "history recv " << recvServer; + +} + +//画坐标轴 +void historyData::paintXY() +{ + axisX = new QValueAxis; + //设置坐标轴的格式 + + axisX->setRange(0,12); //设置范围 + axisX->setLabelFormat("%d"); //设置刻度的格式 + axisX->setGridLineVisible(true); //网格线可见 + axisX->setTickCount(12); //设置多少格 + axisX->setMinorTickCount(5); //设置每格小刻度线的数目 + chart->addAxis(axisX, Qt::AlignBottom); //为chart设置x轴,并把轴附加到线上 + + axisY = new QValueAxis; + axisY->setRange(0,100); //设置范围 + axisY->setLabelFormat("%d"); //设置刻度的格式 + axisY->setGridLineVisible(true); //网格线可见 + axisY->setTickCount(11); //设置多少格 + axisY->setMinorTickCount(5); //设置每格小刻度线的数目 + chart->addAxis(axisY, Qt::AlignLeft); //为chart设置y轴,并把轴附加到线上 + + //用Qchart在QChartView上面 + ui->canvas->setChart(chart); + ui->canvas->setRenderHint(QPainter::Antialiasing); //抗锯齿 +} + +//画温度的折线统计图 +void historyData::paintTemSeries() +{ + //设置一个pen给线 + QPen TemPen; + TemPen.setWidth(2); + TemPen.setColor(Qt::red); + + //把笔交给线 + TemSeries->setPen(TemPen); + TemSeries->setName("温度"); + + *TemSeries << QPointF(0,24) << QPointF(1,23) << QPointF(2,25) << QPointF(3,27) << QPointF(4,29)<< QPointF(5,29) << QPointF(6,30) << QPointF(7,32) << QPointF(8,35)<< QPointF(9,37) << QPointF(10,35) << QPointF(11,33) << QPointF(12,30); + chart->addSeries(TemSeries); + + //把线绑定到坐标轴上 + TemSeries->attachAxis(axisX); + TemSeries->attachAxis(axisY); +} + +//画湿度的折线统计图 +void historyData::paintHumSeries() +{ + //设置一个pen给线 + QPen HumPen; + HumPen.setWidth(2); + HumPen.setColor(Qt::yellow); + + //把笔交给线 + HumSeries->setPen(HumPen); + HumSeries->setName("湿度"); + + *HumSeries << QPointF(0,65) << QPointF(1,67) << QPointF(2,64) << QPointF(3,64) << QPointF(4,62)<< QPointF(5,60) << QPointF(6,58) << QPointF(7,57) << QPointF(8,57)<< QPointF(9,55) << QPointF(10,56) << QPointF(11,58) << QPointF(12,62); + chart->addSeries(HumSeries); + + //把线绑定到坐标轴上 + HumSeries->attachAxis(axisX); + HumSeries->attachAxis(axisY); +} + +//画光照强度的折线统计图 +void historyData::paintLightSeries() +{ + //设置一个pen给线 + QPen LightPen; + LightPen.setWidth(2); + LightPen.setColor(Qt::green); + + //把笔交给线 + LightSeries->setPen(LightPen); + LightSeries->setName("光照强度"); + + *LightSeries << QPointF(0,48) << QPointF(1,53) << QPointF(2,52) << QPointF(3,51) << QPointF(4,53)<< QPointF(5,50) << QPointF(6,55) << QPointF(7,60) << QPointF(8,68)<< QPointF(9,69) << QPointF(10,75) << QPointF(11,62) << QPointF(12,55); + chart->addSeries(LightSeries); + + //把线绑定到坐标轴上 + LightSeries->attachAxis(axisX); + LightSeries->attachAxis(axisY); +} + +//画烟雾浓度的折线统计图 +void historyData::paintSmokeSeries() +{ + //设置一个pen给线 + QPen SmokePen; + SmokePen.setWidth(2); + SmokePen.setColor(Qt::blue); + + //把笔交给线 + SmokeSeries->setPen(SmokePen); + SmokeSeries->setName("烟雾浓度"); + + *SmokeSeries << QPointF(0,10) << QPointF(3,10) << QPointF(7,10) << QPointF(9,10) << QPointF(12,10); + chart->addSeries(SmokeSeries); + + //把线绑定到坐标轴上 + SmokeSeries->attachAxis(axisX); + SmokeSeries->attachAxis(axisY); + +} diff --git a/smart_home_client/historydata.h b/smart_home_client/historydata.h new file mode 100755 index 0000000000000000000000000000000000000000..49161c9d0db29d628dcecb1830eb21f3430ae2e3 --- /dev/null +++ b/smart_home_client/historydata.h @@ -0,0 +1,60 @@ +#ifndef HISTORYDATA_H +#define HISTORYDATA_H + +#include +#include +#include +#include +#include +#include + +QT_CHARTS_USE_NAMESPACE + +namespace Ui { +class historyData; +} + +class historyData : public QWidget +{ + Q_OBJECT + +public: + explicit historyData(QWidget *parent = 0); + ~historyData(); + + //画坐标轴 + void paintXY(); + + //画温度的折线统计图 + void paintTemSeries(); + + //画湿度的折线统计图 + void paintHumSeries(); + + //画光照强度的折线统计图 + void paintLightSeries(); + + //画烟雾浓度的折线统计图 + void paintSmokeSeries(); +signals: + void historyDataToWidgetSignal(); + +private slots: + void on_historyDataReturnBrn_clicked(); + + void on_searchHistoryDataBtn_clicked(); + + void recvA9ServerSlot(); +private: + Ui::historyData *ui; + QTcpSocket * historyDataSocket; + QLineSeries * TemSeries; //创建画温度的线 + QLineSeries * HumSeries; //创建画湿度的线 + QLineSeries * LightSeries; //创建画光照强度的线 + QLineSeries * SmokeSeries; //创建画烟感的线 + QValueAxis * axisX; //X轴 + QValueAxis * axisY; //Y轴 + QChart * chart; +}; + +#endif // HISTORYDATA_H diff --git a/smart_home_client/historydata.ui b/smart_home_client/historydata.ui new file mode 100755 index 0000000000000000000000000000000000000000..5eef1c2e92ca955200e44131cfd5c0fa4fdedab1 --- /dev/null +++ b/smart_home_client/historydata.ui @@ -0,0 +1,85 @@ + + + historyData + + + + 0 + 0 + 992 + 612 + + + + Form + + + + + 410 + 30 + 171 + 41 + + + + + 华文行楷 + 20 + + + + 历史数据 + + + Qt::AlignCenter + + + + + + 330 + 550 + 111 + 41 + + + + 查询历史数据 + + + + + + 580 + 550 + 111 + 41 + + + + 返回 + + + + + + 19 + 79 + 951 + 451 + + + + + + + QChartView + QWidget +
qchartview.h
+ 1 +
+
+ + +
diff --git a/smart_home_client/lightpage.cpp b/smart_home_client/lightpage.cpp new file mode 100755 index 0000000000000000000000000000000000000000..d5a6634970a251c9c398c4e23ce2e10fdf63dd2a --- /dev/null +++ b/smart_home_client/lightpage.cpp @@ -0,0 +1,26 @@ +#include "lightpage.h" +#include "ui_lightpage.h" + +lightPage::lightPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::lightPage) +{ + ui->setupUi(this); + + +} + +lightPage::~lightPage() +{ + delete ui; +} + +void lightPage::on_livingLightONOFFBtn_clicked() +{ + +} + +void lightPage::on_bedroomLightONOFFBtn_clicked() +{ + +} diff --git a/smart_home_client/lightpage.h b/smart_home_client/lightpage.h new file mode 100755 index 0000000000000000000000000000000000000000..1fcc476f15a3756129dabc581ad4019fa9b1fbfe --- /dev/null +++ b/smart_home_client/lightpage.h @@ -0,0 +1,30 @@ +#ifndef LIGHTPAGE_H +#define LIGHTPAGE_H + +#include +#include + +namespace Ui { +class lightPage; +} + +class lightPage : public QWidget +{ + Q_OBJECT + +public: + explicit lightPage(QWidget *parent = 0); + ~lightPage(); + +private slots: + void on_livingLightONOFFBtn_clicked(); + + void on_bedroomLightONOFFBtn_clicked(); + +private: + Ui::lightPage *ui; + QPixmap lightONPix; + QPixmap lightOFFPix; +}; + +#endif // LIGHTPAGE_H diff --git a/smart_home_client/lightpage.ui b/smart_home_client/lightpage.ui new file mode 100755 index 0000000000000000000000000000000000000000..b0a1fbff7e210d09111911a372faa0fa6ef175d6 --- /dev/null +++ b/smart_home_client/lightpage.ui @@ -0,0 +1,89 @@ + + + lightPage + + + + 0 + 0 + 342 + 441 + + + + Form + + + + + 10 + 10 + 321 + 421 + + + + + + + + + + 200 + 280 + 101 + 61 + + + + + + + + + + 40 + 280 + 121 + 61 + + + + 卧室灯 ON + + + + + + 40 + 90 + 121 + 71 + + + + 客厅灯 ON + + + + + + 200 + 90 + 101 + 61 + + + + + + + lightPageLabel + bedroomLightONOFFBtn + bedroomLightONOFFPictureLabel + livingLightONOFFPictureLabel + livingLightONOFFBtn + + + + diff --git a/smart_home_client/main.cpp b/smart_home_client/main.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4d6c97b73516b416b1f9e21e651def8e6baca33e --- /dev/null +++ b/smart_home_client/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + + return a.exec(); +} diff --git a/smart_home_client/picture.qrc b/smart_home_client/picture.qrc new file mode 100755 index 0000000000000000000000000000000000000000..ed2108acb74982f63daa7cce61dd182581b2f1fa --- /dev/null +++ b/smart_home_client/picture.qrc @@ -0,0 +1,14 @@ + + + picture/light.png + picture/temperatureSymbol.png + picture/airconditioner.png + picture/camera.png + picture/humiditySymbol.png + picture/traycon.png + picture/lightON.png + picture/lightOFF.png + picture/airconditionerOFF.png + picture/airconditionerON.png + + diff --git a/smart_home_client/picture/airconditioner.png b/smart_home_client/picture/airconditioner.png new file mode 100755 index 0000000000000000000000000000000000000000..0aea10fe50300ed0d2c78fa03316b26f110b01a7 Binary files /dev/null and b/smart_home_client/picture/airconditioner.png differ diff --git a/smart_home_client/picture/airconditionerOFF.png b/smart_home_client/picture/airconditionerOFF.png new file mode 100755 index 0000000000000000000000000000000000000000..8cfd0a23a34b006e706525c4a03d79f58bf37ddd Binary files /dev/null and b/smart_home_client/picture/airconditionerOFF.png differ diff --git a/smart_home_client/picture/airconditionerON.png b/smart_home_client/picture/airconditionerON.png new file mode 100755 index 0000000000000000000000000000000000000000..bcca401c090c3384793c77712349e2906192cd2d Binary files /dev/null and b/smart_home_client/picture/airconditionerON.png differ diff --git a/smart_home_client/picture/camera.png b/smart_home_client/picture/camera.png new file mode 100755 index 0000000000000000000000000000000000000000..3aaa61434a42e5fb83ec12adc07d4f8a24846017 Binary files /dev/null and b/smart_home_client/picture/camera.png differ diff --git a/smart_home_client/picture/humiditySymbol.png b/smart_home_client/picture/humiditySymbol.png new file mode 100755 index 0000000000000000000000000000000000000000..e6b68bef62775bf87fc2bc6229cebc340307a7de Binary files /dev/null and b/smart_home_client/picture/humiditySymbol.png differ diff --git a/smart_home_client/picture/light.png b/smart_home_client/picture/light.png new file mode 100755 index 0000000000000000000000000000000000000000..3d8cadbf5b0955bbc9397e47256c23100d9eeade Binary files /dev/null and b/smart_home_client/picture/light.png differ diff --git a/smart_home_client/picture/lightOFF.png b/smart_home_client/picture/lightOFF.png new file mode 100755 index 0000000000000000000000000000000000000000..1d5e2dc366bb647923809bb8fae4c0ef2dba0e97 Binary files /dev/null and b/smart_home_client/picture/lightOFF.png differ diff --git a/smart_home_client/picture/lightON.png b/smart_home_client/picture/lightON.png new file mode 100755 index 0000000000000000000000000000000000000000..f144dff9971e57e776eea57fb3ced972c1f06450 Binary files /dev/null and b/smart_home_client/picture/lightON.png differ diff --git a/smart_home_client/picture/temperatureSymbol.png b/smart_home_client/picture/temperatureSymbol.png new file mode 100755 index 0000000000000000000000000000000000000000..fc72ccc205f7732d3929e87c5a8cbaed5ef1cf19 Binary files /dev/null and b/smart_home_client/picture/temperatureSymbol.png differ diff --git a/smart_home_client/picture/traycon.png b/smart_home_client/picture/traycon.png new file mode 100755 index 0000000000000000000000000000000000000000..36a763287c2e64394d7dec7011002cd7176a219f Binary files /dev/null and b/smart_home_client/picture/traycon.png differ diff --git a/smart_home_client/setsecurevalue.cpp b/smart_home_client/setsecurevalue.cpp new file mode 100755 index 0000000000000000000000000000000000000000..2cb5b52df54ab7388dcf5a8b6c3a2e99511050c7 --- /dev/null +++ b/smart_home_client/setsecurevalue.cpp @@ -0,0 +1,85 @@ +#include "setsecurevalue.h" +#include "ui_setsecurevalue.h" + +#include +#include + +setSecureValue::setSecureValue(QWidget *parent) : + QWidget(parent), + ui(new Ui::setSecureValue) +{ + ui->setupUi(this); + + //设置窗口标题 + this->setWindowTitle("设置安全阈值"); + + //创建套接字,和A9服务器取得连接 + setValueSocket = new QTcpSocket(this); + setValueSocket->connectToHost("192.168.200.105", 7777); + connect(setValueSocket,SIGNAL(readyRead()),this,SLOT(recvServerDataSlot())); +} + +setSecureValue::~setSecureValue() +{ + delete ui; + setValueSocket->close(); + setValueSocket = NULL; +} + +void setSecureValue::on_setSecureValueReturnBtn_clicked() +{ + emit setSecureValueToWidgetSignal(); +} + +void setSecureValue::on_setSecureValueSubmitBtn_clicked() +{ + QString cmd = "//"; + QString MessageBuf = "SetSecureValue:"; + MessageBuf.append(ui->temMinComboBox->currentText()); + MessageBuf.append(cmd); + MessageBuf.append(ui->temMaxComboBox->currentText()); + MessageBuf.append(cmd); + MessageBuf.append(ui->humMinComboBox->currentText()); + MessageBuf.append(cmd); + MessageBuf.append(ui->humMaxComboBox->currentText()); + MessageBuf.append(cmd); + MessageBuf.append(ui->lightIntensityMinComboBox->currentText()); + MessageBuf.append(cmd); + MessageBuf.append(ui->lightIntensityMaxComboBox->currentText()); + MessageBuf.append(cmd); + MessageBuf.append(ui->smokeconcentrationMinComboBox->currentText()); + MessageBuf.append(cmd); + MessageBuf.append(ui->smokeconcentrationMaxComboBox->currentText()); + + QByteArray arr, recv; + arr.append(MessageBuf); + qDebug() << arr; + if(this->setValueSocket->write(arr) == -1) + { + int ret = QMessageBox::question(this, "提交失败", "你提交的数据并没有上传到服务器!!!", QMessageBox::Yes); + if(ret == QMessageBox::Yes) + { + emit setSecureValueToWidgetSignal(); + } + } + else + { + int ret = QMessageBox::question(this, "提交成功", "恭喜你成功提交数据到服务器!!!", QMessageBox::Yes); + if(ret == QMessageBox::Yes) + { + emit setSecureValueToWidgetSignal(); + } + } +} + +//接收来自服务器的信息 +void setSecureValue::recvServerDataSlot() +{ + int i = 0; + QByteArray arr = setValueSocket->readAll(); + for(i = 0; i < 11; i++) + { + qDebug() << "arr[i] = " << (int)arr[i]; + } + //qDebug() << "setvalue recv = " << arr; +} diff --git a/smart_home_client/setsecurevalue.h b/smart_home_client/setsecurevalue.h new file mode 100755 index 0000000000000000000000000000000000000000..75301d483072b9bfcbeaf5590edb2afc3b567edb --- /dev/null +++ b/smart_home_client/setsecurevalue.h @@ -0,0 +1,33 @@ +#ifndef SETSECUREVALUE_H +#define SETSECUREVALUE_H + +#include +#include + +namespace Ui { +class setSecureValue; +} + +class setSecureValue : public QWidget +{ + Q_OBJECT + +public: + explicit setSecureValue(QWidget *parent = 0); + ~setSecureValue(); + +signals: + void setSecureValueToWidgetSignal(); + +private slots: + void on_setSecureValueReturnBtn_clicked(); + + void on_setSecureValueSubmitBtn_clicked(); + void recvServerDataSlot(); + +private: + Ui::setSecureValue *ui; + QTcpSocket * setValueSocket; +}; + +#endif // SETSECUREVALUE_H diff --git a/smart_home_client/setsecurevalue.ui b/smart_home_client/setsecurevalue.ui new file mode 100755 index 0000000000000000000000000000000000000000..f69a7dabf78790a507264e5796cd1ffbd25d6b86 --- /dev/null +++ b/smart_home_client/setsecurevalue.ui @@ -0,0 +1,1285 @@ + + + setSecureValue + + + + 0 + 0 + 670 + 478 + + + + Form + + + + + 230 + 20 + 211 + 41 + + + + + 华文行楷 + 20 + + + + 设置安全阈值 + + + Qt::AlignCenter + + + + + + 30 + 80 + 51 + 31 + + + + + 华文行楷 + 16 + + + + color: rgb(255, 0, 0); + + + 温度 + + + + + + 170 + 120 + 87 + 22 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + + 33 + + + + + 34 + + + + + 35 + + + + + 36 + + + + + 37 + + + + + 38 + + + + + 39 + + + + + 40 + + + + + + + 90 + 120 + 72 + 21 + + + + 最小值: + + + + + + 90 + 170 + 72 + 15 + + + + 最大值: + + + + + + 170 + 170 + 87 + 22 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + + 33 + + + + + 34 + + + + + 35 + + + + + 36 + + + + + 37 + + + + + 38 + + + + + 39 + + + + + 40 + + + + + + + 440 + 170 + 72 + 15 + + + + 最大值: + + + + + + 440 + 120 + 72 + 21 + + + + 最小值: + + + + + + 380 + 80 + 51 + 31 + + + + + 华文行楷 + 16 + + + + color: rgb(255, 0, 0); + + + 湿度 + + + + + + 520 + 120 + 87 + 22 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + + 33 + + + + + 34 + + + + + 35 + + + + + 36 + + + + + 37 + + + + + 38 + + + + + 39 + + + + + 40 + + + + + + + 520 + 170 + 87 + 22 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + + 33 + + + + + 34 + + + + + 35 + + + + + 36 + + + + + 37 + + + + + 38 + + + + + 39 + + + + + 40 + + + + + + + 10 + 210 + 651 + 20 + + + + Qt::Horizontal + + + + + + 320 + 80 + 16 + 301 + + + + Qt::Vertical + + + + + + 90 + 340 + 72 + 15 + + + + 最大值: + + + + + + 90 + 290 + 72 + 21 + + + + 最小值: + + + + + + 30 + 250 + 121 + 31 + + + + + 华文行楷 + 16 + + + + color: rgb(255, 0, 0); + + + 光照强度 + + + + + + 170 + 290 + 87 + 22 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + + 33 + + + + + 34 + + + + + 35 + + + + + 36 + + + + + 37 + + + + + 38 + + + + + 39 + + + + + 40 + + + + + + + 170 + 340 + 87 + 22 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + + 33 + + + + + 34 + + + + + 35 + + + + + 36 + + + + + 37 + + + + + 38 + + + + + 39 + + + + + 40 + + + + + + + 420 + 340 + 72 + 15 + + + + 最大值: + + + + + + 360 + 250 + 121 + 31 + + + + + 华文行楷 + 16 + + + + color: rgb(255, 0, 0); + + + 烟雾浓度 + + + + + + 420 + 290 + 72 + 21 + + + + 最小值: + + + + + + 500 + 340 + 87 + 22 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + + 33 + + + + + 34 + + + + + 35 + + + + + 36 + + + + + 37 + + + + + 38 + + + + + 39 + + + + + 40 + + + + + + + 500 + 290 + 87 + 22 + + + + + 18 + + + + + 19 + + + + + 20 + + + + + 21 + + + + + 22 + + + + + 23 + + + + + 24 + + + + + 25 + + + + + 26 + + + + + 27 + + + + + 28 + + + + + 29 + + + + + 30 + + + + + 31 + + + + + 32 + + + + + 33 + + + + + 34 + + + + + 35 + + + + + 36 + + + + + 37 + + + + + 38 + + + + + 39 + + + + + 40 + + + + + + + 210 + 420 + 93 + 41 + + + + 提交 + + + + + + 350 + 420 + 93 + 41 + + + + 返回 + + + + + + diff --git a/smart_home_client/smart_home.pro b/smart_home_client/smart_home.pro new file mode 100755 index 0000000000000000000000000000000000000000..e25fd75b9f53868262329e9e9661b04209dc964d --- /dev/null +++ b/smart_home_client/smart_home.pro @@ -0,0 +1,44 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-08-27T13:31:18 +# +#------------------------------------------------- + +QT += core gui charts +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = smart_home +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + widget.cpp \ + historydata.cpp \ + setsecurevalue.cpp + +HEADERS += \ + widget.h \ + historydata.h \ + setsecurevalue.h + +FORMS += \ + widget.ui \ + historydata.ui \ + setsecurevalue.ui + +RESOURCES += \ + picture.qrc diff --git a/smart_home_client/smart_home.pro.user b/smart_home_client/smart_home.pro.user new file mode 100755 index 0000000000000000000000000000000000000000..95fdc0016fdf9c9ed201cbc4dc50cd6650dd0911 --- /dev/null +++ b/smart_home_client/smart_home.pro.user @@ -0,0 +1,318 @@ + + + + + + EnvironmentId + {2bdcebe0-b828-44ab-aa41-e9b54419a45b} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.10.1 MinGW 32bit + Desktop Qt 5.10.1 MinGW 32bit + qt.qt5.5101.win32_mingw53_kit + 0 + 0 + 0 + + C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + 在本地部署 + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + smart_home + smart_home2 + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Administrator/Desktop/smart_home/smart_home.pro + true + + smart_home.pro + false + + C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/smart_home_client/smart_home.pro.user.2bdcebe b/smart_home_client/smart_home.pro.user.2bdcebe new file mode 100755 index 0000000000000000000000000000000000000000..70e393e202cba80ba43c301b11fb063d542259a4 --- /dev/null +++ b/smart_home_client/smart_home.pro.user.2bdcebe @@ -0,0 +1,318 @@ + + + + + + EnvironmentId + {2bdcebe0-b828-44ab-aa41-e9b54419a45b} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.10.1 MinGW 32bit + Desktop Qt 5.10.1 MinGW 32bit + qt.qt5.5101.win32_mingw53_kit + 0 + 0 + 0 + + C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + 在本地部署 + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + smart_home + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Administrator/Desktop/1/smart_home.pro + true + + smart_home.pro + false + + C:/Users/Administrator/Desktop/build-smart_home-Desktop_Qt_5_10_1_MinGW_32bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/smart_home_client/smart_home.pro.user.2fa79d3 b/smart_home_client/smart_home.pro.user.2fa79d3 new file mode 100755 index 0000000000000000000000000000000000000000..76c0871af6c219b07f0ddbb4c1e30220860eef1a --- /dev/null +++ b/smart_home_client/smart_home.pro.user.2fa79d3 @@ -0,0 +1,318 @@ + + + + + + EnvironmentId + {2fa79d37-8b3a-405c-bcf3-08028e95e509} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.11.1 MinGW 32bit + Desktop Qt 5.11.1 MinGW 32bit + qt.qt5.5111.win32_mingw53_kit + 0 + 0 + 0 + + D:/ubuntuTest/courseDesign/build-smart_home-Desktop_Qt_5_11_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/ubuntuTest/courseDesign/build-smart_home-Desktop_Qt_5_11_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + D:/ubuntuTest/courseDesign/build-smart_home-Desktop_Qt_5_11_1_MinGW_32bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + 部署设置 + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + smart_home + + Qt4ProjectManager.Qt4RunConfiguration:D:/ubuntuTest/courseDesign/smart_home/smart_home.pro + true + + smart_home.pro + false + + D:/ubuntuTest/courseDesign/build-smart_home-Desktop_Qt_5_11_1_MinGW_32bit-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/smart_home_client/widget.cpp b/smart_home_client/widget.cpp new file mode 100755 index 0000000000000000000000000000000000000000..36c7aeb7a48153c17afe9b545ef23168e6580096 --- /dev/null +++ b/smart_home_client/widget.cpp @@ -0,0 +1,480 @@ +#include "widget.h" +#include "ui_widget.h" + +#include +#include +#include +#include + +Widget::Widget(QWidget *parent) : + QWidget(parent), + ui(new Ui::Widget) +{ + ui->setupUi(this); + + //窗口名字 + this->setWindowTitle("智能家居控制平台"); + + //开关窗口背景 + + + //设置托盘 + setWindowIcon(QIcon(":/picture/traycon.png")); + trayIcon = new QSystemTrayIcon(QIcon(":/picture/traycon.png"), this); + + //设置系统托盘图标 + trayIcon->setToolTip("智能家居控制平台"); + QMenu * menu = new QMenu; + menu->addAction(tr("退出"), qApp, SLOT(quit())); + trayIcon->setContextMenu(menu); + + //创建套接字,和A9服务器取得连接 + parentSocket = new QTcpSocket(this); + parentSocket->connectToHost("192.168.200.105", 7777); + + + QByteArray ThisIsWidget; + ThisIsWidget.append("ThisIsWidget"); + qDebug() << "ThisIsWidget " << ThisIsWidget; + this->parentSocket->write(ThisIsWidget); + + //电灯图标 + lightPix.load(":/picture/light.png"); + ui->lightPictureLabel->setPixmap(lightPix); + ui->lightPictureLabel->setScaledContents(true); + + //空调图标 + airconditionPix.load(":/picture/airconditioner.png"); + ui->airconditionPicyureLabel->setPixmap(airconditionPix); + ui->airconditionPicyureLabel->setScaledContents(true); + + //摄像头图标 + cameraPix = new QPixmap(); + cameraPix->load(":/picture/camera.png"); + ui->cameraPictureLabel->setPixmap(*cameraPix); + ui->cameraPictureLabel->setScaledContents(true); + + //温度符号图标 + temperatureSymbol.load(":/picture/temperatureSymbol.png"); + ui->temperationSymbolLabel->setPixmap(temperatureSymbol); + ui->temperationSymbolLabel->setScaledContents(true); + + + //湿度符号图标 + humiditySymbol.load(":/picture/humiditySymbol.png"); + ui->humiditySymbolLabel->setPixmap(humiditySymbol); + ui->humiditySymbolLabel->setScaledContents(true); + + //设置电灯打开图标 + lightONPix.load(":/picture/lightON.png"); + + //设置电灯关闭图标 + lightOFFPix.load(":/picture/lightOFF.png"); + + //设置空调打开图标 + airconditionONPix.load(":/picture/airconditionerON.png"); + + //设置空调关闭图标 + airconditionOFFPix.load(":/picture/airconditionerOFF.png"); + + //摄像头配置 + cameraPix = new QPixmap(); + this->childSocket = NULL; + ui->cameraStartBtn->setEnabled(true);//开启视频按钮的初值给true + ui->cameraStopBtn->setEnabled(false);//关闭视频按钮的初值给false + ui->cameraPage->setMinimumSize(640,480); + ui->cameraPage->setMaximumSize(640,480); + ui->cameraShowPageLabel->setMinimumSize(480,320); + ui->cameraShowPageLabel->setMaximumSize(480,320); + + //接收到设置安全阈值页面发来的信号,并把页面从安全阈值设置页面切换成主页面 + connect(&setValue, SIGNAL(setSecureValueToWidgetSignal()), this, SLOT(setSecureValueTurnWidgetSlot())); + + //接收到历史数据页面发来的信号,并把页面从历史数据页面切换成主页面 + connect(&historyData, SIGNAL(historyDataToWidgetSignal()), this, SLOT(historyDataTurnWidgetSlot())); + + //接收来自服务器的信息 + connect(parentSocket, SIGNAL(readyRead()), this, SLOT(recvServerDataSlot())); + +} + +Widget::~Widget() +{ + delete ui; + parentSocket->close(); + parentSocket = NULL; +} + +void Widget::on_livingLightONOFFBtn_clicked() +{ + if(ui->livingLightONOFFBtn->text() == "客厅灯 ON") + { + //显示电灯打开的图标 + ui->livingLightONOFFPictureLabel->setPixmap(lightONPix); + ui->livingLightONOFFPictureLabel->setScaledContents(true); + + //改变电灯开关上的文本 + ui->livingLightONOFFBtn->setText("客厅灯 OFF"); + + //发送命令给A9服务器,打开客厅灯 + QByteArray openlivingroomLight; + openlivingroomLight.append("Livingroom:ON"); + qDebug() << "openlivingroomLight " << openlivingroomLight; + this->parentSocket->write(openlivingroomLight); + } + else if(ui->livingLightONOFFBtn->text() == "客厅灯 OFF") + { + //显示电灯关闭图标 + ui->livingLightONOFFPictureLabel->setPixmap(lightOFFPix); + ui->livingLightONOFFPictureLabel->setScaledContents(true); + + //改变电灯开关上的文本 + ui->livingLightONOFFBtn->setText("客厅灯 ON"); + + //发送命令给A9服务器,关闭客厅灯 + QByteArray closelivingroomLight; + closelivingroomLight.append("Livingroom:OFF"); + qDebug() << "closelivingroomLight " << closelivingroomLight; + this->parentSocket->write(closelivingroomLight); + } +} + +void Widget::on_bedroomLightONOFFBtn_clicked() +{ + if(ui->bedroomLightONOFFBtn->text() == "卧室灯 ON") + { + //显示电灯打开的图标 + ui->bedroomLightONOFFPictureLabel->setPixmap(lightONPix); + ui->bedroomLightONOFFPictureLabel->setScaledContents(true); + + //改变电灯开关上的文本 + ui->bedroomLightONOFFBtn->setText("卧室灯 OFF"); + + //发送命令给A9服务器,打开卧室灯 + QByteArray openBedroomLight; + openBedroomLight.append("Bedroom:ON"); + qDebug() << "openBedroomLight " << openBedroomLight; + this->parentSocket->write(openBedroomLight); + } + else if(ui->bedroomLightONOFFBtn->text() == "卧室灯 OFF") + { + //显示电灯关闭图标 + ui->bedroomLightONOFFPictureLabel->setPixmap(lightOFFPix); + ui->bedroomLightONOFFPictureLabel->setScaledContents(true); + + //改变电灯开关上的文本 + ui->bedroomLightONOFFBtn->setText("卧室灯 ON"); + + //发送命令给A9服务器,关闭卧室灯 + QByteArray closeBedroomLight; + closeBedroomLight.append("Bedroom:OFF"); + qDebug() << "closeBedroomLight " << closeBedroomLight; + this->parentSocket->write(closeBedroomLight); + } +} + +void Widget::on_lightBtn_clicked() +{ + ui->stackedWidget->setCurrentWidget(ui->lightPage); + + //按下灯光按钮后让灯光按钮变成不可选状态,空调和摄像头按钮变为可选状态 + ui->lightBtn->setEnabled(false); + ui->airconditionBtn->setEnabled(true); + ui->cameraBtn->setEnabled(true); +} + +void Widget::on_airconditionBtn_clicked() +{ + ui->stackedWidget->setCurrentWidget(ui->airconditionPage); + + //按下空调按钮后让空调按钮变成不可选状态,灯光按钮和摄像头按钮变为可选状态 + ui->airconditionBtn->setEnabled(false); + ui->lightBtn->setEnabled(true); + ui->cameraBtn->setEnabled(true); +} + +void Widget::on_cameraBtn_clicked() +{ + ui->stackedWidget->setCurrentWidget(ui->cameraPage); + + //按下摄像头按钮后摄像头按钮变为不可选状态,灯光和空调按钮变为可选状态 + ui->cameraBtn->setEnabled(false); + ui->lightBtn->setEnabled(true); + ui->airconditionBtn->setEnabled(true); +} + +void Widget::on_airconditionONOFFBtn_clicked() +{ + if(ui->airconditionONOFFBtn->text() == "空调 ON") + { + //显示空调开的图标 + ui->airconditionONOFFPictureLabel->setPixmap(airconditionONPix); + ui->airconditionONOFFPictureLabel->setScaledContents(true); + + //改变按钮上的文本为空调关闭 + ui->airconditionONOFFBtn->setText("空调 OFF"); + + //发送命令给A9服务器,打开空调 + QByteArray openAirconditionLight; + openAirconditionLight.append("Aircondition:ON"); + qDebug() << "openAirconditionLight " << openAirconditionLight; + this->parentSocket->write(openAirconditionLight); + } + else if(ui->airconditionONOFFBtn->text() == "空调 OFF") + { + //显示空调关闭的图标 + ui->airconditionONOFFPictureLabel->setPixmap(airconditionOFFPix); + ui->airconditionONOFFPictureLabel->setScaledContents(true); + + //改变按钮上的字 + ui->airconditionONOFFBtn->setText("空调 ON"); + + //发送命令给A9服务器,打开空调 + QByteArray closeAirconditionLight; + closeAirconditionLight.append("Aircondition:OFF"); + qDebug() << "closeAirconditionLight " << closeAirconditionLight; + this->parentSocket->write(closeAirconditionLight); + } +} + +//摄像头页面开始按钮 +void Widget::on_cameraStartBtn_clicked() +{ + if(NULL == this->childSocket) + { + this->childSocket = new QTcpSocket(); + this->childSocket->connectToHost("192.168.200.105",8888); + //发送信号者为socket这个实例,发送的信号是connected(),接收者为Form,槽函数为msconnected() + connect(this->childSocket,SIGNAL(connected()),this,SLOT(msconnected())); + connect(this->childSocket,SIGNAL(disconnected()),this,SLOT(msdisconnected())); + ui->cameraStartBtn->setEnabled(false);//开启视频后让此按钮不可选择 + ui->cameraStopBtn->setEnabled(true);//已经开启视频后让关闭视频按钮可选择(true) + } + else + { + ui->cameraStartBtn->setEnabled(false); + ui->cameraStopBtn->setEnabled(true); + timer->start(100); + } +} + + +void Widget::msconnected() +{ + qDebug() << "connected"; + timer = new QTimer(this); + connect(timer,SIGNAL(timeout()),this,SLOT(updatepic())); + timer->start(100); +} + +//发送不连接请求 +void Widget::msdisconnected() +{ + if(timer->isActive()) + timer->stop(); + ui->cameraStartBtn->setEnabled(true);//按下关闭视频按钮后让开启视频按钮可选择(true) + ui->cameraStopBtn->setEnabled(false);//按下关闭视频按钮后让关闭按钮不可选择(false) + this->childSocket->close(); + this->childSocket = NULL; +} + +//连续读取视频信息 +void Widget::updatepic() +{ + unsigned int ret; + const char *request = "pic"; //请求命令 + char response[20]; //服务器发给QT的回复 + char *len; // + unsigned int piclen; //图片长度 + char picbuf[1024 * 1024]; //存放图片 + + ret = this->childSocket->write(request, strlen(request)); //发送请求图片命令 + if (ret != strlen(request)) { + qDebug() << "send request failed"; + timer->stop(); + this->childSocket->close(); + } + + this->childSocket->flush(); //刷新socket + this->childSocket->waitForReadyRead(30000); + + memset(response, 0, sizeof(response)); + ret = this->childSocket->read(response, sizeof(response)); + if (ret != sizeof(response)) { + qDebug() << "recv response failed"; + timer->stop(); + this->childSocket->close(); + this->childSocket = NULL; + } + + len = strstr(response, "len"); + if (len == NULL) { + qDebug() << "response header is error"; + timer->stop(); + this->childSocket->close(); + this->childSocket = NULL; + } + + *len = '\0'; + //从response中读取图片长度 + piclen = atoi(response); + unsigned int total = 0; + //循环读取pic信息 + while (total < piclen) { + ret = this->childSocket->read(picbuf+total, piclen-total); + if (ret < 0) { + qDebug() << "recv pic failed" << ret; + timer->stop(); + this->childSocket->close(); + this->childSocket = NULL; + return; + } else if (ret == 0) { + this->childSocket->waitForReadyRead(30000); + continue; + } else + total += ret; + } + cameraPix->loadFromData((const uchar *)picbuf,piclen,"JPEG"); + ui->cameraShowPageLabel->setPixmap(*cameraPix); +} + +//暂停显示图像 +void Widget::on_cameraStopBtn_clicked() +{ + qDebug() << "total:----11--------------- "; + if(timer->isActive()) + timer->stop(); + qDebug() << "total:------------------- "; + ui->cameraStartBtn->setEnabled(true);//按下关闭视频按钮后让开启视频按钮变黑(true) + ui->cameraStopBtn->setEnabled(false);//按下关闭视频按钮后让关闭按钮变灰(false) +} + +//接收到设置安全阈值页面发来的信号,并把页面从安全阈值设置页面切换成主页面 +void Widget::setSecureValueTurnWidgetSlot() +{ + //隐藏设置安全阈值界面,显示主页面 + this->show(); + setValue.hide(); +} + +//设置安全阈值按钮,切换界面到设置安全阈值界面 +void Widget::on_setSecureValueBtn_clicked() +{ + //隐藏主页面,显示设置安全阈值界面 + this->hide(); + setValue.show(); +} + +//历史数据按钮,切换界面到历史数据界面 +void Widget::on_historyDataBtn_clicked() +{ + //隐藏主界面,显示历史数据界面 + this->hide(); + historyData.show(); +} + +//接收到历史数据页面发来的信号,并把页面从历史数据页面切换成主页面 +void Widget::historyDataTurnWidgetSlot() +{ + //隐藏历史数据页面,显示主页面 + this->show(); + historyData.hide(); +} + +//接收来自服务器的信息 +void Widget::recvServerDataSlot() +{ + int i = 0; + QByteArray arr = parentSocket->readAll(); + qDebug() << "widget recv = " << arr; + for(i = 0; i < 11; i++) + { + if(i == 0) + { + if((int)arr[i] == 1) + { + //显示电灯打开的图标 + ui->livingLightONOFFPictureLabel->setPixmap(lightONPix); + ui->livingLightONOFFPictureLabel->setScaledContents(true); + + //改变电灯开关上的文本 + ui->livingLightONOFFBtn->setText("客厅灯 OFF"); + } + else if((int)arr[i] == 0) + { + //显示电灯关闭图标 + ui->livingLightONOFFPictureLabel->setPixmap(lightOFFPix); + ui->livingLightONOFFPictureLabel->setScaledContents(true); + + //改变电灯开关上的文本 + ui->livingLightONOFFBtn->setText("客厅灯 ON"); + } + } + else if(i == 1) + { + if((int)arr[i] == 1) + { + //显示电灯打开的图标 + ui->bedroomLightONOFFPictureLabel->setPixmap(lightONPix); + ui->bedroomLightONOFFPictureLabel->setScaledContents(true); + + //改变电灯开关上的文本 + ui->bedroomLightONOFFBtn->setText("卧室灯 OFF"); + } + else if((int)arr[i] == 0) + { + //显示电灯关闭图标 + ui->bedroomLightONOFFPictureLabel->setPixmap(lightOFFPix); + ui->bedroomLightONOFFPictureLabel->setScaledContents(true); + + //改变电灯开关上的文本 + ui->bedroomLightONOFFBtn->setText("卧室灯 ON"); + } + } + else if(i == 2) + { + if((int)arr[i] == 1) + { + //显示空调开的图标 + ui->airconditionONOFFPictureLabel->setPixmap(airconditionONPix); + ui->airconditionONOFFPictureLabel->setScaledContents(true); + + //改变按钮上的文本为空调关闭 + ui->airconditionONOFFBtn->setText("空调 OFF"); + } + else if((int)arr[i] == 0) + { + //显示空调关闭的图标 + ui->airconditionONOFFPictureLabel->setPixmap(airconditionOFFPix); + ui->airconditionONOFFPictureLabel->setScaledContents(true); + + //改变按钮上的字 + ui->airconditionONOFFBtn->setText("空调 ON"); + } + } + else if(i == 3) + { + ui->TemDisplayLabel->setText(tr("%1").arg((float)(((int)arr[i] * 10 + (int)arr[i + 1]) / 10))); + } + else if(i == 5) + { + ui->humidityDisplayLabel->setText(tr("%1").arg((float)(((int)arr[i] * 10 + (int)arr[i + 1]) / 10))); + + } + else if(i == 7) + { + ui->lightIntensityDisplayLabel->setText(tr("%1").arg((int)(((int)arr[i + 3] << 24) + ((int)arr[i + 2]) << 16) + ((int)arr[i + 1] << 8) + (int)arr[i])); + } + } + +} + + +/*void Widget::on_realtimeDataBtn_clicked() +{ + //给服务器发命令,显示告诉这是主页面,然后显示实时数据 + QByteArray ThisIsWidget; + ThisIsWidget.append("ThisIsWidget"); + qDebug() << "ThisIsWidget " << ThisIsWidget; + this->parentSocket->write(ThisIsWidget); +}*/ diff --git a/smart_home_client/widget.h b/smart_home_client/widget.h new file mode 100755 index 0000000000000000000000000000000000000000..f1b21a8ccb36ff5799ed4d094c36591a5cf5ddd5 --- /dev/null +++ b/smart_home_client/widget.h @@ -0,0 +1,82 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include +#include +#include +#include "setsecurevalue.h" +#include "historydata.h" + +namespace Ui { +class Widget; +} + +class Widget : public QWidget +{ + Q_OBJECT + +public: + explicit Widget(QWidget *parent = 0); + ~Widget(); + + +private slots: + + void on_livingLightONOFFBtn_clicked(); + + void on_bedroomLightONOFFBtn_clicked(); + + void on_lightBtn_clicked(); + + void on_airconditionBtn_clicked(); + + void on_cameraBtn_clicked(); + + void on_airconditionONOFFBtn_clicked(); + + void msconnected(); + + void msdisconnected(); + + void updatepic(); + + void on_cameraStartBtn_clicked(); + + void on_cameraStopBtn_clicked(); + + //接收到设置安全阈值页面发来的信号,并把页面从安全阈值设置页面切换成主页面 + void setSecureValueTurnWidgetSlot(); + + void on_setSecureValueBtn_clicked(); + + void on_historyDataBtn_clicked(); + + //接收到历史数据页面发来的信号,并把页面从历史数据页面切换成主页面 + void historyDataTurnWidgetSlot(); + + //接收来自服务器的信息 + void recvServerDataSlot(); + //void on_realtimeDataBtn_clicked(); + +private: + Ui::Widget *ui; + QPixmap lightPix; + QPixmap airconditionPix; + QPixmap *cameraPix; + QTcpSocket * parentSocket; + QTcpSocket * childSocket; + QTimer *timer; + QPixmap temperatureSymbol; + QPixmap humiditySymbol; + QSystemTrayIcon *trayIcon; + QPixmap lightONPix; + QPixmap lightOFFPix; + QPixmap airconditionONPix; + QPixmap airconditionOFFPix; + setSecureValue setValue; + historyData historyData; +}; + +#endif // WIDGET_H diff --git a/smart_home_client/widget.ui b/smart_home_client/widget.ui new file mode 100755 index 0000000000000000000000000000000000000000..31e72dca04288c68ce0d57ef35a274750ac63e25 --- /dev/null +++ b/smart_home_client/widget.ui @@ -0,0 +1,614 @@ + + + Widget + + + + 0 + 0 + 721 + 622 + + + + Widget + + + + + 10 + 90 + 701 + 461 + + + + background-color: rgba(255, 255, 255, 20); + + + + + + + 30 + 110 + 91 + 81 + + + + + + + + + + + + + 30 + 210 + 93 + 41 + + + + + + + 灯光 + + + + + + 140 + 110 + 91 + 81 + + + + + + + + + + 140 + 210 + 93 + 41 + + + + + + + 空调 + + + + + + 250 + 210 + 93 + 41 + + + + + + + 摄像头 + + + + + + 250 + 110 + 91 + 81 + + + + + + + + + + 20 + 100 + 331 + 161 + + + + + + + + + + 350 + 100 + 20 + 441 + + + + Qt::Vertical + + + + + + 20 + 260 + 321 + 16 + + + + Qt::Horizontal + + + + + + 170 + 330 + 101 + 31 + + + + + 华文行楷 + + + + + + + + + + 160 + 390 + 101 + 31 + + + + + 华文行楷 + + + + + + + + + + 280 + 280 + 61 + 31 + + + + + + + + + + 280 + 330 + 61 + 31 + + + + + + + + + + 280 + 390 + 61 + 31 + + + + + 10 + 75 + true + + + + Lux/lx + + + + + + 20 + 450 + 331 + 16 + + + + Qt::Horizontal + + + + + + 40 + 470 + 121 + 61 + + + + 历史数据 + + + + + + 220 + 470 + 121 + 61 + + + + 设置安全阈值 + + + + + + 370 + 100 + 331 + 441 + + + + 2 + + + + + + 190 + 150 + 101 + 61 + + + + + + + + + + 30 + 150 + 121 + 71 + + + + 客厅灯 ON + + + + + + 190 + 350 + 101 + 61 + + + + + + + + + + 30 + 350 + 121 + 61 + + + + 卧室灯 ON + + + + + + 131 + 10 + 71 + 41 + + + + + 华文行楷 + 16 + + + + color: rgb(0, 85, 255); + + + 灯光 + + + Qt::AlignCenter + + + + + + + + 130 + 10 + 72 + 31 + + + + + 华文行楷 + 16 + + + + color: rgb(0, 85, 255); + + + 空调 + + + Qt::AlignCenter + + + + + + 100 + 310 + 131 + 61 + + + + 空调 ON + + + + + + 100 + 170 + 131 + 81 + + + + + + + + + + + + 130 + 10 + 72 + 31 + + + + + 华文行楷 + 16 + + + + color: rgb(0, 85, 255); + + + 摄像头 + + + Qt::AlignCenter + + + + + + 0 + 40 + 331 + 401 + + + + + + + + + + 30 + 380 + 93 + 31 + + + + 开始 + + + + + + 220 + 380 + 93 + 31 + + + + 暂停 + + + + + + + + 220 + 20 + 281 + 31 + + + + + 华文行楷 + 20 + + + + color: rgb(255, 0, 0); + + + 智能家居控制平台 + + + Qt::AlignCenter + + + + + + 30 + 280 + 121 + 31 + + + + + 华文行楷 + 14 + + + + 温 度: + + + + + + 30 + 330 + 121 + 31 + + + + + 华文行楷 + 14 + + + + 湿 度: + + + + + + 30 + 390 + 121 + 31 + + + + + 华文行楷 + 14 + + + + 光照强度: + + + + + + 170 + 280 + 101 + 31 + + + + + + + switchPictureLabel + listView + lightPictureLabel + lightBtn + airconditionPicyureLabel + airconditionBtn + cameraBtn + cameraPictureLabel + line + line_2 + humidityDisplayLabel + lightIntensityDisplayLabel + temperationSymbolLabel + humiditySymbolLabel + lightIntensitySymbolLabel + line_3 + historyDataBtn + setSecureValueBtn + stackedWidget + label_2 + temperationLabel + humidityLabel + lightIntensityLabel + TemDisplayLabel + + + + + diff --git a/smart_home_server/include/modul.h b/smart_home_server/include/modul.h index ccda4f16e4148183c15fa97a13dab22be75a46c6..1ac111f327fa7247555d715b39cd97859db2e839 100755 --- a/smart_home_server/include/modul.h +++ b/smart_home_server/include/modul.h @@ -1,9 +1,11 @@ #ifndef __MODUL_H__ #define __MODUL_H__ struct env_char{ + //char smog; char led_one; char led_two; char fan; + //char buzz; char h_tem; char l_tem; char h_hum; @@ -19,6 +21,7 @@ int zigbee_get_dat(int fd); int zigbee_exe_cmd(int fd, unsigned char *p); int zigbee_exit(int fd); void send_cmd_m0(int signo); +//void send_alarm_m0(int signo); diff --git a/smart_home_server/include/serial.h b/smart_home_server/include/serial.h index 8de90649b7053a2742f87da8f724ce42f4da427b..62023dcf17b883be090bfc4e0fc2dd36c09040a1 100755 --- a/smart_home_server/include/serial.h +++ b/smart_home_server/include/serial.h @@ -7,6 +7,7 @@ struct env{ float tem; float hum; int light; + //int smog; int x; int y; int z; diff --git a/smart_home_server/include/server.h b/smart_home_server/include/server.h index 1eacb71eca61dc31305723f6c6fd3dfeaa0a17d3..12b8dbd89e90081488a5c541f44ef26aeb40ef42 100755 --- a/smart_home_server/include/server.h +++ b/smart_home_server/include/server.h @@ -12,9 +12,10 @@ #include #include -int zgbfd; #define FILEPATH_MAX (80) #define Line_Max 12 +int zgbfd; + int A9_process(); char * getPath(char *dbName); @@ -28,6 +29,5 @@ int sqlSelected(char * tabname,struct sqlite3 *pdb); void if_tabExit(char* tabname,struct sqlite3 *pdb); void sqlDelete(char * tabname,struct sqlite3 *pdb,int templine); int sqlGetData(char * tabname,struct sqlite3 *pdb); -void show(); #endif diff --git a/smart_home_server/main b/smart_home_server/main index 641a8a9e81d019578c82bd1a0c146f65314bd13c..6ee9fc0e4befd98e55b34dc80370e81f41768b84 100755 Binary files a/smart_home_server/main and b/smart_home_server/main differ diff --git a/smart_home_server/modul.c b/smart_home_server/modul.c index 8ab2a8ee67673ce9a712dad533e48e5c7ca0ba30..52463dfb4cd3005ac1a224fcdf7368646861249f 100755 --- a/smart_home_server/modul.c +++ b/smart_home_server/modul.c @@ -1,31 +1,23 @@ #include #include #include -#include -#include -#include -#include -#include - -#include -#include -#include #include "./include/serial.h" #include "./include/server.h" -#define REQ_DATA_SIZE 32 -#define HDR_DATA_SIZE 128 #define ZGB_DATA_SIZE 36 extern int zgbfd; -extern pthread_mutex_t env_mutex; extern char *p_shm; -extern char cmd_buf[5]; +extern char cmd_buf[1]; +extern float value[8]; +//m0的环境变量 struct env_char{ + //char smog; char led_one; char led_two; char fan; + //char buzz; char h_tem; char l_tem; char h_hum; @@ -36,29 +28,36 @@ struct env_char{ char forth_light; }; struct env_char env_char_data; + +//读取共享内存数据 void read_cmd() { - read_shm(p_shm+11,cmd_buf,3); - printf("p_shm[11] = %d\r\n",p_shm[11]); - printf("p_shm[12] = %d\r\n",p_shm[12]); - printf("p_shm[13] = %d\r\n",p_shm[13]); + read_shm(p_shm+11,cmd_buf,1); printf("cmd_buf[0] = %d\r\n",cmd_buf[0]); - printf("cmd_buf[1] = %d\r\n",cmd_buf[1]); - printf("cmd_buf[2] = %d\r\n",cmd_buf[2]); } -int zigbee_init( char *devpath, int baudrate) + +/*void read_secure() +{ + read_shm(p_shm+12,value,sizeof(value)/sizeof(value[0])); + printf("p_shm = %.2f\r\n",p_shm[12]); +}*/ + +//zigbee初始化 +int zigbee_init(char *devpath, int baudrate) { return serial_init(devpath); } +//zigbee采集数据 int zigbee_get_dat(int fd) { + int i = 0; ssize_t ret; unsigned char buf[ZGB_DATA_SIZE]; memset(buf, 0, sizeof(buf)); - fprintf(stdout,"hi\n"); + //fprintf(stdout,"hi\n"); ret = serial_recv_exact_nbytes(fd, buf, sizeof(buf)); - fprintf(stdout,"hi1\n"); + //fprintf(stdout,"hi1\n"); if (ret == sizeof(buf)) { if (buf[0] == 0xBB) @@ -67,12 +66,16 @@ int zigbee_get_dat(int fd) data.id = (int)buf[1]; data.tem = (float)((buf[5]*10 + buf[4])/10) ; data.hum = (float)((buf[7]*10 + buf[6])/10) ; + //data.smog = (int)buf[16]; data.light = (int)((buf[23] << 24) + (buf[22] << 16) + (buf[21] << 8) + buf[20]); + //printf("smog = %d\r\n",data.smog); env_char_data.l_tem = buf[4]; env_char_data.h_tem = buf[5]; env_char_data.l_hum = buf[6]; env_char_data.h_hum = buf[7]; + //env_char_data.smog = buf[16]; //烟雾浓度 + //printf("smog = %d\r\n",(int)buf[16]); env_char_data.first_light = buf[20]; env_char_data.second_light = buf[21]; env_char_data.third_light = buf[22]; @@ -80,17 +83,20 @@ int zigbee_get_dat(int fd) data.led = buf[24]; data.fan = buf[25]; - data.buzz = buf[26]; + //data.buzz = buf[26]; + env_char_data.led_one = buf[24]; env_char_data.fan = buf[25]; + //env_char_data.buzz = buf[26]; env_char_data.led_two = buf[27]; } } return ret; } -int zigbee_exe_cmd(int fd, unsigned char *p) +//zigbee发送命令 +int zigbee_exe_cmd(int fd, unsigned char *p) { unsigned char buf[ZGB_DATA_SIZE] = {0xdd, 0x06, 0x24, 0x00, 0x00}; if (strstr(p, "LIGHT_ON") != NULL){ @@ -110,63 +116,65 @@ int zigbee_exe_cmd(int fd, unsigned char *p) } else if (strstr(p, "SHU_OFF") != NULL){ buf[4] = 0x0a; } - int ret = serial_send_exact_nbytes(fd, buf, sizeof(buf)); - return ret; } - -void ctrl_led_one() +//AP发送给m0命令 +void send_cmd_m0(int signum) { - if(cmd_buf[0]) + read_cmd(); + if(cmd_buf[0] == 1) { - printf("cmd_buf[0] now = %d\r\n",cmd_buf[0]); + printf("Living now:ON = %d\r\n",cmd_buf[0]); zigbee_exe_cmd(zgbfd,"LIGHT_ON"); //led1 - } - - else + } + + else if(cmd_buf[0] == 2) { - printf("cmd_buf[0] now = %d\r\n",cmd_buf[0]); - zigbee_exe_cmd(zgbfd,"LIGHT_OFF"); + printf("Living now:OFF = %d\r\n",cmd_buf[0]); + zigbee_exe_cmd(zgbfd,"LIGHT_OFF"); //led1 } -} - -void ctrl_led_two() -{ - if( cmd_buf[1]) + + else if(cmd_buf[0] == 3) { - printf("cmd_buf[1] now = %d\r\n",cmd_buf[1]); + printf("Bedroom now:ON = %d\r\n",cmd_buf[0]); zigbee_exe_cmd(zgbfd,"SHU_ON"); //led2 } - else + + else if(cmd_buf[0] == 4) { - printf("cmd_buf[1] now = %d\r\n",cmd_buf[1]); - zigbee_exe_cmd(zgbfd,"SHU_OFF"); + printf("Bedroom now:OFF = %d\r\n",cmd_buf[0]); + zigbee_exe_cmd(zgbfd,"SHU_OFF"); //led2 } -} - -void ctrl_fan() -{ - if( cmd_buf[2]) + + else if(cmd_buf[0] == 5) { - printf("cmd_buf[2] now = %d\r\n",cmd_buf[2]); + printf("Aircondition now:ON = %d\r\n",cmd_buf[0]); zigbee_exe_cmd(zgbfd,"FAN_ON"); //fan } - else + + else if(cmd_buf[0] == 6) { - printf("cmd_buf[2] now = %d\r\n",cmd_buf[2]); - zigbee_exe_cmd(zgbfd,"FAN_OFF"); + printf("Aircondition now:OFF%d\r\n",cmd_buf[0]); + zigbee_exe_cmd(zgbfd,"FAN_OFF"); //fan + printf("Aircondition now:OFF%d\r\n",cmd_buf[0]); } } -void send_cmd_m0(int signum) + +/*void send_alarm_m0(int signo) { - read_cmd(); - ctrl_fan(); - ctrl_led_one(); - ctrl_led_two(); -} + read_secure(); + printf("data_tem = %f\r\n",data.tem); + printf("value[1] = %.2f\r\n",value[1]); + printf("value[0] = %.2f\r\n",value[0]); + if(data.tem < value[0] || data.tem > value[1] || data.hum < value[2] || data.hum > value[3] || data.light < value[4] || data.light > value[5]) + zigbee_exe_cmd(zgbfd,"BUZZ_ON"); + else + zigbee_exe_cmd(zgbfd,"BUZZ_OFF"); +}*/ +//zigbee退出 int zigbee_exit(int fd) { return serial_exit(fd); diff --git a/smart_home_server/serial.c b/smart_home_server/serial.c index 6b0c8822df9d390661d1cbd1cd33eb7de47b5c74..2bc79725b77814410d438ebd6379769c93172a62 100755 --- a/smart_home_server/serial.c +++ b/smart_home_server/serial.c @@ -12,7 +12,6 @@ #include #include - #define FALSE -1 #define TRUE 0 @@ -20,196 +19,215 @@ int serial_open(char *devpath) { /*分别为com1,com2, com3对应 ttyUSB0 ttyUSB1 ttyUSB2 */ - int fd = open( devpath, O_RDWR|O_NOCTTY|O_NDELAY); - if (FALSE == fd){ - perror("Can't Open Serial Port"); - return(FALSE); - } - //恢复串口为阻塞状态 - if(fcntl(fd, F_SETFL, 0) < 0){ - printf("fcntl failed!\n"); - return(FALSE); - } else{ - printf("fcntl=%d\n",fcntl(fd, F_SETFL,0)); - } - //测试是否为终端设备 - if(0 == isatty(fd)){ - printf("standard input is not a terminal device\n"); - return(FALSE); - } else{ - printf("isatty success!\n"); - } - printf("fd->open=%d\n",fd); - return fd; + int fd = open( devpath, O_RDWR|O_NOCTTY|O_NDELAY); + if (FALSE == fd){ + perror("Can't Open Serial Port"); + return(FALSE); + } + //恢复串口为阻塞状态 + if(fcntl(fd, F_SETFL, 0) < 0) + { + printf("fcntl failed!\n"); + return(FALSE); + } + else + { + printf("fcntl=%d\n",fcntl(fd, F_SETFL,0)); + } + //测试是否为终端设备 + if(0 == isatty(fd)) + { + printf("standard input is not a terminal device\n"); + return(FALSE); + } + else + { + printf("isatty success!\n"); + } + printf("fd->open=%d\n",fd); + return fd; } //fd串口号;speed传输波特率;databits数据位;flow_ctrl数据流;parity奇偶校验;stopbits停止位 int serial_Set(int fd,int speed,int flow_ctrl,int databits,int stopbits,int parity) { - - int i; - int speed_arr[] = { B115200, B19200, B9600, B4800, B2400, B1200, B300}; - int name_arr[] = {115200, 19200, 9600, 4800, 2400, 1200, 300}; - - struct termios options; - - /*tcgetattr(fd,&options)得到与fd指向对象的相关参数,并将它们保存于options,该函数还可以测试配置是否正确,该串口是否可用等。若调用成功,函数返回值为0,若调用失败,函数返回值为1. - */ - if ( tcgetattr( fd,&options) != 0) { - perror("SetupSerial 1"); - return(FALSE); - } - - //设置串口输入波特率和输出波特率 - for ( i= 0; i < sizeof(speed_arr) / sizeof(int); i++) { - if (speed == name_arr[i]) { - cfsetispeed(&options, speed_arr[i]); - cfsetospeed(&options, speed_arr[i]); - } - } - - //修改控制模式,保证程序不会占用串口 - options.c_cflag |= CLOCAL; - //修改控制模式,使得能够从串口中读取输入数据 - options.c_cflag |= CREAD; - options.c_oflag &= ~(ONLCR | OCRNL); - options.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); - options.c_iflag &= ~(ICRNL | INLCR); - options.c_iflag &= ~(IXON | IXOFF | IXANY); - - //设置数据流控制 - switch(flow_ctrl) { - - case 0 ://不使用流控制 - options.c_cflag &= ~CRTSCTS; - break; - case 1 ://使用硬件流控制 - options.c_cflag |= CRTSCTS; - break; - case 2 ://使用软件流控制 - options.c_cflag |= IXON | IXOFF | IXANY; - break; - } - //设置数据位 - //屏蔽其他标志位 - options.c_cflag &= ~CSIZE; - switch (databits) { - case 5 : - options.c_cflag |= CS5; - break; - case 6 : - options.c_cflag |= CS6; - break; - case 7 : - options.c_cflag |= CS7; - break; - case 8: - options.c_cflag |= CS8; - break; - default: - fprintf(stderr,"Unsupported data size\n"); - return (FALSE); - } - //设置校验位 - switch (parity) { - case 'n': - case 'N': //无奇偶校验位。 - options.c_cflag &= ~PARENB; - options.c_iflag &= ~INPCK; - break; - case 'o': - case 'O'://设置为奇校验 - options.c_cflag |= (PARODD | PARENB); - options.c_iflag |= INPCK; - break; - case 'e': - case 'E'://设置为偶校验 - options.c_cflag |= PARENB; - options.c_cflag &= ~PARODD; - options.c_iflag |= INPCK; - break; - case 's': - case 'S': //设置为空格 - options.c_cflag &= ~PARENB; - options.c_cflag &= ~CSTOPB; - break; - default: - fprintf(stderr,"Unsupported parity\n"); - return (FALSE); - } - // 设置停止位 - switch (stopbits) { - case 1: - options.c_cflag &= ~CSTOPB; - break; - case 2: - options.c_cflag |= CSTOPB; - break; - default: - fprintf(stderr,"Unsupported stop bits\n"); - return (FALSE); - } - - //修改输出模式,原始数据输出 - options.c_oflag &= ~OPOST; - options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);//我加的 + + int i; + int speed_arr[] = { B115200, B19200, B9600, B4800, B2400, B1200, B300}; + int name_arr[] = {115200, 19200, 9600, 4800, 2400, 1200, 300}; + struct termios options; + + /*tcgetattr(fd,&options)得到与fd指向对象的相关参数,并将它们保存于options,该函数还可以测试配置是否正确,该串口是否可用等。若调用成功,函数返回值为0,若调用失败,函数返回值为1. + */ + if ( tcgetattr( fd,&options) != 0) + { + perror("SetupSerial 1"); + return(FALSE); + } + + //设置串口输入波特率和输出波特率 + for ( i= 0; i < sizeof(speed_arr) / sizeof(int); i++) + { + if (speed == name_arr[i]) + { + cfsetispeed(&options, speed_arr[i]); + cfsetospeed(&options, speed_arr[i]); + } + } + + //修改控制模式,保证程序不会占用串口 + options.c_cflag |= CLOCAL; + //修改控制模式,使得能够从串口中读取输入数据 + options.c_cflag |= CREAD; + options.c_oflag &= ~(ONLCR | OCRNL); + options.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); + options.c_iflag &= ~(ICRNL | INLCR); + options.c_iflag &= ~(IXON | IXOFF | IXANY); + + //设置数据流控制 + switch(flow_ctrl) + { + + case 0 ://不使用流控制 + options.c_cflag &= ~CRTSCTS; + break; + case 1 ://使用硬件流控制 + options.c_cflag |= CRTSCTS; + break; + case 2 ://使用软件流控制 + options.c_cflag |= IXON | IXOFF | IXANY; + break; + } + //设置数据位 + //屏蔽其他标志位 + options.c_cflag &= ~CSIZE; + switch (databits) + { + case 5 : + options.c_cflag |= CS5; + break; + case 6 : + options.c_cflag |= CS6; + break; + case 7 : + options.c_cflag |= CS7; + break; + case 8: + options.c_cflag |= CS8; + break; + default: + fprintf(stderr,"Unsupported data size\n"); + return (FALSE); + } + //设置校验位 + switch (parity) + { + case 'n': + case 'N': //无奇偶校验位。 + options.c_cflag &= ~PARENB; + options.c_iflag &= ~INPCK; + break; + case 'o': + case 'O'://设置为奇校验 + options.c_cflag |= (PARODD | PARENB); + options.c_iflag |= INPCK; + break; + case 'e': + case 'E'://设置为偶校验 + options.c_cflag |= PARENB; + options.c_cflag &= ~PARODD; + options.c_iflag |= INPCK; + break; + case 's': + case 'S': //设置为空格 + options.c_cflag &= ~PARENB; + options.c_cflag &= ~CSTOPB; + break; + default: + fprintf(stderr,"Unsupported parity\n"); + return (FALSE); + } + // 设置停止位 + switch (stopbits) + { + case 1: + options.c_cflag &= ~CSTOPB; + break; + case 2: + options.c_cflag |= CSTOPB; + break; + default: + fprintf(stderr,"Unsupported stop bits\n"); + return (FALSE); + } + + //修改输出模式,原始数据输出 + options.c_oflag &= ~OPOST; + options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);//我加的 //options.c_lflag &= ~(ISIG | ICANON); - - //设置等待时间和最小接收字符 - options.c_cc[VTIME] = 1; /* 读取一个字符等待0*(0/10)s */ - options.c_cc[VMIN] = 1; /* 读取字符的最少个数为0 */ - - //如果发生数据溢出,接收数据,但是不再读取 刷新收到的数据但是不读 - tcflush(fd,TCIFLUSH); - - //激活配置 (将修改后的termios数据设置到串口中) - if (tcsetattr(fd,TCSANOW,&options) != 0) { - perror("com set error!\n"); - return (FALSE); - } + + //设置等待时间和最小接收字符 + options.c_cc[VTIME] = 1; /* 读取一个字符等待0*(0/10)s */ + options.c_cc[VMIN] = 1; /* 读取字符的最少个数为0 */ + + //如果发生数据溢出,接收数据,但是不再读取 刷新收到的数据但是不读 + tcflush(fd,TCIFLUSH); + + //激活配置 (将修改后的termios数据设置到串口中) + if (tcsetattr(fd,TCSANOW,&options) != 0) + { + perror("com set error!\n"); + return (FALSE); + } printf("serial set success\n"); - return (TRUE); + return (TRUE); } int serial_init(char *devpath) { - int fd_comport = FALSE; + int fd_comport = FALSE; //打开串口 - if((fd_comport=serial_open(devpath))<0){ + if((fd_comport=serial_open(devpath))<0) + { perror("serial_Open"); return FALSE; } - //设置串口数据帧格式 - if (serial_Set(fd_comport,115200,0,8,1,'N')<0) { + //设置串口数据帧格式 + if (serial_Set(fd_comport,115200,0,8,1,'N')<0) + { perror("serial_Set"); - return FALSE; - } - return fd_comport; + return FALSE; + } + return fd_comport; } ssize_t serial_recv_exact_nbytes(int fd, void *buf, size_t count) { ssize_t ret; ssize_t total = 0; - unsigned char * buf1 = (unsigned char *)buf; + unsigned char * buf1 = (unsigned char *)buf; assert(buf != NULL); - + while (total != count) { - fprintf(stdout,"%d\n",fd); - fprintf(stdout,"hi..\n"); - ret = read(fd, buf + total, count - total); - int i = 0; - for (i = 0; i < 36; i++){ - printf("%.2x ", buf1[i]); - } - fprintf(stdout,"hi2\n"); - if (ret == -1) { + fprintf(stdout,"%d\n",fd); + fprintf(stdout,"hi..\n"); + ret = read(fd, buf + total, count - total); + /*int i = 0; + for (i = 0; i < 36; i++){ + printf("%.2x ", buf1[i]); + }*/ + fprintf(stdout,"hi2\n"); + if (ret == -1) + { perror("serial->recv"); break; - } else if (ret == 0) { + } + else if (ret == 0) + { fprintf(stdout, "serial->recv: timeout or end-of-file\n"); break; - } else + } + else total += ret; } @@ -222,27 +240,30 @@ ssize_t serial_send_exact_nbytes(int fd, unsigned char *buf, size_t count) ssize_t total = 0; assert(buf != NULL); - int i = 0; - for (i = 0; i < 36; i++){ - printf("%.2x ", buf[i]); - } - printf("\n"); - while (total != count) { + //int i = 0; + /*for (i = 0; i < 36; i++){ + printf("%.2x ", buf[i]); + } + printf("\n");*/ + while (total != count) + { ret = write(fd, buf + total, count - total); - fprintf(stdout,"%d\n",ret); - if (ret == -1) { + fprintf(stdout,"%d\n",ret); + if (ret == -1) + { perror("serial->send"); break; - } else + } + else total += ret; } - return total; } int serial_exit(int fd) { - if (close(fd)) { + if (close(fd)) + { perror("serial->exit"); return -1; } diff --git a/smart_home_server/server.c b/smart_home_server/server.c index 14a7786db556e7a88714335f323b5a47df151046..d8e9f03813263ce2bd948d0aac51f472ad8025b1 100755 --- a/smart_home_server/server.c +++ b/smart_home_server/server.c @@ -25,10 +25,13 @@ #define SPORT 7777 #define LISNUM 1024 #define BUFFER_SIZE 128 -char env_buf[128]; +char env_buf[12]; char cmd_buf[5]; char *p_shm = NULL; - +extern char databuf[72][25]; +char get_history_data[72][25]; +//客户端阈值存放 +float value[8] = {0}; void read_env(int signo) { read_shm(p_shm,env_buf,sizeof(env_char_data)); @@ -49,14 +52,12 @@ int A9_process() char cmd[BUFFER_SIZE] = {0}; pid_t pid,pid_zigbee; int signo = 0; - //客户端阈值存放 - float value[8] = {0}; char *pPath = NULL; struct sqlite3 *pdb = NULL; char dbName[] = "/mysqlite"; - char tabname1[] = "data"; - char tabname2[] = "param"; + char tabname1[] = "rt_data"; + char tabname2[] = "max_data"; //获取pPath pPath = getPath(dbName); //open or create db @@ -88,6 +89,7 @@ int A9_process() p_shm = create_shm(); while(1) { + //send_alarm_m0(signo); send_cmd_m0(signo); ret = zigbee_get_dat(zgbfd); if(ret < 0) @@ -167,22 +169,19 @@ int A9_process() if(0 == strncmp(cmd,"SearchHistoryData",17)) { //p_shm = create_shm(); - //write_shm(p_shm,str,sizeof(str)); - printf("cmd = %s\r\n",cmd); - send(connfd,cmd,sizeof(cmd),0); + //read_env(signo); + //send(connfd,env_buf,sizeof(env_buf),0); + printf("cmd = %s\r\n",cmd); + for(i = 0; i < 11; i++) + { + printf("buf = %d\r\n",env_buf[i]); + } } //设置安全阈值 else if(0 == strncmp(cmd,"SetSecureValue:",15)) { - p_shm = create_shm(); - read_env(signo); - - for(i = 0; i < 5; i++) - { - printf("buf = %d\r\n",env_buf[i]); - } - memset(value,0,sizeof(value) / sizeof(value[0])); + //p_shm = create_shm(); buf_ope = strtok(cmd+15,s); while(buf_ope != NULL) { @@ -191,44 +190,36 @@ int A9_process() i++; buf_ope = strtok(NULL,s); } + /*write_shm(p_shm,value,sizeof(value)/sizeof(value[0])); + signal(SIGUSR1,send_alarm_m0); + printf("value[1] = %.2f\r\n",value[1]); + printf("p_shm[1] = %.2f\r\n",p_shm[1]);*/ //将阈值插入到数据库 SqlInsert1(pdb,tabname2,*value,*(value+1),*(value+2),*(value+3),*(value+4),*(value+5),*(value+6),*(value+7)); - sqlSelected(tabname2,pdb); - if(recv_len > 0) - { - memset(cmd,0,sizeof(cmd)); - strncpy(cmd,"SetSecureValue:succeed",23); - send(connfd,cmd,sizeof(cmd),0); - } + //sqlSelected(tabname2,pdb); } - + //解析到是主界面 - /*else if(strncmp(cmd,"ThisIsWidget",12)) + else if(strncmp(cmd,"ThisIsWidget",12)) { p_shm = create_shm(); read_env(signo); - - for(i = 0; i < 5; i++) - { - printf("buf = %d\r\n",env_buf[i]); - } + send(connfd,env_buf,sizeof(env_buf),0); printf("cmd = %s\r\n",cmd); - memset(cmd,0,sizeof(cmd)); - strncpy(cmd,"Main_Theme",10); - send(connfd,cmd,sizeof(cmd),0); - printf("widget\n"); - }*/ + for(i = 0; i < 11; i++) + printf("buf = %d\r\n",env_buf[i]); + } //解析客厅灯 else if(0 == strncmp(cmd,"Livingroom:ON",13)) { - p_shm = create_shm(); printf("cmd = %s\r\n",cmd); memset(cmd,0,sizeof(cmd)); strncpy(cmd,"Livingroom:open",15); send(connfd,cmd,sizeof(cmd),0); led1 = 1; write_shm(p_shm+11,&led1,1); + printf("p_shm = %d\r\n",p_shm[11]); signal(SIGUSR1,send_cmd_m0); } @@ -240,9 +231,9 @@ int A9_process() memset(cmd,0,sizeof(cmd)); strncpy(cmd,"Livingroom:close",16); send(connfd,cmd,sizeof(cmd),0); - led1 = 0; + led1 = 2; write_shm(p_shm+11,&led1,1); - //printf("p_shm+11 = %d\r\n",p_shm[11]); + printf("p_shm = %d\r\n",p_shm[11]); signal(SIGUSR1,send_cmd_m0); } @@ -252,11 +243,11 @@ int A9_process() p_shm = create_shm(); printf("cmd = %s\r\n",cmd); memset(cmd,0,sizeof(cmd)); - strncpy(cmd,"Bedroom:ON",10); + strncpy(cmd,"Bedroom:open",10); send(connfd,cmd,sizeof(cmd),0); - led2 = 1; - write_shm(p_shm+12,&led2,1); - //printf("p_shm+12 = %d\r\n",p_shm[12]); + led2 = 3; + write_shm(p_shm+11,&led2,1); + printf("p_shm = %d\r\n",p_shm[11]); signal(SIGUSR1,send_cmd_m0); } @@ -267,8 +258,9 @@ int A9_process() memset(cmd,0,sizeof(cmd)); strncpy(cmd,"Bedroom:close",13); send(connfd,cmd,sizeof(cmd),0); - led2 = 0; - write_shm(p_shm+12,&led2,1); + led2 = 4; + write_shm(p_shm+11,&led2,1); + printf("p_shm = %d\r\n",p_shm[11]); signal(SIGUSR1,send_cmd_m0); } @@ -280,8 +272,9 @@ int A9_process() memset(cmd,0,sizeof(cmd)); strncpy(cmd,"Aircondition:open",17); send(connfd,cmd,sizeof(cmd),0); - fan = 1; - write_shm(p_shm+13,&fan,1); + fan = 5; + write_shm(p_shm+11,&fan,1); + printf("p_shm = %d\r\n",p_shm[11]); signal(SIGUSR1,send_cmd_m0); } @@ -292,8 +285,9 @@ int A9_process() memset(cmd,0,sizeof(cmd)); strncpy(cmd,"Aircondition:close",18); send(connfd,cmd,sizeof(cmd),0); - fan = 0; - write_shm(p_shm+13,&fan,1); + fan = 6; + write_shm(p_shm+11,&fan,1); + printf("p_shm = %d\r\n",p_shm[11]); signal(SIGUSR1,send_cmd_m0); } recv_len = recv(connfd,cmd,BUFFER_SIZE,0); diff --git a/smart_home_server/shm.c b/smart_home_server/shm.c index a8663004699b8d1b2a5f456744e671143620f998..5ed78dbe655f2e81d3861f7794f9e35a39d20ee0 100755 --- a/smart_home_server/shm.c +++ b/smart_home_server/shm.c @@ -5,7 +5,7 @@ key_t key = 0; char *create_shm() { key = ftok(PATH, 123); - printf("key = %p\r\n",key); + //printf("key = %p\r\n",key); if (key < 0) { perror("ftok error"); @@ -18,7 +18,7 @@ char *create_shm() } //映射 char *p_shm = shmat(shmid, NULL, 0); - printf("shm = %p\r\n",p_shm); + //printf("shm = %p\r\n",p_shm); if (NULL == p_shm) { perror("shmat error"); diff --git a/smart_home_server/sqlite.c b/smart_home_server/sqlite.c index 1961311d11881cd517afecf65fe7051aa6105b9c..ad1af0284c184b452b3fc640a8960b5635d02e7b 100755 --- a/smart_home_server/sqlite.c +++ b/smart_home_server/sqlite.c @@ -2,8 +2,11 @@ char databuf[72][25]; char *pErrMsg = NULL; int dataline = 0; +int dataline1 = 0; + #define FILEPATH_MAX (80) #define Line_Max 12 + void sqlDelete(char * tabname,struct sqlite3 *pdb,int templine); char * getPath(char *dbName) { @@ -64,9 +67,16 @@ tabname//表名 void SqlInsert1(struct sqlite3 *pdb,char *tabname,float tempMax,float tempMin,float humMax,float humMin,float luxMax, float luxMin,float ppmMax,float ppmMin ) { //insert table - //int templine = 0; - // templine = dataline; + int templine = 0; + templine = dataline1; char sqlInsert1[1024] = {0}; + templine %= 1; + //删除对应行 + if(dataline1 >= 1) + { + //删除哪张表的哪一行 + sqlDelete(tabname,pdb,templine); + } //UPDATE tabneme SET ADDRESS = 'Texas' WHERE ID = 6; sprintf(sqlInsert1, "insert into %s (TempMax,TempMin,HumMax,HumMin,LuxMax,LuxMin,PpmMax,PpmMin) values (%5f,%5f,%5f,%5f,%5f,%5f,%5f,%5f)",tabname,tempMax,tempMin,humMax,humMin,luxMax,luxMin,ppmMax,ppmMin); @@ -77,7 +87,7 @@ void SqlInsert1(struct sqlite3 *pdb,char *tabname,float tempMax,float tempMin,fl //sqlite3_free(pErrMsg); } sqlite3_free(pErrMsg); - + dataline1++; } /* @@ -267,11 +277,3 @@ int sqlGetData(char * tabname,struct sqlite3 *pdb) return count; } -void show() -{ - int i = 0; - for(i= 0;i< 72; i++) - { - printf("%s \n",databuf[i]); - } -}