diff --git a/src/python/linux_amd64/rehamove.py b/src/python/linux_amd64/rehamove.py index 12b4d40..5140b07 100644 --- a/src/python/linux_amd64/rehamove.py +++ b/src/python/linux_amd64/rehamove.py @@ -1,18 +1,66 @@ import rehamovelib class Rehamove: + + current_version = "v1.5" + + channel0 = ['r', 'red'] + channel1 = ['b', 'blue'] + channel2 = ['g1', 'gray1', 'grey1', 'black'] + channel3 = ['g2', 'gray2', 'grey2', 'white'] + def __init__(self, port_name): self.rehamove = rehamovelib.open_port(port_name) + def version(self): + c_version = rehamovelib.get_version() + print("Rehamove Version: Python-side " + str(Rehamove.current_version) + ", C-side " + str(c_version)) + return Rehamove.current_version + + def get_channel(self, channel): + chosen_channel = channel + if isinstance(channel, str): + channel = channel.lower() + if channel in Rehamove.channel0: + chosen_channel = 0 + elif channel in Rehamove.channel1: + chosen_channel = 1 + elif channel in Rehamove.channel2: + chosen_channel = 2 + elif channel in Rehamove.channel3: + chosen_channel = 3 + else: + chosen_channel = 0 # Default + elif isinstance(channel, int): + if channel < 0 and channel > 3: + chosen_channel = 0 # Default + else: + chosen_channel = 0 + return chosen_channel + def pulse(self, channel, current, pulse_width): - rehamovelib.pulse(self.rehamove, channel, current, pulse_width) + if self.rehamove == None: + print("python Rehamove pulse() ERROR! Rehamove object does not exist.") + return -1 + chosen_channel = self.get_channel(channel) + result = rehamovelib.pulse(self.rehamove, chosen_channel, current, pulse_width) + if result != 0: + print("python Rehamove pulse() ERROR!") + return -1 + else: + print("python Rehamove pulse() sent.") + return 0 def custom_pulse(self, channel, points_array): + if self.rehamove == None: + print("python Rehamove custom_pulse() ERROR! Rehamove object does not exist.") + return -1 + chosen_channel = self.get_channel(channel) original_length = len(points_array) num_points = len(points_array) # Error handling (warning) if too many points. if num_points > 16: - print("custom_pulse(): WARNING! Maximum of 16 points allowed, truncating points array.") + print("python Rehamove custom_pulse() WARNING! Maximum of 16 points allowed, truncating points array.") num_points = 16 # Error handling (exception) if malformed points. @@ -20,10 +68,9 @@ def custom_pulse(self, channel, points_array): for i in range(0, num_points): current = points_array[i][0] pulse_width = points_array[i][1] - #print("Point {}: {} mA {} us".format(i, current, pulse_width)) except: - print("custom_pulse: ERROR! Malformed points array, should be: [ (current0, pulse_width0), (current1, pulse_width1), ... ]") - return + print("python Rehamove custom_pulse() ERROR! Malformed points array, should be: [ (current0, pulse_width0), (current1, pulse_width1), ... ]") + return -1 # Handle if the user supplies less than 16 points: fill up empty points in the array. remaining_points = 16 - num_points @@ -48,12 +95,31 @@ def custom_pulse(self, channel, points_array): c14, w14 = points_array[14][0], points_array[14][1] c15, w15 = points_array[15][0], points_array[15][1] - rehamovelib.custom_pulse(self.rehamove, channel, original_length, c0, w0, c1, w1, c2, w2, c3, w3, c4, w4, c5, w5, c6, w6, c7, w7, c8, w8, c9, w9, c10, w10, c11, w11, c12, w12, c13, w13, c14, w14, c15, w15) + result = rehamovelib.custom_pulse(self.rehamove, chosen_channel, original_length, c0, w0, c1, w1, c2, w2, c3, w3, c4, w4, c5, w5, c6, w6, c7, w7, c8, w8, c9, w9, c10, w10, c11, w11, c12, w12, c13, w13, c14, w14, c15, w15) + if result != 0: + print("python Rehamove custom_pulse() ERROR!") + return -1 + else: + print("python Rehamove custom_pulse() sent.") + return 0 - #print("PYTHON custom_pulse {} {}, {} {} {} {} {} {} {} {} / {} {} {} {} {} {} {} {} / {} {} {} {} {} {} {} {} / {} {} {} {} {} {} {} {}".format(self.rehamove, channel, c0, w0, c1, w1, c2, w2, c3, w3, c4, w4, c5, w5, c6, w6, c7, w7, c8, w8, c9, w9, c10, w10, c11, w11, c12, w12, c13, w13, c14, w14, c15, w15)) - def battery(self): - rehamovelib.battery(self.rehamove) + if self.rehamove == None: + print("python Rehamove ERROR! Rehamove object does not exist.") + return -1 + result = rehamovelib.battery_request(self.rehamove) + if result != 0: + print("python Rehamove battery() ERROR!") + return -1 + else: + battery_level = rehamovelib.get_battery(self.rehamove) + print("python Rehamove battery(): " + str(battery_level) + "%") + return battery_level def __del__(self): - rehamovelib.close_port(self.rehamove) + # Only close the port if we have a Rehamove object to close + if self.rehamove != None: + result = rehamovelib.close_port(self.rehamove) + if result != 0: + print("python Rehamove close_port() ERROR!") + diff --git a/src/python/linux_amd64/rehamovelib.c b/src/python/linux_amd64/rehamovelib.c index 46d5e67..c2df0cf 100644 --- a/src/python/linux_amd64/rehamovelib.c +++ b/src/python/linux_amd64/rehamovelib.c @@ -1,191 +1,167 @@ +#include "smpt_ll_client.h" #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> -#include "smpt_ll_client.h" + +#if defined(__linux__) +#include <unistd.h> /* Not for Windows */ +#endif + +#define VERSION_NUMBER "v1.5" +#define TIMEOUT_COUNTER 10000000 typedef struct { char port_name[64]; Smpt_device device; + int battery; } Rehamove; -/* -Function declarations in this section. -*/ +char * get_version(); Rehamove * open_port(const char * port_name); -void close_port(Rehamove * r); -void pulse(Rehamove * r, char * channel, int current, int pulse_width); -void custom_pulse(Rehamove * r, char * channel, int num_points, float c0, int w0, float c1, int w1, float c2, int w2, float c3, int w3, float c4, int w4, float c5, int w5, float c6, int w6, float c7, int w7, float c8, int w8, float c9, int w9, float c10, int w10, float c11, int w11, float c12, int w12, float c13, int w13, float c14, int w14, float c15, int w15); -void battery(Rehamove * r); +int close_port(Rehamove * r); +int pulse(Rehamove * r, int channel, float current, int pulse_width); +int get_battery(Rehamove * r); +int battery_request(Rehamove * r); +int custom_pulse(Rehamove * r, int channel, int num_points, float c0, int w0, float c1, int w1, float c2, int w2, float c3, int w3, float c4, int w4, float c5, int w5, float c6, int w6, float c7, int w7, float c8, int w8, float c9, int w9, float c10, int w10, float c11, int w11, float c12, int w12, float c13, int w13, float c14, int w14, float c15, int w15); + +void print_device(Smpt_device d, const char * filename); +void error_callback(const char * message) { + printf("ERROR CALLBACK: %s\n", message); +} + +/* USER-FACING FUNCTIONS */ -/* -Actual implementation details below. -*/ +char * get_version() { + return VERSION_NUMBER; +} Rehamove * open_port(const char * port_name) { - Rehamove * r = (Rehamove *) calloc(1, sizeof(Rehamove)); + smpt_init_error_callback(&error_callback); - for (int i = 0; i < strlen(port_name); i++) { - (r->port_name)[i] = *(port_name + i); - } - (r->port_name)[strlen(port_name)] = '\0'; + uint8_t packet_number = 1; /* The packet_number can be used for debugging purposes */ - printf("open_port(): Created port_name %s\n", r->port_name); + Rehamove * r = (Rehamove *) calloc(1, sizeof(Rehamove)); - Smpt_device device = {0}; - int open_port_result = smpt_open_serial_port(&device, r->port_name); - if (open_port_result == 0) { - printf("open_port(): ERROR! Unable to connect to port %s.\n", r->port_name); + for (int i = 0; i < strlen(port_name); i++) { + (r->port_name)[i] = *(port_name + i); } - else { - printf("open_port(): Successfully opened port.\n"); - } - r->device = device; - return r; -} + (r->port_name)[strlen(port_name)] = '\0'; + r->battery = -1; -void close_port(Rehamove * r) { - int result = smpt_close_serial_port(&(r->device)); - if (result == 0) { - printf("close_port(): ERROR! Unable to close port %s !\n", r->port_name); - return; - } - printf("close_port(): Successfully closed port %s .\n", r->port_name); - free(r); - return; -} - -void print_channel_config(Smpt_ll_channel_config * s) { - - printf("PRINTING CHANNEL CONFIG\n"); - printf("enable_stimulation: %d\n", s->enable_stimulation); - printf("channel: %d\n", s->channel); - printf("modify_demux: %d\n", s->modify_demux); - printf("number_of_points: %d\n", s->number_of_points); - printf("Smpt_Length_Points: %d\n", Smpt_Length_Points); - printf("points array: "); - for (int i = 0; i < Smpt_Length_Points; i++) { - Smpt_point p = *(s->points + i); - printf("(time %d float %f control_mode %d interpolation_mode %d) ", p.time, p.current, p.control_mode, p.interpolation_mode); - } - printf("\n"); - printf("Smpt_Length_Demux_Config: %d\n", Smpt_Length_Demux_Config); - printf("demux_config array: "); - for (int i = 0; i < Smpt_Length_Demux_Config; i++) { - printf("(%d) ", *(s->demux_config + i)); + Smpt_device device = {0}; + r->device = device; + bool open_port_result = smpt_open_serial_port(&(r->device), port_name); + if (!open_port_result) { + printf("open_port() ERROR: Opening connection to port %s failed!\n", port_name); + free(r); + return NULL; } - printf("\n"); - printf("demux_length: %d\n", s->demux_length); - printf("packet_number: %d\n", s->packet_number); -} -void pulse(Rehamove * r, char * channel, int current, int pulse_width) { - - uint8_t packet_number = 0; /* The packet_number can be used for debugging purposes */ Smpt_ll_init ll_init = {0}; /* Struct for ll_init command */ - Smpt_ll_channel_config ll_channel_config = {0}; /* Struct for ll_channel_config command */ - /* Clear ll_init struct and set the data */ smpt_clear_ll_init(&ll_init); - - //print_channel_config(&ll_channel_config); - ll_init.packet_number = packet_number; /* Send the ll_init command to stimulation unit */ - smpt_send_ll_init(&(r->device), &ll_init); + bool ll_init_result = smpt_send_ll_init(&(r->device), &ll_init); + if (!ll_init_result) { + printf("open_port() ERROR: Sending device initialization message failed!\n"); + free(r); + return NULL; + } - packet_number++; + int counter = 0; + while (!smpt_new_packet_received(&(r->device))) { + if (counter > TIMEOUT_COUNTER) { + printf("open_port() ERROR: Receiving device initialization message timed out!\n"); + free(r); + return NULL; + } + counter += 1; + } + Smpt_ack ack; + smpt_last_ack(&(r->device), &ack); - /* Set the data */ - ll_channel_config.enable_stimulation = true; - - char lowercase[strlen(channel) + 1]; - for (int i = 0; i < strlen(channel); i++) { - lowercase[i] = tolower(channel[i]); + if ((ack.result != Smpt_Result_Successful) || (ack.command_number != Smpt_Cmd_Ll_Init_Ack)) { + printf("open_port() ERROR: Unsuccessful device initialization response! Expected: command %d result %d, Received: command %d result %d.\n", Smpt_Cmd_Ll_Init_Ack, Smpt_Result_Successful, ack.command_number, ack.result); + free(r); + return NULL; } - lowercase[strlen(channel)] = '\0'; - int chosen_channel = Smpt_Channel_Blue; - if (strncmp(lowercase, "red", strlen("red")) == 0) { - chosen_channel = Smpt_Channel_Red; - } - else if (strncmp(lowercase, "blue", strlen("blue")) == 0) { - chosen_channel = Smpt_Channel_Blue; - } - else if (strncmp(lowercase, "black", strlen("gray")) == 0) { - chosen_channel = Smpt_Channel_Black; + Smpt_ll_init_ack init_ack; + smpt_get_ll_init_ack(&(r->device), &init_ack); + printf("open_port() SUCCESS: Connected to port %s and initialized device.\n", port_name); + return r; +} + +int pulse(Rehamove * r, int channel, float current, int pulse_width) { + if (r == NULL) { + printf("pulse() ERROR: No Rehamove object found!\n"); + return 1; } - ll_channel_config.channel = chosen_channel; /* Use blue channel */ + uint8_t packet_number = 1; + + Smpt_ll_channel_config ll_channel_config = {0}; /* Struct for ll_channel_config command */ + /* Set the data */ + ll_channel_config.enable_stimulation = true; + ll_channel_config.channel = channel; ll_channel_config.number_of_points = 3; /* Set the number of points*/ ll_channel_config.packet_number = packet_number; - /* Set the stimulation pulse */ - /* First point, current: 20 mA, positive, pulse width: 200 µs */ - ll_channel_config.points[0].current = current; + ll_channel_config.points[0].current = current; ll_channel_config.points[0].time = pulse_width; - - /* Second point, pause 100 µs */ - ll_channel_config.points[1].time = pulse_width / 2; - - /* Third point, current: -20 mA, negative, pulse width: 200 µs */ + ll_channel_config.points[1].time = pulse_width / 2; ll_channel_config.points[2].current = current * -1; ll_channel_config.points[2].time = pulse_width; - //print_channel_config(&ll_channel_config); - /* Send the ll_channel_list command to the stimulation unit */ - smpt_send_ll_channel_config(&(r->device), &ll_channel_config); + bool ll_config_result = smpt_send_ll_channel_config(&(r->device), &ll_channel_config); + if (!ll_config_result) { + printf("pulse() ERROR: Pulse command not sent!\n"); + return 1; + } - //print_channel_config(&ll_channel_config); + int counter = 0; + while (!smpt_new_packet_received(&(r->device))) { + if (counter > TIMEOUT_COUNTER) { + printf("pulse() ERROR: Receiving pulse response timed out!\n"); + return 1; + } + counter += 1; + } - packet_number++; + Smpt_ack ack; + smpt_last_ack(&(r->device), &ack); - /* Send the ll_stop command to the stimulation unit */ - smpt_send_ll_stop(&(r->device), packet_number); - //printf("pulse(): Successfully finished.\n"); + if ((ack.result != Smpt_Result_Successful) || (ack.command_number != Smpt_Cmd_Ll_Channel_Config_Ack)) { + // Common error situation -> electrode error (e.g. electrode not connected). + if (ack.result == Smpt_Result_Electrode_Error) { + printf("pulse() ERROR: Unsuccessful pulse response - electrode error! Expected: command %d result %d, Received: command %d result %d.\n", Smpt_Cmd_Ll_Channel_Config_Ack, Smpt_Result_Successful, ack.command_number, ack.result); + return 1; + } + // Default error message -> specify the code. + printf("pulse() ERROR: Unsuccessful pulse response! Expected: command %d result %d, Received: command %d result %d.\n", Smpt_Cmd_Ll_Channel_Config_Ack, Smpt_Result_Successful, ack.command_number, ack.result); + return 1; + } else { + Smpt_ll_channel_config_ack channel_config_ack; + smpt_get_ll_channel_config_ack(&(r->device), &channel_config_ack); + } + return 0; } -void custom_pulse(Rehamove * r, char * channel, int num_points, float c0, int w0, float c1, int w1, float c2, int w2, float c3, int w3, float c4, int w4, float c5, int w5, float c6, int w6, float c7, int w7, float c8, int w8, float c9, int w9, float c10, int w10, float c11, int w11, float c12, int w12, float c13, int w13, float c14, int w14, float c15, int w15) { +int custom_pulse(Rehamove * r, int channel, int num_points, float c0, int w0, float c1, int w1, float c2, int w2, float c3, int w3, float c4, int w4, float c5, int w5, float c6, int w6, float c7, int w7, float c8, int w8, float c9, int w9, float c10, int w10, float c11, int w11, float c12, int w12, float c13, int w13, float c14, int w14, float c15, int w15) { - //printf("C custom_pulse: %p %s, %f %d %f %d %f %d %f %d / %f %d %f %d %f %d %f %d / %f %d %f %d %f %d %f %d / %f %d %f %d %f %d %f %d", r, channel, c0, w0, c1, w1, c2, w2, c3, w3, c4, w4, c5, w5, c6, w6, c7, w7, c8, w8, c9, w9, c10, w10, c11, w11, c12, w12, c13, w13, c14, w14, c15, w15); + if (r == NULL) { + printf("custom_pulse() ERROR: No Rehamove object found!\n"); + return 1; + } - uint8_t packet_number = 0; /* The packet_number can be used for debugging purposes */ - Smpt_ll_init ll_init = {0}; /* Struct for ll_init command */ + uint8_t packet_number = 2; Smpt_ll_channel_config ll_channel_config = {0}; /* Struct for ll_channel_config command */ - - /* Clear ll_init struct and set the data */ - smpt_clear_ll_init(&ll_init); - - ll_init.packet_number = packet_number; - - /* Send the ll_init command to stimulation unit */ - smpt_send_ll_init(&(r->device), &ll_init); - - packet_number++; - /* Set the data */ ll_channel_config.enable_stimulation = true; - - char lowercase[strlen(channel) + 1]; - for (int i = 0; i < strlen(channel); i++) { - lowercase[i] = tolower(channel[i]); - } - lowercase[strlen(channel)] = '\0'; - - int chosen_channel = Smpt_Channel_Blue; - if (strncmp(lowercase, "red", strlen("red")) == 0) { - chosen_channel = Smpt_Channel_Red; - } - else if (strncmp(lowercase, "blue", strlen("blue")) == 0) { - chosen_channel = Smpt_Channel_Blue; - } - else if (strncmp(lowercase, "black", strlen("gray")) == 0) { - chosen_channel = Smpt_Channel_Black; - } - - ll_channel_config.channel = chosen_channel; /* Use blue channel */ + ll_channel_config.channel = channel; ll_channel_config.number_of_points = num_points; /* Set the number of points*/ ll_channel_config.packet_number = packet_number; @@ -223,53 +199,186 @@ void custom_pulse(Rehamove * r, char * channel, int num_points, float c0, int w0 ll_channel_config.points[15].current = c15; ll_channel_config.points[15].time = w15; - //print_channel_config(&ll_channel_config); - /* Send the ll_channel_list command to the stimulation unit */ - smpt_send_ll_channel_config(&(r->device), &ll_channel_config); + bool ll_config_result = smpt_send_ll_channel_config(&(r->device), &ll_channel_config); + if (!ll_config_result) { + printf("custom_pulse() ERROR: Pulse command not sent!\n"); + return 1; + } - packet_number++; + int counter = 0; + while (!smpt_new_packet_received(&(r->device))) { + if (counter > TIMEOUT_COUNTER) { + printf("custom_pulse() ERROR: Receiving pulse response timed out!\n"); + return 1; + } + } - /* Send the ll_stop command to the stimulation unit */ - smpt_send_ll_stop(&(r->device), packet_number); - //printf("custom_pulse(): Successfully finished.\n"); + Smpt_ack ack; + smpt_last_ack(&(r->device), &ack); + + if ((ack.result != Smpt_Result_Successful) || (ack.command_number != Smpt_Cmd_Ll_Channel_Config_Ack)) { + // Common error situation -> electrode error (e.g. electrode not connected). + if (ack.result == Smpt_Result_Electrode_Error) { + printf("custom_pulse() ERROR: Unsuccessful pulse response - electrode error! Expected: command %d result %d, Received: command %d result %d.\n", Smpt_Cmd_Ll_Channel_Config_Ack, Smpt_Result_Successful, ack.command_number, ack.result); + return 1; + } + // Default error message -> specify the code. + printf("custom_pulse() ERROR: Unsuccessful pulse response! Expected: command %d result %d, Received: command %d result %d.\n", Smpt_Cmd_Ll_Channel_Config_Ack, Smpt_Result_Successful, ack.command_number, ack.result); + return 1; + } else { + Smpt_ll_channel_config_ack channel_config_ack; + smpt_get_ll_channel_config_ack(&(r->device), &channel_config_ack); + } + return 0; } -void battery(Rehamove * r) { - // Annoyingly have to close and reopen a new port. - smpt_close_serial_port(&(r->device)); - printf("close(): Successfully finished.\n"); +int close_port(Rehamove * r) { + if (r == NULL) { + printf("close_port() ERROR: No Rehamove object found!\n"); + return 1; + } - Smpt_device device = {0}; - int open_port_result = smpt_open_serial_port(&device, r->port_name); - if (open_port_result == 0) { - printf("open(): ERROR! Unable to connect to port %s.\n", r->port_name); + uint8_t packet_number = 1; + bool ll_stop_result = smpt_send_ll_stop(&(r->device), packet_number); + if (!ll_stop_result) { + printf("close_port() ERROR: Stopping device request not sent!\n"); + return 1; } - else { - printf("open(): Successfully opened port.\n"); + + int counter = 0; + while (!smpt_new_packet_received(&(r->device))) { + if (counter > TIMEOUT_COUNTER) { + printf("close_port() ERROR: Receiving device stop response timed out!\n"); + return 1; + } } - r->device = device; - /* Send the call to get the battery status. Signature is: - - SMPT_API bool smpt_send_get_battery_status ( Smpt_device *const device, - uint8_t packet_number - ) - */ - uint8_t packet_number = 42; /* The packet_number can be used for debugging purposes */ - bool send_result = smpt_send_get_battery_status(&(r->device), packet_number); + Smpt_ack ack; + smpt_last_ack(&(r->device), &ack); + if ((ack.result != Smpt_Result_Successful) || (ack.command_number != Smpt_Cmd_Ll_Stop_Ack)) { + // Default error message -> specify the code. + printf("close_port() ERROR: Unsuccessful device stop response! Expected: command %d result %d, Received: command %d result %d.\n", Smpt_Cmd_Ll_Stop_Ack, Smpt_Result_Successful, ack.command_number, ack.result); + return 1; + } + bool close_port_result = smpt_close_serial_port(&(r->device)); + if (!close_port_result) { + printf("close_port() ERROR! Close port request not sent!\n"); + return 1; + } + free(r); + printf("close_port() SUCCESS: Stopped device and closed port successfully.\n"); + return 0; +} + +int get_battery(Rehamove * r) { + if (r == NULL) { + printf("get_battery() ERROR: No Rehamove object found!\n"); + return -1; + } + return r->battery; +} + +int battery_request(Rehamove * r) { + if (r == NULL) { + printf("battery_request() ERROR: No Rehamove object found!\n"); + return 1; + } + uint8_t packet_number = 42; + bool battery_result = smpt_send_get_battery_status(&(r->device), packet_number); + if (!battery_result) { + printf("battery_result() ERROR: Battery request not sent!\n"); + return 1; + } int counter = 0; while (!smpt_new_packet_received(&(r->device))) { - - counter += 1; + if (counter > TIMEOUT_COUNTER) { + printf("battery_result() ERROR: Receiving battery response timed out!\n"); + return 1; + } } - + Smpt_ack ack; smpt_last_ack(&(r->device), &ack); - Smpt_get_battery_status_ack battery_ack; - smpt_get_get_battery_status_ack(&(r->device), &battery_ack); - - printf("Battery life is at %d %%.\n", battery_ack.battery_level); + if ((ack.result != Smpt_Result_Successful) || (ack.command_number != Smpt_Cmd_Get_Battery_Status_Ack)) { + // Default error message -> specify the code. + printf("battery_result() ERROR: Unsuccessful battery response! Expected: command %d result %d, Received: command %d result %d.\n", Smpt_Cmd_Get_Battery_Status_Ack, Smpt_Result_Successful, ack.command_number, ack.result); + return 1; + } else { + Smpt_get_battery_status_ack battery_ack; + smpt_get_get_battery_status_ack(&(r->device), &battery_ack); + r->battery = battery_ack.battery_level; + } + return 0; } + + +/* FOR DEBUGGING */ + +void print_device(Smpt_device d, const char * filename) { + + FILE * file = fopen(filename, "w+, css=UTF-8"); + if (file == NULL) { + printf("Could not print to file %s\n", filename); + return; + } + + fprintf(file, "PRINTING DEVICE.\n"); + fprintf(file, "packet_length %d\n", d.packet_length); + fprintf(file, "packet array of size %d: ", Smpt_Length_Max_Packet_Size); + for (int i = 0; i < Smpt_Length_Max_Packet_Size; i++) { + fprintf(file, "%d ", (d.packet)[i]); + } + fprintf(file, "\n"); + fprintf(file, "cmd_list c:\n"); + Smpt_cmd_list c = d.cmd_list; + fprintf(file, "c.acks_length %d\n", c.acks_length); + fprintf(file, "c.acks_current_index %d\n", c.acks_current_index); + fprintf(file, "c.acks array of size %d: ( ", Smpt_Length_Number_Of_Acks); + for (int i = 0; i < Smpt_Length_Number_Of_Acks; i++) { + Smpt_ack a = *(c.acks + i); + fprintf(file, "[packet %d command %d result %d] ", a.packet_number, a.command_number, a.result); + } + fprintf(file, ")\n"); + fprintf(file, "c.requests_current_index %d\n", c.requests_current_index); + fprintf(file, "c.requests_expected_index %d\n", c.requests_expected_index); + fprintf(file, "c.number_of_expected %d\n", c.number_of_expected); + fprintf(file, "c.requests array of size %d: ( ", Smpt_Length_Number_Of_Acks); + for (int i = 0; i < Smpt_Length_Number_Of_Acks; i++) { + Smpt_cmd a = *(c.requests + i); + fprintf(file, "[packet %d command %d] ", a.packet_number, a.command_number); + } + fprintf(file, ")\n"); + fprintf(file, "c.new_ack_available %d\n", c.new_ack_available); + //fprintf(file, "serial_port_handle %p\n", d.serial_port_handle_); + fprintf(file, "current_packet_number %d\n", d.current_packet_number); + fprintf(file, "serial_port_name array of size %d: ( ", Smpt_Length_Serial_Port_Chars); + for (int i = 0; i < Smpt_Length_Serial_Port_Chars; i++) { + fprintf(file, "%c ", *(d.serial_port_name + i)); + } + fprintf(file, ")\n"); + fprintf(file, "packet_input_buffer p:\n"); + Packet_input_buffer p = d.packet_input_buffer; + fprintf(file, "p.buffer %p\n", p.buffer); + fprintf(file, "p.buffer_state %p\n", p.buffer_state); + fprintf(file, "p.write_row_length_count %d\n", p.write_row_length_count); + fprintf(file, "p.write_row_count %d\n", p.write_row_count); + fprintf(file, "p.read_row_count %d\n", p.read_row_count); + fprintf(file, "p.ignore_next_byte %d\n", p.ignore_next_byte); + fprintf(file, "p.number_of_rows %d\n", p.number_of_rows); + fprintf(file, "p.row_length %d\n", p.row_length); + fprintf(file, "packet_input_buffer_data array of size (%d * %d): ( ", Smpt_Length_Packet_Input_Buffer_Rows, Smpt_Length_Max_Packet_Size); + for (int i = 0; i < Smpt_Length_Packet_Input_Buffer_Rows * Smpt_Length_Max_Packet_Size; i++) { + fprintf(file, "%d ", *(d.packet_input_buffer_data + i)); + } + fprintf(file, ")\n"); + fprintf(file, "packet_input_buffer_state array of size %d: ( ", Smpt_Length_Packet_Input_Buffer_Rows); + for (int i = 0; i < Smpt_Length_Packet_Input_Buffer_Rows; i++) { + fprintf(file, "%d ", *(d.packet_input_buffer_state + i)); + } + fprintf(file, ")\n"); + fprintf(file, "END PRINT DEVICE.\n"); + fclose(file); +} \ No newline at end of file diff --git a/src/python/linux_amd64/rehamovelib.i b/src/python/linux_amd64/rehamovelib.i index c3801b2..e17258e 100644 --- a/src/python/linux_amd64/rehamovelib.i +++ b/src/python/linux_amd64/rehamovelib.i @@ -3,28 +3,33 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include "smpt_ll_client.h" typedef struct { char port_name[64]; Smpt_device device; + int battery; } Rehamove; +extern char * get_version(); extern Rehamove * open_port(const char * port_name); -extern void close_port(Rehamove * r); -extern void pulse(Rehamove * r, char * channel, int current, int pulse_width); -extern void custom_pulse(Rehamove * r, char * channel, int num_points, float c0, int w0, float c1, int w1, float c2, int w2, float c3, int w3, float c4, int w4, float c5, int w5, float c6, int w6, float c7, int w7, float c8, int w8, float c9, int w9, float c10, int w10, float c11, int w11, float c12, int w12, float c13, int w13, float c14, int w14, float c15, int w15); -extern void battery(Rehamove * r); +extern int pulse(Rehamove * r, int channel, float current, int pulse_width); +extern int close_port(Rehamove * r); +extern int get_battery(Rehamove * r); +extern int battery_request(Rehamove * r); +extern int custom_pulse(Rehamove * r, int channel, int num_points, float c0, int w0, float c1, int w1, float c2, int w2, float c3, int w3, float c4, int w4, float c5, int w5, float c6, int w6, float c7, int w7, float c8, int w8, float c9, int w9, float c10, int w10, float c11, int w11, float c12, int w12, float c13, int w13, float c14, int w14, float c15, int w15); %} typedef struct { char port_name[64]; Smpt_device device; + int battery; } Rehamove; +extern char * get_version(); extern Rehamove * open_port(const char * port_name); -extern void close_port(Rehamove * r); -extern void pulse(Rehamove * r, char * channel, int current, int pulse_width); -extern void custom_pulse(Rehamove * r, char * channel, int num_points, float c0, int w0, float c1, int w1, float c2, int w2, float c3, int w3, float c4, int w4, float c5, int w5, float c6, int w6, float c7, int w7, float c8, int w8, float c9, int w9, float c10, int w10, float c11, int w11, float c12, int w12, float c13, int w13, float c14, int w14, float c15, int w15); -extern void battery(Rehamove * r); \ No newline at end of file +extern int pulse(Rehamove * r, int channel, float current, int pulse_width); +extern int close_port(Rehamove * r); +extern int get_battery(Rehamove * r); +extern int battery_request(Rehamove * r); +extern int custom_pulse(Rehamove * r, int channel, int num_points, float c0, int w0, float c1, int w1, float c2, int w2, float c3, int w3, float c4, int w4, float c5, int w5, float c6, int w6, float c7, int w7, float c8, int w8, float c9, int w9, float c10, int w10, float c11, int w11, float c12, int w12, float c13, int w13, float c14, int w14, float c15, int w15); \ No newline at end of file