void MessagesDialog::markMsgAsRead() { //std::cerr << "MessagesDialog::markMsgAsRead()" << std::endl; std::string cid, mid; if (!getCurrentMsg(cid, mid)) { //std::cerr << "MessagesDialog::markMsgAsRead()"; //std::cerr << " No Message selected" << std::endl; return; } rsicontrol -> MessageRead(mid); return; }
void MessagesDialog::removemessage() { //std::cerr << "MessagesDialog::removemessage()" << std::endl; std::string cid, mid; if (!getCurrentMsg(cid, mid)) { //std::cerr << "MessagesDialog::removemessage()"; //std::cerr << " No Message selected" << std::endl; return; } rsicontrol -> MessageDelete(mid); return; }
void MessagesDialog::insertMessages() { rsiface->lockData(); /* Lock Interface */ std::list<MessageInfo>::const_iterator it; const std::list<MessageInfo> &msgs = rsiface->getMessages(); /* get a link to the table */ QTreeWidget *msgWidget = ui.msgWidget; /* get the MsgId of the current one ... */ std::string cid; std::string mid; bool oldSelected = getCurrentMsg(cid, mid); QTreeWidgetItem *newSelected = NULL; /* remove old items ??? */ int listrow = ui.listWidget -> currentRow(); //std::cerr << "MessagesDialog::insertMessages()" << std::endl; //std::cerr << "Current Row: " << listrow << std::endl; /* check the mode we are in */ unsigned int msgbox = 0; switch(listrow) { case 3: msgbox = RS_MSG_SENTBOX; break; case 2: msgbox = RS_MSG_DRAFTBOX; break; case 1: msgbox = RS_MSG_OUTBOX; break; case 0: default: msgbox = RS_MSG_INBOX; break; } QList<QTreeWidgetItem *> items; for(it = msgs.begin(); it != msgs.end(); it++) { /* check the message flags, to decide which * group it should go in... * * InBox * OutBox * Drafts * Sent * * FLAGS = OUTGOING. * -> Outbox/Drafts/Sent * + SENT -> Sent * + IN_PROGRESS -> Draft. * + nuffing -> Outbox. * FLAGS = INCOMING = (!OUTGOING) * -> + NEW -> Bold. * */ if ((it -> msgflags & RS_MSG_BOXMASK) != msgbox) { //std::cerr << "Msg from other box: " << it->msgflags; //std::cerr << std::endl; continue; } /* make a widget per friend */ QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0); /* So Text should be: * (1) Msg / Broadcast * (1b) Person / Channel Name * (2) Rank * (3) Date * (4) Title * (5) Msg * (6) File Count * (7) File Total */ // Date First.... (for sorting) { QDateTime qtime; qtime.setTime_t(it->ts); QString timestamp = qtime.toString("yyyy-MM-dd hh:mm:ss"); item -> setText(0, timestamp); } // From .... { std::ostringstream out; out << it -> srcname; item -> setText(1, QString::fromStdString(out.str())); } item -> setText(2, QString::fromStdString(it->title)); // No of Files. { std::ostringstream out; out << it -> count; item -> setText(3, QString::fromStdString(out.str())); } // Size. // Msg. // Rank { std::ostringstream out; out << it -> size; item -> setText(4, QString::fromStdString(out.str())); } /* strip out the \n and \r symbols */ std::string tmsg = it -> msg; for(int i = 0; i < tmsg.length(); i++) { if ((tmsg[i] == '\n') || (tmsg[i] == '\r')) { tmsg[i] = ' '; } } item -> setText(5, QString::fromStdString(tmsg)); { std::ostringstream out; out << "5"; // RANK item -> setText(6, QString::fromStdString(out.str())); } { std::ostringstream out; out << it -> id; item -> setText(7, QString::fromStdString(out.str())); } { std::ostringstream out; out << it -> msgId; item -> setText(8, QString::fromStdString(out.str())); if ((oldSelected) && (mid == out.str())) { newSelected = item; } } if (it -> msgflags & RS_MSG_NEW) { for(int i = 0; i < 10; i++) { QFont qf = item->font(i); qf.setBold(true); item->setFont(i, qf); //std::cerr << "Setting Item BOLD!" << std::endl; } } /* add to the list */ items.append(item); } /* add the items in! */ msgWidget->clear(); msgWidget->insertTopLevelItems(0, items); if (newSelected) { msgWidget->setCurrentItem(newSelected); } rsiface->unlockData(); /* UnLock Interface */ }
//外网模式接收测试 USER_FUNC void recvTest(void *arg) { if (hfthread_create(fdthread, "feed", 256, NULL, HFTHREAD_PRIORITIES_LOW, NULL, NULL) != HF_SUCCESS) //创建喂食线程 { u_printf("create feed thread fail\n"); } if (hfthread_create(wtthread, "water", 256, NULL, HFTHREAD_PRIORITIES_LOW, NULL, NULL) != HF_SUCCESS) //创建喂水线程 { u_printf("create water thread fail\n"); } if (hfthread_create(time_fdthread, "timed_fd", 256, NULL, HFTHREAD_PRIORITIES_LOW, NULL, NULL) != HF_SUCCESS) //创建定时线程 { u_printf("create timed_fd thread fail\n"); } while (getMessageThreadFlag()) { sleep(1); ///因为设备在连接服务器过程中此线程一直在循环,实际使用时需要删除这个时延 u_printf("Enter while!\n"); int msgType = recvMessage(); if (msgType == MESSAGE_FLAG) { //如果收到的是控制指令 // u_printf("recv-> %s",getCurrentMsg()); // sendMessage(getCurrentUser(),getCurrentMsg()); /** *第一步:调用getCurrentMsg()函数,获取收到的指令字符串,该函数返回字符数组(char*类型) *第二步:根据需要解析字符串得到有效指令码,并发到底层进行控制 *第三步:控制结束后,反馈的信息通过sendMessage(user,msg)函数发出,该函数需要传入两个参数 * user参数通过调用getCurrentUser()获得,msg参数即为底层要发给客户端的反馈信息(字符串类型) * *示例:char* codeStr = getCurrentMsg(); * char* code = 指令解析函数(); * 进行底层控制,并得到反馈字符串; * sendMessage(getCurrentUser(),"反馈字符串"); * */ u_printf("recv control cmd!\n"); memset(recvbuf, 0, sizeof(recvbuf)); char* str = getCurrentMsg(); u_printf("The client has received a message: %s\n", str); strcpy(recvbuf, str); // sendto(udp_fd, recvbuf, sizeof(recvbuf), 0, (struct sockaddr *)&address, sizeof(address)); p = strtok(recvbuf, "#"); n = 0; while(p) { cmd[n] = p; n++; p = strtok(NULL, "#"); } u_printf("cmd[1] is :%s\n", cmd[1]); if (strncmp(cmd[0],"action",sizeof("action"))==0) //控制喂水、喂食,指令格式:action#1,10 { q = strtok(cmd[1], ","); j = 0; while(q) { actcmd[j] = q; j++; q = strtok(NULL, ","); } u_printf("actcmd[0] is :%s\n", actcmd[0]); if (strncmp(actcmd[0],"1",sizeof("1"))==0) { if (fdstate == 0) { fdstate = 1; //将喂食状态改为1,触发喂食线程 } else { sendMessage(getCurrentUser(), "fdbusy"); u_printf("Warning: fdbusy!\n"); } } else if (strncmp(actcmd[0],"0",sizeof("0"))==0) { if (wtstate == 0) { wtstate = 1; //将喂水状态改为1,触发喂水线程 } else { sendMessage(getCurrentUser(), "wtbusy"); u_printf("Warning: wtbusy!\n"); } } } else if(strncmp(cmd[0],"set",sizeof("set"))==0) //定时设置(添加和修改) { memset(read_flashbuf, 0, sizeof(read_flashbuf)); hfuflash_read(0, read_flashbuf, sizeof(read_flashbuf)); if (read_flashbuf[1] == ',') ///用户flash中有定时设置 { ///第一步:竖线分割flash中时间值,存于指针数组flash_set_str中 p_str = strtok(read_flashbuf, "|"); n_str = 0; while(p_str) { flash_set_str[n_str] = p_str; n_str++; p_str = strtok(NULL, "|"); } ///第二步:取flash_set_str值中标识与cmd[1]进行比较 k_str = n_str - 1; while(k_str >= 0) { memset(tmp_flash_strcmp, 0, sizeof(tmp_flash_strcmp)); strcpy(tmp_flash_strcmp, flash_set_str[k_str]); ///strcpy慎用 u_printf("The tmp_flash_strcmp is: %s\n", tmp_flash_strcmp); memset(tmp_cmd_strcmp, 0, sizeof(tmp_cmd_strcmp)); strcpy(tmp_cmd_strcmp, cmd[1]); u_printf("The tmp_cmd_strcmp is: %s\n", tmp_cmd_strcmp); if (strncmp(strtok(tmp_cmd_strcmp, ","), strtok(tmp_flash_strcmp, ","), 1) == 0) ///比较时间的标识 { // strcpy(flash_set_str[k_str], cmd[1]); flash_set_str[k_str] = cmd[1]; break; } k_str--; } ///第三步:连接字符串后放到store_flashbuf中 memset(store_flashbuf, 0, sizeof(store_flashbuf)); if (k_str < 0) //flash中没有该标识,即表示添加 { c_str = 0; while(c_str < n_str) { strcat(store_flashbuf, flash_set_str[c_str]); strcat(store_flashbuf, vertLine); c_str++; } strcat(store_flashbuf, cmd[1]); } else //修改某个标识的设置 { c_str = 0; while(c_str < n_str) { strcat(store_flashbuf, flash_set_str[c_str]); if (c_str < (n_str - 1)) strcat(store_flashbuf, vertLine); c_str++; } } } else ///flash中为空 { memset(store_flashbuf, 0, sizeof(store_flashbuf)); strcat(store_flashbuf, cmd[1]); } ///第四步:存储到用户flash中 hfuflash_erase_page(0, 1); hfuflash_write(0, store_flashbuf, sizeof(store_flashbuf)); u_printf("We have stored the store_flashbuf: %s\n", store_flashbuf); sendto(udp_fd, store_flashbuf, sizeof(store_flashbuf), 0, (struct sockaddr *)&address, sizeof(address)); sendMessage(getCurrentUser(),"control success"); } else if(strncmp(cmd[0], "cancel", sizeof("cancel")) == 0) //取消定时设置 { memset(read_flashbuf, 0, sizeof(read_flashbuf)); hfuflash_read(0, read_flashbuf, sizeof(read_flashbuf)); if (read_flashbuf[1] == ',') ///用户flash中有定时设置 { ///第一步:竖线分割flash中时间值,存于指针数组flash_set_str中 p_str = strtok(read_flashbuf, "|"); n_str = 0; while(p_str) { flash_set_str[n_str] = p_str; n_str++; p_str = strtok(NULL, "|"); } ///第二步:取flash_set_str值中标识与cmd[1]进行比较 k_str = 0; while(k_str < n_str) { memset(tmp_flash_strcmp, 0, sizeof(tmp_flash_strcmp)); strcpy(tmp_flash_strcmp, flash_set_str[k_str]); if (strncmp(strtok(tmp_flash_strcmp, ","), cmd[1], 1) == 0) { break; } k_str++; } ///第三步:flash_set_str[k_str]即为要删除的定时字符串,连接其余的放到store_flashbuf中 c_str = 0; memset(store_flashbuf, 0, sizeof(store_flashbuf)); while(c_str < n_str) { if(c_str == k_str) { c_str++; continue; } if (k_str < (n_str -1)) { strcat(store_flashbuf, flash_set_str[c_str]); if (c_str < (n_str - 1)) strcat(store_flashbuf, vertLine); c_str++; } else { strcat(store_flashbuf, flash_set_str[c_str]); if (c_str < (n_str - 2)) strcat(store_flashbuf, vertLine); c_str++; } } ///第四步:存储到用户flash中 hfuflash_erase_page(0,1); hfuflash_write(0, store_flashbuf, sizeof(store_flashbuf)); u_printf("We have stored the store_flashbuf: %s\n", store_flashbuf); sendto(udp_fd, store_flashbuf, sizeof(store_flashbuf), 0, (struct sockaddr *)&address, sizeof(address)); sendMessage(getCurrentUser(),"control success"); } } else if (strncmp(cmd[0],"flashMemory",sizeof("flashMemory"))==0) //读取内存中设定的时间值 { memset(read_flashbuf, 0, sizeof(read_flashbuf)); hfuflash_read(0, read_flashbuf, sizeof(read_flashbuf)); u_printf("The time setting is: %s\n", read_flashbuf); sendto(udp_fd, read_flashbuf, sizeof(read_flashbuf), 0, (struct sockaddr *)&address, sizeof(address)); sendMessage(getCurrentUser(), read_flashbuf); } // else if (strncmp(cmd[0],"clearAll",sizeof("clearAll"))==0) //清空内存中所有设定的时间值 // { // hfuflash_erase_page(0,1); // sendMessage(getCurrentUser(),"control success"); // } } } }