Renamed

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ffxx68
Date:
Tue Mar 29 10:06:20 2022 +0000
Parent:
3:6237f9e5e798
Commit message:
Receiving the file through serial port

Changed in this revision

bin_file.h Show annotated file Show diff for this revision Revisions of this file
bit_send.cpp Show annotated file Show diff for this revision Revisions of this file
bit_send.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
send_pc1403.cpp Show annotated file Show diff for this revision Revisions of this file
send_pc1403.h Show annotated file Show diff for this revision Revisions of this file
serial_file.cpp Show annotated file Show diff for this revision Revisions of this file
serial_file.h Show annotated file Show diff for this revision Revisions of this file
--- a/bin_file.h	Wed Feb 23 12:24:16 2022 +0000
+++ b/bin_file.h	Tue Mar 29 10:06:20 2022 +0000
@@ -1,14 +1,71 @@
 #ifndef BIN_FILE_SIZE
-#define BIN_FILE_SIZE  40 // need to set manually (does NOT include closing 0xFF)
-char bin_file_name[] = "HELLO";
+#define BIN_FILE_SIZE  40 // HARDCODED file, size to be set manually (does NOT include closing EOF, 0xFF)
+
+static uint32_t file_pos ;
+const char bin_file_name[] = "SUBMAR";
 // Byte stream from file generated with BAS2IMG (PocketTools)
-char bin_file_bytes[] =
+const char bin_file_bytes[] =
 { 
+// HELLO.BAS , size 40
 0x00, 0x01, 0x0D, 0xD7, 0x48, 0x65, 0x6C, 0x6C, 
 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x0D, 
 0x00, 0x0A, 0x10, 0xDE, 0x22, 0x48, 0x65, 0x6C, 
 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 
 0x21, 0x22, 0x0D, 0x00, 0x14, 0x02, 0xD8, 0x0D,
+/* submarine , size 1030
+ 0x0F, 0x3E, 0x11, 0x22, 0x41, 0x22, 0xC9, 0x3A, 0x58, 0x3D, 0x31, 0x32, 0x33, 0x31, 0x37, 0x3A, 0x59, 0x3D, 0x38, 0x0D,
+ 0x0F, 0x3F, 0x11, 0xDF, 0x22, 0x4B, 0x41, 0x52, 0x54, 0x45, 0x28, 0x31, 0x2D, 0x37, 0x29, 0x3A, 0x22, 0x3B, 0x5A, 0x0D,
+ 0x0F, 0x41, 0x07, 0xC5, 0x30, 0x3A, 0xDE, 0x22, 0x22, 0x0D, 0x0F, 0x46, 0x11, 0xCC, 0x31, 0x32, 0x30, 0x38, 0x3A, 0xE4,
+ 0x33, 0x39, 0x37, 0x30, 0x2B, 0x5A, 0x2A, 0x33, 0x30, 0x0D, 0x0F, 0x4B, 0x12, 0xD5, 0x49, 0x3D, 0x31, 0x32, 0x33, 0x31,
+ 0x37, 0xD0, 0x31, 0x32, 0x32, 0x38, 0x38, 0xD1, 0x2D, 0x31, 0x0D, 0x0F, 0x50, 0x08, 0xDB, 0x41, 0x3A, 0xCD, 0x49, 0x2C,
+ 0x41, 0x0D, 0x0F, 0x5A, 0x03, 0xD9, 0x49, 0x0D, 0x0F, 0x5F, 0x0B, 0xE4, 0x33, 0x39, 0x37, 0x30, 0x2B, 0x5A, 0x2A, 0x33,
+ 0x30, 0x0D, 0x0F, 0x64, 0x2A, 0x22, 0x22, 0x58, 0x3D, 0x58, 0x2D, 0x31, 0x3A, 0xD4, 0x58, 0x3C, 0x31, 0x32, 0x32, 0x38,
+ 0x38, 0xC4, 0x33, 0x3A, 0xDD, 0x22, 0x4B, 0x41, 0x52, 0x54, 0x45, 0x22, 0x3B, 0x5A, 0x3B, 0x22, 0x47, 0x45, 0x53, 0x43,
+ 0x48, 0x41, 0x46, 0x46, 0x54, 0x22, 0x0D, 0x0F, 0x66, 0x15, 0xD4, 0x28, 0x59, 0xA1, 0x28, 0xA7, 0x58, 0x29, 0x29, 0x3C,
+ 0x3E, 0x30, 0xC4, 0x31, 0x3A, 0xC6, 0x33, 0x39, 0x30, 0x32, 0x0D, 0x0F, 0x69, 0x16, 0xCD, 0x58, 0x2C, 0x59, 0xA2, 0x28,
+ 0xA7, 0x58, 0x29, 0x3A, 0xDB, 0x58, 0x31, 0x3A, 0xCD, 0x58, 0x2B, 0x31, 0x2C, 0x58, 0x31, 0x0D, 0x0F, 0x6E, 0x03, 0xC6,
+ 0xAD, 0x0D, 0x0F, 0x78, 0x15, 0x22, 0x38, 0x22, 0x59, 0x3D, 0x59, 0x2F, 0x28, 0x28, 0x59, 0x3E, 0x31, 0x29, 0x2B, 0x31,
+ 0x29, 0x3A, 0xC6, 0x22, 0x22, 0x0D, 0x0F, 0x82, 0x16, 0x22, 0x32, 0x22, 0x59, 0x3D, 0x59, 0x2A, 0x28, 0x28, 0x59, 0x3C,
+ 0x36, 0x34, 0x29, 0x2B, 0x31, 0x29, 0x3A, 0xC6, 0x22, 0x22, 0x0D, 0x0F, 0xA0, 0x4C, 0xDC, 0x31, 0x31, 0x33, 0x2C, 0x39,
+ 0x39, 0x2C, 0x39, 0x39, 0x2C, 0x31, 0x30, 0x33, 0x2C, 0x31, 0x31, 0x33, 0x2C, 0x39, 0x37, 0x2C, 0x36, 0x37, 0x2C, 0x37,
+ 0x2C, 0x31, 0x35, 0x2C, 0x37, 0x31, 0x2C, 0x39, 0x35, 0x2C, 0x36, 0x37, 0x2C, 0x36, 0x37, 0x2C, 0x31, 0x30, 0x33, 0x2C,
+ 0x31, 0x31, 0x33, 0x2C, 0x39, 0x37, 0x2C, 0x37, 0x31, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x36, 0x37, 0x2C, 0x37, 0x31, 0x2C,
+ 0x31, 0x31, 0x35, 0x2C, 0x37, 0x31, 0x2C, 0x37, 0x39, 0x0D, 0x0F, 0xA5, 0x17, 0xDC, 0x39, 0x39, 0x2C, 0x36, 0x35, 0x2C,
+ 0x37, 0x39, 0x2C, 0x36, 0x37, 0x2C, 0x31, 0x31, 0x33, 0x2C, 0x37, 0x39, 0x2C, 0x39, 0x39, 0x0D, 0x0F, 0xBE, 0x49, 0xDC,
+ 0x36, 0x37, 0x2C, 0x37, 0x31, 0x2C, 0x37, 0x39, 0x2C, 0x39, 0x39, 0x2C, 0x39, 0x37, 0x2C, 0x36, 0x35, 0x2C, 0x31, 0x31,
+ 0x35, 0x2C, 0x31, 0x30, 0x33, 0x2C, 0x36, 0x37, 0x2C, 0x37, 0x31, 0x2C, 0x33, 0x31, 0x2C, 0x31, 0x35, 0x2C, 0x33, 0x31,
+ 0x2C, 0x36, 0x33, 0x2C, 0x33, 0x31, 0x2C, 0x37, 0x39, 0x2C, 0x31, 0x30, 0x33, 0x2C, 0x36, 0x37, 0x2C, 0x31, 0x31, 0x33,
+ 0x2C, 0x37, 0x31, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x30, 0x33, 0x0D, 0x0F, 0xC3, 0x1B, 0xDC, 0x31, 0x30, 0x33, 0x2C,
+ 0x31, 0x31, 0x35, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x37, 0x31, 0x2C, 0x37, 0x39, 0x2C, 0x33, 0x2C, 0x33, 0x31, 0x2C, 0x36,
+ 0x37, 0x0D, 0x0F, 0xDC, 0x48, 0xDC, 0x39, 0x37, 0x2C, 0x39, 0x37, 0x2C, 0x31, 0x32, 0x33, 0x2C, 0x31, 0x32, 0x33, 0x2C,
+ 0x36, 0x37, 0x2C, 0x37, 0x31, 0x2C, 0x36, 0x37, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x39, 0x39, 0x2C,
+ 0x39, 0x37, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x39, 0x37, 0x2C, 0x39, 0x39, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x31, 0x35,
+ 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x36, 0x37, 0x2C, 0x36, 0x37, 0x2C, 0x37, 0x39, 0x2C, 0x37, 0x39, 0x0D, 0x0F, 0xE1, 0x1E,
+ 0xDC, 0x39, 0x37, 0x2C, 0x39, 0x37, 0x2C, 0x39, 0x39, 0x2C, 0x37, 0x39, 0x2C, 0x37, 0x31, 0x2C, 0x39, 0x39, 0x2C, 0x31,
+ 0x31, 0x33, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x37, 0x31, 0x0D, 0x0F, 0xFA, 0x49, 0xDC, 0x31, 0x30, 0x33, 0x2C, 0x31, 0x30,
+ 0x33, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x39, 0x37,
+ 0x2C, 0x39, 0x39, 0x2C, 0x37, 0x31, 0x2C, 0x39, 0x39, 0x2C, 0x31, 0x30, 0x33, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x30,
+ 0x33, 0x2C, 0x33, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x31, 0x31, 0x33, 0x2C,
+ 0x39, 0x39, 0x2C, 0x37, 0x31, 0x0D, 0x0F, 0xFF, 0x25, 0xDC, 0x37, 0x39, 0x2C, 0x37, 0x31, 0x2C, 0x31, 0x30, 0x33, 0x2C,
+ 0x31, 0x30, 0x33, 0x2C, 0x31, 0x30, 0x33, 0x2C, 0x31, 0x30, 0x33, 0x2C, 0x39, 0x39, 0x2C, 0x31, 0x31, 0x33, 0x2C, 0x31,
+ 0x32, 0x31, 0x2C, 0x39, 0x39, 0x0D, 0x10, 0x18, 0x47, 0xDC, 0x37, 0x31, 0x2C, 0x37, 0x31, 0x2C, 0x39, 0x39, 0x2C, 0x31,
+ 0x31, 0x33, 0x2C, 0x31, 0x32, 0x30, 0x2C, 0x31, 0x32, 0x34, 0x2C, 0x31, 0x32, 0x30, 0x2C, 0x36, 0x34, 0x2C, 0x39, 0x39,
+ 0x2C, 0x31, 0x31, 0x32, 0x2C, 0x31, 0x31, 0x33, 0x2C, 0x39, 0x39, 0x2C, 0x39, 0x39, 0x2C, 0x39, 0x39, 0x2C, 0x31, 0x31,
+ 0x33, 0x2C, 0x31, 0x32, 0x34, 0x2C, 0x39, 0x36, 0x2C, 0x31, 0x32, 0x30, 0x2C, 0x39, 0x36, 0x2C, 0x31, 0x32, 0x36, 0x0D,
+ 0x10, 0x1D, 0x25, 0xDC, 0x31, 0x32, 0x34, 0x2C, 0x31, 0x31, 0x32, 0x2C, 0x39, 0x37, 0x2C, 0x37, 0x31, 0x2C, 0x31, 0x30,
+ 0x33, 0x2C, 0x31, 0x30, 0x33, 0x2C, 0x39, 0x39, 0x2C, 0x31, 0x31, 0x33, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x36, 0x37, 0x0D,
+ 0x10, 0x36, 0x48, 0xDC, 0x36, 0x35, 0x2C, 0x39, 0x39, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x31,
+ 0x35, 0x2C, 0x31, 0x31, 0x33, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x31, 0x32, 0x30, 0x2C, 0x31, 0x32, 0x30, 0x2C, 0x31, 0x32,
+ 0x34, 0x2C, 0x31, 0x32, 0x35, 0x2C, 0x31, 0x32, 0x31, 0x2C, 0x31, 0x31, 0x33, 0x2C, 0x39, 0x39, 0x2C, 0x36, 0x37, 0x2C,
+ 0x37, 0x31, 0x2C, 0x31, 0x35, 0x2C, 0x31, 0x35, 0x2C, 0x31, 0x35, 0x2C, 0x33, 0x31, 0x0D, 0x10, 0x3B, 0x1F, 0xDC, 0x37,
+ 0x2C, 0x33, 0x2C, 0x36, 0x35, 0x2C, 0x39, 0x37, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x31, 0x31, 0x35, 0x2C, 0x39, 0x39, 0x2C,
+ 0x36, 0x37, 0x2C, 0x39, 0x35, 0x2C, 0x37, 0x31, 0x0D, 0x10, 0x54, 0x4B, 0xDC, 0x31, 0x31, 0x39, 0x2C, 0x31, 0x31, 0x39,
+ 0x2C, 0x39, 0x39, 0x2C, 0x39, 0x37, 0x2C, 0x39, 0x37, 0x2C, 0x31, 0x30, 0x35, 0x2C, 0x37, 0x33, 0x2C, 0x37, 0x33, 0x2C,
+ 0x39, 0x2C, 0x33, 0x31, 0x2C, 0x37, 0x35, 0x2C, 0x37, 0x35, 0x2C, 0x33, 0x2C, 0x33, 0x2C, 0x31, 0x30, 0x33, 0x2C, 0x31,
+ 0x30, 0x33, 0x2C, 0x31, 0x35, 0x2C, 0x31, 0x35, 0x2C, 0x33, 0x31, 0x2C, 0x33, 0x31, 0x2C, 0x31, 0x35, 0x2C, 0x31, 0x35,
+ 0x2C, 0x31, 0x35, 0x2C, 0x37, 0x31, 0x0D, 0x10, 0x59, 0x14, 0xDC, 0x37, 0x31, 0x2C, 0x36, 0x37, 0x2C, 0x36, 0x35, 0x2C,
+ 0x37, 0x32, 0x2C, 0x37, 0x36, 0x2C, 0x31, 0x32, 0x35, 0x0D,
+*/
 0xFF // BAS_NEW_EOF
 };
 #endif
--- a/bit_send.cpp	Wed Feb 23 12:24:16 2022 +0000
+++ b/bit_send.cpp	Tue Mar 29 10:06:20 2022 +0000
@@ -6,6 +6,7 @@
 // Serial pc1(USBTX,USBRX); defined in main
 Ticker bit_ticker;
 Timer total_time1;
+Timer bit_time;
 
 // volatile when read & write from both interrupts and main
 // static is to keep value between calls
@@ -78,7 +79,6 @@
             led1 = 0; // ticker stopped
             bit_out_port = 0; // stream closure
             total_time1.stop();
-            debug_printf("BIT_LAST_PROCESSING time(us): %d\r\n", total_time1.read_us());
         } else {
             // update read position (shift left mask)
             // and reset tick and cycle counters
@@ -123,13 +123,15 @@
 // as thread signals (Mbed-RTOS) are not available on the L053R8
 int bitWaitSend ( uint8_t bit_value, uint8_t invert ) {
 
+    bit_time.reset();
+    bit_time.start();
     // Both bit_read_position and bit_write_position cycle through the buffer
     // When they are the same, put sender on hold, for consumer to complete.
     // Polling regularly, then writing a new bit to buffer
     // when pointers are different (the slower handler has moved bit_read_mask).
-    // Bit handler takes 2ms to spool a single bit:
+    // Bit handler takes about 2ms to spool a single bit:
     //  ( BIT_TICK_x_CYCLE+1 ) * BIT_TICK_x_REPEAT * BIT_TICK_DELAY (us)
-    // hence, as soon as writer can write new data, it has 2x32ms to write 
+    // hence, as soon as writer can write new data, it has 32x2ms to write 
     // new bits before filling again the buffer.
     // Polling has to be frequent enough not to let consumer pull wrong bits...
     while ( ( bit_write_mask == bit_read_mask ) && ( bit_sync_flags & BIT_FIRST_SENT ) )
@@ -154,7 +156,7 @@
         total_time1.start();
     }
     
-    return 0;
+    return bit_time.read_us();
 
 }
 
--- a/bit_send.h	Wed Feb 23 12:24:16 2022 +0000
+++ b/bit_send.h	Tue Mar 29 10:06:20 2022 +0000
@@ -12,11 +12,13 @@
 #define BIT_LAST_PROCESSING ( 1UL << 2 ) // last bit is being processes
 #define BIT_SENDING         ( 1UL << 3 ) // bit being processed
 
-#define DEBUG 1
-#ifdef DEBUG
+#ifdef FILE_BUF_SIZE
+//extern volatile char debugOut[];  //  holding debug info to print at the end
+//static char debugLine[128];
+//#define debug_printf(f_, ...) { sprintf((char*)debugLine,(f_), ##__VA_ARGS__); strcat ( (char*)debugOut, debugLine ); }
+#define debug_printf(f_, ...)
+#else
 #define debug_printf(f_, ...) printf((f_), ##__VA_ARGS__)
-#else
-#define debug_printf(...) 
 #endif
 
 void bitHandlerInit( void ) ;
--- a/main.cpp	Wed Feb 23 12:24:16 2022 +0000
+++ b/main.cpp	Tue Mar 29 10:06:20 2022 +0000
@@ -1,62 +1,123 @@
+/********************************************
+Send File to Sharp PC-1403(H)
+==========================================
+
+Author: Fabio Fumi
+Date:   04.03.2022
+
+This software comes with the GNU public licence (GPL).
+
+It is an adaptation to the Mbed OS of the 
+img2wav from the "Pocket Tools" suite
+https://www.peil-partner.de/ifhe.de/sharp/
+*********************************************/
 #include "mbed.h" 
 #include "send_pc1403.h"
-#include "bin_file.h" // in-memory BIN file (until I integrate an SD-Card to store it...=
-#include "bit_send.h"
+//#ifdef FILE_BUF_SIZE
+//volatile char debugOut[1024];
+//#endif
+RawSerial   pc(USBTX,USBRX); // better than Serial, when using interrupts
+DigitalOut  my_led(LED1);
+DigitalIn   my_button(USER_BUTTON);
+InterruptIn btn(USER_BUTTON);
+Timer       total_time;
+Ticker      blink;
+
+ // bin-to-wav conversion information (from Pocket Tools code)
+int       send_err;
+
+void ledBlink () {
+    my_led = !my_led;
+}
 
-Serial pc(USBTX,USBRX);
-DigitalOut led(LED1);
-Timer total_time;
-DigitalIn    my_button(USER_BUTTON);
+#ifdef FILE_BUF_SIZE 
+void printInfo() 
+{
+    int i ;
+    // printout info
+    pc.printf("totBytesReceived %d\n\r", totBytesReceived);
+    pc.printf("fileBufReceivePtr %d\n\r", fileBufReceivePtr);
+    for ( i=0; i<10; i++ ) 
+        pc.printf("0x%.2X ", fileOverSerialBuffer[i] );
+    pc.printf("...\n\r");
+    pc.printf("fileBufSendPtr %d\n\r", fileBufSendPtr);
+    //pc.printf("<%s>\n\r", debugOut);
+    pc.printf("fileReceiveComplete %d\n\r", fileReceiveComplete);
+    pc.printf("fileError %d\n\r", fileError);
+    pc.printf("fileInfo.total %d\n\r", fileInfo.total);
+    pc.printf("time (ms): %d [send_err %d]\n\r", total_time.read_us()/1000, send_err);
+    
+}
 
+// invoked at each character received over serial
+void serial_rx() {
+    
+    // getting data from serial
+    if ( totBytesReceived == 0 ) {
+        timeout.start(); // new file: enable a watchdog
+        timeout.reset();
+        blink.attach( &ledBlink, 0.05 ); // fast blink: receiving
+    }
+    // push character on the circular buffer
+    filePushData ( pc.getc() );
+    totBytesReceived++;
+    timeout.reset();
 
+}
+#endif
 
+ 
 int main()
 {
-
-    int i, error;
-    char inVal;
-    FileInfo  info ; // PC bin-to-wav conversion information
-    // flashing led on startup
-    for (i=0; i<10; i+=1) {
-        wait (0.1);
-        led = !led;
-    }
-    // init vars
-    led = 0;
-     
-    pc.baud(57600);
-
-    // welcome message 
-    pc.printf("\n\r ** MBED ** send to PC1403 ** \n\r");
+    
+    my_led = 0;
+    pc.baud(600); // file-over-serial can't go faster (sending to Sharp is about 500baud)
     fflush(stdout);
-    
+#ifdef FILE_BUF_SIZE 
+    btn.rise(&printInfo);
+    pc.attach(&serial_rx, Serial::RxIrq);
+    fileReceiveInit( );
+#endif
     // main loop
     while(true) {
-     
-        pc.printf(" (push user button to send) \n\r");
-        // wait for button pressed
+        
+        blink.attach( &ledBlink, 1.0 ); // slow blink - waiting for file
+        
+#ifdef FILE_BUF_SIZE 
+        // File-over-serial
+        // serial interrupt - pushing to buffer
+        // main thread - pulling from buffer
+        fileInfo.debug = 0x1000; // disable verbose printf while using serial
+        fileReceiveInit( ); 
+        // wait for data available, before starting to send  
+        while ( !totBytesReceived  ) 
+            wait (.1);
+#else
+        // hardcoded BIN file
+        pc.printf("Push user button to start sending \n\r"); 
+        // wait for button pressed, only for the hardcoded BIN file
         while ( my_button == 1 )
             wait ( .1 );
+#endif
         
+        // start sending new file to Sharp
+        fileInfo.ident = IDENT_NEW_BAS;
+        fileInfo.debug = 0x0040; // 0x0000 disable printf; 0x0040 DEBUG
+        bitHandlerInit(); // new bit stream being sent
         total_time.reset();
         total_time.start();
-    
-        ///////////////////////////////////////////////
-        // FILE SENDING
-        bitHandlerInit(); // before a new bit stream to be sent
-        info.ident = IDENT_NEW_BAS;
-        info.debug = 0x0040; // 0x0000 disable printf ;  0x0040 DEBUG
-        error = FileSend ( bin_file_name, bin_file_bytes, BIN_FILE_SIZE, &info ) ; 
-        pc.printf("\n\rFileSend completed - (%d)\n\r", error);
-        bitHandlerStop(); // stop consumer after last bit
-        while( bitHandlerRunning() )  // time for handler to complete
+        send_err = FileSend ( ) ;  // removed for debug !
+        bitHandlerStop(); // stop bit consumer, after last bit
+        while( bitHandlerRunning() )  // time for bit handler to complete
             wait (.1); 
-        ///////////////////////////////////////////////
-       
         total_time.stop();
-        pc.printf("DONE - time (ms): %d [send_err %d]\n\r", total_time.read_us()/1000, error);
+#ifdef FILE_BUF_SIZE 
+        printInfo() ;
+#endif
+        pc.printf("DONE - time (ms): %d [send_err %d]\n\r", total_time.read_us()/1000, send_err);
 
         // doing nothing...
-        wait(.1);              
+        wait(.1);       
+               
     }
 }
\ No newline at end of file
--- a/send_pc1403.cpp	Wed Feb 23 12:24:16 2022 +0000
+++ b/send_pc1403.cpp	Tue Mar 29 10:06:20 2022 +0000
@@ -1,5 +1,4 @@
 #include "send_pc1403.h"
-#include "bit_send.h"
 
 ///////////////////////////////////////////////////////
 // variables from PocketTools code
@@ -24,11 +23,12 @@
 ulong  err_cnt = 0 ;    /* counts minor errors */
 ulong  wrn_cnt = 0 ;    /* counts warnings */
 
+FileInfo  fileInfo ;    /* File information */
+
 ////////////////////////////////////////////////////////////////////////////////
 // WriteBitToWav replaced from PocketTools version (writing to a WAV file)
 // Here we send directly signals to OUT lines
-int WriteBitToWav (int   value,
-              FileInfo*  ptrFile)
+int WriteBitToWav (int   value)
 {
     // Calling the buffered bit-sending routine
     switch ( value ) {
@@ -51,33 +51,32 @@
 // Write* methods taken from Pocket-Tools source code 
 // https://www.peil-partner.de/ifhe.de/sharp/
 int WriteQuaterToWav (uint   value,
-                      uint   stopBits,
-                 FileInfo*   ptrFile)
+                      uint   stopBits)
 {
       uint  tmp ;
       uint  ii ;
        int  error ;
 
-    // if (TAPc > 0) return (WriteQuaterToTap (value, ptrFile)); // no  
+    // if (TAPc > 0) return (WriteQuaterToTap (value )); // no  
     
     do {
         
-        error = WriteBitToWav (0, ptrFile) ;
+        error = WriteBitToWav (0 ) ;
         if (error != ERR_OK) break ;
 
         for ( ii = 0 ; ii < 4 ; ++ii ) {
             tmp = 1 << ii ;
             if ( (value & tmp) == 0 )
-                error = WriteBitToWav (0, ptrFile) ;
+                error = WriteBitToWav (0 ) ;
             else
-                error = WriteBitToWav (1, ptrFile) ;
+                error = WriteBitToWav (1 ) ;
 
             if (error != ERR_OK) break ;
         }
         if (error != ERR_OK) break ;
 
         for ( ii = 0 ; ii < stopBits ; ++ii ) {
-            error = WriteBitToWav (1, ptrFile) ;
+            error = WriteBitToWav (1 ) ;
             if (error != ERR_OK) break ;
         }
         if (error != ERR_OK) break ;
@@ -88,30 +87,29 @@
 
 int WriteByteToWav (ulong  value,
                     uchar  order,
-                    uchar  mode,
-                FileInfo*  ptrFile)
+                    uchar  mode)
 {
       uint  lsq ;
       uint  msq ;
       int  error ;
 
-    // if (TAPc > 0) return (WriteByteToTap (value, order, ptrFile)) ; // no  
+    // if (TAPc > 0) return (WriteByteToTap (value, order )) ; // no  
 
-    // if (order == ORDER_E) return (WriteByteToEWav (value, ptrFile)) ; // no  1403
+    // if (order == ORDER_E) return (WriteByteToEWav (value )) ; // no  1403
 
     do {
         lsq = value & 0x0F ;
         msq = (value >> 4) & 0x0F ;
         if (order == ORDER_INV) {
-            error = WriteQuaterToWav (lsq, Mode[mode].stopb1, ptrFile) ;
+            error = WriteQuaterToWav (lsq, Mode[mode].stopb1 ) ;
             if (error != ERR_OK) break ;
-            error = WriteQuaterToWav (msq, Mode[mode].stopb2, ptrFile) ;
+            error = WriteQuaterToWav (msq, Mode[mode].stopb2 ) ;
             if (error != ERR_OK) break ;
         }
         else {
-            error = WriteQuaterToWav (msq, Mode[mode].stopb1, ptrFile) ;
+            error = WriteQuaterToWav (msq, Mode[mode].stopb1 ) ;
             if (error != ERR_OK) break ;
-            error = WriteQuaterToWav (lsq, Mode[mode].stopb2, ptrFile) ;
+            error = WriteQuaterToWav (lsq, Mode[mode].stopb2 ) ;
             if (error != ERR_OK) break ;
         }
 
@@ -119,26 +117,25 @@
     return (error);
 }
 
-int CheckSumB1 (  ulong  Byte,
-              FileInfo*  ptrFile)
+int CheckSumB1 (  ulong  Byte )
 {
     ushort sum ;
 
     /* Update the checksum */
-        sum = ptrFile->sum + ((Byte & 0xF0) >> 4) ;
+        sum = fileInfo.sum + ((Byte & 0xF0) >> 4) ;
         if (sum > 0xFF) {
             ++sum ;
             sum &= 0xFF ;
             }
-        ptrFile->sum = (sum + (Byte & 0x0F)) & 0xFF ;
+        fileInfo.sum = (sum + (Byte & 0x0F)) & 0xFF ;
 
     return (0);
 }
 
 
-int CheckSumE (  ulong  Byte,
-//               ulong*  ptrSum )
-               FileInfo*  ptrFile)
+int CheckSumE (  ulong  Byte 
+//               ulong*  ptrSum 
+      )
 {
     uint tmp, ii ;
 
@@ -147,14 +144,13 @@
     for ( ii = 0 ; ii < 8 ; ++ii, tmp >>= 1 )
         if ( (Byte & tmp) != 0 )  
             // ++ *ptrSum ;
-             ++ ptrFile->sum ;
+             ++ fileInfo.sum ;
 
     return (0);
 }
 
 
-int WriteSyncToWav (ulong  nbSync,  // 
-                FileInfo*  ptrFile)
+int WriteSyncToWav (ulong  nbSync )
 {
     ulong  ii ;
     int    error = ERR_OK ;
@@ -164,7 +160,7 @@
     do {
         /* Write the Synchro patern */
         for ( ii = 0 ; ii < nbSync ; ++ii ) {
-            error = WriteBitToWav (1, ptrFile) ;
+            error = WriteBitToWav (1 ) ;
             if (error != ERR_OK) break ;
         }
         if (error != ERR_OK) break ;
@@ -174,62 +170,58 @@
 }
 
 int WriteUsedatLenToQTWav ( uchar  order, /* Quick-Tape incomplete blocks with fill data */
-                            uchar  mode,
-                        FileInfo*  ptrFile)
+                            uchar  mode )
 {   long tmpL ;
     int  error ;
 
-    tmpL = ptrFile->nbByte - ptrFile->total_diff - ptrFile->total ; //not for IDENT_QT_DAT: variable block in RAM based
+    tmpL = fileInfo.nbByte - fileInfo.total_diff - fileInfo.total ; //not for IDENT_QT_DAT: variable block in RAM based
 
     if (tmpL > 0) {
             if (tmpL > BLK_OLD) tmpL = BLK_OLD ;
             --tmpL ;
-            if (tmpL < BLK_OLD -1) ptrFile->usedat_len = tmpL + 1 ;
-            else ptrFile->usedat_len = 0 ; /* L:0x4F ignored, no effect */
+            if (tmpL < BLK_OLD -1) fileInfo.usedat_len = tmpL + 1 ;
+            else fileInfo.usedat_len = 0 ; /* L:0x4F ignored, no effect */
 
-            error = WriteByteToWav (tmpL, order, mode, ptrFile) ;
+            error = WriteByteToWav (tmpL, order, mode ) ;
             if (error != ERR_OK) return (error) ;
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG (L:%02X)", (uint) tmpL);
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG (L:%02X)", (uint) tmpL);
 
-            ptrFile->sum = tmpL ;
+            fileInfo.sum = tmpL ;
     }
     else if (tmpL == 0 ) error = ERR_OK ;
     else {
             printf(" WUsedatLQT: End of file was expected");
             error = ERR_FMT ;
     }
-    ptrFile->count = 0 ;
+    fileInfo.count = 0 ;
 
     return (error);
 }
 
 int WriteByteSumToWav (ulong  value,
                        uchar  order,
-                       uchar  mode,
-                       FileInfo*  ptrFile)
+                       uchar  mode)
 {
     int   error ;
     bool  writ_full_block = false ;
     
     do {
 
-        if ( (ptrFile->debug & 0x0040) > 0) {
+        if ( (fileInfo.debug & 0x0040) > 0)  
             debug_printf(" %02X", (uchar) value);
-            if ( ptrFile->total %0x100 == 0xFF ) printf("\n");
-        }
-        error = WriteByteToWav (value, order, mode, ptrFile) ;
+        error = WriteByteToWav (value, order, mode ) ;
         if (error != ERR_OK) break ;
 
-        if (mode == MODE_B22 || mode == MODE_B11) ptrFile->sum += value ;
-        else if (mode == MODE_B9 || mode == MODE_B10) CheckSumE (value, ptrFile) ; //ptrFile
-        else CheckSumB1 (value, ptrFile) ;
+        if (mode == MODE_B22 || mode == MODE_B11) fileInfo.sum += value ;
+        else if (mode == MODE_B9 || mode == MODE_B10) CheckSumE (value ) ; //ptrFile
+        else CheckSumB1 (value ) ;
 
-        ++ptrFile->count ;
-        if (!writ_full_block) ++ptrFile->total ;
+        ++fileInfo.count ;
+        if (!writ_full_block) ++fileInfo.total ;
 
-        if ( ptrFile->usedat_len > 0) { /* QTape incomplete block */
-            if (--ptrFile->usedat_len == 0) {
-                if ( ( (ptrFile->debug & 0x0040) > 0 ) && (Qcnt == 0) ) debug_printf("DEBUG Fill data:");
+        if ( fileInfo.usedat_len > 0) { /* QTape incomplete block */
+            if (--fileInfo.usedat_len == 0) {
+                if ( ( (fileInfo.debug & 0x0040) > 0 ) && (Qcnt == 0) ) debug_printf("DEBUG Fill data:");
                 value = 0x00 ;
                 writ_full_block = true ;
             }
@@ -237,40 +229,40 @@
 
         switch (mode) {
         case MODE_B22 :
-            if ( ptrFile->count >= BLK_OLD ) {
+            if ( fileInfo.count >= BLK_OLD ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%04X)", (uint) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%04X)\n\r", (uint) fileInfo.sum);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum >> 8 & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum >> 8 & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
-                error = WriteByteToWav (ptrFile->sum & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B21 :
         case MODE_B20 :
         case MODE_B19 :
-            if ( (ptrFile->count % BLK_OLD_SUM) == 0) {
+            if ( (fileInfo.count % BLK_OLD_SUM) == 0) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%02X)", (uchar) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%02X)\n\r", (uchar) fileInfo.sum);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                if ( ptrFile->count >= BLK_OLD ) {
-                    ptrFile->count = 0 ;
-                    ptrFile->sum   = 0 ;
-                    // if (pcgrpId==IDENT_PC1211) error = WriteSyncToWav (1803, ptrFile) ; //DATA not
-                    if (ptrFile->ident == IDENT_PC1211) /* default 1803 bits, data not */
-                        error = WriteSyncToWav (ptrFile->nbSync, ptrFile) ;
+                if ( fileInfo.count >= BLK_OLD ) {
+                    fileInfo.count = 0 ;
+                    fileInfo.sum   = 0 ;
+                    // if (pcgrpId==IDENT_PC1211) error = WriteSyncToWav (1803 ) ; //DATA not
+                    if (fileInfo.ident == IDENT_PC1211) /* default 1803 bits, data not */
+                        error = WriteSyncToWav (fileInfo.nbSync ) ;
                 }
             }
             break ;
@@ -278,93 +270,93 @@
         case MODE_B17 :
         case MODE_B16 :
         case MODE_B15 :
-            if ( ptrFile->count >= BLK_OLD_SUM) {
+            if ( fileInfo.count >= BLK_OLD_SUM) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%02X)", (uchar) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%02X)\n\r", (uchar) fileInfo.sum);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum, order, mode) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B14 :
         case MODE_B13 :
-            if ( ptrFile->count >= BLK_NEW) {
+            if ( fileInfo.count >= BLK_NEW ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%02X)", (uchar) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" *(%02X)", (uchar) fileInfo.sum);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B9 : /* PC-E/G/1600 */
-            if ( ptrFile->count >= ptrFile->block_len ) {
+            if ( fileInfo.count >= fileInfo.block_len ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%04X)", (uint) ptrFile->sum & 0xFFFF);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%04X)\n\r", (uint) fileInfo.sum & 0xFFFF);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum >> 8 & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum >> 8 & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
-                error = WriteByteToWav (ptrFile->sum & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B10 : /* SuperTape */
-            if ( ptrFile->count >= ptrFile->block_len ) {
+            if ( fileInfo.count >= fileInfo.block_len ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%04X)", (uint) ptrFile->sum & 0xFFFF);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%04X)", (uint) fileInfo.sum & 0xFFFF);
 
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
-                error = WriteByteToWav (ptrFile->sum >> 8 & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum >> 8 & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                if ( (ptrFile->debug & 0x0040) > 0) debug_printf(" %02X", (uchar) SUPT_END);
-                error = WriteByteToWav (SUPT_END, order, mode, ptrFile) ;
+                if ( (fileInfo.debug & 0x0040) > 0) debug_printf(" %02X", (uchar) SUPT_END);
+                error = WriteByteToWav (SUPT_END, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                ptrFile->count = 0 ;
-                ptrFile->sum   = 0 ;
+                fileInfo.count = 0 ;
+                fileInfo.sum   = 0 ;
             }
             break ;
 
         case MODE_B11 :
-            if ( ptrFile->count >= BLK_OLD ) {
+            if ( fileInfo.count >= BLK_OLD ) {
 
-                if ( (ptrFile->debug & 0x0040) > 0 )
-                    debug_printf(" (%04X)", (uint) ptrFile->sum);
+                if ( (fileInfo.debug & 0x0040) > 0 )
+                    debug_printf(" (%04X)\n\r", (uint) fileInfo.sum);
                 /* Write the checksum */
-                error = WriteByteToWav (ptrFile->sum >> 8 & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum >> 8 & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
-                error = WriteByteToWav (ptrFile->sum & 0xFF, order, mode, ptrFile) ;
+                error = WriteByteToWav (fileInfo.sum & 0xFF, order, mode ) ;
                 if (error != ERR_OK) break ;
 
-                error = WriteByteToWav (EOF_15, order, mode, ptrFile) ;
+                error = WriteByteToWav (EOF_15, order, mode ) ;
                 if (error != ERR_OK) break ;
-                if ( (ptrFile->debug & 0x0040) > 0) debug_printf(" (E:%02X)", (uint) EOF_15);
+                if ( (fileInfo.debug & 0x0040) > 0) debug_printf(" (E:%02X)", (uint) EOF_15);
                 writ_full_block = false ;
 
-                error = WriteSyncToWav (50, ptrFile) ; /* 0.02 s */
+                error = WriteSyncToWav (50 ) ; /* 0.02 s */
                 if (error != ERR_OK) break ;
-                error = WriteUsedatLenToQTWav (order, mode, ptrFile) ;
+                error = WriteUsedatLenToQTWav (order, mode ) ;
             }
             break ;
 
@@ -385,8 +377,7 @@
 
 /* File name for New and Old BASIC */
 int WriteSaveNameToWav (char*  ptrName,
-                        uchar  mode,
-                    FileInfo*  ptrFile)
+                        uchar  mode)
 {
      uint  ii ;
      uint  tmpL ;
@@ -394,7 +385,7 @@
      char  tmpS[20] ;
       int  error ;
 
-   if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG ptrName %s\n\r", ptrName);
+   if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG ptrName %s\n\r", ptrName);
 
     do {
         /* Uppercase the name is done in main if needed */
@@ -421,7 +412,7 @@
        for ( ii = 0 ; ii < tmpL ; ++ii )
             tmpS[ii] = 0 ;
 
-        if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG tmpS %s\n\r", tmpS);
+        if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG tmpS %s\n\r", tmpS);
         for ( ii = tmpL ; ii < 7 ; ++ii ) {
             byte = (ulong) ptrName[6 - ii] ;
 
@@ -430,9 +421,9 @@
             case MODE_B20 :
 
                 if (byte < 0x80)
-                    byte = CodeOld[byte] ;
+                    byte = (char)CodeOld[byte] ;
                 else
-                    byte = CodeOld[0] ;
+                    byte = (char)CodeOld[0] ;
                 break ;
 
             default :
@@ -446,28 +437,27 @@
         tmpS[7] = 0x5F ;
 
         /* Write the Name */
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
         for ( ii = 0 ; ii < 8 ; ++ii ) {
-            error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode, ptrFile) ;
+            error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode ) ;
             if (error != ERR_OK) break ;
         }
 
-        if (ptrFile->ident == IDENT_PC1211)
-            error = WriteSyncToWav (151, ptrFile) ;
-        else if (ptrFile->ident == IDENT_PC121_DAT)
-            error = WriteSyncToWav (111, ptrFile) ;
+        if (fileInfo.ident == IDENT_PC1211)
+            error = WriteSyncToWav (151 ) ;
+        else if (fileInfo.ident == IDENT_PC121_DAT)
+            error = WriteSyncToWav (111 ) ;
 
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
 
     } while (0) ;
     return (error);
 }
 
 int DEBUGSaveNameToWav (char*  ptrName,
-                        uchar  mode,
-                    FileInfo*  ptrFile)
+                        uchar  mode)
 {
      uint  ii ;
      uint  i ;
@@ -521,9 +511,9 @@
             case MODE_B20 :
 
                 if (byte < 0x80)
-                    byte = CodeOld[byte] ;
+                    byte = (char)CodeOld[byte] ;
                 else
-                    byte = CodeOld[0] ;
+                    byte = (char)CodeOld[0] ;
                 break ;
 
             default :
@@ -538,25 +528,21 @@
         debug_printf("DEBUG ii %u\n\r", ii);
 
         /* Write the Name */
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
         for ( ii = 0 ; ii < 8 ; ++ii ) {
-            error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode, ptrFile) ;
+            error = WriteByteSumToWav (tmpS[ii], ORDER_STD, mode ) ;
             if (error != ERR_OK) break ;
         }
-        if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Name - Bytes was printed swapped.\n\r");
-
-        debug_printf("DEBUG WriteSyncToWav prima\n\r");
+        if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Name - Bytes was printed swapped.\n\r");
 
-        if (ptrFile->ident == IDENT_PC1211)
-            error = WriteSyncToWav (151, ptrFile) ;
-        else if (ptrFile->ident == IDENT_PC121_DAT)
-            error = WriteSyncToWav (111, ptrFile) ;
-        debug_printf("DEBUG WriteSyncToWav dopo\n\r");
+        if (fileInfo.ident == IDENT_PC1211)
+            error = WriteSyncToWav (151 ) ;
+        else if (fileInfo.ident == IDENT_PC121_DAT)
+            error = WriteSyncToWav (111 ) ;
 
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
-        debug_printf("DEBUG fine\n\r");
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
 
     } while (0) ;
     return (error);
@@ -565,8 +551,7 @@
 /* Head of Binary Data for New and Old series */
 int WriteHeadToBinWav (ulong  addr,
                        ulong  size,
-                       uchar  mode,
-                   FileInfo*  ptrFile)
+                       uchar  mode)
 {
       int  ii ;
     ulong  len ;
@@ -581,67 +566,67 @@
     }
     */
 
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
         for ( ii = 0 ; ii < 4 ; ++ii ) {
-            error = WriteByteSumToWav (0, ORDER_STD, mode, ptrFile) ;
+            error = WriteByteSumToWav (0, ORDER_STD, mode ) ;
             if (error != ERR_OK) break ;
         }
 
         /* Write the address, this method is necessary because of swapped checksums in the header. */
         tmpL = ((addr >> 4) & 0xF0) + (addr >> 12) ;        /* H swapped */
-        error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ;
+        error = WriteByteSumToWav (tmpL, ORDER_STD, mode ) ;
         if (error != ERR_OK) break ;
 
         tmpL = ((addr << 4) & 0xF0) + ((addr >> 4) & 0x0F) ;/* L swapped */
-        error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ;
+        error = WriteByteSumToWav (tmpL, ORDER_STD, mode ) ;
         if (error != ERR_OK) break ;
 
         /* Write the Length */
         len = size - 1 ;
         tmpL = ((len >> 4) & 0xF0) + (len >> 12) ;
-        error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ;
+        error = WriteByteSumToWav (tmpL, ORDER_STD, mode ) ;
         if (error != ERR_OK) break ;
 
         tmpL = ((len << 4) & 0xF0) + ((len >> 4) & 0x0F) ;
-        error = WriteByteSumToWav (tmpL, ORDER_STD, mode, ptrFile) ;
+        error = WriteByteSumToWav (tmpL, ORDER_STD, mode ) ;
         if (error != ERR_OK) break ;
 
-        ptrFile->count = 0 ;
-        ptrFile->sum   = 0 ;
+        fileInfo.count = 0 ;
+        fileInfo.sum   = 0 ;
 
     } while (0) ;
     return (error);
 }
 
-int WriteFooterToNewWav (FileInfo*  ptrFile)
+int WriteFooterToNewWav ( void )
 {
     int  error ;
 
     do {
-        ptrFile->count = 0 ; /* no checksum writing from here until the end */
+        fileInfo.count = 0 ; /* no checksum writing from here until the end */
 
-        error = WriteByteSumToWav(BAS_NEW_EOF, ORDER_STD, ptrFile->mode, ptrFile) ;
-        // error = WriteByteSumToB13Wav (BAS_NEW_EOF, ptrFile) ;
+        error = WriteByteSumToWav(BAS_NEW_EOF, ORDER_STD, fileInfo.mode ) ;
+        // error = WriteByteSumToB13Wav (BAS_NEW_EOF ) ;
         if (error != ERR_OK) break ;
 
-        error = WriteByteToWav(BAS_NEW_EOF, ORDER_STD, ptrFile->mode, ptrFile) ;
+        error = WriteByteToWav(BAS_NEW_EOF, ORDER_STD, fileInfo.mode ) ;
         if (error != ERR_OK) break ;
 
-        if ( (ptrFile->debug & 0x00C0) > 0 )
+        if ( (fileInfo.debug & 0x00C0) > 0 )
             debug_printf(" EOF:%02X", (uchar) BAS_NEW_EOF);
 
-        error = WriteByteToWav(ptrFile->sum, ORDER_STD, ptrFile->mode, ptrFile) ;
+        error = WriteByteToWav(fileInfo.sum, ORDER_STD, fileInfo.mode ) ;
         if (error != ERR_OK) break ;
 
-        if ( (ptrFile->debug & 0x0040) > 0 )
-            debug_printf(" (%02X)", (uchar) ptrFile->sum);
+        if ( (fileInfo.debug & 0x0040) > 0 )
+            debug_printf(" (%02X)", (uchar) fileInfo.sum);
 
     /* there are 2bits more HIGH at the end of transmission (at least for PC-1402) M. NOSSWITZ */
-     error = WriteBitToWav (1, ptrFile) ;
+     error = WriteBitToWav (1 ) ;
     if (error != ERR_OK) break ;
 
-    error = WriteBitToWav (1, ptrFile) ;
+    error = WriteBitToWav (1 ) ;
     if (error != ERR_OK) break ;
  
     /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */
@@ -650,9 +635,39 @@
     /* end of transmission, before the motor of the cassette recorder is switched off.        */
     /* This level out is visible in the CSAVE audio signal after the last bit. T. Muecker     */
     /* not needed for the MBed direct-write version
-    error = WriteBitToWav (3, ptrFile) ; 125us High , 
+    error = WriteBitToWav (3 ) ; 125us High , 
+    if (error != ERR_OK) break ;
+    error = WriteBitToWav (2 ) ; 1 ms Midsignal
     if (error != ERR_OK) break ;
-    error = WriteBitToWav (2, ptrFile) ; 1 ms Midsignal
+    */
+
+    } while (0) ;
+    return (error);
+}
+
+int WriteFooterToMemoWav ( void )
+{
+    int  error ;
+
+    do {
+        error = WriteByteToWav(fileInfo.sum, ORDER_STD, fileInfo.mode ) ;
+        if (error != ERR_OK) break ;
+
+        if ( (fileInfo.debug & 0x0040) > 0 )
+            debug_printf(" (%02X)", (uchar) fileInfo.sum);
+
+    error = WriteBitToWav (1 ) ;
+    if (error != ERR_OK) break ;
+
+    error = WriteBitToWav (1 ) ;
+    if (error != ERR_OK) break ;
+
+    /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */
+    /* not needed for the MBed send version
+    error = WriteBitToWav (3 ) ;
+    if (error != ERR_OK) break ;
+
+    error = WriteBitToWav (2 ) ;
     if (error != ERR_OK) break ;
     */
 
@@ -660,62 +675,47 @@
     return (error);
 }
 
-int WriteFooterToMemoWav (FileInfo*  ptrFile)
-{
-    int  error ;
-
-    do {
-        error = WriteByteToWav(ptrFile->sum, ORDER_STD, ptrFile->mode, ptrFile) ;
-        if (error != ERR_OK) break ;
-
-        if ( (ptrFile->debug & 0x0040) > 0 )
-            debug_printf(" (%02X)", (uchar) ptrFile->sum);
-
-    error = WriteBitToWav (1, ptrFile) ;
-    if (error != ERR_OK) break ;
 
-    error = WriteBitToWav (1, ptrFile) ;
-    if (error != ERR_OK) break ;
+// File completion check
+bool isFileSendComplete ( void ) {
+#ifdef FILE_BUF_SIZE 
+    return ( isFilePullComplete() ) ;
+#else
+    return ( file_pos == BIN_FILE_SIZE - 1 ) ; 
+#endif
+}
 
-    /* This puts 2 bits of silence (or 2 HIGH bits alternatively) to the end of the wave file. */
-    /* not needed for the MBed send version
-    error = WriteBitToWav (3, ptrFile) ;
-    if (error != ERR_OK) break ;
-
-    error = WriteBitToWav (2, ptrFile) ;
-    if (error != ERR_OK) break ;
-    */
-
-    } while (0) ;
-    return (error);
+// Input file data access, depends on build
+char fileGetNext ( void ) {
+    // byte = fgetc (srcFd) ; // DOS / UNIX file - not applicable here 
+#ifdef FILE_BUF_SIZE 
+    return ( filePullData () ) ;
+#else
+    return ( bin_file_bytes[file_pos++] ); 
+#endif
 }
 
+
 /////////////////////////////////////////////////////////////////////////////
-// My file-send implementation
-// Inspired to Pocket-Tools source code ...
-int FileSend ( char* FileName, char* FileStream, uint FileSize, FileInfo*  ptrFile )
+// file-send implementation, largely inspired to Pocket-Tools source code
+int FileSend ( void )
 {
-    int      pcId  =  PC_ID; 
+    
+    int      pcId  =  PC_ID;  // hardcoded for PC-1403 here
+    uint32_t nbSync = N_SYNC_BITS; 
+    int      ii;
     uchar    type ;
-    
-    uint32_t ii ;
     uint32_t nbByte;
-    uint32_t nbSync = N_SYNC_BITS;
     uint32_t addr;
     int      error ;
-    char     inVal;
- 
-
-    // BIN file stored statically, until I integrate an SD-Card...      
-    nbByte = FileSize; 
-    ptrFile->nbSync = nbSync;
+    char     inVal;   
 
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG FileName %s\n\r",FileName);
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG ptrFile->ident %u\n\r",ptrFile->ident);
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG nbSync %u\n\r",nbSync);
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG nbByte %u\n\r",nbByte);
+    fileInfo.nbSync = nbSync;
+#ifndef FILE_BUF_SIZE 
+    file_pos = 0;
+#endif
 
-    switch (ptrFile->ident) {
+    switch (fileInfo.ident) {
     /* . . .*/
         case IDENT_NEW_BIN :
             pcgrpId = GRP_NEW ; /*or GRP_EXT */
@@ -736,8 +736,8 @@
     }   
     else { //   PC-1211 to PC-1500, QTape 
     */   
-        if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG WriteSyncToWav\n\r");
-        error = WriteSyncToWav (nbSync, ptrFile) ;
+        if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG WriteSyncToWav\n\r");
+        error = WriteSyncToWav (nbSync ) ;
     /*
         . . .
     */
@@ -754,7 +754,7 @@
     */
         break;
     default :
-        debug_printf ("%s: Pocket computer %d is not implemented\n", argP, pcId) ;
+        debug_printf ("%s: Sharp PC-%d not implemented\n", argP, pcId) ;
         // MoreInfo (ERR_ARG);
         error = ERR_ARG ;
             // break ;
@@ -764,11 +764,11 @@
 /*  ...
     else { // PC-121x ... PC-1475 
 */
-    if ( (ptrFile->debug & 0x0040) > 0 ) 
-        debug_printf("DEBUG set Header Mode (ident %d)\n\r", ptrFile->ident);
-    switch (ptrFile->ident) { /* Header Mode */
+    if ( (fileInfo.debug & 0x0040) > 0 ) 
+        debug_printf("DEBUG set Header Mode (ident %d)\n\r", fileInfo.ident);
+    switch (fileInfo.ident) { /* Header Mode */
     case IDENT_PC1211 :
-        ptrFile->mode = ptrFile->mode_h = MODE_B20 ;
+        fileInfo.mode = fileInfo.mode_h = MODE_B20 ;
         break ;
 
     case IDENT_PC121_DAT :
@@ -776,7 +776,7 @@
     case IDENT_OLD_DAT :
     case IDENT_OLD_BIN :
     case IDENT_OLD_MEM :
-        ptrFile->mode = ptrFile->mode_h = MODE_B19 ;
+        fileInfo.mode = fileInfo.mode_h = MODE_B19 ;
         break ;
 
     case IDENT_NEW_TEL :
@@ -790,43 +790,43 @@
     case IDENT_EXT_BAS :
     case IDENT_NEW_DAT :
     case IDENT_NEW_BIN :
-        ptrFile->mode = ptrFile->mode_h = MODE_B16 ;
+        fileInfo.mode = fileInfo.mode_h = MODE_B16 ;
         break ;
 
     default :
         debug_printf ("%s: Unknown Ident\n", argP) ;
-        ptrFile->mode = ptrFile->mode_h = MODE_B21 ;
+        fileInfo.mode = fileInfo.mode_h = MODE_B21 ;
         return (ERR_ARG);
     }
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Header ptrFile->mode_h %u\n\r",ptrFile->mode_h);
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Header fileInfo.mode_h %u\n\r",fileInfo.mode_h);
 
     /* Write the TAPE code */
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Write the TAPE code\n\r");
-    error = WriteByteToWav ( (ulong) ptrFile->ident, ORDER_STD, ptrFile->mode_h, ptrFile) ;
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Write the TAPE code\n\r");
+    error = WriteByteToWav ( (ulong) fileInfo.ident, ORDER_STD, fileInfo.mode_h ) ;
     if (error != ERR_OK) return ( error )  ;
 
     /* Write the Name */
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Write the Name\n\r");
-    error = WriteSaveNameToWav ( FileName, ptrFile->mode_h, ptrFile) ;
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG error (ERR_OK) %d (%d)\n\r", error, ERR_OK);
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Writing Name...\n\r");
+    error = WriteSaveNameToWav ( "NONAME", fileInfo.mode_h ) ; // NOT USING FILENAME !!
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG error (ERR_OK) %d (%d)\n\r", error, ERR_OK);
     if (error != ERR_OK) return ( error )  ;
-
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG set Body Data Mode\n\r");
-    switch (ptrFile->ident) { /* Body Data Mode */
+    
+    if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG set Body Data Mode\n\r");
+    switch (fileInfo.ident) { /* Body Data Mode */
         case IDENT_PC1211 :
-            ptrFile->mode = MODE_B20 ;
+            fileInfo.mode = MODE_B20 ;
             break ;
     
         case IDENT_PC121_DAT :
         case IDENT_OLD_BAS :
         case IDENT_OLD_BIN :
         case IDENT_OLD_MEM :
-            ptrFile->mode = MODE_B19 ;
+            fileInfo.mode = MODE_B19 ;
             break ;
     
         case IDENT_OLD_DAT :
         case IDENT_NEW_DAT :
-            ptrFile->mode = MODE_B15 ;
+            fileInfo.mode = MODE_B15 ;
         break ;
     
         case IDENT_EXT_BAS :
@@ -840,80 +840,76 @@
         case IDENT_NEW_CRD :
         case IDENT_NEW_BIN :
           // TODO (mr#2#): Check whitch MODE_B13 or _B14
-            if (cnvstr_upr && pcId < 1440) ptrFile->mode = MODE_B13 ; /*older part of new series*/
-            else  ptrFile->mode = MODE_B14 ;     /*new series and extended series*/
+            if (cnvstr_upr && pcId < 1440) fileInfo.mode = MODE_B13 ; /*older part of new series*/
+            else  fileInfo.mode = MODE_B14 ;     /*new series and extended series*/
             break ;
     
         default :
             debug_printf ("%s: Unknown Ident\n", argP) ;
             return ( ERR_ARG );
         }
-        if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Body ptrFile->mode %u\n\r", ptrFile->mode);
+        if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Body fileInfo.mode %u\n\r", fileInfo.mode);
 
-        ptrFile->total = 0 ; /* count bytes of body only */
+        fileInfo.total = 0 ; /* count bytes of body only */
                 
-        switch (ptrFile->ident) { /* header was written, write all data now */
+        switch (fileInfo.ident) { /* header was written, write all data now */
         /* ... 
         case 
         ... */
         case IDENT_NEW_BAS :
         case IDENT_NEW_CSL :
         case IDENT_EXT_BAS :
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG Write the datas\n\r");
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG Writing data...\n\r");
             /* Write the datas */
-//            info.mode = MODE_B13 ; /*PC-1403 and newer should be MODE_14 */
+//            info.mode = MODE_B13 ; /* PC-1403 and newer should be MODE_14 */
             /* the older simple algorithm seems to work as well, but this is now, what the PC does originally */
-            for ( ii = 0 ; ii < nbByte - 1 ; ++ii ) {
-                //if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG LOOP ii %u\n\r", ii);
-
-                inVal = FileStream[ii] ; // fgetc (srcFd) ;
-                if ( inVal == EOF ) break ; // premature ending shouldn't happen...
-
+            while  ( !isFileSendComplete() ) {
+                inVal = fileGetNext();
+                if ( inVal == EOF ) break ; // ending if 
                 if ( inVal == BAS_NEW_EOF ) {
-                    if (ptrFile->count + 1 == BLK_NEW && ptrFile->sum == 0xE1) { /* Constellation will generate 2-times BAS_NEW_EOF */
-                        printf ("\nERROR %i at %lu. byte, usually the low byte of a BASIC line number\n", ERR_SUM, ptrFile->total) ;
+                    if (fileInfo.count + 1 == BLK_NEW && fileInfo.sum == 0xE1) { /* Constellation will generate 2-times BAS_NEW_EOF */
+                        printf ("\nERROR %i at %lu. byte, usually the low byte of a BASIC line number\n", ERR_SUM, fileInfo.total) ;
                         printf ("This binary constellation activates the CLOAD bug of this series. The line\n") ;
                         printf ("number must be changed or minor changes done in the BASIC text before.\n") ;
                         /* Seldom Bug in CLOAD, for PC-1402/(01) at known ROM address: 40666 */
-                        if ((ptrFile->debug & 0x800) == 0 ) {
+                        if ((fileInfo.debug & 0x800) == 0 ) {
                             error = ERR_SUM ;
                             break ;
                         }
                     }
                 }
-                error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ;
+                error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, fileInfo.mode ) ;
                 if (error != ERR_OK) break ;
             }
             if (error != ERR_OK) break ;
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("\n\rDEBUG ii %u\n\r", ii);
-
-            inVal = FileStream[ii] ; // fgetc (srcFd) ; /* Read the last byte before EOF mark */
-            if (inVal == EOF) break ;
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("\n\rDEBUG ii %u\n\r", ii);
 
+            inVal = fileGetNext(); /* Read the last byte before EOF mark */
+            if (inVal == EOF) break ;
             if (inVal == BAS_NEW_EOF) {
-                        /* EOF mark should not be included for this file type normally*/
-                        if (Qcnt == 0) printf ("End of File mark %i should not be included in the image\n", inVal) ;
-                        /* if end of block, then an additional checksum would be written, but this does work anyhow */
+                /* EOF mark should not be included for this file type normally*/
+                if (Qcnt == 0) printf ("End of File mark %i should not be included in the image\n", inVal) ;
+                /* if end of block, then an additional checksum would be written, but this does work anyhow */
             }
             else {
-                if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG last byte: %02X\n\r", (uchar) inVal);
-                error = WriteByteToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ;
+                if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG last byte: %02X\n\r", (uchar) inVal);
+                error = WriteByteToWav ( (uint) inVal, ORDER_STD, fileInfo.mode ) ;
                 if (error != ERR_OK) break ;
-                CheckSumB1 ((uint) inVal, ptrFile) ; /* never write the checksum before BAS_NEW_EOF */
+                CheckSumB1 ((uint) inVal ) ; /* never write the checksum before BAS_NEW_EOF */
 
-                ++ptrFile->total ;
-                ++ptrFile->count ; /* for debug purposes only, WriteFooter will reset it */
+                ++fileInfo.total ;
+                ++fileInfo.count ; /* for debug purposes only, WriteFooter will reset it */
             }
 
             /* Write the END code */
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG WriteFooterToNewWav\n\r");
-            error = WriteFooterToNewWav (ptrFile) ;
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG WriteFooterToNewWav\n\r");
+            error = WriteFooterToNewWav ( ) ;
 
             break ; // IDENT_NEW_BAS, IDENT_EXT_BAS
 
         case IDENT_NEW_BIN :
             /* Write the address and length */
-            error = WriteHeadToBinWav (addr, nbByte, ptrFile->mode_h, ptrFile) ;
+            error = WriteHeadToBinWav (addr, nbByte, fileInfo.mode_h ) ;
             if (error != ERR_OK) break ;
             /* no break */
 
@@ -923,28 +919,28 @@
         case IDENT_NEW_CRD :
 
             /* Write the datas */
-            for ( ii = 0 ; ii < nbByte - 1 ; ++ii ) {
-                inVal = FileStream[ii] ; // fgetc (srcFd) ;
-                if (inVal == EOF) break ; // premature ending shouldn't happen ...
+            while  ( !isFileSendComplete() ) {
+                inVal = fileGetNext();
+                if (inVal == EOF ) break ; // premature ending shouldn't happen ...
 
-                error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ;
+                error = WriteByteSumToWav ( (uint) inVal, ORDER_STD, fileInfo.mode ) ;
                 if (error != ERR_OK) break ;
             }
             if (error != ERR_OK) break ;
 
-            inVal = FileStream[ii] ; // fgetc (srcFd) ; /* Read the last byte before EOF mark */
+            inVal = fileGetNext();
             if (inVal == EOF) break ;
 
-            if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("DEBUG %02X", (uchar) inVal);
-            error = WriteByteToWav ( (uint) inVal, ORDER_STD, ptrFile->mode, ptrFile) ;
+            if ( (fileInfo.debug & 0x0040) > 0 ) debug_printf("DEBUG %02X", (uchar) inVal);
+            error = WriteByteToWav ( (uint) inVal, ORDER_STD, fileInfo.mode ) ;
             if (error != ERR_OK) break ;
-            CheckSumB1 ( (uint) inVal, ptrFile ) ; /* never write the checksum before BAS_NEW_EOF */
-            ++ptrFile->total ;
-            ++ptrFile->count ; /* for debug purposes only, WriteFooter will reset it */
+            CheckSumB1 ( (uint) inVal  ) ; /* never write the checksum before BAS_NEW_EOF */
+            ++fileInfo.total ;
+            ++fileInfo.count ; /* for debug purposes only, WriteFooter will reset it */
 
             /* Write the END code */
-            if ( ptrFile->ident == IDENT_NEW_BIN) error = WriteFooterToNewWav ( ptrFile ) ;
-            else WriteFooterToMemoWav ( ptrFile ) ;
+            if ( fileInfo.ident == IDENT_NEW_BIN) error = WriteFooterToNewWav ( ) ;
+            else WriteFooterToMemoWav ( ) ;
 
             break ; // IDENT_NEW_BIN and IDENT_NEW_Memos
         default:
@@ -953,7 +949,7 @@
             break;
         }        
 
-    if ( (ptrFile->debug & 0x0040) > 0 ) debug_printf("\n\rDEBUG FileSend error %d\n\r", error);
     return (error);
 
-}
\ No newline at end of file
+}
+
--- a/send_pc1403.h	Wed Feb 23 12:24:16 2022 +0000
+++ b/send_pc1403.h	Tue Mar 29 10:06:20 2022 +0000
@@ -1,22 +1,29 @@
 #ifndef SEND_PC1403
 #define SEND_PC1403
 
+#include "mbed.h" 
+
+#include "serial_file.h" // file-over-serial
+#ifndef FILE_BUF_SIZE 
+#include "bin_file.h"  // hardcoded file stream
+#endif
+
+#include "bit_send.h"
+
 // remapping to MBed types
-#include "mbed.h" 
 #define uchar  uint8_t
 #define ushort uint16_t
 #define uint   uint32_t
 #define ulong  uint32_t
 
-
 #define  PC_ID          1403 
 #define  TYPE_BIN_ADDR  0xE030 
 
 //  bit timings
-#define BIT_DURATION       (8*250) //  us, PC1403
-#define SYNC_DURATION      3    // s
+#define BIT_DURATION       (8*250) // us, PC1403
+#define SYNC_DURATION      1       // seconds
 #define N_SYNC_BITS        SYNC_DURATION * 1000000 / BIT_DURATION  
-#define MAX_BIT_TIME_ERR   10000 // timing error, per bit: 10ms - UNLIKELY!!
+#define MAX_BIT_TIME_ERR   50000 // timing error, per bit: 50ms - UNLIKELY!!
 
 #define argP "" // main NOT using command-line input arguments
 
@@ -231,6 +238,8 @@
     uint  stopb2 ;
 } ModeInfo ;
 
+extern FileInfo  fileInfo ; // extern, for other modules too
+
 ///////////////////////////////////////
 // static variables
 static ModeInfo Mode[] = { /* stop bits of first and second nibble */
@@ -240,7 +249,7 @@
 
 static bool bitMirroring = false ;
 
-static ulong CodeOld[] = {
+const static char CodeOld[] = {
     0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
     0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
     0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
@@ -260,10 +269,21 @@
 } ;
 
 
-
 ////////////////////////////////////////////////////////////////////////////////
 // published method
+int sharp_fileloop ( FileInfo*  ptrFile ) ;
+int FileSend ( void );
 
-int FileSend ( char* FileName, char* FileStream, uint FileSize, FileInfo*  ptrFile );
+// From Pocket Tools
+int WriteSaveNameToWav (char*  ptrName,
+                        uchar  mode);
+int WriteFooterToMemoWav ( void );
+int WriteSyncToWav (ulong  nbSync);
+int WriteByteSumToWav (ulong  value,
+                       uchar  order,
+                       uchar  mode);
+int WriteByteSumToWav (ulong  value,
+                       uchar  order,
+                       uchar  mode);
 
 #endif // SEND_PC1403
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/serial_file.cpp	Tue Mar 29 10:06:20 2022 +0000
@@ -0,0 +1,60 @@
+#include "serial_file.h"
+// file-over-serial implementation, using a circular buffer
+// between feeder, pushing data received from serial port,
+// and consumer, pulling and sending to sharp PC
+// Serial is not buffered on the MBed board
+// Sharp PC data sending is timed by the bit-handler modulator
+// Since neither can be stopped, assumptions are:
+// - feeder must be faster than consumer
+// - buffer (although circular) limits maximum size to be processed
+
+Timer timeout;
+
+// volatile because shared among 
+volatile int totBytesReceived;
+volatile int fileBufReceivePtr; 
+volatile int fileBufSendPtr; 
+volatile int fileReceiveComplete;
+volatile int fileError;
+volatile char fileOverSerialBuffer[FILE_BUF_SIZE];   // circular file buffer (for serial get)
+
+extern DigitalOut  my_led;
+extern Ticker      blink;
+
+void  fileReceiveInit( void ) {
+    
+    totBytesReceived = 0;
+    fileBufReceivePtr = 0; 
+    fileBufSendPtr = 0; 
+    fileReceiveComplete = false;
+    fileError = 0;
+    timeout.stop();
+    timeout.reset();
+    
+}
+
+char  filePullData ( void ) {
+    return ( fileOverSerialBuffer[ ((fileBufSendPtr++)%FILE_BUF_SIZE) ] ); 
+}
+
+void   filePushData ( char byte ) {
+    fileOverSerialBuffer[ ((fileBufReceivePtr++)%FILE_BUF_SIZE) ] = byte;
+    if ( fileOverSerialBuffer[fileBufReceivePtr] == '0xFF' ) { // terminator char, force receive end
+        fileReceiveComplete = true;
+        fileError = ERR_FILE_TERMINATED;
+        blink.detach( );
+        my_led = 1;
+        return;
+    }
+    if ( fileBufReceivePtr == fileBufSendPtr ) { // buffer not large enough, feeder reached consumer
+        fileReceiveComplete = true;
+        fileError = ERR_FILE_BUF_FULL;
+        blink.detach( );
+        my_led = 1;
+        return;
+    }
+}
+
+bool  isFilePullComplete( void ) {
+  return ( fileBufSendPtr == fileBufReceivePtr - 1 ) ;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/serial_file.h	Tue Mar 29 10:06:20 2022 +0000
@@ -0,0 +1,22 @@
+#ifndef FILE_BUF_SIZE
+#define FILE_BUF_SIZE 1024
+#include "mbed.h" 
+
+#define  ERR_FILE_BUF_FULL   10
+#define  ERR_FILE_TERMINATED 20
+
+// shared with other modules
+extern Timer timeout;
+extern volatile int totBytesReceived;
+extern volatile int fileBufReceivePtr; 
+extern volatile int fileBufSendPtr; 
+extern volatile int fileReceiveComplete;
+extern volatile int fileError;
+extern volatile char fileOverSerialBuffer[];
+
+void  fileReceiveInit( void );
+char  filePullData ( void ) ;
+void  filePushData ( char byte ) ;
+bool  isFilePullComplete( void );
+
+#endif
\ No newline at end of file