嵌入式项目最终版——transducer.h

#ifndef TRANSDUCER_H
#define TRANSDUCER_H
#include
#include<string.h>
#include<time.h>
#include<stdio.h>
#include <stdlib.h>
#include
using namespace std;

class Transducer {
private:
int id, num1, num2; // 应记录historyvalues数组是否已满,num2为刷新次数
char name[32];
char currentvalue[32] = { 0 };
string historyvalues;

public:
Transducer(int id, const char* name);
~Transducer();
void init();
char* data_Generation();
};

Transducer::Transducer(int id_send, const char* name_send) {
id = id_send;
strcpy_s(name, name_send);
num1 = 0; num2 = 0;
}

Transducer::~Transducer() {};

/* 初始化随机数 */
void Transducer::init() {
srand((unsigned)time(NULL));
}

/* 产生数据,且对历史数据进行记录 /
char
Transducer::data_Generation() {
if (strcmp(name, “DHT11”) == 0) {
for (int i = 0; i < 32; i++)
currentvalue[i] = ‘0’ + rand() % 2;
if (num1 != 1024)
{
historyvalues.append((const char*)currentvalue, 32);
num1 += 32;
}
else
{
num2++;
historyvalues.clear();
historyvalues.append((const char*)currentvalue, 32);
num1 = 32;
}
}
else if (strcmp(name, “MQ-2”) == 0) {
currentvalue[0] = ‘0’ + rand() % 2;
for (int i = 1; i < 4; i++)
currentvalue[i] = ‘0’ + rand() % 10;
currentvalue[4] = ‘0’ + rand() % 2;
if (num1 != 1024) {
historyvalues.append((const char*)currentvalue, 4);
num1 += 5;
}
else {
num2++;
historyvalues.clear();
historyvalues.append((const char*)currentvalue, 4);
num1 = 5;
}
}
return currentvalue;
}

#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值