IEC60601-1-8 Audible Alert Generator

Dependencies:   mbed

See here for more info.

Committer:
wim
Date:
Fri May 18 19:51:12 2012 +0000
Revision:
0:07767204347b
First Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:07767204347b 1 /**************************************************************
wim 0:07767204347b 2 * commands.c
wim 0:07767204347b 3 *
wim 0:07767204347b 4 * This Module contains the command handler and menus for the
wim 0:07767204347b 5 * Medical alert tone demo
wim 0:07767204347b 6 *
wim 0:07767204347b 7 * Copyright(C) 2007, NXP Semiconductor
wim 0:07767204347b 8 * All rights reserved.
wim 0:07767204347b 9 *
wim 0:07767204347b 10 * Port to mbed 2012 (WH)
wim 0:07767204347b 11 **************************************************************/
wim 0:07767204347b 12
wim 0:07767204347b 13 #include "mbed.h"
wim 0:07767204347b 14 #include "commands.h"
wim 0:07767204347b 15 #include "IEC60601-1-8.h"
wim 0:07767204347b 16
wim 0:07767204347b 17 //Externals from main
wim 0:07767204347b 18 extern Serial pc;
wim 0:07767204347b 19 extern bool running;
wim 0:07767204347b 20 extern IEC60601 IEC_Alarm;
wim 0:07767204347b 21
wim 0:07767204347b 22 enum State_Type {MAIN_STATE, HI_PRI_STATE, MED_PRI_STATE, LO_PRI_STATE, TST_STATE};
wim 0:07767204347b 23 State_Type cmd_state;
wim 0:07767204347b 24
wim 0:07767204347b 25 unsigned char proc_cmd;
wim 0:07767204347b 26
wim 0:07767204347b 27 // Menus
wim 0:07767204347b 28 void MainMenu(void) {
wim 0:07767204347b 29 pc.printf ("Main Commands:\n\r");
wim 0:07767204347b 30 pc.printf ("Press '0' to Exit\n\r");
wim 0:07767204347b 31 pc.printf ("Press '1' for High Priority Alarm Menu\n\r");
wim 0:07767204347b 32 pc.printf ("Press '2' for Medium Priority Alarm Menu\n\r");
wim 0:07767204347b 33 pc.printf ("Press '3' for Low Priority Alarm Menu\n\r");
wim 0:07767204347b 34 pc.printf ("Press '4' for Test Menu\n\r");
wim 0:07767204347b 35 pc.printf ("Enter Command Number: ");
wim 0:07767204347b 36 }
wim 0:07767204347b 37
wim 0:07767204347b 38 void HPMenu(void) {
wim 0:07767204347b 39 pc.printf ("High Priority Commands:\n\r");
wim 0:07767204347b 40 pc.printf (" 0 - Exit High Priority Commands\n\r");
wim 0:07767204347b 41 pc.printf (" 1 - High Priority General Alarm\n\r");
wim 0:07767204347b 42 pc.printf (" 2 - High Priority Cardiac Alarm\n\r");
wim 0:07767204347b 43 pc.printf (" 3 - High Priority Artificial Perfusion Alarm\n\r");
wim 0:07767204347b 44 pc.printf (" 4 - High Priority Ventilation Alarm\n\r");
wim 0:07767204347b 45 pc.printf (" 5 - High Priority Temperature Alarm\n\r");
wim 0:07767204347b 46 pc.printf (" 6 - High Priority Oxygen Alarm\n\r");
wim 0:07767204347b 47 pc.printf (" 7 - High Priority Drug Delivery Alarm\n\r");
wim 0:07767204347b 48 pc.printf (" 8 - High Priority Equipment/Supply Failure Alarm\n\r");
wim 0:07767204347b 49 pc.printf ("Enter Command Number: ");
wim 0:07767204347b 50 }
wim 0:07767204347b 51
wim 0:07767204347b 52 void MPMenu(void) {
wim 0:07767204347b 53 pc.printf ("Medium Priority Commands:\n\r");
wim 0:07767204347b 54 pc.printf (" 0 - Exit Medium Priority Commands\n\r");
wim 0:07767204347b 55 pc.printf (" 1 - Medium Priority General Alarm\n\r");
wim 0:07767204347b 56 pc.printf (" 2 - Medium Priority Cardiac Alarm\n\r");
wim 0:07767204347b 57 pc.printf (" 3 - Medium Priority Artificial Perfusion Alarm\n\r");
wim 0:07767204347b 58 pc.printf (" 4 - Medium Priority Ventilation Alarm\n\r");
wim 0:07767204347b 59 pc.printf (" 5 - Medium Priority Temperature Alarm\n\r");
wim 0:07767204347b 60 pc.printf (" 6 - Medium Priority Oxygen Alarm\n\r");
wim 0:07767204347b 61 pc.printf (" 7 - Medium Priority Drug Delivery Alarm\n\r");
wim 0:07767204347b 62 pc.printf (" 8 - Medium Priority Equipment/Supply Failure Alarm\n\r");
wim 0:07767204347b 63 pc.printf ("Enter Command Number: ");
wim 0:07767204347b 64 }
wim 0:07767204347b 65
wim 0:07767204347b 66 void LPMenu(void) {
wim 0:07767204347b 67 pc.printf ("Low Priority Commands:\n\r");
wim 0:07767204347b 68 pc.printf (" 0 - Exit Low Priority Commands\n\r");
wim 0:07767204347b 69 pc.printf (" 1 - Low Priority General Alarm\n\r");
wim 0:07767204347b 70 pc.printf ("Enter Command Number: ");
wim 0:07767204347b 71
wim 0:07767204347b 72 }
wim 0:07767204347b 73
wim 0:07767204347b 74 void TSTMenu(void) {
wim 0:07767204347b 75 pc.printf ("Test Commands:\n\r");
wim 0:07767204347b 76 pc.printf (" 0 - Exit Test Commands\n\r");
wim 0:07767204347b 77 pc.printf (" 1 - Sound Low Multi-Tone\n\r");
wim 0:07767204347b 78 pc.printf (" 2 - Sound High Multi-Tone\n\r");
wim 0:07767204347b 79 pc.printf (" 3 - Sound Low Single Tone\n\r");
wim 0:07767204347b 80 pc.printf (" 4 - Sound High Single Tone\n\r");
wim 0:07767204347b 81 pc.printf (" 5 - Reset Test Settings\n\r");
wim 0:07767204347b 82 pc.printf ("Enter Command Number: ");
wim 0:07767204347b 83
wim 0:07767204347b 84 }
wim 0:07767204347b 85
wim 0:07767204347b 86 void ShowMenu() {
wim 0:07767204347b 87
wim 0:07767204347b 88 switch (cmd_state) {
wim 0:07767204347b 89 case MAIN_STATE:
wim 0:07767204347b 90 MainMenu();
wim 0:07767204347b 91 break;
wim 0:07767204347b 92 case HI_PRI_STATE:
wim 0:07767204347b 93 HPMenu();
wim 0:07767204347b 94 break;
wim 0:07767204347b 95 case MED_PRI_STATE:
wim 0:07767204347b 96 MPMenu();
wim 0:07767204347b 97 break;
wim 0:07767204347b 98 case LO_PRI_STATE:
wim 0:07767204347b 99 LPMenu();
wim 0:07767204347b 100 break;
wim 0:07767204347b 101 case TST_STATE:
wim 0:07767204347b 102 TSTMenu();
wim 0:07767204347b 103 break;
wim 0:07767204347b 104 default:
wim 0:07767204347b 105 break;
wim 0:07767204347b 106 }
wim 0:07767204347b 107 }
wim 0:07767204347b 108
wim 0:07767204347b 109
wim 0:07767204347b 110
wim 0:07767204347b 111 //Commands
wim 0:07767204347b 112 void MainCommnds(char command) {
wim 0:07767204347b 113 switch (command) {
wim 0:07767204347b 114 case '0':
wim 0:07767204347b 115 pc.printf("Done\n\r");
wim 0:07767204347b 116 running = false;
wim 0:07767204347b 117 break;
wim 0:07767204347b 118
wim 0:07767204347b 119 case '1':
wim 0:07767204347b 120 cmd_state = HI_PRI_STATE;
wim 0:07767204347b 121 break;
wim 0:07767204347b 122
wim 0:07767204347b 123 case '2':
wim 0:07767204347b 124 cmd_state = MED_PRI_STATE;
wim 0:07767204347b 125 break;
wim 0:07767204347b 126
wim 0:07767204347b 127 case '3':
wim 0:07767204347b 128 cmd_state = LO_PRI_STATE;
wim 0:07767204347b 129 break;
wim 0:07767204347b 130
wim 0:07767204347b 131 case '4':
wim 0:07767204347b 132 cmd_state = TST_STATE;
wim 0:07767204347b 133 break;
wim 0:07767204347b 134 default:
wim 0:07767204347b 135 break;
wim 0:07767204347b 136 }
wim 0:07767204347b 137 }
wim 0:07767204347b 138
wim 0:07767204347b 139
wim 0:07767204347b 140 void HPCommnds(char command) {
wim 0:07767204347b 141
wim 0:07767204347b 142 switch (command)
wim 0:07767204347b 143 {
wim 0:07767204347b 144 case '0':
wim 0:07767204347b 145 cmd_state = MAIN_STATE;
wim 0:07767204347b 146 break;
wim 0:07767204347b 147 case '1':
wim 0:07767204347b 148 pc.printf ("High Priority General Alarm\n\r");
wim 0:07767204347b 149 IEC_Alarm.TurnOnAlarm(HIGH, GENERAL);
wim 0:07767204347b 150 break;
wim 0:07767204347b 151 case '2':
wim 0:07767204347b 152 pc.printf ("High Priority Cardiac Alarm\n\r");
wim 0:07767204347b 153 IEC_Alarm.TurnOnAlarm(HIGH, CARDIOVASCULAR);
wim 0:07767204347b 154 break;
wim 0:07767204347b 155 case '3':
wim 0:07767204347b 156 pc.printf ("High Priority Artificial Perfusion Alarm\n\r");
wim 0:07767204347b 157 IEC_Alarm.TurnOnAlarm(HIGH, PERFUSION);
wim 0:07767204347b 158 break;
wim 0:07767204347b 159 case '4':
wim 0:07767204347b 160 pc.printf ("High Priority Ventilation Alarm\n\r");
wim 0:07767204347b 161 IEC_Alarm.TurnOnAlarm(HIGH, VENTILATION);
wim 0:07767204347b 162 break;
wim 0:07767204347b 163 case '5':
wim 0:07767204347b 164 pc.printf ("High Priority Temperature Alarm\n\r");
wim 0:07767204347b 165 IEC_Alarm.TurnOnAlarm(HIGH, TEMPERATURE);
wim 0:07767204347b 166 break;
wim 0:07767204347b 167 case '6':
wim 0:07767204347b 168 pc.printf ("High Priority Oxygen Alarm\n\r");
wim 0:07767204347b 169 IEC_Alarm.TurnOnAlarm(HIGH, OXYGEN);
wim 0:07767204347b 170 break;
wim 0:07767204347b 171 case '7':
wim 0:07767204347b 172 pc.printf ("High Priority Drug Delivery Alarm\n\r");
wim 0:07767204347b 173 IEC_Alarm.TurnOnAlarm(HIGH, DRUG_DELIVERY);
wim 0:07767204347b 174 break;
wim 0:07767204347b 175 case '8':
wim 0:07767204347b 176 pc.printf ("High Priority Equipment/Supply Failure Alarm\n\r");
wim 0:07767204347b 177 IEC_Alarm.TurnOnAlarm(HIGH, POWER_FAIL);
wim 0:07767204347b 178 break;
wim 0:07767204347b 179 default:
wim 0:07767204347b 180 pc.printf ("Command not supported\n\r");
wim 0:07767204347b 181 break;
wim 0:07767204347b 182 }
wim 0:07767204347b 183 }
wim 0:07767204347b 184
wim 0:07767204347b 185 void MPCommnds(char command) {
wim 0:07767204347b 186
wim 0:07767204347b 187 switch (command)
wim 0:07767204347b 188 {
wim 0:07767204347b 189 case '0':
wim 0:07767204347b 190 cmd_state = MAIN_STATE;
wim 0:07767204347b 191 break;
wim 0:07767204347b 192 case '1':
wim 0:07767204347b 193 pc.printf ("Medium Priority General Alarm\n\r");
wim 0:07767204347b 194 IEC_Alarm.TurnOnAlarm(MEDIUM, GENERAL);
wim 0:07767204347b 195 break;
wim 0:07767204347b 196 case '2':
wim 0:07767204347b 197 pc.printf ("Medium Priority Cardiac Alarm\n\r");
wim 0:07767204347b 198 IEC_Alarm.TurnOnAlarm(MEDIUM, CARDIOVASCULAR);
wim 0:07767204347b 199 break;
wim 0:07767204347b 200 case '3':
wim 0:07767204347b 201 pc.printf ("Medium Priority Artificial Perfusion Alarm\n\r");
wim 0:07767204347b 202 IEC_Alarm.TurnOnAlarm(MEDIUM, PERFUSION);
wim 0:07767204347b 203 break;
wim 0:07767204347b 204 case '4':
wim 0:07767204347b 205 pc.printf ("Medium Priority Ventilation Alarm\n\r");
wim 0:07767204347b 206 IEC_Alarm.TurnOnAlarm(MEDIUM, VENTILATION);
wim 0:07767204347b 207 break;
wim 0:07767204347b 208 case '5':
wim 0:07767204347b 209 pc.printf ("Medium Priority Temperature Alarm\n\r");
wim 0:07767204347b 210 IEC_Alarm.TurnOnAlarm(MEDIUM, TEMPERATURE);
wim 0:07767204347b 211 break;
wim 0:07767204347b 212 case '6':
wim 0:07767204347b 213 pc.printf ("Medium Priority Oxygen Alarm\n\r");
wim 0:07767204347b 214 IEC_Alarm.TurnOnAlarm(MEDIUM, OXYGEN);
wim 0:07767204347b 215 break;
wim 0:07767204347b 216 case '7':
wim 0:07767204347b 217 pc.printf ("Medium Priority Drug Delivery Alarm\n\r");
wim 0:07767204347b 218 IEC_Alarm.TurnOnAlarm(MEDIUM, DRUG_DELIVERY);
wim 0:07767204347b 219 break;
wim 0:07767204347b 220 case '8':
wim 0:07767204347b 221 pc.printf ("Medium Priority Equipment/Supply Failure Alarm\n\r");
wim 0:07767204347b 222 IEC_Alarm.TurnOnAlarm(MEDIUM, POWER_FAIL);
wim 0:07767204347b 223 break;
wim 0:07767204347b 224 default:
wim 0:07767204347b 225 pc.printf ("Command not supported\n\r");
wim 0:07767204347b 226 break;
wim 0:07767204347b 227 }
wim 0:07767204347b 228 }
wim 0:07767204347b 229
wim 0:07767204347b 230 void LPCommnds(char command)
wim 0:07767204347b 231 {
wim 0:07767204347b 232 switch (command) {
wim 0:07767204347b 233 case '0':
wim 0:07767204347b 234 cmd_state = MAIN_STATE;
wim 0:07767204347b 235 break;
wim 0:07767204347b 236 case '1':
wim 0:07767204347b 237 pc.printf ("Low Priority Alarm\n\r");
wim 0:07767204347b 238 IEC_Alarm.TurnOnAlarm(LOW, LOW_ALARM);
wim 0:07767204347b 239 break;
wim 0:07767204347b 240
wim 0:07767204347b 241 default:
wim 0:07767204347b 242 pc.printf ("Command not supported\n\r");
wim 0:07767204347b 243 break;
wim 0:07767204347b 244 }
wim 0:07767204347b 245 }
wim 0:07767204347b 246
wim 0:07767204347b 247 void TestCommnds(char command) {
wim 0:07767204347b 248
wim 0:07767204347b 249 switch (command) {
wim 0:07767204347b 250 case '0':
wim 0:07767204347b 251 cmd_state = MAIN_STATE;
wim 0:07767204347b 252 IEC_Alarm.TestAlarm(C4, 255, 255, 255, 255, 255); // make sure weightfactors are reset
wim 0:07767204347b 253 break;
wim 0:07767204347b 254 case '1':
wim 0:07767204347b 255 pc.printf ("Sound Low Multi Tone\n\r");
wim 0:07767204347b 256 IEC_Alarm.TestAlarm(C4, 255, 255, 255, 255, 255);
wim 0:07767204347b 257 break;
wim 0:07767204347b 258 case '2':
wim 0:07767204347b 259 pc.printf ("Sound High Multi Tone\n\r");
wim 0:07767204347b 260 IEC_Alarm.TestAlarm(C5, 255, 255, 255, 255, 255);
wim 0:07767204347b 261 break;
wim 0:07767204347b 262 case '3':
wim 0:07767204347b 263 pc.printf ("Sound Low Single Tone\n\r");
wim 0:07767204347b 264 IEC_Alarm.TestAlarm(C4, 255, 0, 0, 0, 0);
wim 0:07767204347b 265 break;
wim 0:07767204347b 266 case '4':
wim 0:07767204347b 267 pc.printf ("Sound High Single Tone\n\r");
wim 0:07767204347b 268 IEC_Alarm.TestAlarm(C5, 0, 0, 0, 0, 255);
wim 0:07767204347b 269 break;
wim 0:07767204347b 270 case '5':
wim 0:07767204347b 271 pc.printf ("Reset Test Settings\n\r");
wim 0:07767204347b 272 IEC_Alarm.TestAlarm(C4, 255, 255, 255, 255, 255);
wim 0:07767204347b 273 break;
wim 0:07767204347b 274 default:
wim 0:07767204347b 275 pc.printf ("Command not supported\n\r");
wim 0:07767204347b 276 break;
wim 0:07767204347b 277 }
wim 0:07767204347b 278 }
wim 0:07767204347b 279
wim 0:07767204347b 280 void InitCommand(void) {
wim 0:07767204347b 281
wim 0:07767204347b 282 cmd_state = MAIN_STATE;
wim 0:07767204347b 283 }
wim 0:07767204347b 284
wim 0:07767204347b 285
wim 0:07767204347b 286
wim 0:07767204347b 287 void DecodeCommand(char command) {
wim 0:07767204347b 288
wim 0:07767204347b 289 switch (cmd_state) {
wim 0:07767204347b 290 case MAIN_STATE:
wim 0:07767204347b 291 // pc.printf ("Main Commands:\n\r");
wim 0:07767204347b 292 MainCommnds(command);
wim 0:07767204347b 293 break;
wim 0:07767204347b 294
wim 0:07767204347b 295 case HI_PRI_STATE:
wim 0:07767204347b 296 // pc.printf ("High Priority Commands:\n\r");
wim 0:07767204347b 297 HPCommnds(command);
wim 0:07767204347b 298 break;
wim 0:07767204347b 299
wim 0:07767204347b 300 case MED_PRI_STATE:
wim 0:07767204347b 301 // pc.printf ("Medium Priority Commands:\n\r");
wim 0:07767204347b 302 MPCommnds(command);
wim 0:07767204347b 303 break;
wim 0:07767204347b 304
wim 0:07767204347b 305 case LO_PRI_STATE:
wim 0:07767204347b 306 // pc.printf ("Low Priority Commands:\n\r");
wim 0:07767204347b 307 LPCommnds(command);
wim 0:07767204347b 308 break;
wim 0:07767204347b 309
wim 0:07767204347b 310 case TST_STATE:
wim 0:07767204347b 311 // pc.printf ("Test Commands:\n\r");
wim 0:07767204347b 312 TestCommnds(command);
wim 0:07767204347b 313 break;
wim 0:07767204347b 314
wim 0:07767204347b 315 default:
wim 0:07767204347b 316 break;
wim 0:07767204347b 317 }
wim 0:07767204347b 318 }
wim 0:07767204347b 319
wim 0:07767204347b 320
wim 0:07767204347b 321
wim 0:07767204347b 322
wim 0:07767204347b 323
wim 0:07767204347b 324