just some more cleanups..

This commit is contained in:
Solomon Peachy 2013-12-22 19:29:27 -05:00
parent 46a3d1fa6a
commit 42cdb26c32
3 changed files with 37 additions and 24 deletions

View File

@ -114,9 +114,9 @@ int main(int argc, const char* argv[]){
} }
poptFreeContext(popt_aldl); // free the popt context poptFreeContext(popt_aldl); // free the popt context
// ======================================================================== // =======================================================
// CONNECT / VERIFY ALDL INTERFACE // CONNECT / VERIFY ALDL INTERFACE
// ======================================================================== // =======================================================
// Establish a connection to the aldl // Establish a connection to the aldl
// =================================== // ===================================
@ -131,16 +131,27 @@ int main(int argc, const char* argv[]){
return -1; return -1;
} }
// set the custom baud rate: /* Set custom baud rate:
// the ALDL interface operates at 8192. it would be preferable to get as close to this ALDL has two variants;
// baud rate as possible. if it cannot be set; it should still work at the standard 1) 160 baud with non-RS232 framing. Clock up to 1600 baud
// baud rate of 9600; the framing errors aren't excessive enough to cause problems, and take one byte from each bit to get us the 8 data bits
// and will be caught by bad checksums. plus one start and one stop bit.
2) 8192 baud with RS232 framing.
Prefer to set exact baud rate if possible, but they are non-standard
PC datarates..
8192 should work at 9600; the packets are short enough that framing
errors should be minimal and checksums will catch them anyway.
*/
aldl_settings.customrate = 1;
if (set_custom_baud_rate(aldl_settings.faldl, aldl_settings.definition->ideal_baudrate)!=0) { if (set_custom_baud_rate(aldl_settings.faldl, aldl_settings.definition->ideal_baudrate)!=0) {
fprintf(stderr," Couldn't set baud rate to %d. Using standard rate (%d).\n", fprintf(stderr," Couldn't set baud rate to %d. Using standard rate (%d).\n",
aldl_settings.definition->ideal_baudrate, aldl_settings.definition->ideal_baudrate,
aldl_settings.definition->basic_baudrate); aldl_settings.definition->basic_baudrate);
fprintf(stderr," There may be framing errors.\n"); fprintf(stderr," There may be framing errors.\n");
aldl_settings.customrate = 0;
} }
// verify the aldl // verify the aldl
@ -175,9 +186,9 @@ int main(int argc, const char* argv[]){
} }
// ======================================================================== // ============================================================
// CLEANUP (FLUSH SERIAL LINE, CLOSE PORT) // CLEANUP (FLUSH SERIAL LINE, CLOSE PORT)
// ======================================================================== // ============================================================
// discard any unwritten data // discard any unwritten data
tcflush(aldl_settings.faldl, TCIOFLUSH); tcflush(aldl_settings.faldl, TCIOFLUSH);
@ -253,7 +264,7 @@ int send_aldl_message(char* msg_buf, unsigned int size)
// so that mode 8 isn't even required. // so that mode 8 isn't even required.
int get_mode1_message(char* inbuffer, unsigned int size) int get_mode1_message(char* inbuffer, unsigned int size)
{ {
int res; int res = 0;
char outbuffer[__MAX_REQUEST_SIZE]; // max request size defined in linuxaldl_definitions.h char outbuffer[__MAX_REQUEST_SIZE]; // max request size defined in linuxaldl_definitions.h
aldl_definition* def = aldl_settings.definition; aldl_definition* def = aldl_settings.definition;
@ -287,6 +298,7 @@ int get_mode1_message(char* inbuffer, unsigned int size)
seq, 3, 0, seq, 3, 0,
aldl_settings.scan_timeout*1000); aldl_settings.scan_timeout*1000);
} else { } else {
/* Wait for Framing START ? */
// XXX what sequence to match for 160baud rate? // XXX what sequence to match for 160baud rate?
} }

View File

@ -120,7 +120,7 @@ typedef struct _linuxaldl_definition {
// message is the 4th byte onward, this should be 3. (1+3 = 4) // message is the 4th byte onward, this should be 3. (1+3 = 4)
byte_def_t* mode1_def; // pointer to start of table of byte_def_t structs. byte_def_t* mode1_def; // pointer to start of table of byte_def_t structs.
// the last element must be LINUXALDL_MODE1_END_DEF // the last element must be LINUXALDL_MODE1_END_DEF
char mode8_request[__MAX_REQUEST_SIZE]; // the mode 8 (silence) request message, incl checksum char mode8_request[__MAX_REQUEST_SIZE]; // the mode 8 (silence) request message, incl checksum
unsigned int mode8_request_length; // the length of the mode 8 message incl checksum unsigned int mode8_request_length; // the length of the mode 8 message incl checksum
@ -141,31 +141,32 @@ typedef struct _linuxaldl_settings
{ {
/* Configuration fields */ /* Configuration fields */
const char* aldlportname; // path to aldl interface port const char* aldlportname; // path to aldl interface port
const char* logfilename; // filename for the log file const char* logfilename; // filename for the log file
const char* aldldefname; // name for the ALDL definition to be used const char* aldldefname; // name for the ALDL definition to be used
unsigned int scan_interval; // msec between scan requests unsigned int scan_interval; // msec between scan requests
unsigned int scan_timeout; // msec to timeout on scan request. unsigned int scan_timeout; // msec to timeout on scan request.
// note that read-sequence takes timeout in usec. // usec = msec*1000 // note that read-sequence takes timeout in usec.
// usec = msec*1000
/* Data definitions */ /* Data definitions */
aldl_definition** aldl_definition_table; // array of pointers to data definitions. (see linuxaldl_definitions.h) aldl_definition** aldl_definition_table; // array of pointers to data definitions. (see linuxaldl_definitions.h)
/* Runtime stuff */ /* Runtime stuff */
int faldl; // aldl serial interface file descriptor int customrate; // 1 if we are using accurate datarate.
int faldl; // aldl serial interface file descriptor
int flogfile; // file descriptor for log file int flogfile; // file descriptor for log file
int scanning; // 1 when the timer has been set for making scans, otherwise 0. int scanning; // 1 when the timer has been set for making scans, otherwise 0.
aldl_definition* definition; // see linuxaldl_definitions.h aldl_definition* definition; // see linuxaldl_definitions.h
char* data_set_raw; // the current/most recent set of data from a mode1 message. char* data_set_raw; // the current/most recent set of data from a mode1 message.
// this is allocated when a definition is selected // this is allocated when a definition is selected
char** data_set_strings; // pointer to array of data set in string format. char** data_set_strings;// pointer to array of data set in string format.
// allocated when a definition is selected in the GUI // allocated when a definition is selected in the GUI
float* data_set_floats; // data set in float format
// allocated when a definition is selected in the GUI
float* data_set_floats; // data set in float format
// allocated when a definition is selected in the GUI
} linuxaldl_settings; } linuxaldl_settings;
// function prototypes // function prototypes

View File

@ -255,7 +255,7 @@ aldl_definition aldl_9A = { .mask = "9A",
.mode1_data_offset = 1, .mode1_data_offset = 1,
.mode1_def = aldl_9A_mode1, .mode1_def = aldl_9A_mode1,
.basic_baudrate = B4800, .basic_baudrate = B4800,
.ideal_baudrate = 160, .ideal_baudrate = 1600, /* ie basic baud rate / 3 */
}; };
/* Definition table */ /* Definition table */