summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-07-15 05:34:22 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-07-15 05:34:22 +0000
commite644919d89a8b8799d8a85b58c7af3504dc01358 (patch)
treeb57826a5aea880a951d3053f193706481a743401
parent2af9e393322183b1ac41c00ba5d4a11ce14f869e (diff)
downloadgpsd-e644919d89a8b8799d8a85b58c7af3504dc01358.tar.gz
Remove SiRF-specific assumptions from srecord.c and add it to libgps.c
for future use.
-rw-r--r--Makefile.am3
-rw-r--r--gpsd.h8
-rw-r--r--gpsflash.c4
-rw-r--r--gpsflash.h11
-rw-r--r--srecord.c44
5 files changed, 34 insertions, 36 deletions
diff --git a/Makefile.am b/Makefile.am
index 97cf2f58..1c3b1ad2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -63,7 +63,7 @@ rtcmdecode_LDADD = $(LIBM) -lncurses libgps.la -lm $(LIBPTHREAD)
#
# Build gpsflash
#
-gpsflash_SOURCES = gpsflash.c gpsflash.h srecord.c utils.c
+gpsflash_SOURCES = gpsflash.c gpsflash.h utils.c
gpsflash_LDADD = $(LIBM) libgps.la -lm
#
@@ -93,6 +93,7 @@ libgps_c_sources = \
report.c \
rtcm.c \
rtcm.h \
+ srecord.c \
bits.h \
timebase.h
diff --git a/gpsd.h b/gpsd.h
index 05c40100..80bf7548 100644
--- a/gpsd.h
+++ b/gpsd.h
@@ -243,6 +243,14 @@ extern void ecef_to_wgs84fix(struct gps_data_t *,
double, double, double);
extern gps_mask_t dop(struct gps_data_t *);
+/* srecord.c */
+extern void hexdump(int , unsigned char *, unsigned char *);
+extern unsigned char sr_sum(int, int, unsigned char *);
+extern int bin2srec(int, int, int, unsigned char *, unsigned char *);
+extern int srec_hdr(int num, unsigned char *bbuf, unsigned char *sbuf);
+extern int srec_fin(int, unsigned char *);
+extern char hc(char);
+
/* External interface */
extern void gpsd_init(struct gps_device_t *,
struct gps_context_t *, char *device);
diff --git a/gpsflash.c b/gpsflash.c
index 65e33674..44de60c3 100644
--- a/gpsflash.c
+++ b/gpsflash.c
@@ -189,3 +189,7 @@ usage(void){
exit(1);
}
+/*
+ dlgsp2.bin looks for this header
+ unsigned char hdr[] = "S00600004844521B\r\n";
+*/
diff --git a/gpsflash.h b/gpsflash.h
index 98057dff..3ca09584 100644
--- a/gpsflash.h
+++ b/gpsflash.h
@@ -66,7 +66,7 @@
#define WRBLK 128
/* Prototypes */
-/* sirfflash.c */
+/* gpsflash.c */
int main(int, char **);
void usage(void);
@@ -80,13 +80,4 @@ int sirfSendFirmware(int, char *, int);
int sirfWrite(int, unsigned char *);
unsigned char nmea_checksum(unsigned char *);
-/* srecord.c */
-void hexdump(int , unsigned char *, unsigned char *);
-unsigned char sr_sum(int, int, unsigned char *);
-int bin2srec(int, int, unsigned char *, unsigned char *);
-int srec_hdr(unsigned char *);
-int srec_fin(int, unsigned char *);
-char hc(char);
-
-
#endif /* _GPSFLASH_H_ */
diff --git a/srecord.c b/srecord.c
index 2fb41cf5..122288bf 100644
--- a/srecord.c
+++ b/srecord.c
@@ -13,56 +13,54 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <stdio.h>
+#include <string.h>
-#ifdef _SRECORD_
-#include "cskprog.h"
+#include "gpsd.h"
/*
- * http://www.amelek.gda.pl/avr/uisp/srecord.htm
+ * See srec(5) for a description of this format.
+ * We read and write 4-byte addresses.
* S0: Comments
* S3: Memory Loadable Data, 4byte address
* S5: Count of S1, S2 and S3 Records
- * S7: starting execution address intrepreted as a 4byte address
+ * S7: starting execution address intrepreted as a 4-byte address
*/
+#define MAX_BYTES_PER_RECORD 16
/*
- * bin2srec: turn a chunk of binary into an srecord file
+ * bin2srec: turn a chunk of binary into an S-record
* offset: used to specify load address
- * num: up to 16 bytes can be encoded at one time
+ * num: up to MAX_BYTES_PER_RECORD bytes can be encoded at one time
* bytes are read from bbuf and a ready-to-go srecord is placed in sbuf
*/
int
-bin2srec(int offset, int num, unsigned char *bbuf, unsigned char *sbuf){
- unsigned char abuf[34], sum;
+bin2srec(int type, int offset, int num, unsigned char *bbuf, unsigned char *sbuf){
+ unsigned char abuf[MAX_BYTES_PER_RECORD*2 + 2], sum;
int len;
- if ((num < 1) || (num > 16))
+ if ((num < 1) || (num > MAX_BYTES_PER_RECORD))
return -1;
len = 4 + num + 1;
- bzero(abuf, 34);
- bzero(sbuf, 64);
+ memset(abuf, 0, sizeof(abuf));
hexdump(num, bbuf, abuf);
sum = sr_sum(len, offset, bbuf);
- snprintf((char *)sbuf, 49, "S3%02X%08X%s%02X\r\n", len, offset, abuf, sum);
+ snprintf((char *)sbuf, MAX_BYTES_PER_RECORD*2 + 17,
+ "S%d%02X%08X%s%02X\r\n", type, len, offset, abuf, sum);
return 0;
}
int
-srec_hdr(unsigned char *sbuf){
- /* dlgsp2.bin looks for this header */
- unsigned char hdr[] = "S00600004844521B\r\n";
- bzero(sbuf, 64);
- snprintf((char *)sbuf, 19, "%s", hdr);
- return 0;
+srec_hdr(int num, unsigned char *bbuf, unsigned char *sbuf){
+ return bin2srec(0, 0, num, bbuf, sbuf);
}
int
srec_fin(int num, unsigned char *sbuf){
unsigned char bbuf[4], sum;
- bzero(bbuf, 4);
- bzero(sbuf, 64);
+ memset(bbuf, 0, 4);
bbuf[0] = (unsigned char)(num & 0xff);
bbuf[1] = (unsigned char)((num >> 8) & 0xff);
@@ -76,7 +74,7 @@ void
hexdump(int j, unsigned char *bbuf, unsigned char *abuf){
int i;
- bzero(abuf, 34);
+ memset(abuf, 0, MAX_BYTES_PER_RECORD*2 + 2);
if (j > 32)
j = 32;
@@ -133,7 +131,3 @@ sr_sum(int count, int addr, unsigned char *bbuf){
}
return ~sum;
}
-
-#else
-extern int errno;
-#endif