@@ -29,6 +29,9 @@ spectranext_state_t spectranext_state = {
2929static char scan_ap_names [SPECTRANEXT_SCAN_AP_MAX ][64 ];
3030static uint8_t scan_ap_count ;
3131
32+ static char pending_message [SPECTRANEXT_MESSAGE_MAX ];
33+ static bool message_pending ;
34+
3235volatile struct spectranext_controller_t spectranext_controller = {
3336 .command = SPECTRANEXT_CMD_REG_IDLE ,
3437 .status = SPECTRANEXT_STATUS_SUCCESS ,
@@ -57,6 +60,52 @@ static void spectranext_set_status(uint8_t status)
5760 spectranext_controller .status = status ;
5861}
5962
63+ bool spectranext_controller_post_message_bytes (const uint8_t * message , size_t length )
64+ {
65+ if (message == NULL && length != 0u )
66+ return false;
67+
68+ if (length >= SPECTRANEXT_MESSAGE_MAX )
69+ length = SPECTRANEXT_MESSAGE_MAX - 1u ;
70+
71+ if (length != 0u )
72+ memcpy (pending_message , message , length );
73+ pending_message [length ] = '\0' ;
74+ message_pending = true;
75+
76+ return true;
77+ }
78+
79+ bool spectranext_controller_post_message (const char * message )
80+ {
81+ if (message == NULL )
82+ return false;
83+
84+ return spectranext_controller_post_message_bytes ((const uint8_t * )message , strlen (message ));
85+ }
86+
87+ void spectranext_controller_clear_messages (void )
88+ {
89+ pending_message [0 ] = '\0' ;
90+ message_pending = false;
91+ }
92+
93+ static void spectranext_controller_get_message (void )
94+ {
95+ memset ((void * )& spectranext_controller .workspace .get_message .out , 0 ,
96+ sizeof (spectranext_controller .workspace .get_message .out ));
97+
98+ if (message_pending )
99+ {
100+ memcpy ((void * )spectranext_controller .workspace .get_message .out .message , pending_message ,
101+ sizeof (spectranext_controller .workspace .get_message .out .message ));
102+ spectranext_controller .workspace .get_message .out .pending = 1u ;
103+ spectranext_controller_clear_messages ();
104+ }
105+
106+ spectranext_set_status (SPECTRANEXT_STATUS_SUCCESS );
107+ }
108+
60109static void spectranext_controller_process_command (void )
61110{
62111 const uint8_t cmd = spectranext_controller .command ;
@@ -188,6 +237,10 @@ static void spectranext_controller_process_command(void)
188237 spectranext_set_status ((uint8_t )(int8_t )spectranext_enginecall_args .result );
189238 break ;
190239
240+ case SPECTRANEXT_CMD_GET_MESSAGE :
241+ spectranext_controller_get_message ();
242+ break ;
243+
191244 default :
192245 spectranext_set_status (SPECTRANEXT_STATUS_ERROR );
193246 break ;
@@ -202,6 +255,7 @@ void spectranext_controller_init(void)
202255 spectranext_state .connection_status = WIFI_CONNECT_CONNECT_IP_OBTAINED ;
203256 spectranext_state .ipv4_host = 0x7f000001u ;
204257 scan_ap_count = 0 ;
258+ spectranext_controller_post_message ("FuseX: OK\n" );
205259}
206260
207261libspectrum_byte spectranext_controller_read (memory_page * page , libspectrum_word address )
0 commit comments