[Dsctl-devel] SF.net SVN: dsctl: [138] firmware-work.c
Status: Alpha
Brought to you by:
roger-linux
|
From: <rog...@us...> - 2007-08-07 02:25:32
|
Revision: 138
http://dsctl.svn.sourceforge.net/dsctl/?rev=138&view=rev
Author: roger-linux
Date: 2007-08-06 19:25:29 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
firmware-work.c - Since I'm not going to be developing for a short term, I'm uploading the functions needing to be implemented for firmware load function.
Signed-off-by: Roger <ro...@es...>
Acked-by: Roger <ro...@es...>
Added Paths:
-----------
firmware-work.c
Added: firmware-work.c
===================================================================
--- firmware-work.c (rev 0)
+++ firmware-work.c 2007-08-07 02:25:29 UTC (rev 138)
@@ -0,0 +1,216 @@
+/***********************************************************************
+* Firmware Mode Get Model Info
+***********************************************************************/
+int fwmode_get_model_info(int fd, char *fwmode_model)
+{
+ char answer[100], command[100];
+
+ memset(answer, 0, 100);
+ memset(command, 0, 100);
+
+ snprintf(command, 100, "*MDL");
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ /* TODO: Some compatible scanners use "MOT" */
+ check_err(command, answer);
+
+ printf("%s\n", answer);
+ strcpy(fwmode_model, answer);
+
+ return (0);
+}
+
+/***********************************************************************
+* Firmware Mode Set Speed
+***********************************************************************/
+int fwmode_set_speed(int fd, int fwmode_speed)
+{
+ char answer[100], command[100];
+
+ memset(answer, 0, 100);
+ memset(command, 0, 100);
+
+ snprintf(command, 100, "*SPD %i", fwmode_speed);
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ check_err(command, answer);
+ printf("%s\n", answer);
+
+ return (0);
+}
+
+/***********************************************************************
+* Firmware Mode Set *PGL (NOT KNOWN - Clear Page Memory ???)
+***********************************************************************/
+int fwmode_set_pgl(int fd, int fwmode_pgl)
+{
+ char answer[100], command[100];
+
+ memset(answer, 0, 100);
+ memset(command, 0, 100);
+
+ snprintf(command, 100, "*PGL %i", fwmode_pgl);
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ check_err(command, answer);
+ printf("%s\n", answer);
+
+ return (0);
+}
+
+/***********************************************************************
+* Firmware Mode Set *ULE (NOT KNOWN - Unlock EEPROM ???)
+***********************************************************************/
+int fwmode_set_ule(int fd)
+{
+ char answer[100], command[100];
+
+ memset(answer, 0, 100);
+ memset(command, 0, 100);
+
+ snprintf(command, 100, "*ULE");
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ check_err(command, answer);
+ printf("ULE %s\n", answer);
+
+ return (0);
+}
+
+/***********************************************************************
+* Firmware Mode Set *SCB (NOT KNOWN - Send/Return Checksum Bytes ???)
+***********************************************************************/
+int fwmode_set_scb(int fd, int fwmode_scb)
+{
+ char answer[100], command[100];
+
+ memset(answer, 0, 100);
+ memset(command, 0, 100);
+
+ snprintf(command, 100, "*SCB %i", fwmode_scb);
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ check_err(command, answer);
+ printf("%s\n", answer);
+
+ return (0);
+}
+
+/***********************************************************************
+* Firmware Mode Enter Program Mode
+***********************************************************************/
+int fwmode_set_pgl(int fd, int fwmode_pgl)
+{
+ char answer[100], command[100];
+
+ memset(answer, 0, 100);
+ memset(command, 0, 100);
+
+ snprintf(command, 100, "*PGL %i", fwmode_pgl);
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ check_err(command, answer);
+ printf("Entered Firmware Mode Program Mode\n");
+
+ return (0);
+}
+
+/***********************************************************************
+* Firmware Mode Send File
+***********************************************************************/
+int fwmode_send_file(int fd, char *infile)
+{
+ /* Push InFile -- Last line "S804000000FB" triggers the
+ * following:
+ * "PROGRAM END"
+ * "CHECKSUM= EC8BH" */
+
+ char answer[100], command[100];
+
+ memset(answer, 0, 100);
+ memset(command, 0, 100);
+
+ snprintf(command, 100, "%s", line);
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ check_err(command, answer);
+
+ while (fgets(line, MAXLINELEN, infile) != NULL)
+ {
+ snprintf(command, 100, "%s", line);
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ check_err(command, answer);
+ }
+
+ /* TODO: Verify returned checksum is good! */
+ printf("%s", answer);
+
+ return (0);
+}
+
+/***********************************************************************
+* Firmware Mode Power Cycle
+***********************************************************************/
+int fwmode_powercycle(int fd)
+{
+ char answer[100], command[100];
+
+ memset(answer, 0, 100);
+ memset(command, 0, 100);
+
+ snprintf(command, 100, "*OFF");
+ /*printf("\nCommand == %s\n", command); */
+ do_command(fd, command, answer);
+ /*printf("%s\n(%i)\n", answer, strlen(answer)); */
+
+ check_err(command, answer);
+}
+
+/***********************************************************************
+* Load Firmware
+***********************************************************************/
+int load_firmware(int fd, int infile) /* blah -- see sync'ed svn version for approp func name! */
+{
+ fwmode_get_model_info(fd, fwmode_model);
+
+ if (strcmp(fwmode_model, "bcd996t") == 0)
+ {
+ printf("Found BCD996T Model\n");
+ /* TODO: Let the user specify custom speed
+ * SPD = 9600
+ * SPD 4 = 57600
+ * SPD 5 = 115200 */
+ fwmode_set_speed(fd, 5);
+
+ fwmode_set_pgl(fd, 1000000000000000000);
+ fwmode_set_ule(fd);
+ fwmode_set_scb(fd, 1);
+ fwmode_set_prg(fd);
+
+ printf("\nVerify You Want To Load Firmware? (Y/n):");
+ if (getchar() == 'Y')
+ fwmode_send_file(fd, infile);
+
+ printf("Firmware Load Appears Successful, Power Cycling Unit\n");
+ fwmode_powercycle(fd);
+ }
+
+ return (0);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|