Ika Shouyu Poppoyaki - LPC82x supported
Fork of ika_shouyu_poppoyaki by
command_interface.cpp
- Committer:
- okano
- Date:
- 2013-09-13
- Revision:
- 26:a63e73885b21
- Parent:
- 22:bd98a782fba6
- Child:
- 27:2b5c1eb39bb5
File content as of revision 26:a63e73885b21:
#include "mbed.h" #include "command_interface.h" #include "serial_utilities.h" #include "ika.h" int try_and_check( char *command, char *expected_return_str, int mode ) { char rtn_str[ STR_BUFF_SIZE ]; int result = 1; print_command( command ); put_string( command ); get_string( rtn_str ); print_result( result = strcmp( expected_return_str, rtn_str ) ); if ( result && !mode ) error( "command failed\r\n" ); error_state |= result; return ( result ); } int try_and_check2( char *command, char *expected_return_str, int mode ) { char rtn_str[ STR_BUFF_SIZE ]; int result = 1; print_command( command ); put_string( command ); get_string( rtn_str ); // just readout echoback get_string( rtn_str ); print_result( result = strcmp( expected_return_str, rtn_str ) ); if ( result && !mode ) error( "command failed\r\n" ); error_state |= result; return ( result ); } void print_command( char *command ) { char s[ STR_BUFF_SIZE ]; char *pos; strcpy( s, command ); if ( pos = strchr( s, '\r' ) ) *pos = '\0'; if ( pos = strchr( s, '\n' ) ) *pos = '\0'; printf( " command-\"%s\" : ", s ); } void print_result( int r ) { printf( "%s\r\n", r ? "Fail" : "Pass" ); } void send_RAM_transfer_checksum( int checksum ) { char command[ 16 ]; sprintf( command, "%d\n", checksum ); try_and_check( command, "OK", 0 ); } void erase_sectors( int last_sector ) { char command_str[ STR_BUFF_SIZE ]; sprintf( command_str, "P 0 %d\r\n", last_sector ); try_and_check( command_str, "0", 0 ); *(command_str) = 'E'; try_and_check( command_str, "0", 0 ); }