@@ -279,21 +279,21 @@ int main(int argc, char *argv[])
279
279
if (file) {
280
280
nmessage (INFO_OPENING_FILE, file);
281
281
if (!(image = Loader::readFile (file, &imageSize))) {
282
- message ( " 103-Can't open file '%s' " , file);
282
+ nmessage (ERROR_CANT_OPEN_FILE , file);
283
283
return 1 ;
284
284
}
285
285
switch (PropImage::validate (image, imageSize)) {
286
286
case PropImage::SUCCESS:
287
287
// success
288
288
break ;
289
289
case PropImage::IMAGE_TRUNCATED:
290
- message ( " 110-File is truncated or not a Propeller application image " );
290
+ nmessage (ERROR_FILE_TRUNCATED );
291
291
return 1 ;
292
292
case PropImage::IMAGE_CORRUPTED:
293
- message ( " 111-File is corrupt or not a Propeller application " );
293
+ nmessage (ERROR_FILE_CORRUPTED );
294
294
return 1 ;
295
295
default :
296
- message ( " 998-Internal error " );
296
+ nmessage (ERROR_INTERNAL_CODE_ERROR );
297
297
return 1 ;
298
298
}
299
299
}
@@ -374,24 +374,24 @@ int main(int argc, char *argv[])
374
374
if (useSerial) {
375
375
SerialInfo info; // needs to stay in scope as long as we're using port
376
376
if (!(serialConnection = new SerialPropConnection)) {
377
- message ( " 999-Insufficient memory " );
377
+ nmessage (ERROR_INSUFFICIENT_MEMORY );
378
378
return 1 ;
379
379
}
380
380
if (!port) {
381
381
SerialInfoList ports;
382
382
if (SerialPropConnection::findPorts (PORT_PREFIX, true , ports) != 0 ) {
383
- message ( " 115-Serial port discovery failed " );
383
+ nmessage (ERROR_SERIAL_PORT_DISCOVERY_FAILED );
384
384
return 1 ;
385
385
}
386
386
if (ports.size () == 0 ) {
387
- message ( " 116-No serial ports found " );
387
+ nmessage (ERROR_NO_SERIAL_PORTS_FOUND );
388
388
return 1 ;
389
389
}
390
390
info = ports.front ();
391
391
port = info.port ();
392
392
}
393
393
if ((sts = serialConnection->open (port)) != 0 ) {
394
- message ( " 117-Unable to connect to port %s " , port);
394
+ nmessage (ERROR_UNABLE_TO_CONNECT_TO_PORT , port);
395
395
return 1 ;
396
396
}
397
397
connection = serialConnection;
@@ -400,41 +400,38 @@ int main(int argc, char *argv[])
400
400
/* do a wifi download */
401
401
else {
402
402
if (!(wifiConnection = new WiFiPropConnection)) {
403
- message ( " 999-Insufficient memory " );
403
+ nmessage (ERROR_INSUFFICIENT_MEMORY );
404
404
return 1 ;
405
405
}
406
406
if (!ipaddr) {
407
407
WiFiInfoList addrs;
408
408
if (WiFiPropConnection::findModules (false , addrs, 1 ) != 0 ) {
409
- message ( " 113-Wifi module discovery failed " );
409
+ nmessage (ERROR_WIFI_MODULE_DISCOVERY_FAILED );
410
410
return 1 ;
411
411
}
412
412
if (addrs.size () == 0 ) {
413
- message ( " 114-No wifi modules found " );
413
+ nmessage (ERROR_NO_WIFI_MODULES_FOUND );
414
414
return 1 ;
415
415
}
416
416
const char *ipaddr2 = addrs.front ().address ();
417
417
char *p;
418
418
if (!(p = (char *)malloc (strlen (ipaddr2) + 1 ))) {
419
- message ( " 999-Insufficient memory " );
419
+ nmessage (ERROR_INSUFFICIENT_MEMORY );
420
420
return 1 ;
421
421
}
422
422
strcpy (p, ipaddr2);
423
423
ipaddr = p;
424
424
}
425
425
if ((sts = wifiConnection->setAddress (ipaddr)) != 0 ) {
426
- message ( " 101-Invalid address: %s " , ipaddr);
426
+ nmessage (ERROR_INVALID_MODULE_ADDRESS , ipaddr);
427
427
return 1 ;
428
428
}
429
429
if (wifiConnection->getVersion () != 0 ) {
430
- message ( " 118-Unable to connect to module at %s " , ipaddr);
430
+ nmessage (ERROR_UNABLE_TO_CONNECT_TO_MODULE , ipaddr);
431
431
return 1 ;
432
432
}
433
433
if ((sts = wifiConnection->checkVersion ()) != 0 ) {
434
- message (" \
435
- 106-Unrecognized wi-fi module firmware\n \
436
- Version is %s but expected %s.\n \
437
- Recommended action: update firmware and/or PropLoader to latest version(s)." , wifiConnection->version (), WIFI_REQUIRED_MAJOR_VERSION);
434
+ nmessage (ERROR_WRONG_WIFI_MODULE_FIRMWARE, wifiConnection->version (), WIFI_REQUIRED_MAJOR_VERSION);
438
435
return 1 ;
439
436
}
440
437
connection = wifiConnection;
@@ -497,25 +494,25 @@ int main(int argc, char *argv[])
497
494
498
495
/* if we deleted every character then this is an invalid name */
499
496
if (!cleanName[0 ]) {
500
- message ( " 108-Invalid module name " );
497
+ nmessage (ERROR_INVALID_MODULE_NAME );
501
498
return 1 ;
502
499
}
503
500
504
501
/* show the clean name if it is different from what the user requested */
505
502
if (strcmp (name, cleanName) != 0 )
506
- message ( " 010-Setting module name to '%s' " , cleanName);
503
+ nmessage (INFO_SETTING_MODULE_NAME , cleanName);
507
504
508
505
if (wifiConnection->setName (cleanName) != 0 ) {
509
- message ( " 109-Failed to set module name " );
506
+ nmessage (ERROR_FAILED_TO_SET_MODULE_NAME );
510
507
return 1 ;
511
508
}
512
509
}
513
510
514
511
/* write a file to the SD card */
515
512
if (writeFile) {
516
- message ( " 007-Writing '%s' to the SD card " , file);
513
+ nmessage (INFO_WRITING_TO_SD_CARD , file);
517
514
if (WriteFileToSDCard (config, connection, file, file) != 0 ) {
518
- message ( " 107-Failed to write SD card file '%s' " , file);
515
+ nmessage (ERROR_FAILED_TO_WRITE_TO_SD_CARD , file);
519
516
return 1 ;
520
517
}
521
518
}
@@ -524,32 +521,32 @@ int main(int argc, char *argv[])
524
521
else if (file) {
525
522
loader.setConnection (connection);
526
523
if (file && (sts = loader.fastLoadImage (image, imageSize, (LoadType)loadType)) != 0 ) {
527
- message ( " 102-Download failed: %d " , sts);
524
+ nmessage (ERROR_DOWNLOAD_FAILED , sts);
528
525
return 1 ;
529
526
}
530
- message ( " 005-Download successful! " );
527
+ nmessage (INFO_DOWNLOAD_SUCCESSFUL );
531
528
}
532
529
533
530
/* set the baud rate used by the program */
534
531
if (connection->setBaudRate (connection->programBaudRate ()) != 0 ) {
535
- message ( " 119-Failed to set baud rate " );
532
+ nmessage (ERROR_FAILED_TO_SET_BAUD_RATE );
536
533
return 1 ;
537
534
}
538
535
539
536
/* enter terminal mode */
540
537
if (terminalMode) {
541
- message ( " 006-[ Entering terminal mode. Type ESC or Control-C to exit. ] " );
538
+ nmessage (INFO_TERMINAL_MODE );
542
539
543
540
/* open a connection to the target */
544
541
if (!connection->isOpen () && connection->connect () != 0 ) {
545
542
message (" Can't open connection to target" );
546
- message ( " 105-Failed to enter terminal mode " );
543
+ nmessage (ERROR_FAILED_TO_ENTER_TERMINAL_MODE );
547
544
return 1 ;
548
545
}
549
546
550
547
/* enter terminal mode */
551
548
if (connection->terminal (false , pstTerminalMode) != 0 ) {
552
- message ( " 105-Failed to enter terminal mode " );
549
+ nmessage (ERROR_FAILED_TO_ENTER_TERMINAL_MODE );
553
550
return 1 ;
554
551
}
555
552
}
@@ -592,9 +589,9 @@ static int WriteFileToSDCard(BoardConfig *config, PropConnection *connection, co
592
589
FILE *fp;
593
590
594
591
/* open the file */
595
- message ( " 001-Opening file '%s' " , path);
592
+ nmessage (INFO_OPENING_FILE , path);
596
593
if ((fp = fopen (path, " rb" )) == NULL )
597
- return error ( " 103-Can't open file '%s' " , path);
594
+ return nerror (ERROR_CANT_OPEN_FILE , path);
598
595
599
596
if (!target) {
600
597
if (!(target = strrchr (path, ' /' )))
@@ -623,14 +620,14 @@ static int WriteFileToSDCard(BoardConfig *config, PropConnection *connection, co
623
620
}
624
621
625
622
while ((cnt = fread (buf, 1 , PKTMAXLEN, fp)) > 0 ) {
626
- progress ( " 008-%ld bytes remaining " , (long )remaining);
623
+ nprogress (INFO_BYTES_REMAINING , (long )remaining);
627
624
if (!packetDriver.sendPacket (TYPE_DATA, buf, cnt)) {
628
625
fclose (fp);
629
626
return error (" SendPacket DATA failed" );
630
627
}
631
628
remaining -= cnt;
632
629
}
633
- message ( " 009-%ld bytes sent " , (long )size);
630
+ nmessage (INFO_BYTES_SENT , (long )size);
634
631
635
632
fclose (fp);
636
633
0 commit comments