Just4Trionic - CAN and BDM FLASH programmer for Saab cars

Dependencies:   mbed

Revision:
0:e0b964252a05
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SRecUtils.cpp	Wed May 19 12:39:18 2010 +0000
@@ -0,0 +1,40 @@
+
+#include "SRecUtils.h"
+
+// SRecGetByte
+//
+// Returns an int which is a single byte made up from two ascii characters read from an S-record file
+//
+// inputs:	a file pointer for the S-record file
+// return:	an integer which is the byte in hex format
+
+int SRecGetByte(FILE *fp) {
+    int c = 0;
+    int retbyte = 0;
+
+    for(int i=0; i<2; i++) {
+        if ((c = fgetc(fp)) == EOF) return -1;
+        c -= (c > '9') ? ('A' - 10) : '0';
+        retbyte = (retbyte << 4) + c;
+    }
+    return retbyte;
+}
+
+// SRecGetAddress
+//
+// Returns an int which is the address part of the S-record line
+// The S-record type 1/2/3 or 9/8/7 determines if there are 2, 3 or 4 bytes in the address
+//
+// inputs:	an integer which is the number of bytes that make up the address; 2, 3 or 4 bytes
+//			a file pointer for the S-record file
+// return:	an integer which is the load address for the S-record
+
+int SRecGetAddress(int size, FILE *fp) {
+    int address = 0;
+    for (int i = 0; i<size; i++)
+    {
+        address <<= 8;
+        address |= SRecGetByte (fp);
+    }
+    return address;
+}
\ No newline at end of file