Skip to content

Commit

Permalink
Update Commands_Info.ino, Commands_Sample.ino, and 43 more files...
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverZobel committed Jan 11, 2023
0 parents commit c19ed95
Show file tree
Hide file tree
Showing 45 changed files with 10,312 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Commands_Info.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Displays information about the device
void C_Info(){
Serial.println("--------------------------------------------------------------------------");
Serial.println(" OASIS Device Information ");
Serial.println("--------------------------------------------------------------------------");

// Hardware Version
Serial.print("[OASIS] Device Hardware Version is ");
Serial.print(HW_MAJOR);
Serial.print(".");
Serial.println(HW_MINOR);

// Firmware Version
Serial.print("[OASIS] Device Firmware Version is ");
Serial.print(FW_MAJOR);
Serial.print(".");
Serial.println(FW_MINOR);

// ADC Resolution
Serial.print("[OASIS] ADC resolution: ");
Serial.println(ADC_BITS);

// Feature - TEDS
Serial.print("[OASIS] TEDS module installed (1=yes, 0=no): ");
Serial.println(F_TEDS);

// Feature - WSS
Serial.print("[OASIS] WSS module installed (1=yes, 0=no): ");
Serial.println(F_WSS);

// Custom Device Name
Serial.print("[OASIS] Device name: ");
Serial.print(DeviceName);
Serial.println();
Serial.println("--------------------------------------------------------------------------");
}

// Returns raw values over serial for GUI
void C_RawInfo(){
// Hardware Version
Serial.print(HW_MAJOR);
Serial.print(".");
Serial.print(HW_MINOR);
Serial.print(";");

// Firmware Version
Serial.print(FW_MAJOR);
Serial.print(".");
Serial.print(FW_MINOR);
Serial.print(";");

// ADC Resolution
Serial.print(ADC_BITS);
Serial.print(";");

// Feature - TEDS
Serial.print(F_TEDS);
Serial.print(";");

// Feature - WSS
Serial.print(F_WSS);
Serial.print(";");

// Custom Device Name
Serial.print(DeviceName);
Serial.println(";");
}
182 changes: 182 additions & 0 deletions Commands_Sample.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// Sample routine
void C_Sample(int source){

resetVars();

// Get Acquisition parameters
StringPointer = strtok(NULL, delimiter);
t_sample = strtof(StringPointer, NULL);
StringPointer = strtok(NULL, delimiter);
f_sample = strtof(StringPointer, NULL);
StringPointer = strtok(NULL, delimiter);
TRIGG_LEVEL = strtof(StringPointer, NULL);
StringPointer = strtok(NULL, delimiter);
sync_mode = strtof(StringPointer, NULL);
T_sample = 1/f_sample*1000000; //Sample periode in microseconds
n_sample = f_sample*t_sample;

if(n_sample>PS_CACHE_SIZE*BYTES_PER_SAMPLE){
Serial.print("[OASIS] FATAL ERROR: Sample size too long to fit into buffer. Aborting data acquisition.");
ledError();
Sound_Fatal_Error();
return;
}

OASISPaw.setTimer(T_sample);

// Switch between normal and triggered mode
if(TRIGG_LEVEL==0){
TRIGG = 1;
}
else {
TRIGG = 0;
}

// Filter triggered mode if synchronization enabled
if(sync_mode){
TRIGG = 1;
}

// Confirming Acquisition parameters (Serial)
Serial.print("[OASIS] Sampling for ");
Serial.print(t_sample);
Serial.print(" second(s) with ");
Serial.print(f_sample);
Serial.println(" Hz.");
if(!TRIGG){
Serial.print("[OASIS] Waiting for TRIGGER on channel 1; when surpassing ");
Serial.print(TRIGG_LEVEL);
Serial.println(" V ...");
}

// Confirming Acquisition parameters (UDP)
if(source==2){
udp.beginPacket(udpTargetIP,udpPort);
udp.print("[OASIS] Sampling for ");
udp.print(t_sample);
udp.print(" second(s) with ");
udp.print(f_sample);
udp.println(" Hz.");
if(!TRIGG){
udp.print("[OASIS] Waiting for TRIGGER on channel 1; when surpassing ");
udp.print(TRIGG_LEVEL);
udp.println(" V ...");
}
udp.endPacket();
}

// Set send API
if(source==1){
SendSerial = true;
}
if(source==2){
SendUDP = true;
}

// Announce Data Incoming for normal sampling
//if(TRIGG){
if(source==1){
Serial.println("<>");
}
if(source==2){
Serial.println("[OASIS] Data incoming on UDP.");
udp.beginPacket(udpTargetIP,udpPort);
udp.println("<>");
udp.endPacket();
}
//}

xTaskCreatePinnedToCore(SendData, "DataSendTask", 10000, NULL, 0, &DataSender, 0);
if(sync_mode==0){
// Start Sampling
ledBlue();
Sound_Sample_Start();
OASISPaw.enableTimer();
}
else {
attachInterrupt(CC_GDO2, WSS_ISR, RISING);

// Trigger Sync Source
if(sync_mode==1){
ledCyan();
Sound_Sample_Start();
WSS_send();
}
// Arm Sync Sink
else{
ledPurple();
Sound_WSS_armed();
WSS_listen();
}
}

// Sample Loop
while(sampleCount<n_sample){
if(OASISPaw.FaultFlag){
OASISPaw.disableTimer();
resetVars();
Serial.print("[OASIS] FATAL ERROR: Sampling too fast! Data processing did not finish in time.");
Serial.println();
ledError();
Sound_Fatal_Error();
break;
}
if(OASISPaw.InterruptFlag){
OASISPaw.InterruptFlag = 0;
if(TRIGG){sampleCount++;}
OASISPaw.OASISBusy = 0;
}
}

// Disable Sampling
OASISPaw.disableTimer();
if(sync_mode){
detachInterrupt(CC_GDO2);
}
ledWaiting();
Sound_Sample_End();

// Handle last data packet
while(PacketToSend){
delay(1); // Wait
}
if(CacheIndex){
SendLastPacket = true;
}
while(SendLastPacket){
delay(1); // Wait
}
vTaskDelete(DataSender);

// Send Data from PSRAM - Not implemented yet
//for(long l=0; l<n_sample*8; l++){
// Serial.write(OASISBuffer[l]);
//}

// Send preTRIGG data
if(TRIGG_LEVEL!=0){
while(true){
if(Serial.available()){
Command = Serial.readString();
Command.toCharArray(StrValues,42);
StringPointer = strtok(StrValues, delimiter);
Command = String(StringPointer);
}
if(udp.parsePacket()){
udp.read(udpBuffer, 255);
StringPointer = strtok(udpBuffer, delimiter);
Command = String(StringPointer);
}
if(Command=="Drq"){
break;
}
}
sendPreTRIGGData(source);
}

if(source==2){
Serial.println("[OASIS] Finished Data Acquisition over UDP.");
Serial.println();
}
ledReady();
}
73 changes: 73 additions & 0 deletions Commands_Sound.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Mute the buzzer
void C_Mute(){
EEPROM.write(0, 1); // Write variable to address 0x00
EEPROM.commit();
OASISMute = EEPROM.read(0);
Serial.println("[OASIS] Muted buzzer.");
}

// Unmute the buzzer
void C_Unmute(){
EEPROM.write(0, 0); // Write variable to address 0x00
EEPROM.commit();
OASISMute = EEPROM.read(0);
Serial.println("[OASIS] Unmuted buzzer.");
StartupSound();
}

// Startup Sound
void StartupSound(){
Wire.beginTransmission(0x70>>1);
Wire.write(0x01); // Select output register
Wire.write(0x10);
Wire.endTransmission();
OASISPaw.tone(500, 120);

Wire.beginTransmission(0x70>>1);
Wire.write(0x01); // Select output register
Wire.write(0x30);
Wire.endTransmission();
OASISPaw.tone(600, 120);

Wire.beginTransmission(0x70>>1);
Wire.write(0x01); // Select output register
Wire.write(0x70);
Wire.endTransmission();
OASISPaw.tone(700, 120);

Wire.beginTransmission(0x70>>1);
Wire.write(0x01); // Select output register
Wire.write(0xF0);
Wire.endTransmission();
OASISPaw.tone(800, 120);
}

// Sample Start Sound
void Sound_Sample_Start(){
OASISPaw.tone(1047, 125);
}

// Sample End Sound
void Sound_Sample_End(){
OASISPaw.tone(947, 125);
}

void Sound_Fatal_Error(){
OASISPaw.tone(1047, 300);
delay(300);
OASISPaw.tone(1047, 300);
delay(300);
OASISPaw.tone(1047, 300);
}

void Sound_Bad_Command(){
OASISPaw.tone(1047, 200);
delay(100);
OASISPaw.tone(1047, 500);
}

void Sound_WSS_armed(){
OASISPaw.tone(500, 100);
delay(100);
OASISPaw.tone(500, 200);
}
29 changes: 29 additions & 0 deletions Commands_TEDDY.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Function to read TEDS and return contents over serial interface - Not implemented yet
void C_ReadTEDS(){
// Init TEDS reading on Channel X

// SwitchChannelXToTEDS(); (not implemented yet)
Serial.print("TEDS read status: ");
Serial.println(teddy.read());
Serial.print("ROM device type: ");
Serial.println(teddy.getROMDeviceType());
Serial.print("Transducer manufacturer: ");
Serial.println(teddy.getManufacturer());
Serial.print("Transducer type: ");
Serial.println(teddy.getTransducerType());
Serial.print("Serial number: ");
unsigned long int SerialNum = teddy.getSerialNumber();
Serial.println(SerialNum);
Serial.print("Sensor direction: ");
Serial.println(teddy.getSensorDirection());
Serial.print("Sensor sensitivity [V/(m/s^2)]: ");
Serial.printf("%.8f", teddy.getSensitivity());
Serial.println();
Serial.print("Sensor sensitivity [mV/g]: ");
Serial.printf("%.8f",teddy.getSensitivity()*9806.65);
Serial.println();
Serial.print("Calibration date (days since January 1st, 1998): ");
Serial.println(teddy.getCalibrationDate());
Serial.println();
// SwitchChannelXToICP(); (not implemented yet)
}
Loading

0 comments on commit c19ed95

Please sign in to comment.