📄 cdevice.cpp
字号:
cout << "class " << hex << (int)wpt->wpt_class << endl; cout << "dspl_color " << hex << (int)wpt->dspl_color << endl; cout << "dspl_attr " << hex << (int)wpt->dspl_attr << endl; cout << "smbl " << dec <<(int)wpt->smbl << endl; cout << "lat " << wpt->lat << endl; cout << "lon " << wpt->lon << endl; cout << "alt " << wpt->alt << endl; cout << "dpth " << wpt->dpth << endl; cout << "dist " << wpt->dist << endl; cout << "state " << wpt->state << endl; cout << "cc " << wpt->cc << endl; cout << "ete " << wpt->ete << endl; cout << "temp " << wpt->temp << endl; cout << "time " << wpt->time << endl; cout << "category " << wpt->wpt_cat << endl; cout << "ident " << wpt->ident << endl; cout << "comment " << wpt->comment << endl; cout << "facility " << wpt->facility << endl; cout << "city " << wpt->city << endl; cout << "addr " << wpt->addr << endl; cout << "crossroad " << wpt->crossroad << endl; ++wpt; }#endif}void CDevice::_uploadWaypoints(std::list<Garmin::Wpt_t>& waypoints){ if(usb == 0) return; // count number of proximity waypoints uint16_t prx_wpt_cnt = 0; list<Wpt_t>::const_iterator wpt = waypoints.begin(); while(wpt != waypoints.end()){ if(wpt->dist != 1e25f) ++prx_wpt_cnt; ++wpt; } Packet_t command; Packet_t response; // ??? command.type = GUSB_APPLICATION_LAYER; command.id = 0x1C; command.size = 2; *(uint16_t*)command.payload = 0x0000; usb->write(command); // transmit proximity waypoints first if(prx_wpt_cnt){ //announce number of records command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Records; command.size = 2; *(uint16_t*)command.payload = prx_wpt_cnt; usb->write(command); wpt = waypoints.begin(); while(wpt != waypoints.end()){ if(wpt->dist != 1e25f){ command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Prx_Wpt_Data; D110_Wpt_t * p = (D110_Wpt_t *)command.payload; command.size = *wpt >> *p; usb->write(command); } ++wpt; } //announce number of records command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Xfer_Cmplt; command.size = 2; *(uint16_t*)command.payload = Cmnd_Transfer_Prx; usb->write(command); } //transmit _all_ waypoints //announce number of records command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Records; command.size = 2; *(uint16_t*)command.payload = waypoints.size(); usb->write(command); wpt = waypoints.begin(); while(wpt != waypoints.end()){ command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Wpt_Data; D110_Wpt_t * p = (D110_Wpt_t *)command.payload; command.size = *wpt >> *p; usb->write(command); ++wpt; } //announce number of records command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Xfer_Cmplt; command.size = 2; *(uint16_t*)command.payload = Cmnd_Transfer_Wpt; usb->write(command);}void CDevice::_downloadTracks(std::list<Garmin::Track_t>& tracks){ tracks.clear(); if(usb == 0) return; Packet_t command; Packet_t response; // ??? command.type = GUSB_APPLICATION_LAYER; command.id = 0x1C; command.size = 2; *(uint16_t*)command.payload = 0x0000; usb->write(command); command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Command_Data; command.size = 2; *(uint16_t*)command.payload = Cmnd_Transfer_Trk; usb->write(command); int trackidx = 0; string name; Track_t * track = 0; while(1){ if(!usb->read(response)) continue; if(response.id == Pid_Trk_Hdr){ trackidx = 0; D312_Trk_Hdr_t * hdr = (D312_Trk_Hdr_t*)response.payload; tracks.push_back(Track_t()); track = &tracks.back(); *track << *hdr; name = hdr->ident; } if(response.id == Pid_Trk_Data){ D302_Trk_t * data = (D302_Trk_t*)response.payload; TrkPt_t pt; if(data->new_trk){ if(trackidx){ tracks.push_back(Track_t()); Track_t& t = tracks.back(); t.color = track->color; t.dspl = track->dspl; char str[256]; sprintf(str,"%s_%d",name.c_str(),trackidx++); t.ident = str; track = &t; } else{ ++trackidx; } } pt << *data; track->track.push_back(pt); } if(response.id == Pid_Xfer_Cmplt){ break; } }}void CDevice::_uploadRoutes(list<Garmin::Route_t>& routes){ if(usb == 0) return; // count number of proximity waypoints Packet_t command; Packet_t response; // ??? command.type = GUSB_APPLICATION_LAYER; command.id = 0x1C; command.size = 2; *(uint16_t*)command.payload = 0x0000; usb->write(command); list<Garmin::Route_t>::const_iterator route = routes.begin(); while(route != routes.end()){ //announce number of records // D202_Rte_Hdr_t + (D110_Wpt_t + D210_Tre_Link_t) * number of route points uint16_t nrec = 1 + route->route.size() * 2; command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Records; command.size = 2; *(uint16_t*)command.payload = nrec; usb->write(command); // write route header command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Rte_Hdr; D202_Rte_Hdr_t * p = (D202_Rte_Hdr_t *)command.payload; command.size = *route >> *p; usb->write(command); vector<RtePt_t>::const_iterator rtept = route->route.begin(); while(rtept != route->route.end()){ command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Rte_Wpt_Data; D110_Wpt_t * p = (D110_Wpt_t *)command.payload; command.size = *rtept >> *p; usb->write(command); command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Rte_Link_Data; D210_Rte_Link_t * l = (D210_Rte_Link_t *)command.payload; command.size = *rtept >> *l; usb->write(command); ++rtept; } // finish block command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Xfer_Cmplt; command.size = 2; *(uint16_t*)command.payload = Cmnd_Transfer_Rte; usb->write(command); ++route; }}void CDevice::_uploadCustomIcons(list<Garmin::Icon_t>& icons){ if(usb == 0) return; Packet_t command; Packet_t response; // ??? command.type = GUSB_APPLICATION_LAYER; command.id = 0x1C; command.size = 2; *(uint16_t*)command.payload = 0x0000; usb->write(command); list<Garmin::Icon_t>::const_iterator icon = icons.begin(); while(icon != icons.end()){ uint32_t tan = 0; // get tan command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Req_Icon_Id; command.size = 2; *(uint16_t*)command.payload = icon->idx + 1; usb->write(command); while(usb->read(response)){ if(response.id == Pid_Ack_Icon_Id){ tan = *(uint32_t*)response.payload; } } // request color table command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Req_Clr_Tbl; command.size = 4; *(uint32_t*)command.payload = tan; usb->write(command); while(usb->read(response)){ if(response.id == Pid_Ack_Clr_Tbl){ // send back color table command = response; } } usb->write(command); while(usb->read(response)){ if(response.id == Pid_Req_Clr_Tbl){ // TODO: ignore? } } // send icon data command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Icon_Data; command.size = 0x104; *(uint32_t*)command.payload = tan; memcpy(command.payload + sizeof(tan),icon->data,sizeof(icon->data)); usb->write(command); while(usb->read(response)){ if(response.id == Pid_Ack_Icon_Data){ // TODO: ignore? } } ++icon; }}void CDevice::_screenshot(char *& clrtbl, char *& data, int& width, int& height){ if(usb == 0) return; Packet_t command; Packet_t response; // ??? command.type = GUSB_APPLICATION_LAYER; command.id = 0x1C; command.size = 2; *(uint16_t*)command.payload = 0x0000; usb->write(command); uint32_t tan = 0; // get tan command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Req_Icon_Id; command.size = 2; *(uint16_t*)command.payload = 0; usb->write(command); bool started = false; while(usb->read(response)){ if(response.id == Pid_Ack_Icon_Id){ tan = *(uint32_t*)response.payload; started = true; } if(response.type == 0 && response.id == 0 && started ){ break; // no bytes returned, so I guess we are done } } // request color table command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Req_Clr_Tbl; command.size = 4; *(uint32_t*)command.payload = tan; usb->write(command); started = false; while(usb->read(response)){ if(response.id == Pid_Ack_Clr_Tbl){ // send back color table memcpy(aClrtbl,_clrtbl,sizeof(aClrtbl)); command = response; started = true; } if(response.type == 0 && response.id == 0 && started ){ break; // no bytes returned, so I guess we are done } } started = false; usb->write(command); while(usb->read(response)){ if(response.id == Pid_Req_Clr_Tbl){ // TODO: ignore? started = true; } if(response.type == 0 && response.id == 0 && started ){ break; // no bytes returned, so I guess we are done } } char buffer[400 * 400]; char * pData = buffer; uint32_t byteCnt; uint32_t byteCntTotal = 0; if(pScreen == 0){ pScreen = new char[screenwidth * screenheight]; } command.type = GUSB_APPLICATION_LAYER; command.id = Pid_Ack_Icon_Data; command.size = 4; *(uint32_t*)command.payload = tan; usb->write(command); // loop will end after reception of Pid_Icon_Data with length of 4 (tan only) // or too much data while(1){ if(!usb->read(response)){ usb->write(command); continue; } if(response.type == 0 && response.id == 0 ){ usb->write(command); continue; } if(response.id == Pid_Icon_Data){ if(response.size == sizeof(tan)) break; byteCnt = response.size - sizeof(tan); memcpy(pData,response.payload + sizeof(tan), byteCnt); pData += byteCnt; byteCntTotal += byteCnt; if(byteCntTotal > sizeof(buffer)) break; } } command.type = GUSB_APPLICATION_LAYER; command.id = 0x373; command.size = 4; *(uint32_t*)command.payload = tan; usb->write(command); if(devid == 0x0312 || devid == 0x02b6){ for(int r = 0; r < screenheight; ++r){ for(int c = 0; c < screenwidth; ++c){ pScreen[r * screenwidth + c] = buffer[(r + 1) * screenwidth - c]; } } } else{ for(int r = 0; r < screenheight; ++r){ for(int c = 0; c < screenwidth; ++c){ pScreen[r * screenwidth + c] = buffer[(screenheight - 1 - r) * screenwidth + c]; } } } clrtbl = aClrtbl; data = pScreen; width = screenwidth; height = screenheight;}void CDevice::_setRealTimeMode(bool on){ CMutexLocker lock(dataMutex); if(doRealtimeThread == on) return; doRealtimeThread = on; if(doRealtimeThread){ pthread_create(&thread,NULL,rtThread, this); }}void CDevice::_getRealTimePos(Garmin::Pvt_t& pvt){ if(pthread_mutex_trylock(&mutex) != EBUSY){ pthread_mutex_unlock(&mutex); throw exce_t(errRuntime,lasterror); } CMutexLocker lock(dataMutex); pvt = PositionVelocityTime;}void CDevice::_release(){ if(usb == 0) return; usb->close(); delete usb; usb = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -