1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
/***************************************************************************
* Copyright (C) 2005 by David Saxton *
* david@bluehaze.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "languagemanager.h"
#include "picprogrammer.h"
#include "src/core/ktlconfig.h"
#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <tqapplication.h>
#include <tqfile.h>
#include <kprocess.h>
#include <tqregexp.h>
#include <tqtextstream.h>
#include <tqdatetime.h>
#include <stdio.h>
//BEGIN class ProgrammerConfig
ProgrammerConfig::ProgrammerConfig()
{
}
void ProgrammerConfig::reset()
{
initCommand = TQString();
readCommand = TQString();
writeCommand = TQString();
verifyCommand = TQString();
blankCheckCommand = TQString();
eraseCommand = TQString();
}
//END class ProgrammerConfig
//BEGIN class PicProgrammerSettings
bool PicProgrammerSettings::m_bDoneStaticConfigsInit = false;
ProgrammerConfigMap PicProgrammerSettings::m_staticConfigs = ProgrammerConfigMap();
PicProgrammerSettings::PicProgrammerSettings()
{
if ( !m_bDoneStaticConfigsInit )
initStaticConfigs();
}
void PicProgrammerSettings::initStaticConfigs()
{
m_bDoneStaticConfigsInit = true;
ProgrammerConfig config;
config.description = i18n("Supported programmers: %1").arg("JuPic, PICStart Plus, Warp-13");
config.description += i18n("<br>Interface: Serial Port");
config.initCommand = "";
config.readCommand = "picp %port %device -rp %file";
config.writeCommand = "picp %port %device -wp %file";
config.verifyCommand = "";
config.blankCheckCommand = "picp %port %device -b";
config.eraseCommand = "picp %port %device -e";
// config.executable = "picp";
m_staticConfigs[ "PICP" ] = config;
config.description = i18n("Supported programmers: %1").arg("Epic Plus");
config.description += i18n("<br>Interface: Parallel Port");
config.initCommand = "odyssey init";
config.readCommand = "odyssey %device read %file";
config.writeCommand = "odyssey %device write %file";
config.verifyCommand = "odyssey %device verify %file";
config.blankCheckCommand = "odyssey %device blankcheck";
config.eraseCommand = "odyssey %device erase";
// config.executable = "odyssey";
m_staticConfigs[ "Odyssey" ] = config;
config.description = i18n("Supported programmers: %1").arg("JDM PIC-Programmer 2, PIC-PG2C");
config.description += i18n("<br>Interface: Serial Port");
config.initCommand = "";
config.readCommand = "picprog --output %file --pic %port";
config.writeCommand = "picprog --burn --input %file --pic %port --device %device";
config.verifyCommand = "";
config.blankCheckCommand = "";
config.eraseCommand = "picprog --erase --pic %device";
m_staticConfigs[ "PICProg" ] = config;
config.description = i18n("Supported programmers: %1").arg("Epic Plus");
config.description += i18n("<br>Interface: Parallel Port");
config.initCommand = "";
config.readCommand = "dump84 --dump-all --output=%file";
config.writeCommand = "prog84 --intel16=%file";
config.verifyCommand = "";
config.blankCheckCommand = "";
config.eraseCommand = "prog84 --clear";
m_staticConfigs[ "prog84" ] = config;
config.description = i18n("Supported programmers: %1").arg("Kit 149, Kit 150");
config.description += i18n("<br>Interface: USB Port");
config.initCommand = "";
config.readCommand = "pp -d %device -r %file";
config.writeCommand = "pp -d %device -w %file";
config.verifyCommand = "pp -d %device -v %file";
config.blankCheckCommand = "";
config.eraseCommand = "pp -d %device -e";
m_staticConfigs[ "PP" ] = config;
config.description = i18n("Supported programmers: %1").arg("Wisp628");
config.description += i18n("<br>Interface: Serial Port");
config.initCommand = "";
config.readCommand = "xwisp ID %device PORT %device DUMP";
config.writeCommand = "xwisp ID %device PORT %device WRITE %file";
config.verifyCommand = "";
config.blankCheckCommand = "";
config.eraseCommand = "xwisp ID %device PORT %device ERASE";
m_staticConfigs[ "XWisp" ] = config;
#if 0
config.description = i18n("Supported programmers: %1").arg("Epic Plus, JDM PIC-Programmer 2, PICCOLO, PICCOLO Grande, Trivial HVP Programmer");
config.description += i18n("<br>Interface: Serial Port and Parallel Port");
config.initCommand = "";
config.readCommand = "";
config.writeCommand = "";
config.verifyCommand = "";
config.blankCheckCommand = "";
config.eraseCommand = "";
config.executable = "pkp";
m_staticConfigs[ "PiKdev" ] = config;
config.executable = "";
config.description = i18n("Supported programmers: %1").arg("Trivial LVP programmer, Trivial HVP Programmer");
config.description += i18n("<br>Interface: Parallel Port");
config.initCommand = "";
config.readCommand = "";
config.writeCommand = "";
config.verifyCommand = "";
config.blankCheckCommand = "";
config.eraseCommand = "";
m_staticConfigs[ "PicPrg2" ] = config;
config.description = i18n("Supported programmers: %1").arg("El Cheapo");
config.description += i18n("<br>Interface: Parallel Port");
config.initCommand = "";
config.readCommand = "";
config.writeCommand = "";
config.verifyCommand = "";
config.blankCheckCommand = "";
config.eraseCommand = "";
m_staticConfigs[ "PP06" ] = config;
config.description = i18n("Supported programmers: %1").arg("NOPPP");
config.description += i18n("<br>Interface: Parallel Port");
config.initCommand = "";
config.readCommand = "";
config.writeCommand = "";
config.verifyCommand = "";
config.blankCheckCommand = "";
config.eraseCommand = "";
m_staticConfigs[ "NOPPP" ] = config;
config.description = i18n("Supported programmers: %1").arg("SNOPPP");
config.description += i18n("<br>Interface: Parallel Port");
config.initCommand = "";
config.readCommand = "";
config.writeCommand = "";
config.verifyCommand = "";
config.blankCheckCommand = "";
config.eraseCommand = "";
m_staticConfigs[ "SNOPPP" ] = config;
#endif
}
void PicProgrammerSettings::load( KConfig * config )
{
TQStringList oldCustomProgrammers = config->groupList().grep("CustomProgrammer_");
TQStringList::iterator ocpEnd = oldCustomProgrammers.end();
for ( TQStringList::iterator it = oldCustomProgrammers.begin(); it != ocpEnd; ++it )
{
// The CustomProgrammer_ string we searched for might appear half way through... (don't want)
if ( (*it).startsWith("CustomProgrammer_") )
{
config->setGroup(*it);
ProgrammerConfig pc;
pc.initCommand = config->readEntry( "InitCommand" );
pc.readCommand = config->readEntry( "ReadCommand" );
pc.writeCommand = config->readEntry( "WriteCommand" );
pc.verifyCommand = config->readEntry( "VerifyCommand" );
pc.blankCheckCommand = config->readEntry( "BlankCheckCommand" );
pc.eraseCommand = config->readEntry( "EraseCommand" );
TQString name = config->readEntry( "Name" );
m_customConfigs[name] = pc;
}
}
}
void PicProgrammerSettings::save( KConfig * config )
{
TQStringList oldCustomProgrammers = config->groupList().grep("CustomProgrammer_");
TQStringList::iterator ocpEnd = oldCustomProgrammers.end();
for ( TQStringList::iterator it = oldCustomProgrammers.begin(); it != ocpEnd; ++it )
{
// The CustomProgrammer_ string we searched for might appear half way through... (don't want)
if ( (*it).startsWith("CustomProgrammer_") )
config->deleteGroup(*it);
}
int at = 0;
ProgrammerConfigMap::iterator end = m_customConfigs.end();
for ( ProgrammerConfigMap::iterator it = m_customConfigs.begin(); it != end; ++it )
{
config->setGroup( TQString("CustomProgrammer_%1").arg(at++) );
config->writeEntry( "Name", it.key() );
config->writeEntry( "InitCommand", it.data().initCommand );
config->writeEntry( "ReadCommand", it.data().readCommand );
config->writeEntry( "WriteCommand", it.data().writeCommand );
config->writeEntry( "VerifyCommand", it.data().verifyCommand );
config->writeEntry( "BlankCheckCommand", it.data().blankCheckCommand );
config->writeEntry( "EraseCommand", it.data().eraseCommand );
}
}
ProgrammerConfig PicProgrammerSettings::config( const TQString & name )
{
if ( name.isEmpty() )
return ProgrammerConfig();
TQString l = name.lower();
ProgrammerConfigMap::const_iterator end = m_customConfigs.end();
for ( ProgrammerConfigMap::const_iterator it = m_customConfigs.begin(); it != end; ++it )
{
if ( it.key().lower() == l )
return *it;
}
end = m_staticConfigs.end();
for ( ProgrammerConfigMap::const_iterator it = m_staticConfigs.begin(); it != end; ++it )
{
if ( it.key().lower() == l )
return *it;
}
return m_customConfigs[ name ];
}
void PicProgrammerSettings::removeConfig( const TQString & name )
{
if ( isPredefined( name ) )
{
kdWarning() << k_funcinfo << "Cannot remove a predefined PIC programmer configuration." << endl;
return;
}
TQString l = name.lower();
ProgrammerConfigMap::iterator end = m_customConfigs.end();
for ( ProgrammerConfigMap::iterator it = m_customConfigs.begin(); it != end; ++it )
{
if ( it.key().lower() == l )
{
m_customConfigs.remove( it );
return;
}
}
}
void PicProgrammerSettings::saveConfig( const TQString & name, const ProgrammerConfig & config )
{
if ( isPredefined( name ) )
{
kdWarning() << k_funcinfo << "Cannot save to a predefined PIC programmer configuration." << endl;
return;
}
TQString l = name.lower();
ProgrammerConfigMap::iterator end = m_customConfigs.end();
for ( ProgrammerConfigMap::iterator it = m_customConfigs.begin(); it != end; ++it )
{
if ( it.key().lower() == l )
{
*it = config;
return;
}
}
m_customConfigs[ name ] = config;
}
TQStringList PicProgrammerSettings::configNames( bool makeLowercase ) const
{
if ( !makeLowercase )
return m_customConfigs.keys() + m_staticConfigs.keys();
TQStringList names;
ProgrammerConfigMap::const_iterator end = m_customConfigs.end();
for ( ProgrammerConfigMap::const_iterator it = m_customConfigs.begin(); it != end; ++it )
names << it.key().lower();
end = m_staticConfigs.end();
for ( ProgrammerConfigMap::const_iterator it = m_staticConfigs.begin(); it != end; ++it )
names << it.key().lower();
return names;
}
bool PicProgrammerSettings::isPredefined( const TQString & name ) const
{
TQString l = name.lower();
ProgrammerConfigMap::const_iterator end = m_staticConfigs.end();
for ( ProgrammerConfigMap::const_iterator it = m_staticConfigs.begin(); it != end; ++it )
{
if ( it.key().lower() == l )
return true;
}
return false;
}
//END class PicProgrammerSettings
//BEGIN class PicProgrammer
PicProgrammer::PicProgrammer( ProcessChain *processChain, KTechlab * parent )
: ExternalLanguage( processChain, parent, "PicProgrammer" )
{
m_successfulMessage = i18n("*** Programming successful ***");
m_failedMessage = i18n("*** Programming failed ***");
}
PicProgrammer::~PicProgrammer()
{
}
void PicProgrammer::processInput( ProcessOptions options )
{
resetLanguageProcess();
m_processOptions = options;
PicProgrammerSettings settings;
settings.load( kapp->config() );
TQString program = options.m_program;
if ( !settings.configNames( true ).contains( program.lower() ) )
{
kdError() << k_funcinfo << "Invalid program" << endl;
finish( false );
return;
}
ProgrammerConfig config = settings.config( program );
TQString command = config.writeCommand;
command.replace( "%port", options.m_port );
command.replace( "%device", TQString( options.m_picID ).remove("P") );
command.replace( "%file", KProcess::quote( options.inputFiles().first() ) );
m_languageProcess->setUseShell( true );
*m_languageProcess << command;
if ( !start() )
{
// KMessageBox::sorry( LanguageManager::self()->logView(), i18n("Could not program PIC.") );
processInitFailed();
return;
}
}
bool PicProgrammer::isError( const TQString &message ) const
{
return message.contains( "Error", false );
}
bool PicProgrammer::isWarning( const TQString &message ) const
{
return message.contains( "Warning", false );
}
ProcessOptions::ProcessPath::Path PicProgrammer::outputPath( ProcessOptions::ProcessPath::Path inputPath ) const
{
switch (inputPath)
{
case ProcessOptions::ProcessPath::PIC_AssemblyAbsolute:
case ProcessOptions::ProcessPath::Program_PIC:
return ProcessOptions::ProcessPath::None;
case ProcessOptions::ProcessPath::AssemblyAbsolute_PIC:
case ProcessOptions::ProcessPath::AssemblyAbsolute_Program:
case ProcessOptions::ProcessPath::AssemblyRelocatable_Library:
case ProcessOptions::ProcessPath::AssemblyRelocatable_Object:
case ProcessOptions::ProcessPath::AssemblyRelocatable_PIC:
case ProcessOptions::ProcessPath::AssemblyRelocatable_Program:
case ProcessOptions::ProcessPath::C_AssemblyRelocatable:
case ProcessOptions::ProcessPath::C_Library:
case ProcessOptions::ProcessPath::C_Object:
case ProcessOptions::ProcessPath::C_PIC:
case ProcessOptions::ProcessPath::C_Program:
case ProcessOptions::ProcessPath::FlowCode_AssemblyAbsolute:
case ProcessOptions::ProcessPath::FlowCode_Microbe:
case ProcessOptions::ProcessPath::FlowCode_PIC:
case ProcessOptions::ProcessPath::FlowCode_Program:
case ProcessOptions::ProcessPath::Microbe_AssemblyAbsolute:
case ProcessOptions::ProcessPath::Microbe_PIC:
case ProcessOptions::ProcessPath::Microbe_Program:
case ProcessOptions::ProcessPath::Object_Disassembly:
case ProcessOptions::ProcessPath::Object_Library:
case ProcessOptions::ProcessPath::Object_PIC:
case ProcessOptions::ProcessPath::Object_Program:
case ProcessOptions::ProcessPath::Program_Disassembly:
case ProcessOptions::ProcessPath::Invalid:
case ProcessOptions::ProcessPath::None:
return ProcessOptions::ProcessPath::Invalid;
}
return ProcessOptions::ProcessPath::Invalid;
}
//END class PicProgrammer
|