void WmLButtonDblclkProc(HWND hwnd, LPARAM lParam){ ChannelData *cd; bool changeFlg = FALSE; ChannelDataLock.on(); cd = channelDataTop; while(cd){ int x = LOWORD(lParam); int y = HIWORD(lParam); if (cd->checkDown(LOWORD(lParam), HIWORD(lParam))){ if (!(cd->isSelected())){ changeFlg = TRUE; } if (!(cd->getOpenFlg())){ changeFlg = TRUE; cd->setOpenFlg(TRUE); } else { changeFlg = TRUE; cd->setOpenFlg(FALSE); } cd->setSelected(TRUE); } else { if (cd->isSelected()){ changeFlg = TRUE; } cd->setSelected(FALSE); } /* int sx = cd->getPosX() + cd->getWidth(); int sy = cd->getPosY(); int index = 0; ServentData *sd = cd->getServentDataTop(); while(sd){ if ( ( (!cd->getOpenFlg()) && (sx + index*14 < x) && (x < sx + (index+1)*14) && (sy < y) && (y < sy + 14) ) || sd->checkDown(LOWORD(lParam), HIWORD(lParam)) ){ if (!sd->getSelected()){ changeFlg = TRUE; } sd->setSelected(TRUE); } else { if (sd->getSelected()){ changeFlg = TRUE; } sd->setSelected(FALSE); } sd = sd->getNextData(); index++; }*/ cd = cd->getNextData(); } ChannelDataLock.off(); if (changeFlg){ MakeBack(hwnd); } }
void MakeBack(HWND hwnd, UINT x, UINT y){ MakeBackLock.on(); winWidth = x; winHeight = y; if (backGra){ ::delete backBmp; ::delete backGra; } backBmp = ::new Bitmap(x,y); backGra = ::new Graphics(backBmp); // 全て白で塗りつぶし SolidBrush b(Color(255,255,255,255)); backGra->FillRectangle(&b, 0, 0, x, y); backWidth = backImage->GetWidth(); backHeight = backImage->GetHeight(); // 背景画像を描画 for (UINT xx = 0; xx < x/backWidth + 1; xx++){ for (UINT yy = 0; yy < y/backHeight + 1; yy++){ UINT width,height; if (backWidth*(xx+1) > x){ width = x % backWidth; } else { width = backWidth; } if (backHeight*(yy+1) > y){ height = y % backHeight; } else { height = backHeight; } Rect r((INT)backWidth*xx, (INT)backHeight*yy, width, height); backGra->DrawImage(backImage, r, 0, 0, (INT)width, (INT)height, UnitPixel); } } INT posX = 20; INT posY = 20; // 速度描画 drawSpeed(backGra, winWidth-205, 5); // チャンネル情報を描画 ChannelDataLock.on(); ChannelData *cd = channelDataTop; while(cd){ posY = cd->drawChannel(backGra, 20, posY); cd = cd->getNextData(); } ChannelDataLock.off(); MakeBackLock.off(); }
ChannelData *findChannelData(int channel_id){ ChannelData *cd = channelDataTop; while(cd){ if (cd->getChannelId() == channel_id){ return cd; } cd = cd->getNextData(); } return NULL; }
// // Implementation of the receiveData for both Data and Status consumers // The execution of these methods happens in a thread created by the Enobio // instance so accesing GUI resources might lead to a program crash // void EnobioDataConsumer::receiveData(const PData &data) { // The EnobioData is destroyed after the execution of receiveData by // the caller ChannelData * pData = (ChannelData *)data.getData(); // Provide the data to whatever slot is connected to that signal emit newData(QString::number(pData->data()[0]) + "\t" + QString::number(pData->data()[1]) + "\t" + QString::number(pData->data()[2]) + "\t" + QString::number(pData->data()[3]) + "\t" + QString::number(pData->data()[4]) + "\t" + QString::number(pData->data()[5]) + "\t" + QString::number(pData->data()[6]) + "\t" + QString::number(pData->data()[7]) + "\t" + QString::number(pData->timestamp())); }
LoggedDataSweep DatalogDownloader::getNextData() { if(complete()) { throw Error_NoData("There is no more data available to download from the Node."); } const uint32 startReadIndex = m_nodeMemory->readIndex(); ChannelData chData; try { //check if the next group of bytes look like the start of a trigger if(m_nodeMemory->isNextByteNewHeader()) { //Download Version 1 if(m_datalogDownloadVersion == 1) { //parse the trigger header and update all of the trigger session info parseTriggerHeader_v1(); m_foundFirstTrigger = true; } //Download Version 2 else { //parse the trigger header for v2 and update any new trigger session info parseTriggerHeader_v2(); m_foundFirstTrigger = true; } } else { //if the first trigger hasn't been found yet if(!m_foundFirstTrigger) { //the start of trigger isn't at the first memory location on the Node m_outOfMemory = true; throw Error_NoData("No triggers were found on the Node."); } //set the startOfTrigger flag to false m_sessionInfo.startOfTrigger = false; } uint8 lastActiveCh = m_sessionInfo.activeChannels.lastChEnabled(); Utils::Endianness dataEndian = Utils::bigEndian; if(m_datalogDownloadVersion == 2) { dataEndian = Utils::littleEndian; } //calibrations are applied if floating point data m_sessionInfo.calsApplied = (m_sessionInfo.dataType == WirelessTypes::dataType_float32); //loop through all the channels for(uint8 chItr = 1; chItr <= lastActiveCh; ++chItr) { //if the current channel is enabled if(m_sessionInfo.activeChannels.enabled(chItr)) { anyType dataPoint; switch(m_sessionInfo.dataType) { //4 byte float case WirelessTypes::dataType_float32: case WirelessTypes::dataType_float32_noCals: dataPoint = m_nodeMemory->read_float(dataEndian); break; //uint32 case WirelessTypes::dataType_uint32: dataPoint = m_nodeMemory->read_uint32(dataEndian); break; //uint24 (get as a uint32) case WirelessTypes::dataType_uint24: dataPoint = m_nodeMemory->read_uint24(dataEndian); break; //uint16 (from a 18-bit device, shift bits) case WirelessTypes::dataType_uint16_18bitTrunc: { uint32 val = m_nodeMemory->read_uint16(dataEndian); dataPoint = (val << 2); break; } //uint16 case WirelessTypes::dataType_uint16_shifted: case WirelessTypes::dataType_uint16_12bitRes: case WirelessTypes::dataType_uint16: default: dataPoint = m_nodeMemory->read_uint16(dataEndian); break; } //create a WirelessDataPoint and add it to the ChannelData vector chData.push_back(WirelessDataPoint(static_cast<WirelessChannel::ChannelId>(chItr), chItr, m_sessionInfo.valueType, dataPoint)); } } } catch(Error_Communication&) { //downloader v1 needs to reset the memory position on comm failure if(m_datalogDownloadVersion == 1) { //set the read address back so that we the user can retry m_nodeMemory->setAddress(startReadIndex); } //then rethrow the exception throw; } //calculate the timestamp and tick for the sweep uint64 sweepTime = m_sessionInfo.timestamp + (m_sessionInfo.timeBetweenSweeps * m_sweepCount); uint64 sweepTick = m_sweepCount; //increment the sweep count m_sweepCount++; //return the LoggedDataSweep object containing the data that was downloaded return LoggedDataSweep(Timestamp(sweepTime), sweepTick, chData); }
void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mtpRequestId req) { const MTPDmessages_chatFull &d(result.c_messages_chatFull()); const QVector<MTPChat> &vc(d.vchats.c_vector().v); bool badVersion = false; if (peer->isChat()) { badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_chat && vc.at(0).c_chat().vversion.v < peer->asChat()->version); } else if (peer->isChannel()) { badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_channel && vc.at(0).c_channel().vversion.v < peer->asChannel()->version); } App::feedUsers(d.vusers, false); App::feedChats(d.vchats, false); if (peer->isChat()) { if (d.vfull_chat.type() != mtpc_chatFull) { LOG(("MTP Error: bad type in gotChatFull for chat: %1").arg(d.vfull_chat.type())); return; } const MTPDchatFull &f(d.vfull_chat.c_chatFull()); App::feedParticipants(f.vparticipants, false, false); const QVector<MTPBotInfo> &v(f.vbot_info.c_vector().v); for (QVector<MTPBotInfo>::const_iterator i = v.cbegin(), e = v.cend(); i < e; ++i) { switch (i->type()) { case mtpc_botInfo: { const MTPDbotInfo &b(i->c_botInfo()); UserData *user = App::userLoaded(b.vuser_id.v); if (user) { user->setBotInfo(*i); App::clearPeerUpdated(user); emit fullPeerUpdated(user); } } break; } } PhotoData *photo = App::feedPhoto(f.vchat_photo); ChatData *chat = peer->asChat(); if (photo) { chat->photoId = photo->id; photo->peer = chat; } else { chat->photoId = 0; } chat->invitationUrl = (f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString(); App::main()->gotNotifySetting(MTP_inputNotifyPeer(peer->input), f.vnotify_settings); } else if (peer->isChannel()) { if (d.vfull_chat.type() != mtpc_channelFull) { LOG(("MTP Error: bad type in gotChatFull for channel: %1").arg(d.vfull_chat.type())); return; } const MTPDchannelFull &f(d.vfull_chat.c_channelFull()); PhotoData *photo = App::feedPhoto(f.vchat_photo); ChannelData *channel = peer->asChannel(); channel->flagsFull = f.vflags.v; if (photo) { channel->photoId = photo->id; photo->peer = channel; } else { channel->photoId = 0; } if (f.has_migrated_from_chat_id()) { if (!channel->mgInfo) { channel->flags |= MTPDchannel::flag_megagroup; channel->flagsUpdated(); } ChatData *cfrom = App::chat(peerFromChat(f.vmigrated_from_chat_id)); bool updatedTo = (cfrom->migrateToPtr != channel), updatedFrom = (channel->mgInfo->migrateFromPtr != cfrom); if (updatedTo) { cfrom->migrateToPtr = channel; } if (updatedFrom) { channel->mgInfo->migrateFromPtr = cfrom; if (History *h = App::historyLoaded(cfrom->id)) { if (History *hto = App::historyLoaded(channel->id)) { if (!h->isEmpty()) { h->clear(true); } if (!hto->dialogs.isEmpty() && !h->dialogs.isEmpty()) { App::removeDialog(h); } } } Notify::migrateUpdated(channel); } if (updatedTo) { Notify::migrateUpdated(cfrom); App::main()->peerUpdated(cfrom); } } const QVector<MTPBotInfo> &v(f.vbot_info.c_vector().v); for (QVector<MTPBotInfo>::const_iterator i = v.cbegin(), e = v.cend(); i < e; ++i) { switch (i->type()) { case mtpc_botInfo: { const MTPDbotInfo &b(i->c_botInfo()); UserData *user = App::userLoaded(b.vuser_id.v); if (user) { user->setBotInfo(*i); App::clearPeerUpdated(user); emit fullPeerUpdated(user); } } break; } } channel->about = qs(f.vabout); int32 newCount = f.has_participants_count() ? f.vparticipants_count.v : 0; if (newCount != channel->count) { if (channel->isMegagroup() && !channel->mgInfo->lastParticipants.isEmpty()) { channel->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated; channel->mgInfo->lastParticipantsCount = channel->count; } channel->count = newCount; } channel->adminsCount = f.has_admins_count() ? f.vadmins_count.v : 0; channel->invitationUrl = (f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString(); if (History *h = App::historyLoaded(channel->id)) { if (h->inboxReadBefore < f.vread_inbox_max_id.v + 1) { h->setUnreadCount(channel->isMegagroup() ? f.vunread_count.v : f.vunread_important_count.v); h->inboxReadBefore = f.vread_inbox_max_id.v + 1; h->asChannelHistory()->unreadCountAll = f.vunread_count.v; } } channel->fullUpdated(); App::main()->gotNotifySetting(MTP_inputNotifyPeer(peer->input), f.vnotify_settings); } if (req) { QMap<PeerData*, mtpRequestId>::iterator i = _fullPeerRequests.find(peer); if (i != _fullPeerRequests.cend() && i.value() == req) { _fullPeerRequests.erase(i); } } if (badVersion) { if (peer->isChat()) { peer->asChat()->version = vc.at(0).c_chat().vversion.v; } else if (peer->isChannel()) { peer->asChannel()->version = vc.at(0).c_channel().vversion.v; } requestPeer(peer); } App::clearPeerUpdated(peer); emit fullPeerUpdated(peer); App::emitPeerUpdated(); }
THREAD_PROC GUIDataUpdate(ThreadInfo *thread){ int i; // set GUI thread status to running thread->finish = false; while(thread->active){ // チャンネルデータロック ChannelDataLock.on(); // チャンネルデータの更新フラグを全てFALSEにする ChannelData *cd = channelDataTop; while(cd){ // Serventの更新フラグをFALSEにする ServentData *sv = cd->getServentDataTop(); while(sv){ sv->setEnableFlg(FALSE); sv = sv->getNextData(); } cd->setEnableFlg(FALSE); cd = cd->getNextData(); } Channel *c = chanMgr->channel; // 現在存在するチャンネル分ループ while(c){ // 既にチャンネルデータを持っているか cd = channelDataTop; // 発見フラグFALSE bool bFoundFlg = FALSE; while(cd){ if (cd->getChannelId() == c->channel_id){ //既にチャンネルデータがあるので、そのまま更新 cd->setData(c); // 更新フラグTRUE cd->setEnableFlg(TRUE); // 発見フラグTRUE bFoundFlg = TRUE; // ループ離脱 break; } // 見つからなかった場合、次のデータをチェック cd = cd->getNextData(); } // 新しいチャンネルの場合、新規データ作成 if (!bFoundFlg){ // 新規データ作成 cd = ::new ChannelData(); // データ更新 cd->setData(c); // 更新フラグTRUE cd->setEnableFlg(TRUE); // 新規データをリストの先頭に入れる cd->setNextData(channelDataTop); channelDataTop = cd; } // 次のチャンネルを取得 c = c->next; } #if 1 // COUTを検索 { bool foundFlg = false; bool foundFlg2 = false; Servent *s = servMgr->servents; while (s) { if (s->type == Servent::T_COUT && s->status == Servent::S_CONNECTED) { foundFlg = true; // ChannelData末尾まで探索 ChannelData *prev = NULL; cd = channelDataTop; while (cd) { if (cd->type == Servent::T_COUT && cd->servent_id == s->servent_id) { foundFlg2 = true; cd->setEnableFlg(true); break; } prev = cd; cd = cd->getNextData(); } cd = prev; if (foundFlg2) break; // ノード追加 if (channelDataTop) { // channelDataが空でない。cdはここでリスト末尾を指してる(はず) cd->setNextData(::new ChannelData()); cd = cd->getNextData(); memset(cd, 0, sizeof(cd)); cd->setNextData(NULL); } else { // channelDataが空 channelDataTop = ::new ChannelData(); channelDataTop->setNextData(NULL); cd = channelDataTop; } // データ設定 cd->type = s->type; cd->servent_id = s->servent_id; cd->setEnableFlg(true); } s = s->next; } // COUTが切れてたら削除 if (!foundFlg) { cd = channelDataTop; ChannelData *prev = NULL; while (cd) { // COUTの情報を削除 if (cd->type == Servent::T_COUT) { // 先頭 if (!prev) { channelDataTop = cd->getNextData(); } else { prev->setNextData(cd->getNextData()); } //::delete cd; } prev = cd; cd = cd->getNextData(); } } } #endif // チャンネルがなくなっている場合の処理 cd = channelDataTop; ChannelData *prev = NULL; while(cd){ // データを更新しなかったか if (cd->getEnableFlg() == FALSE){ // チャンネルがなくなっているので削除 ChannelData *next; next = cd->getNextData(); if (!prev){ // 先頭のデータを削除 // ここメモリリークしそう by えるー channelDataTop = next; } else { // 途中のデータを削除 prev->setNextData(next); } // 次のデータへ cd = next; } else { // データ更新済:次のデータへ prev = cd; cd = cd->getNextData(); } } Servent *s = servMgr->servents; while(s){ // 初期化 ChanHitList *chl; bool infoFlg = false; bool relay = true; bool firewalled = false; unsigned int numRelays = 0; int vp_ver = 0; char ver_ex_prefix[2] = {' ', ' '}; int ver_ex_number = 0; // 直下ホスト情報チェック unsigned int totalRelays = 0; unsigned int totalListeners = 0; ChanHit hitData; // 受信中か if ((s->type == Servent::T_RELAY) && (s->status == Servent::S_CONNECTED)){ // ホスト情報ロック chanMgr->hitlistlock.on(); // 直下ホストが受信しているチャンネルのホスト情報を取得 chl = chanMgr->findHitListByID(s->chanID); // チャンネルのホスト情報があるか if (chl){ // チャンネルのホスト情報がある場合 ChanHit *hit = chl->hit; // チャンネルのホスト情報を全走査して while(hit){ // IDが同じものであれば if (hit->servent_id == s->servent_id){ // トータルリレーとトータルリスナーを加算 totalRelays += hit->numRelays; totalListeners += hit->numListeners; // 直下であれば if (hit->numHops == 1){ // 情報を一旦保存 infoFlg = true; hitData.relay = hit->relay; hitData.firewalled = hit->firewalled; hitData.numRelays = hit->numRelays; hitData.version_vp = hit->version_vp; hitData.version_ex_prefix[0] = hit->version_ex_prefix[0]; hitData.version_ex_prefix[1] = hit->version_ex_prefix[1]; hitData.version_ex_number = hit->version_ex_number; } } // 次をチェック hit = hit->next; } } // チャンネルデータからServentを検索 bool bFoundFlg = FALSE; cd = channelDataTop; while(cd){ ServentData *sv = cd->findServentData(s->servent_id); // ServentDataがあれば if (sv && cd->getChannelId() == s->channel_id){ // データ設定 sv->setData(s, &hitData, totalListeners, totalRelays, infoFlg); sv->setEnableFlg(TRUE); bFoundFlg = TRUE; break; } cd = cd->getNextData(); } // ServentDataが見つからなかった場合 if (!bFoundFlg){ // チャンネルデータを探す cd = channelDataTop; while(cd){ // チャンネルIDが同じか if (cd->getChannelId() == s->channel_id){ // データ設定 ServentData *sv = ::new ServentData(); sv->setData(s, &hitData, totalListeners, totalRelays, infoFlg); sv->setEnableFlg(TRUE); // チャンネルデータにServentData追加 cd->addServentData(sv); // ホスト名を取得する IdData *id = ::new IdData(cd->getChannelId(), sv->getServentId(), sv->getHost().ip); ThreadInfo *t; t = ::new ThreadInfo(); t->func = GetHostName; t->data = (void*)id; sys->startThread(t); LOG_DEBUG("resolving thread was started(%d)", id->getServentId()); // ループ終了 break; } // 次のデータへ cd = cd->getNextData(); } } // ホスト情報アンロック chanMgr->hitlistlock.off(); } s = s->next; } // 更新していないServentDataを削除 cd = channelDataTop; while(cd){ cd->deleteDisableServents(); cd = cd->getNextData(); } // チャンネルデータアンロック ChannelDataLock.off(); // 描画更新 if (guiWnd){ MakeBack(guiWnd); } // 0.1秒×10で1秒待ち for(i=0; i<2; i++) { if (!thread->active) break; sys->sleep(100); } } // set GUI thread status to terminated thread->finish = true; return 0; }
void WmRButtonDownProc(HWND hwnd, LPARAM lParam){ ChannelData *cd; bool changeFlg = FALSE; bool channel_selected = FALSE; bool servent_selected = FALSE; int channel_id = 0; int servent_id = 0; cd = channelDataTop; while(cd){ if (cd->checkDown(LOWORD(lParam), HIWORD(lParam))){ if (!(cd->isSelected())){ changeFlg = TRUE; } cd->setSelected(TRUE); channel_id = cd->getChannelId(); channel_selected = TRUE; // COUT識別 if (cd->type == Servent::T_COUT) { channel_selected = FALSE; servent_selected = TRUE; servent_id = cd->servent_id; } } else { if (cd->isSelected()){ changeFlg = TRUE; } cd->setSelected(FALSE); } ServentData *sd = cd->getServentDataTop(); while(sd){ if (sd->checkDown(LOWORD(lParam), HIWORD(lParam))){ if (!sd->getSelected()){ changeFlg = TRUE; } sd->setSelected(TRUE); servent_id = sd->getServentId(); servent_selected = TRUE; } else { if (sd->getSelected()){ changeFlg = TRUE; } sd->setSelected(FALSE); } sd = sd->getNextData(); } cd = cd->getNextData(); } if (changeFlg){ MakeBack(hwnd); } if (channel_selected){ PopupChannelMenu(channel_id); } else if (servent_selected){ PopupServentMenu(servent_id); } else { PopupOtherMenu(); } }
void PopupOtherMenu(){ POINT pos; MENUITEMINFO info, separator; HMENU hMenu; DWORD dwID; hMenu = CreatePopupMenu(); memset(&separator, 0, sizeof(MENUITEMINFO)); separator.cbSize = sizeof(MENUITEMINFO); separator.fMask = MIIM_ID | MIIM_TYPE; separator.fType = MFT_SEPARATOR; separator.wID = 8000; memset(&info, 0, sizeof(MENUITEMINFO)); info.cbSize = sizeof(MENUITEMINFO); info.fMask = MIIM_ID | MIIM_TYPE; info.fType = MFT_STRING; info.wID = 1107; info.dwTypeData = "非リレー中のチャンネルを削除"; InsertMenuItem(hMenu, -1, true, &info); InsertMenuItem(hMenu, -1, true, &separator); if (!gbDispTop){ info.wID = 1101; info.dwTypeData = "最前面表示"; InsertMenuItem(hMenu, -1, true, &info); } else { info.wID = 1102; info.dwTypeData = "最前面解除"; InsertMenuItem(hMenu, -1, true, &info); } InsertMenuItem(hMenu, -1, true, &separator); if (!gbAllOpen){ info.wID = 1103; info.dwTypeData = "全直下展開"; InsertMenuItem(hMenu, -1, true, &info); } else { info.wID = 1104; info.dwTypeData = "全直下隠蔽"; InsertMenuItem(hMenu, -1, true, &info); } InsertMenuItem(hMenu, -1, true, &separator); if (!servMgr->autoServe){ info.wID = 1105; info.dwTypeData = "有効"; InsertMenuItem(hMenu, -1, true, &info); } else { info.wID = 1106; info.dwTypeData = "無効"; InsertMenuItem(hMenu, -1, true, &info); } GetCursorPos(&pos); dwID = TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RETURNCMD, pos.x, pos.y, 0, guiWnd, NULL); DestroyMenu(hMenu); ChannelData *cd = channelDataTop; switch(dwID){ case 1101: // 最前面表示 gbDispTop = true; ::SetWindowPos(guiWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); break; case 1102: // 最前面解除 gbDispTop = false; ::SetWindowPos(guiWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); break; case 1103: // 全直下展開 gbAllOpen = true; while(cd){ cd->setOpenFlg(true); cd = cd->getNextData(); } break; case 1104: // 全直下隠蔽 gbAllOpen = false; while(cd){ cd->setOpenFlg(false); cd = cd->getNextData(); } break; case 1105: // 有効 servMgr->autoServe = true; break; case 1106: // 無効 servMgr->autoServe = false; break; case 1107: // 非リレー中のチャンネル情報を全て削除 { LOG_DEBUG("Start cleaning up unused channels"); while (cd) { if (cd->getStatus() == Channel::S_NOTFOUND || cd->getStatus() == Channel::S_IDLE) { Channel *c = chanMgr->findChannelByChannelID(cd->getChannelId()); if (c && !c->bumped) { c->thread.active = false; c->thread.finish = true; } } cd = cd->getNextData(); } LOG_DEBUG("Finish a cleanup of unused channels"); } break; } }
void PopupServentMenu(int servent_id){ POINT pos; MENUITEMINFO info, separator; HMENU hMenu; DWORD dwID; hMenu = CreatePopupMenu(); memset(&separator, 0, sizeof(MENUITEMINFO)); separator.cbSize = sizeof(MENUITEMINFO); separator.fMask = MIIM_ID | MIIM_TYPE; separator.fType = MFT_SEPARATOR; separator.wID = 8000; memset(&info, 0, sizeof(MENUITEMINFO)); info.cbSize = sizeof(MENUITEMINFO); info.fMask = MIIM_ID | MIIM_TYPE; info.fType = MFT_STRING; ServentData *sd = NULL; ChannelData *cd = channelDataTop; while(cd){ // COUT if (cd->type == Servent::T_COUT && cd->servent_id == servent_id) break; sd = cd->findServentData(servent_id); if (sd){ break; } cd = cd->getNextData(); } if (cd == NULL || sd == NULL && cd->type != Servent::T_COUT) // COUT { return; } info.wID = 1001; info.dwTypeData = "切断"; InsertMenuItem(hMenu, -1, true, &info); // InsertMenuItem(hMenu, -1, true, &separator); GetCursorPos(&pos); dwID = TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RETURNCMD, pos.x, pos.y, 0, guiWnd, NULL); DestroyMenu(hMenu); cd = channelDataTop; while(cd){ // COUT if (cd->type == Servent::T_COUT && cd->servent_id == servent_id) break; sd = cd->findServentData(servent_id); if (sd){ break; } cd = cd->getNextData(); } if (cd == NULL || sd == NULL && cd->type != Servent::T_COUT) // COUT { return; } Servent *s = servMgr->findServentByServentID(servent_id); if (s == NULL){ return; } switch(dwID){ case 1001: // 切断 s->thread.active = false; // COUT切断 if (s->type == Servent::T_COUT) s->thread.finish = true; break; } }
void PopupChannelMenu(int channel_id){ POINT pos; MENUITEMINFO info, separator; HMENU hMenu; DWORD dwID; hMenu = CreatePopupMenu(); memset(&separator, 0, sizeof(MENUITEMINFO)); separator.cbSize = sizeof(MENUITEMINFO); separator.fMask = MIIM_ID | MIIM_TYPE; separator.fType = MFT_SEPARATOR; separator.wID = 8000; memset(&info, 0, sizeof(MENUITEMINFO)); info.cbSize = sizeof(MENUITEMINFO); info.fMask = MIIM_ID | MIIM_TYPE; info.fType = MFT_STRING; ChannelData *cd = findChannelData(channel_id); if (cd == NULL){ return; } info.wID = 1001; info.dwTypeData = "切断"; InsertMenuItem(hMenu, -1, true, &info); InsertMenuItem(hMenu, -1, true, &separator); info.wID = 1000; info.dwTypeData = "再生"; InsertMenuItem(hMenu, -1, true, &info); InsertMenuItem(hMenu, -1, true, &separator); info.wID = 1002; info.dwTypeData = "再接続"; InsertMenuItem(hMenu, -1, true, &info); info.wID = 1003; info.dwTypeData = "キープ"; InsertMenuItem(hMenu, -1, true, &info); InsertMenuItem(hMenu, -1, true, &separator); if (!cd->getOpenFlg()){ info.wID = 1004; info.dwTypeData = "直下表示"; InsertMenuItem(hMenu, -1, true, &info); } else { info.wID = 1005; info.dwTypeData = "直下隠蔽"; InsertMenuItem(hMenu, -1, true, &info); } GetCursorPos(&pos); dwID = TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RETURNCMD, pos.x, pos.y, 0, guiWnd, NULL); DestroyMenu(hMenu); cd = findChannelData(channel_id); if (cd == NULL){ return; } Channel *c = chanMgr->findChannelByChannelID(channel_id); if (c == NULL){ return; } switch(dwID){ case 1000: // 再生 chanMgr->playChannel(c->info); break; case 1001: // 切断 // bump中は切断しない if (!c->bumped) { c->thread.active = false; c->thread.finish = true; } break; case 1002: // 再接続 // 直下かつ受信中であれば確認メッセージ表示 if (cd->isTracker() && cd->getStatus() == Channel::S_RECEIVING) { int id; id = MessageBox(guiWnd, "直下ですが再接続しますか?", "直下警告", MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2); if (id != IDYES) break; } c->bump = true; break; case 1003: // キープ if (!c->stayConnected){ c->stayConnected = true; } else { c->stayConnected = false; } break; case 1004: // 直下表示 cd->setOpenFlg(TRUE); MakeBack(guiWnd); break; case 1005: // 直下隠蔽 cd->setOpenFlg(FALSE); MakeBack(guiWnd); break; } }
THREAD_PROC GetHostName(ThreadInfo *thread){ IdData *id = (IdData*)(thread->data); //HOSTENT *he; u_long ip; struct sockaddr_in sa; char host[256]; char *tmp; bool flg = TRUE; bool findFlg; int error; ip = htonl(id->getIpAddr()); memset(&sa, 0, sizeof(sa)); sa.sin_addr.S_un.S_addr = ip; sa.sin_family = AF_INET; for (int i=0; i<10 && flg; i++){ error = getnameinfo(reinterpret_cast<sockaddr*>(&sa), sizeof(sa), host, sizeof(host)/sizeof(host[0]), NULL, 0, NI_NAMEREQD); switch (error) { case 0: // success flg = FALSE; break; case WSAHOST_NOT_FOUND: LOG_ERROR("cannot resolve host for %s", ((tmp = inet_ntoa(sa.sin_addr)) ? tmp : "")); flg = TRUE; break; default: LOG_ERROR("an error occurred while resolving hostname of %s (%ld)", ((tmp = inet_ntoa(sa.sin_addr)) ? tmp : ""), error); } } if (error) return 0; for (flg=TRUE, findFlg=FALSE; flg; ) { ChannelDataLock.on(); ChannelData* cd = channelDataTop; while(cd){ if (cd->getChannelId() == id->getChannelId()) { findFlg = TRUE; if (cd->findServentData(id->getServentId())) { if (cd->setName(id->getServentId(), host)) { LOG_DEBUG("successfully resolved(%d)", id->getServentId()); flg = FALSE; break; } else { LOG_ERROR("cannot update servent data with resolved information"); flg = FALSE; break; } } else { LOG_DEBUG("servent data has been removed"); flg = FALSE; break; } } cd = cd->getNextData(); } // ::delete id; ChannelDataLock.off(); if (!findFlg) { LOG_DEBUG("servent data has been removed(channel)"); flg = FALSE; } sys->sleep(1000); } return 0; }
void AsyncDigitalAnalogPacket::parseSweeps() { const uint32 TS_OFFSET_LEN = 2; //timestamp offset is always 2 bytes const uint32 DIGITAL_LEN = 2; //digital data is always 2 bytes //read the values from the payload uint16 channelMask = m_payload.read_uint16(PAYLOAD_OFFSET_CHANNEL_MASK); uint8 dataType = m_payload.read_uint8(PAYLOAD_OFFSET_DATA_TYPE); uint16 tick = m_payload.read_uint16(PAYLOAD_OFFSET_TICK); uint64 timestampSeconds = m_payload.read_uint32(PAYLOAD_OFFSET_TS_SEC); //the timestamp (UTC) seconds part uint64 timestampNanos = m_payload.read_uint32(PAYLOAD_OFFSET_TS_NANOSEC); //the timestamp (UTC) nanoseconds part //build the full nanosecond resolution timestamp from the seconds and nanoseconds values read above uint64 packetTimestamp = (timestampSeconds * TimeSpan::NANOSECONDS_PER_SECOND) + timestampNanos; //build the ChannelMask from the channel mask ChannelMask channels(channelMask); //set the data type of the packet m_dataType = static_cast<WirelessTypes::DataType>(dataType); //create a sample rate for this data static const SampleRate digitalRate = SampleRate::Event(); std::size_t payloadLen = m_payload.size(); uint16 sweepItr = 0; //find the offset into the payload to get the data uint32 byteItr = PAYLOAD_OFFSET_CHANNEL_DATA; //while there is still more data for us to read while(byteItr < payloadLen) { //build a sweep to add DataSweep sweep; sweep.samplingType(DataSweep::samplingType_AsyncDigitalAnalog); sweep.frequency(m_frequency); sweep.tick(tick++); sweep.nodeAddress(m_nodeAddress); sweep.sampleRate(digitalRate); //get this sweep's timestamp offset uint64 timeOffset = m_payload.read_uint16(byteItr); byteItr += TS_OFFSET_LEN; //get this sweep's digital data value uint16 digitalData = m_payload.read_uint16(byteItr); byteItr += DIGITAL_LEN; //build this sweep's timestamp sweep.timestamp(Timestamp(packetTimestamp + ((timeOffset * TimeSpan::NANOSECONDS_PER_SECOND) / 32768) )); //get this sweep's node and base rssi values sweep.nodeRssi(m_nodeRSSI); sweep.baseRssi(m_baseRSSI); sweep.calApplied(m_dataType == WirelessTypes::dataType_float32); //the digital data is represented as the same structure as a channel mask (16 values, 1 or 0) ChannelMask digitalDataMask(digitalData); ChannelData chData; uint8 lastActiveCh = channels.lastChEnabled(); //loop through all the channels for(uint8 chItr = 1; chItr <= lastActiveCh; ++chItr) { //if the current channel is enabled if(channels.enabled(chItr)) { //if the digital value is enabled (active) for this channel if(digitalDataMask.enabled(chItr)) { //create a WirelessDataPoint from the analog data WirelessDataPoint analogPoint = createAnalogDataPoint(chItr, byteItr); //move the byteItr forward for the amount of bytes we read byteItr += WirelessTypes::dataTypeSize(m_dataType); //add the point to the ChannelData vector chData.push_back(analogPoint); } } } //add the channel data to the sweep sweep.data(chData); //add the sweep to the container of sweeps addSweep(sweep); //moving on to the next sweep in the packet sweepItr++; } //if we didn't add any sweeps, there was an error in the packet if(sweepItr == 0) { throw Error("Invalid Packet"); } }
void HclSmartBearing_RawPacket::parseSweeps_baseBoard() { typedef WirelessChannel WC; static const uint16 PAYLOAD_OFFSET_MAG_CONVERSION = 13; //read the values from the payload uint8 sensorErrorMask = m_payload.read_uint8(PAYLOAD_OFFSET_ERROR_MASK); uint8 sampleRate = m_payload.read_uint8(PAYLOAD_OFFSET_SAMPLE_RATE); uint16 tick = m_payload.read_uint16(PAYLOAD_OFFSET_TICK); uint64 timestampSeconds = m_payload.read_uint32(PAYLOAD_OFFSET_TS_SEC); //the timestamp (UTC) seconds part uint64 timestampNanos = m_payload.read_uint32(PAYLOAD_OFFSET_TS_NANOSEC); //the timestamp (UTC) nanoseconds part m_magConversionVal = static_cast<float>(m_payload.read_uint16(PAYLOAD_OFFSET_MAG_CONVERSION)); //build the full nanosecond resolution timestamp from the seconds and nanoseconds values read above uint64 realTimestamp = (timestampSeconds * TimeSpan::NANOSECONDS_PER_SECOND) + timestampNanos; //create a SampleRate object from the sampleRate byte SampleRate currentRate = SampleUtils::convertToSampleRate(sampleRate); //build the single sweep DataSweep sweep; sweep.samplingType(DataSweep::samplingType_SyncSampling); sweep.frequency(m_frequency); sweep.tick(tick); sweep.nodeAddress(m_nodeAddress); sweep.sampleRate(currentRate); sweep.timestamp(Timestamp(realTimestamp)); sweep.nodeRssi(m_nodeRSSI); sweep.baseRssi(m_baseRSSI); static const uint16 DATA_START = 15; ChannelData chData; chData.reserve(28); chData.emplace_back(WC::channel_error_code, 0, valueType_uint8, anyType(sensorErrorMask)); //Error Mask (not actually in payload) chData.emplace_back(WC::channel_hcl_rawBase_mag1_x, 1, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 0))); //Mag 1 - X chData.emplace_back(WC::channel_hcl_rawBase_mag1_y, 2, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 2))); //Mag 1 - Y chData.emplace_back(WC::channel_hcl_rawBase_mag1_z, 3, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 4))); //Mag 1 - Z chData.emplace_back(WC::channel_hcl_rawBase_mag2_x, 4, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 6))); //Mag 2 - X chData.emplace_back(WC::channel_hcl_rawBase_mag2_y, 5, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 8))); //Mag 2 - Y chData.emplace_back(WC::channel_hcl_rawBase_mag2_z, 6, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 10))); //Mag 2 - Z chData.emplace_back(WC::channel_hcl_rawBase_mag3_x, 7, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 12))); //Mag 3 - X chData.emplace_back(WC::channel_hcl_rawBase_mag3_y, 8, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 14))); //Mag 3 - Y chData.emplace_back(WC::channel_hcl_rawBase_mag3_z, 9, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 16))); //Mag 3 - Z chData.emplace_back(WC::channel_hcl_rawBase_mag4_x, 10, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 18))); //Mag 4 - X chData.emplace_back(WC::channel_hcl_rawBase_mag4_y, 11, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 20))); //Mag 4 - Y chData.emplace_back(WC::channel_hcl_rawBase_mag4_z, 12, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 22))); //Mag 4 - Z chData.emplace_back(WC::channel_hcl_rawBase_mag5_x, 13, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 24))); //Mag 5 - X chData.emplace_back(WC::channel_hcl_rawBase_mag5_y, 14, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 26))); //Mag 5 - Y chData.emplace_back(WC::channel_hcl_rawBase_mag5_z, 15, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 28))); //Mag 5 - Z chData.emplace_back(WC::channel_hcl_rawBase_mag6_x, 16, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 30))); //Mag 6 - X chData.emplace_back(WC::channel_hcl_rawBase_mag6_y, 17, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 32))); //Mag 6 - Y chData.emplace_back(WC::channel_hcl_rawBase_mag6_z, 18, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 34))); //Mag 6 - Z chData.emplace_back(WC::channel_hcl_rawBase_mag7_x, 19, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 36))); //Mag 7 - X chData.emplace_back(WC::channel_hcl_rawBase_mag7_y, 20, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 38))); //Mag 7 - Y chData.emplace_back(WC::channel_hcl_rawBase_mag7_z, 21, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 40))); //Mag 7 - Z chData.emplace_back(WC::channel_hcl_rawBase_mag8_x, 22, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 42))); //Mag 8 - X chData.emplace_back(WC::channel_hcl_rawBase_mag8_y, 23, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 44))); //Mag 8 - Y chData.emplace_back(WC::channel_hcl_rawBase_mag8_z, 24, valueType_float, getMagChValue(m_payload.read_uint16(DATA_START + 46))); //Mag 8 - Z chData.emplace_back(WC::channel_hcl_rawBase_gyro_x, 25, valueType_float, anyType(m_payload.read_float(DATA_START + 48))); //Gyro - X chData.emplace_back(WC::channel_hcl_rawBase_gyro_y, 26, valueType_float, anyType(m_payload.read_float(DATA_START + 52))); //Gyro - Y chData.emplace_back(WC::channel_hcl_rawBase_gyro_z, 27, valueType_float, anyType(m_payload.read_float(DATA_START + 56))); //Gyro - Z //add all of the channel data to the sweep sweep.data(chData); //add the sweep to the container of sweeps addSweep(sweep); }
void DiagnosticPacket::addDataPoint(ChannelData& container, DataBuffer& payload, uint8 infoLength, uint8 infoId) const { switch(infoId) { //Current State case 0: container.emplace_back(WirelessChannel::channel_diag_state, 0, valueType_uint8, anyType(payload.read_uint8())); break; //Run Time case 1: //idle time container.emplace_back(WirelessChannel::channel_diag_runtime_idle, 0, valueType_uint32, anyType(payload.read_uint32())); //sleep time container.emplace_back(WirelessChannel::channel_diag_runtime_sleep, 0, valueType_uint32, anyType(payload.read_uint32())); //active run time container.emplace_back(WirelessChannel::channel_diag_runtime_activeRun, 0, valueType_uint32, anyType(payload.read_uint32())); //inactive run time container.emplace_back(WirelessChannel::channel_diag_runtime_inactiveRun, 0, valueType_uint32, anyType(payload.read_uint32())); break; //Reset Counter case 2: container.emplace_back(WirelessChannel::channel_diag_resetCounter, 0, valueType_uint16, anyType(payload.read_uint16())); break; //Battery flag case 3: container.emplace_back(WirelessChannel::channel_diag_lowBatteryFlag, 0, valueType_uint8, anyType(payload.read_uint8())); break; //Sample info case 4: //sweep index container.emplace_back(WirelessChannel::channel_diag_sweepIndex, 0, valueType_uint32, anyType(payload.read_uint32())); //bad sweep count container.emplace_back(WirelessChannel::channel_diag_badSweepCount, 0, valueType_uint32, anyType(payload.read_uint32())); break; //Transmit info case 5: //total transmissions container.emplace_back(WirelessChannel::channel_diag_totalTx, 0, valueType_uint32, anyType(payload.read_uint32())); //total retransmissions container.emplace_back(WirelessChannel::channel_diag_totalReTx, 0, valueType_uint32, anyType(payload.read_uint32())); //total dropped packets container.emplace_back(WirelessChannel::channel_diag_totalDroppedPackets, 0, valueType_uint32, anyType(payload.read_uint32())); break; //Built in Test result case 6: //BIT container.emplace_back(WirelessChannel::channel_diag_builtInTestResult, 0, valueType_uint32, anyType(payload.read_uint32())); break; //Unknown info default: { //read past the bytes we don't know about for(uint8 i = 0; i < infoLength; i++) { payload.read_uint8(); } } break; } }
void HclSmartBearing_CalPacket::parseSweeps() { typedef WirelessChannel WC; //read the values from the payload uint8 sensorErrorMask = m_payload.read_uint8(PAYLOAD_OFFSET_ERROR_MASK); uint8 sampleRate = m_payload.read_uint8(PAYLOAD_OFFSET_SAMPLE_RATE); uint16 tick = m_payload.read_uint16(PAYLOAD_OFFSET_TICK); uint64 timestampSeconds = m_payload.read_uint32(PAYLOAD_OFFSET_TS_SEC); //the timestamp (UTC) seconds part uint64 timestampNanos = m_payload.read_uint32(PAYLOAD_OFFSET_TS_NANOSEC); //the timestamp (UTC) nanoseconds part //build the full nanosecond resolution timestamp from the seconds and nanoseconds values read above uint64 realTimestamp = (timestampSeconds * TimeSpan::NANOSECONDS_PER_SECOND) + timestampNanos; //create a SampleRate object from the sampleRate byte SampleRate currentRate = SampleUtils::convertToSampleRate(sampleRate); //build the single sweep DataSweep sweep; sweep.samplingType(DataSweep::samplingType_SyncSampling); sweep.frequency(m_frequency); sweep.tick(tick); sweep.nodeAddress(m_nodeAddress); sweep.sampleRate(currentRate); sweep.timestamp(Timestamp(realTimestamp)); sweep.nodeRssi(m_nodeRSSI); sweep.baseRssi(m_baseRSSI); sweep.calApplied(true); static const uint16 DATA_START = 13; ChannelData chData; chData.reserve(12); chData.emplace_back(WC::channel_error_code, 0, valueType_uint8, anyType(sensorErrorMask)); //Error Mask (not actually in payload) chData.emplace_back(WC::channel_hcl_axialLoadX, 1, valueType_int16, anyType(m_payload.read_int16(DATA_START + 0))); chData.emplace_back(WC::channel_hcl_axialLoadY, 2, valueType_int16, anyType(m_payload.read_int16(DATA_START + 2))); chData.emplace_back(WC::channel_hcl_axialLoadZ, 3, valueType_float, anyType(static_cast<float>(m_payload.read_int16(DATA_START + 4)) * 10)); chData.emplace_back(WC::channel_hcl_bendingMomentFlap, 4, valueType_int16, anyType(m_payload.read_int16(DATA_START + 6))); chData.emplace_back(WC::channel_hcl_bendingMomentLag, 5, valueType_int16, anyType(m_payload.read_int16(DATA_START + 8))); chData.emplace_back(WC::channel_hcl_bendingMomentPitch, 6, valueType_int16, anyType(m_payload.read_int16(DATA_START + 10))); chData.emplace_back(WC::channel_hcl_motionFlap_mag, 7, valueType_float, anyType(static_cast<float>(m_payload.read_int16(DATA_START + 12) / 1000.0))); chData.emplace_back(WC::channel_hcl_motionLag_mag, 8, valueType_float, anyType(static_cast<float>(m_payload.read_int16(DATA_START + 14) / 1000.0))); chData.emplace_back(WC::channel_hcl_motionPitch_mag, 9, valueType_float, anyType(static_cast<float>(m_payload.read_int16(DATA_START + 16) / 1000.0))); chData.emplace_back(WC::channel_hcl_motionFlap_inertial, 10, valueType_float, anyType(static_cast<float>(m_payload.read_int16(DATA_START + 18) / 1000.0))); chData.emplace_back(WC::channel_hcl_motionLag_inertial, 11, valueType_float, anyType(static_cast<float>(m_payload.read_int16(DATA_START + 20) / 1000.0))); chData.emplace_back(WC::channel_hcl_motionPitch_inertial, 12, valueType_float, anyType(static_cast<float>(m_payload.read_int16(DATA_START + 22) / 1000.0))); chData.emplace_back(WC::channel_hcl_cockingStiffness_mag, 13, valueType_int16, anyType(m_payload.read_int16(DATA_START + 24))); chData.emplace_back(WC::channel_hcl_cockingStiffness_inertial, 14, valueType_int16, anyType(m_payload.read_int16(DATA_START + 26))); chData.emplace_back(WC::channel_hcl_temperature, 15, valueType_int16, anyType(static_cast<int16>(m_payload.read_int8(DATA_START + 28)))); //add all of the channel data to the sweep sweep.data(chData); //add the sweep to the container of sweeps addSweep(sweep); }