Oliver Eichler wrote: > Jan-Pascal van Best schrieb: > >> Oliver Eichler wrote: >> >>> Track/waypoint download works here too, but map upload doesn't. I forgot >>> to implement the new _uploadMap method. After doing so, however, map >>> upload still fails at "Failed to set serial link to xxx bit per second". >>> I'm looking into it... >>> > > Yes I noticed and adjusted the support matrix :) > > http://www.qlandkarte.org/index.php?option=com_content&view=article&id=16&Itemid=18 > > For the record, here's the patch to implement to new _uploadMap method. Upload starts OK, but after a while the serial link is lost. Looking into that...
Jan-Pascal -- Jan-Pascal van Best [EMAIL PROTECTED], [EMAIL PROTECTED] http://www.vanbest.org/janpascal/ GPG key fingerprint 4617 E5FB C56D ACB6 7C8C DE64 3A4C B270 1A89 CC23
Index: src/EtrexLegend/CDevice.cpp
===================================================================
--- src/EtrexLegend/CDevice.cpp (revision 1007)
+++ src/EtrexLegend/CDevice.cpp (working copy)
@@ -221,6 +221,133 @@
}
+void CDevice::_uploadMap(const char * filename, uint32_t size, const char * key)
+{
+ if(supportsMaps == false)
+ {
+ IDeviceDefault::_uploadMap(filename, size, key);
+ return;
+ }
+ if(serial == 0) return;
+ int ready= 0;
+ int cancel = 0;
+
+ PROGR_CALLBACK ( 0,"starting upload filename" );
+ cerr << "Uploading " << filename << endl;
+
+ Packet_t command;
+ Packet_t response;
+
+ // ???
+ command.id = 0x1C;
+ command.size = 2;
+ *(uint16_t*)command.payload = 0x0000;
+ serial->write(command);
+
+ // read SD Ram capacity
+ command.id = Pid_Command_Data;
+ command.size = 2;
+ *(uint16_t*)command.payload = Cmnd_Transfer_Mem;
+ serial->write(command);
+
+ // FIXME:
+ while(serial->read(response) > 0) {
+
+ if(response.id == Pid_Capacity_Data) {
+ cout << "free memory: " << dec << (((uint32_t*)response.payload)[1] / (1024*1024)) << " MB" << endl;
+ uint32_t memory = ((uint32_t*)response.payload)[1];
+ if(memory < size) {
+ stringstream msg;
+ msg << "Failed to send map: Unit has not enought memory (available/needed): " << memory << "/" << size << " bytes";
+ throw exce_t(errBlocked,msg.str());
+ }
+ }
+ }
+
+#ifdef EXPERIMENTAL
+ // KEY_UPLOAD: UNTESTED: someone should check how/if this works
+ // send unlock key if present
+ if(key) {
+ command.id = Pid_Tx_Unlock_Key;
+ command.size = strlen(key) + 1;
+ memcpy(command.payload,key,command.size);
+
+ serial->write(command);
+
+ // FIXME:
+ while(serial->read(response) > 0 ) {
+ if(response.id == Pid_Ack_Unlock_key) {
+ //TODO read data
+ }
+ }
+
+ }
+#endif
+
+ if (serial->setBitrate( MAP_UPLOAD_BITRATE)) {
+ throw exce_t(errBlocked,"Failed to change serial link to xxx bit per second");
+ }
+
+ // switch to map transfer mode erase old map(?)
+ command.id = 75;
+ command.size = 2;
+ *(uint16_t*)command.payload = 0x000A;
+ serial->write(command);
+
+ sleep(3);
+
+ ready= 0;
+ while(!ready && serial->read(response) > 0) {
+ if(response.id == 74) {
+ ready= 1;
+ //TODO read data
+ }
+ }
+
+ callback(0,0,&cancel,"Upload maps ...",0);
+
+ FILE *fid = fopen(filename,"r");
+ if(fid == NULL){
+ stringstream msg;
+ msg << "Failed to send map: Can't open " << filename;
+ throw exce_t(errRuntime,msg.str());
+ }
+
+
+ uint32_t total = size;
+ uint32_t offset = 0, chunkSize;
+ uint8_t buffer[254 - sizeof(offset)];
+ command.id = 36;
+ // USB: transfer file by chunks of 0x1000 - 0x0000C - sizeof(offset) = 0x0FF0 bytes
+ // Serial: transfer file by chunks of 0xfe - sizeof(offset) = 0xfa = 250 bytes
+ while(size && !cancel) {
+ chunkSize = (size < (254 - sizeof(offset))) ? size : (254 - sizeof(offset));
+ command.size = chunkSize + sizeof(offset);
+
+ fread(buffer, chunkSize, 1, fid);
+
+ *(uint32_t*)command.payload = offset;
+ memcpy(command.payload + sizeof(offset),buffer,chunkSize);
+ size -= chunkSize;
+ offset += chunkSize;
+
+ serial->write(command);
+ // set progress
+ double progress = ((total - size) * 100.0) / total;
+ callback(progress,0,&cancel,0,"Transfering map data.");
+
+ }
+
+ callback(100,0,&cancel,0,"done");
+
+ // terminate map transfer mode (?)
+ command.id = 45;
+ command.size = 2;
+ *(uint16_t*)command.payload = 0x000A;
+ serial->write(command);
+}
+
+
void CDevice::_queryMap(std::list<Map_t>& maps)
{
maps.clear();
Index: src/EtrexLegend/CDevice.h
===================================================================
--- src/EtrexLegend/CDevice.h (revision 1007)
+++ src/EtrexLegend/CDevice.h (working copy)
@@ -43,6 +43,7 @@
private:
void _acquire();
void _uploadMap(const uint8_t * mapdata, uint32_t size, const char * key);
+ void _uploadMap(const char * filename, uint32_t size, const char * key);
void _queryMap(std::list<Garmin::Map_t>& maps);
void _downloadWaypoints(std::list<Garmin::Wpt_t>& waypoints);
void _uploadWaypoints(std::list<Garmin::Wpt_t>& waypoints);
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ QLandkarte-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/qlandkarte-users
