Functions | Variables

main.c File Reference

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include <signal.h>
#include <sys/time.h>
#include "times_header.h"
#include "network_header.h"
#include "gpca_header.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

void * downstream_thread (void *ptr)
 Manages streams from socket clients to GPCA-StateMachine.
void * upstream_thread (void *ptr)
 Manages streams from GPCA-Controller to GPCA-StateMachine.
void * gpca_state_machine_thread (void *ptr)
 GPCA state machine thread :Mainly execute TIMES codes.
void * gpca_clock_manager (void *ptr)
 GPCA clock manager.
void * observer_adapter (void *ptr)
 Observer adapter.
static void clear_and_set (unsigned char sync)
 TIMES interface.
void setClock (time_t clockID, long value)
 TIMES interface.
time_t rdClock (time_t clockID)
 TIMES interface.
void assign (int trn)
 TIMES interface.
bool eval_guard (int trn)
 TIMES interface.
void check_trans (void)
 TIMES interface.
int action_handler_on_state_change (int prev_state, int current_state)
 An action handler on state change (Glue code).
int getCurrentState (void)
 Return the current GPCA state (Glue code).
int activate_gpca_channel (unsigned char cmd)
 Activate a channel based on the environmental stimulus.
int send_gpca_pkt_to_client (void)
 Function to send gpca packets to client.
int send_channel_ack_to_client (void)
 Fuction to send channel acks to client.
int write_byte_to_controller (int fd, char data)
 A function to send one-byte command to the infusion controller.
int main (int Parm_Count, char *Parms[])
 Main function.

Variables

int servPort = 0
 Server port number.
int sockfd = 0
 Server Socket Descriptor.
int clnt_socket = 0
 Client Socket Descriptor.
struct sockaddr_in serv_addr clnt_addr
 Server and Client address structure.
char sock_write_buf [SOCK_WRITE_BUF_SIZE]
 socket writing buffer.
char sock_read_buf [SOCK_READ_BUF_SIZE]
 socket read buffer.
int serial_fd
 Serial File Descriptor.
unsigned char serial_read_buf [SERIAL_READ_BUF_SIZE]
 Serial read buffer.
char buf [1024]
char devicename [80]
 Contain a serial device name (e.g. /dev/ttyUSB0).
time_t GPCA_Instance_clk_x1
int E_RequestBolus = 0
 An event channel for Bolus request from patients.
int E_StopInfusion = 0
 An event channel for pushing [stop button] by patients.
int E_PowerButton = 0
 Pressing of the power button.
int E_PauseInfusion = 0
 An event channel for pushing [pause button] by patients.
int E_ConfirmPauseInfusion = 0
 An event channel for pushing [confirm pause] by patients.
int E_ClearAlarm = 0
 An event channel for clearing the current alarm by patients or caregivers.
int E_Cancel = 0
 An event channel for cancelling the previous actions done by patients or caregivers.
int E_ChangeDoseRate = 0
 An event channel for pushing [Change Dose Rate] button by patients or caregivers.
int E_ConfigureInfusionProgram = 0
 The action of programming infusion parameters.
int E_ConfirmStopInfusion = 0
 An event channel for pushing [Confirm Stop Infusion] by patients or caregivers.
int E_ConfirmDoseRate = 0
 An event channel for pushing [Confirm Dose Rate] by patients or caregivers.
int E_NewInfusion = 0
 An event channel for initiating [infusion session submachine] after pump is being stopped.
int E_ChangeVTBI = 0
 Request to change the current VTBI.
int E_ConfirmVTBI = 0
 The action of accepting the currently programmed VTBI.
int E_StartInfusion = 0
 The action of accepting the current programmed parameters and starting the infusion.
int E_CheckAdminSet = 0
 Request for an administration set check.
int E_CheckAdminSet_1 = 0
int E_CheckDrug = 0
 Request to check the loaded drug against the prescription.
int E_ConfirmConcentration = 0
 The action of accepting the concentration of the loaded drug.
int E_Prime = 0
 Request to prime the pump.
int T_Cond_6_6 = 0
 An event channel for indicating [Warning Low Reservoir].
int T_Cond_6_3 = 0
 An event channel for indicating [Alarm Empty Reservoir].
int T_Cond_6_4 = 0
 An event channel for indicating a new valid syringe has been inserted.
int T_Cond_6_5 = 0
 An event channel for indicating an invalid syringe has been inserted.
int MCond_6_6 = 0
 A condition variable for indicating [Wrn_LowReservior].
int TCond_6_3 = 0
int Cond_6_3 = 0
 A condition variable for indicating [Alrm_EmptyReservior].
int TCond_6_5 = 0
 A condition variable for indicating [Alrm_WrongDrug].
int TCond_6_4 = 0
 A condition variable for indicating that the reloaded drug matches the drug expected by the current infusion session.
int Cond_7_4 = 0
 A condition variable for indicating that the new infusion rate that the users input during the current infusion satisfies both soft and hard limits suggested by the drug library.
int Cond_7_3 = 0
 A condition variable for indicating that the new infusion rate that the user inputs during the current infusion violates either soft or hard limits suggested by the drug library.
int Cond_2 = 0
 A condition variable for indicating that the pump is functioning properly and all necessary parts are ready for the infusion to start.
int Level_Two_Alarm = 0
 An event channel for indicating [Level Two Alarm].
int Cond_4_1 = 0
 The value of VTBI provided by the user violates hard limits specified by the drug library.
int Cond_4_2 = 0
 The value of VTBI provided by the user violates soft limits specified by the drug library.
int Cond_4_3 = 0
 The VTBI provided by the user complies with that prescribed by the drug library.
int Cond_4_4 = 0
 The value of infusion dose rate provided by the user violates hard limits specified by the drug library.
int Cond_4_5 = 0
 The value of infusion dose rate provided by the user violates soft limits specified by the drug library.
int Cond_4_6 = 0
 The infusion dose rate provided by the user complies with that prescribed by the drug library.
int Cond_5_1 = 0
int MCDR_In_Progress = 0
int Cond_3_1 = 0
 Administration Check failed.
int Cond_3_2 = 0
 Administration Check passed.
int Cond_3_3 = 0
 Prime Check failed.
int Cond_3_4 = 0
 Prime Check passed.
int Cond_3_5 = 0
 The drug label does not reflect correctly and precisely the drug in the reservoir, or the drug is not prescribed by the drug library.
int Cond_3_6 = 0
 The drug label reflects correctly and precisely the drug in the reservoir.
int Cond_3_7 = 0
 The drug dose unit read by the barcode reader does not match that prescribed by the drug library.
int Cond_3_8 = 0
 The drug dose unit read by the barcode reader matches that prescribed by the drug library.
int Cond_3_9 = 0
 The drug concentration read by the barcode reader violates soft limits suggested by the drug library.
int Cond_3_11 = 0
 The drug concentration read by the barcode reader complies with that prescribed by the drug library.
int Cond_3_10 = 0
 The drug concentration read by the barcode reader violates hard limits suggested by the drug library.
int Power_ON = 0
int MCond_1_3 = 0
int MCond_1_4 = 0
int Cond_5_2 = 0
int Cond_6_2 = 0
int Cond_7_1 = 0
int Cond_7_2 = 0
trans_t trans [NB_TRANS]
loc_t loc [NB_TRANS+NB_LOC]
int current_GPCA_state = GPCA_Instance_POST_Init
 A global variable to keep track of the current GPCA state (Glue code).
int prev_GPCA_state = GPCA_Instance_POST_Init
uint8_t MOTOR_SPEED_LEVEL = 1
 Pump motor speed : 1 (20ms), 2 (40ms), 3 (60ms) 5 (100ms).
uint8_t MOTOR_DIRECTION = CLOCKWISE
 Motor direction.
uint8_t MOTOR_STATE = MOTOR_STOP
 Motor state : Stop or Active.
uint8_t INFUSION_DURATION = 1
 Infusion duration : 1 (30sec), 2 (60sec), 3 (90sec), 4 (120 sec), 5 (150 sec), 6 (180 sec).
uint8_t REMAIN_VOL_PERCENT
 Remaining volume percent.
uint8_t pkt_gpca [PKT_SIZE]
 Buffer to contain gpca packets.
int parsing_state = PARSE_INIT
 Parsing state (upstream).
int ctl_parsing_state = PARSE_CTL_INIT
 Parsing state (downstream from client to GPCA).

Function Documentation

int main ( int  Parm_Count,
char *  Parms[] 
)

Main function.

Parameters:
Parm_Count the number of parameters passed to main function.
Parms[] 1) device name 2) Server port number.
Exceptions:
fail to open serial devices.
Returns:
0

Check stdin parameters.

Open serial device connection.

Fill the address for server socket.

Create threads for upstream and downstream independently.

Definition at line 427 of file main.c.

Here is the call graph for this function:

int write_byte_to_controller ( int  fd,
char  data 
)

A function to send one-byte command to the infusion controller.

Send one-byte data to the infusion controller through RS232. fd file descriptor of the RS232 connection to the infusion controller. data command to send to the infusion controller. The result of sending command to the infusion controller, -1 in case fails to send the commmand.

Definition at line 1509 of file main.c.

 All Classes Files Functions Variables Typedefs Defines