Add to 11U68 11E68

Dependencies:   DirectoryList MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Committer:
okano
Date:
Thu Sep 19 01:08:20 2013 +0000
Revision:
27:2b5c1eb39bb5
Parent:
26:a63e73885b21
Child:
29:96e28bc1bd99
{cannot be build} an a precess of clean-up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 22:bd98a782fba6 1 #include "mbed.h"
okano 22:bd98a782fba6 2 #include "command_interface.h"
okano 22:bd98a782fba6 3 #include "serial_utilities.h"
okano 22:bd98a782fba6 4 #include "ika.h"
okano 22:bd98a782fba6 5
okano 22:bd98a782fba6 6
okano 22:bd98a782fba6 7 int try_and_check( char *command, char *expected_return_str, int mode )
okano 22:bd98a782fba6 8 {
okano 22:bd98a782fba6 9 char rtn_str[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 10 int result = 1;
okano 22:bd98a782fba6 11
okano 22:bd98a782fba6 12 print_command( command );
okano 22:bd98a782fba6 13 put_string( command );
okano 22:bd98a782fba6 14
okano 22:bd98a782fba6 15 get_string( rtn_str );
okano 22:bd98a782fba6 16 print_result( result = strcmp( expected_return_str, rtn_str ) );
okano 22:bd98a782fba6 17
okano 22:bd98a782fba6 18 if ( result && !mode )
okano 22:bd98a782fba6 19 error( "command failed\r\n" );
okano 22:bd98a782fba6 20
okano 22:bd98a782fba6 21 error_state |= result;
okano 22:bd98a782fba6 22
okano 22:bd98a782fba6 23 return ( result );
okano 22:bd98a782fba6 24 }
okano 22:bd98a782fba6 25
okano 22:bd98a782fba6 26
okano 22:bd98a782fba6 27 int try_and_check2( char *command, char *expected_return_str, int mode )
okano 22:bd98a782fba6 28 {
okano 22:bd98a782fba6 29 char rtn_str[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 30 int result = 1;
okano 22:bd98a782fba6 31
okano 22:bd98a782fba6 32 print_command( command );
okano 22:bd98a782fba6 33 put_string( command );
okano 22:bd98a782fba6 34
okano 22:bd98a782fba6 35 get_string( rtn_str ); // just readout echoback
okano 22:bd98a782fba6 36 get_string( rtn_str );
okano 22:bd98a782fba6 37 print_result( result = strcmp( expected_return_str, rtn_str ) );
okano 22:bd98a782fba6 38
okano 22:bd98a782fba6 39 if ( result && !mode )
okano 22:bd98a782fba6 40 error( "command failed\r\n" );
okano 22:bd98a782fba6 41
okano 22:bd98a782fba6 42 error_state |= result;
okano 22:bd98a782fba6 43
okano 22:bd98a782fba6 44 return ( result );
okano 22:bd98a782fba6 45 }
okano 22:bd98a782fba6 46
okano 22:bd98a782fba6 47
okano 22:bd98a782fba6 48 void print_command( char *command )
okano 22:bd98a782fba6 49 {
okano 22:bd98a782fba6 50 char s[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 51 char *pos;
okano 22:bd98a782fba6 52
okano 22:bd98a782fba6 53 strcpy( s, command );
okano 22:bd98a782fba6 54
okano 22:bd98a782fba6 55 if ( pos = strchr( s, '\r' ) )
okano 22:bd98a782fba6 56 *pos = '\0';
okano 22:bd98a782fba6 57
okano 22:bd98a782fba6 58 if ( pos = strchr( s, '\n' ) )
okano 22:bd98a782fba6 59 *pos = '\0';
okano 22:bd98a782fba6 60
okano 22:bd98a782fba6 61 printf( " command-\"%s\" : ", s );
okano 22:bd98a782fba6 62 }
okano 22:bd98a782fba6 63
okano 22:bd98a782fba6 64
okano 22:bd98a782fba6 65 void print_result( int r )
okano 22:bd98a782fba6 66 {
okano 22:bd98a782fba6 67 printf( "%s\r\n", r ? "Fail" : "Pass" );
okano 22:bd98a782fba6 68 }
okano 22:bd98a782fba6 69
okano 22:bd98a782fba6 70
okano 27:2b5c1eb39bb5 71 int send_RAM_transfer_checksum( int checksum )
okano 22:bd98a782fba6 72 {
okano 22:bd98a782fba6 73 char command[ 16 ];
okano 22:bd98a782fba6 74
okano 22:bd98a782fba6 75 sprintf( command, "%d\n", checksum );
okano 27:2b5c1eb39bb5 76
okano 27:2b5c1eb39bb5 77 return ( try_and_check( command, "OK", 0 ) );
okano 22:bd98a782fba6 78 }
okano 22:bd98a782fba6 79
okano 22:bd98a782fba6 80
okano 27:2b5c1eb39bb5 81 int erase_sectors( int last_sector )
okano 26:a63e73885b21 82 {
okano 26:a63e73885b21 83 char command_str[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 84
okano 26:a63e73885b21 85 sprintf( command_str, "P 0 %d\r\n", last_sector );
okano 27:2b5c1eb39bb5 86 if ( try_and_check( command_str, "0", 0 ) )
okano 27:2b5c1eb39bb5 87 return ( 1 );
okano 26:a63e73885b21 88
okano 26:a63e73885b21 89 *(command_str) = 'E';
okano 27:2b5c1eb39bb5 90 return ( try_and_check( command_str, "0", 0 ) );
okano 26:a63e73885b21 91 }
okano 26:a63e73885b21 92
okano 26:a63e73885b21 93