Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kukulo2011/OpenCovid_ventilator
Browse files Browse the repository at this point in the history
  • Loading branch information
zathras committed Apr 4, 2020
2 parents bbfbf68 + e54d9d2 commit b85cc85
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 47 deletions.
134 changes: 87 additions & 47 deletions testing_firmware/Ventilator_testing.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,101 @@
Testing sketch for Breezy app for Arduino Nano
*/

#include "crc16.h"

float volume = 450;
float flow = 120;
float pressure = 50;
float ppeak = 50;
float peep = 65;
float pmean= 35;
float RR=85;
float Ti=25;
float Ttot=20;
float O2conc=35;
float VTo=1254.21;
float VTi=1245;
float MVo=1100;
float MV2=1005;
float p_act=35; // actual pressure (cmH2O)
float slm=65; // flow (l/min)
float slm_sum=250; // volume (ml)
float p_peak=50; // peak pressure (cmH2O)
float p_mean=35; // mean pressure (cmH2O)
float peep=65; // positive end-expiratory pressure
float rr=85; // respiratory rate
float o2_perc=35; // O2 concentration
float ti=25; // inspiration time (s)
float te=20; // expiration time (s) // not printed in message
float i_e=0.7; // inspiraton : exspiration
float mvi=12; // mean volume inspiration (l/min)
float mve=11.8; // mean volume expiration (l/min)
float vti=468; // volume tidal inspiration (ml)
float vte=457; // volume tidal expiration (ml)

float p_o2; // O2 supply pressure

CRC16 Crc16;

void setup() {
Serial.begin(115200);
Serial.println("Breezy app testing sketch");

}
void loop() {
Serial.print("breezy,1,");
Serial.print(millis(), 1);
Serial.print(",");
Serial.print(volume, 1);
Serial.print(",");
Serial.print(flow, 1);
Serial.print(",");
Serial.print(pressure, 1);
Serial.print(",");
Serial.print(ppeak, 1);
Serial.print(",");
Serial.print(peep, 1);
Serial.print(",");
Serial.print(pmean, 1);
Serial.print(",");
Serial.print(RR, 1);
Serial.print(",");
Serial.print(Ti, 1);
Serial.print(",");
Serial.print(Ttot, 1);
Serial.print(",");
Serial.print(O2conc, 1);
Serial.print(",");
Serial.print(VTo, 1);
Serial.print(",");
Serial.print(VTi, 1);
Serial.print(",");
Serial.print(MVo, 1);
Serial.print(",");
Serial.print(MV2, 1);
Serial.print(",");
Serial.print("-1");
Serial.println();

uint16_t time = (uint16_t)millis();

char msg[200];
sprintf(msg, "breezy,1,%5u,", time );

dtostrf(p_act, 5, 2, &msg[strlen(msg)]);
strcat(msg, ",");

p_act=p_act+15*sin(random(0,6.28));

if (p_act>=50) p_act=25;
if (p_act<=0) p_act=25;

dtostrf(slm, 5, 2, &msg[strlen(msg)]);
strcat(msg, ",");

slm=slm+1;

if (slm==101) slm=-100;

dtostrf(slm_sum, 5, 2, &msg[strlen(msg)]);
strcat(msg, ",");

slm_sum=slm_sum+10*cos(random(0,6.28));

if (slm_sum>=800) slm_sum=230;
if (slm_sum<=0) slm_sum=250;

dtostrf(p_peak, 5, 1, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(p_mean, 2, 0, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(peep, 2, 0, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(rr, 2, 0, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(o2_perc, 3, 0, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(ti, 5, 2, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(i_e, 4, 1, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(mvi, 4, 1, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(mve, 4, 1, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(vti, 3, 0, &msg[strlen(msg)]);
strcat(msg, ",");

dtostrf(vte, 3, 0, &msg[strlen(msg)]);
strcat(msg, ",");

uint16_t crc = Crc16.get_crc16(msg);

sprintf(&msg[strlen(msg)], "%5u\r\n", crc);
Serial.print(msg);

delay(50);

}
95 changes: 95 additions & 0 deletions testing_firmware/crc16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* Code to calculate CRC16-CCITT
* was adopted from the following site
* http://srecord.sourceforge.net/crc16-ccitt.html
*
*/





#include "crc16.h"

#define poly 0x1021 /* crc-ccitt mask */

uint16_t CRC16::get_crc16(char *text)
{
uint8_t ch, i;

good_crc = 0xffff;
i = 0;
while((ch=text[i])!=0)
{
update_good_crc(ch);
i++;
}
augment_message_for_good_crc();

return good_crc;
}

void CRC16::update_good_crc(uint8_t ch)
{
uint8_t i, v, xor_flag;

/*
Align test bit with leftmost bit of the message byte.
*/
v = 0x80;

for (i=0; i<8; i++)
{
if (good_crc & 0x8000)
{
xor_flag= 1;
}
else
{
xor_flag= 0;
}
good_crc = good_crc << 1;

if (ch & v)
{
/*
Append next bit of message to end of CRC if it is not zero.
The zero bit placed there by the shift above need not be
changed if the next bit of the message is zero.
*/
good_crc= good_crc + 1;
}

if (xor_flag)
{
good_crc = good_crc ^ poly;
}

/*
Align test bit with next bit of the message byte.
*/
v = v >> 1;
}
}

void CRC16::augment_message_for_good_crc()
{
uint8_t i, xor_flag;

for (i=0; i<16; i++)
{
if (good_crc & 0x8000)
{
xor_flag= 1;
}
else
{
xor_flag= 0;
}
good_crc = good_crc << 1;

if (xor_flag)
{
good_crc = good_crc ^ poly;
}
}
}
24 changes: 24 additions & 0 deletions testing_firmware/crc16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef CRC16_H
#define CRC16_H


#include <Arduino.h>

class CRC16
{
public:
uint16_t CRC16::get_crc16(char *text);


private:
uint16_t good_crc;
void update_good_crc(uint8_t ch);
void augment_message_for_good_crc();

};

extern CRC16 Crc16;



#endif // #ifndef CRC16_H

0 comments on commit b85cc85

Please sign in to comment.