Add to 11U68 11E68

Dependencies:   DirectoryList MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Committer:
okano
Date:
Fri Sep 13 12:56:23 2013 +0000
Revision:
26:a63e73885b21
Parent:
22:bd98a782fba6
Child:
27:2b5c1eb39bb5
code is still dirty but it works. I hope I will have chance to clean up some day...

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 22:bd98a782fba6 71 void 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 22:bd98a782fba6 76 try_and_check( command, "OK", 0 );
okano 22:bd98a782fba6 77 }
okano 22:bd98a782fba6 78
okano 22:bd98a782fba6 79
okano 26:a63e73885b21 80 void erase_sectors( int last_sector )
okano 26:a63e73885b21 81 {
okano 26:a63e73885b21 82 char command_str[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 83
okano 26:a63e73885b21 84 sprintf( command_str, "P 0 %d\r\n", last_sector );
okano 26:a63e73885b21 85 try_and_check( command_str, "0", 0 );
okano 26:a63e73885b21 86
okano 26:a63e73885b21 87 *(command_str) = 'E';
okano 26:a63e73885b21 88 try_and_check( command_str, "0", 0 );
okano 26:a63e73885b21 89 }
okano 26:a63e73885b21 90
okano 26:a63e73885b21 91