Add message sending and clean exit/quit

This commit is contained in:
Tobias Mädel 2021-07-04 22:48:11 +02:00
parent 6b63877aea
commit 21cc24d8b7
No known key found for this signature in database
GPG Key ID: 494E2F56C30460E1
4 changed files with 74 additions and 84 deletions

View File

@ -10,6 +10,7 @@
#include "network.h"
#include "clock-arch.h"
#include "hayes.h"
#include "uip/irc.h"
int __Serial_Open (unsigned char *mode);
int __Serial_Close (int mode);
@ -75,14 +76,18 @@ int main(void)
if (ui_handle_keyboard())
{
// Exit
/*irc_exit();
uint32_t now = clock_time();
while (clock_time() - now < 50)
if (!messagelength)
{
}*/
memcpy(messagebuffer, "QUIT", 4);
messagelength = 4;
uint32_t now = clock_time();
while ((clock_time() - now < 50) && messagelength)
{
network_poll();
}
}
gint_world_switch(GINT_CALL(casioos_Serial_Close));
return 1;
}

View File

@ -9,12 +9,13 @@
#include "util.h"
#include "log.h"
#include "uip/uip.h"
#include "uip/irc.h"
extern struct uip_stats uip_stat;
uint8_t cursor_blink = 0;
char page_logs_input_buffer[128];
char page_irc_channel_input_buffer[128];
uint8_t objectlog_storage[2048];
objectlog_t objectlog;
@ -23,9 +24,15 @@ void ui_cursor_blink()
cursor_blink = !cursor_blink;
}
void ui_page_logs_submit(page_t *page)
void ui_page_irc_message_submit(page_t *page)
{
fxip_log(page->input_buffer);
unsigned length = snprintf(messagebuffer, sizeof(messagebuffer), "PRIVMSG ##manawyrmtest :%s", page->input_buffer);
if (length > sizeof(messagebuffer))
{
length = sizeof(messagebuffer);
}
messagelength = length;
}
const page_t pages[] = {
@ -34,10 +41,7 @@ const page_t pages[] = {
.id = PAGE_LOGS,
.key = KEY_F1,
.render_callback = ui_render_logs,
.input_enabled = 1,
.input_buffer = page_logs_input_buffer,
.input_buffer_size = sizeof(page_logs_input_buffer),
.input_submit_callback = ui_page_logs_submit
.input_enabled = 0,
},
{
/* Statistics */
@ -58,7 +62,10 @@ const page_t pages[] = {
.id = PAGE_IRC_CHANNEL,
.key = KEY_F4,
.render_callback = ui_render_logs,
.input_enabled = 0
.input_enabled = 1,
.input_buffer = page_irc_channel_input_buffer,
.input_buffer_size = sizeof(page_irc_channel_input_buffer),
.input_submit_callback = ui_page_irc_message_submit
},
};
@ -109,10 +116,17 @@ void ui_update_logs()
void ui_render_logs(page_t *page)
{
uint16_t lines_drawn = 0;
for (unsigned int i = 0; i < objectlog.num_entries && lines_drawn < UI_DISPLAY_LINES; i++)
uint8_t max_lines = UI_DISPLAY_LINES;
if (page->input_enabled)
{
max_lines--;
}
for (unsigned int i = 0; i < objectlog.num_entries && lines_drawn < max_lines; i++)
{
uint8_t pencil_x = 0;
uint8_t pencil_y = (UI_DISPLAY_LINES - lines_drawn) * 8;
uint8_t pencil_y = (max_lines - lines_drawn) * 8;
int width = 0;
int height = 0;
@ -244,52 +258,7 @@ void ui_render_statistics(page_t *page)
ui_printf(10, 45, C_BLACK, "Chksum err: %u", uip_stat.tcp.chkerr);
ui_printf(10, 55, C_BLACK, "Rexmit: %u", uip_stat.tcp.rexmit);
}
/*
void ui_render_irc(page_t *page)
{
uint16_t lines_drawn = 0;
for (unsigned int i = 0; i < objectlog.num_entries && lines_drawn < UI_DISPLAY_LINES; i++)
{
uint8_t pencil_x = 0;
uint8_t pencil_y = (UI_DISPLAY_LINES - lines_drawn) * 8;
int width = 0;
int height = 0;
message_hdr_t hdr;
uint8_t length;
objectlog_iterator_t iter;
const uint8_t *ptr;
ptr = ui_objectlog_get_message(&objectlog, -i, &iter, &hdr, &length);
if (!ptr)
{
continue;
}
if (hdr.page_id == page->id)
{
do
{
if (length)
{
dtext_opt(pencil_x, pencil_y, C_BLACK, C_NONE, DTEXT_LEFT, DTEXT_TOP, ptr, length);
dnsize(ptr, length, NULL, &width, &height);
pencil_x += width;
if (pencil_x > UI_DISPLAY_PIXEL_X)
{
goto next;
}
}
iter = objectlog_next(&objectlog, iter);
ptr = objectlog_get_fragment(&objectlog, iter, &length);
} while (iter >= 0);
next:
lines_drawn++;
}
}
}
*/
extern char printf_buffer[128];
void ui_printf(int x, int y, int fg, const char * format, ...)
{

View File

@ -13,6 +13,7 @@ static char *localhostname;
static const char irc_command_privmsg[] = "PRIVMSG";
static const char irc_command_error[] = "ERROR";
static const char irc_command_ping[] = "PING";
static int irc_parse_command(irc_message message)
{
@ -36,11 +37,21 @@ static int irc_parse_command(irc_message message)
return;
}
else
{
ui_write_log(PAGE_IRC_OVERVIEW, 0, 0, message.command_arguments, strlen(message.command_arguments));
}
/*if (strncasecmp(message.command, irc_command_ping, strlen(message.command)) == 0)
{
//ui_write_log(PAGE_IRC_CHANNEL, 0, 0, "privmsg", 7);
whitespace = memchr(message.command_arguments, ' ', strlen(message.command_arguments));
if (whitespace == NULL)
return;
ui_write_log(PAGE_IRC_CHANNEL, 0, 0, &whitespace[2], strlen(&whitespace[2]) - 1);
return;
}*/
ui_write_log(PAGE_IRC_OVERVIEW, 0, 0, message.command_arguments, strlen(message.command_arguments));
}
static int irc_parse_line(char *data, uint16_t length)
@ -113,33 +124,25 @@ static int irc_thread(struct irc_state *s)
PSOCK_END(&s->psock);
}
int irc_send_quit_thread(struct irc_state *s)
static int irc_send_thread(struct irc_state *s)
{
PSOCK_BEGIN(&s->psock);
PSOCK_BEGIN(&s->psock_out);
PSOCK_SEND_STR(&s->psock, "QUIT meow!\r\n");
PSOCK_SEND(&s->psock_out, messagebuffer, messagelength);
PSOCK_SEND_STR(&s->psock_out, "\r\n");
PSOCK_END(&s->psock);
messagelength = 0;
PSOCK_END(&s->psock_out);
}
/*---------------------------------------------------------------------------*/
void irc_exit(void)
{
struct irc_state *s = &(uip_conn->appstate);
if (&s->psock == NULL)
{
return;
}
irc_send_quit_thread(s);
}
void irc_appcall(void)
{
struct irc_state *s = &(uip_conn->appstate);
if (&s->psock == NULL)
if (&s->psock == NULL || &s->psock_out == NULL)
{
return;
}
@ -155,6 +158,11 @@ void irc_appcall(void)
}
irc_thread(&(uip_conn->appstate));
if (messagelength)
{
irc_send_thread(&(uip_conn->appstate));
}
}
unsigned char irc_connect(u16_t *server)
@ -167,10 +175,12 @@ unsigned char irc_connect(u16_t *server)
}
struct irc_state *s = &conn->appstate;
messagelength = 0;
s->connected = 1;
s->connection_state = IRC_CONNECTION_NEW;
PSOCK_INIT(&s->psock, s->inputbuffer, 1024);
PSOCK_INIT(&s->psock_out, s->inputbuffer, 1024);
return 1;
}

View File

@ -16,8 +16,10 @@ typedef enum {
IRC_CONNECTION_USER,
IRC_CONNECTION_JOIN,
IRC_CONNECTION_ESTABLISHED
} irc_connection_state_t;
} irc_connection_state_t;
uint8_t messagebuffer[256];
uint16_t messagelength;
typedef struct irc_state
{
@ -26,7 +28,11 @@ typedef struct irc_state
uint8_t connected;
struct psock psock;
struct psock psock_out;
uint8_t inputbuffer[128];
} uip_tcp_appstate_t;
typedef struct {