Skip to content

Commit

Permalink
Update unified_voice.c
Browse files Browse the repository at this point in the history
IO socket to arc-agi benchmark solution to provide diagonsis output.

Signed-off-by: Josef Edwards <joed6834@colorado.edu>
  • Loading branch information
bearycool11 authored Nov 10, 2024
1 parent 589b2e5 commit 56ffe44
Showing 1 changed file with 126 additions and 1 deletion.
127 changes: 126 additions & 1 deletion unified_voice.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "memory_silo.h"
#include "io_socket.h"

Expand All @@ -18,6 +21,22 @@ void unified_voice_init(int memory_silo_id, int io_socket_id) {
unified_voice->id = 1;
unified_voice->memory_silo_id = memory_silo_id;
unified_voice->io_socket_id = io_socket_id;

// Create the IO socket
int sock = socket(AF_INET, SOCK_STREAM, 0);
unified_voice->io_socket_id = sock;

// Set up the server address
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8080);
inet_pton(AF_INET, "127.0.0.1", &server_addr.sin_addr);

// Bind the socket to the server address
bind(sock, (struct sockaddr*)&server_addr, sizeof(server_addr));

// Listen for incoming connections
listen(sock, 1);
}

void unified_voice_read(int io_socket_id, void* buffer, int length) {
Expand All @@ -35,6 +54,112 @@ void unified_voice_write(int io_socket_id, void* buffer, int length) {
// Get Unified Voice Function
unified_voice_t* get_unified_voice(int io_socket_id) {
// Get the unified voice associated with the IO socket
unified_voice_t* unified_voice = malloc(sizeof(unified_voice_t));
unified_voice->id = 1;
unified_voice->memory_silo_id = 1;
unified_voice->io_socket_id = io_socket_id;
return unified_voice;
}

// IO Socket Functions
void io_socket_init(int io_socket_id) {
// Initialize the IO socket
int sock = socket(AF_INET, SOCK_STREAM, 0);
io_socket_id = sock;

// Set up the server address
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons;

// IO Socket Functions
void io_socket_init(int io_socket_id) {
// Initialize the IO socket
int sock = socket(AF_INET, SOCK_STREAM, 0);
io_socket_id = sock;

// Set up the server address
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8080);
inet_pton(AF_INET, "127.0.0.1", &server_addr.sin_addr);

// Bind the socket to the server address
bind(sock, (struct sockaddr*)&server_addr, sizeof(server_addr));

// Listen for incoming connections
listen(sock, 1);
}

void io_socket_read(int io_socket_id, void* buffer, int length) {
// Read from the IO socket
read(io_socket_id, buffer, length);
}

void io_socket_write(int io_socket_id, void* buffer, int length) {
// Write to the IO socket
write(io_socket_id, buffer, length);
}

// Diagnosis Window Functions
void diagnosis_window_init(int io_socket_id) {
// Initialize the diagnosis window
// ...
return NULL;

// Create the diagnosis window
// ...

// Set up the diagnosis window layout
// ...
}

void diagnosis_window_update(int io_socket_id, void* buffer, int length) {
// Update the diagnosis window
// ...

// Read from the IO socket
io_socket_read(io_socket_id, buffer, length);

// Update the diagnosis window with the new data
// ...
}

void diagnosis_window_close(int io_socket_id) {
// Close the diagnosis window
// ...

// Close the IO socket
close(io_socket_id);
}

int main() {
// Initialize the unified voice
unified_voice_init(1, 1);

// Initialize the IO socket
io_socket_init(1);

// Initialize the diagnosis window
diagnosis_window_init(1);

// Main loop
while (1) {
// Read from the IO socket
void* buffer = malloc(1024);
io_socket_read(1, buffer, 1024);

// Update the diagnosis window
diagnosis_window_update(1, buffer, 1024);

// Write to the IO socket
io_socket_write(1, buffer, 1024);

// Free the buffer
free(buffer);
}

// Close the diagnosis window
diagnosis_window_close(1);

return 0;
}

0 comments on commit 56ffe44

Please sign in to comment.