void output2_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message) { if(message->payloadlen){ printf("%s %s\n", (char *)message->topic, (char *)message->payload); char value = 0; value = *(char*)message->payload; int fd; fd=OpenToSerial("/dev/ttyS0"); usleep(50000); if(value == '1') { WriteToSerial(fd, "B1E"); printf("Set output B\n"); } if(value == '0') { WriteToSerial(fd, "B0E"); printf("Clear output B\n"); } //usleep(600000); //ReadFromSerial(fd); close(fd); }else{ printf("%s (null)\n", message->topic); } fflush(stdout); }
void output1_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message) { if(message->payloadlen){ //Do the funny stuff Here printf("%s %s\n", (char*)message->topic, (char*)message->payload); char value = 0; value = *(char*)message->payload; int fd; fd=OpenToSerial("/dev/ttyS0"); usleep(50000); if(value == '1') { WriteToSerial(fd, "A1E"); printf("Set output A\n"); } if(value == '0') { WriteToSerial(fd, "A0E"); printf("Clear output A\n"); } //usleep(600000); //ReadFromSerial(fd); close(fd); //Set callback to send status that it has been updated even if we dont know if the output was really set. }else{ printf("%s (null)\n", message->topic); } fflush(stdout); }
void Curtain::SendMsg(qint8 &, qint8 &content) { msg_[4] = content==0x01?0x01:0x00; unsigned char var; char *str; str = msg_.data(); var = Moudle::Varify((unsigned char *)str, 6); msg_[6] = var; qDebug() << "Curtain : " << msg_; WriteToSerial(msg_); }
void Replays::ConfirmOpen() { if(pre_status_[0]!=replays_status_[0] ||pre_status_[1]!=replays_status_[1] ||pre_status_[2]!=replays_status_[2] ||pre_status_[3]!=replays_status_[3]) { WriteToSerial(msg_); qDebug()<<"undone"; } else { confirm_timer_->stop(); qDebug()<<"done"; } }
void Replays::SendMsg(qint8 &cmd, qint8 &content)//发送消息 { if (1 > cmd || 5 < cmd) { return ; } if(!(content == 0||content == 1)) return; if(cmd == 0x01) { msg_[4] = 0x08; if(content) { msg_[5] = 0x08; replays_status_[0] = true; } else { msg_[5] = 0x00; replays_status_[0] = false; } } else if(cmd == 0x02) { msg_[4] = 0x04; if(content) { msg_[5] = 0x04; replays_status_[1] = true; } else { msg_[5] = 0x00; replays_status_[1] = false; } } else if(cmd == 0x03) { msg_[4] = 0x02; if(content) { msg_[5] = 0x02; replays_status_[2] = true; } else { msg_[5] = 0x00; replays_status_[2] = false; } } else if(cmd == 0x04) { msg_[4] = 0x01; if(content) { msg_[5] = 0x01; replays_status_[3] = true; } else { msg_[5] = 0x00; replays_status_[3] = false; } } unsigned char var; char *str; str = msg_.data(); var = Moudle::Varify((unsigned char *)str, 6); msg_[6] = var; WriteToSerial(msg_); confirm_timer_->start(500); }