/* Copyright 2025 by COG9 Enterprises LLC
 * All rights reserved.
 * Title: ascii.ino
 * Author: Jed Marti KI7NNP
 * Description: Dump collected data in ASCII format (sort of CSV like).
 * Created: Mon Oct 13 12:34:06 2025
 * Revision History:
 */

#include <I2C_24LC1025.h>

#include "powerard.h"
#include "record.h"

// The EEPROM.
extern I2C_24LC1025 seeprom;

// Use the buffer from record.
extern uint8_t  whichRecord;
extern recordAmperage            rA;
extern recordAmperageVoltage     rAV;
extern recordAmperageTemperature rAT;
extern recordAll                 rAVT;

extern uint32_t recordByte;


void asciiDump(void)
/*     Read the SEEPROM until we reach the end and write it out as ASCII.  Generates way too much.
 * Parameters: none
 * External References:
 *   SEEBuf: a buffer for all SEEPROM records.
 *   recordByte: The global byte in the SEEPROM.
 * Returned Values: none
 * Errors detected: Fail on read.
 */
{
  char     msg[20];
  uint32_t readthem;

  Serial.println();
  recordByte = 0;
  /* loop:
 readthem = seeprom.readBlock(recordByte, (uint8_t*) &SEEBuf, sizeof(record) - sizeof(uint16_t));
  if (readthem != sizeof(record) - sizeof(uint16_t))
  {
    Serial.println("Read ");
    Serial.print(readthem);
    Serial.print(" but expected ");
    Serial.println(sizeof(record) - sizeof(uint16_t));
    return;
  }

 // Some 0's indicate we're done.
  if (SEEBuf.dateTime[0] == 0 &&
      SEEBuf.dateTime[1] == 0 &&
      (SEEBuf.dateTime[2] == 0 || SEEBuf.dateTime[2] == 0xFF) &&
      (SEEBuf.dateTime[3] == 0 || SEEBuf.dateTime[3] == 0xFF))
  {
    Serial.println("EOF detected");
    return;
  }
  
  // Date.
  ctimec(msg, SEEBuf.dateTime);
  Serial.print(msg);
  Serial.print("  ");

  Serial.print(F("5v:"));
  Serial.print(SEEBuf.mamps5);

  Serial.print(F("ma 12v:"));
  Serial.print(SEEBuf.mamps12);

  Serial.print(F("ma 18v:"));
  Serial.print(SEEBuf.mamps18);

  Serial.print(F("ma Bat:"));
  Serial.print(((float) SEEBuf.battery) / 10.0f, 1);
  Serial.println("v");

  recordByte += sizeof(record) - sizeof(uint16_t);
  goto loop;
  */
}



// EOF
