📄 senddata.c
字号:
/** \file
* MSP430FE427 Application Program Example
*
* This file send the data from the ESP430 via the serial communication
* port
*
* \author Stefan Schauer
* \date 04/29/2003
*/
// 01/30/04 JEN changed sprintf's to call l_to_a and ul_to_a
//====================================================================
#include "device.h"
#include "comms_uart.h"
#include "SendData.h"
#include "fet4xx_rtclcd.h"
#include "emeter.h"
#include "parameter.h"
//#include <stdio.h>
#include "NumConv.h"
#include <math.h>
#ifdef withUARTComm
#define ldfs "%ld"
// const and var definition
unsigned int TX_Mode = tx_off; // Transmit mode
void SendData(void)
{
static unsigned int value;
static unsigned long lvalue;
static char strbuf[20];
switch (TX_Mode)
{
// static unsigned i =0;
case tx_off: break;
case tx_ch1:
_DINT();
SendResult((unsigned char*) &wfs1, 2);
SendString("\r");
_EINT(); // Enable Interrupts
/*
SendChar((char)(wfs1>>8));
SendChar((char)(wfs1&0xff));
i++;
if (i < 0x400) {;}
else if (i == 0x5400) { TX_Mode = tx_off; i = 0; }
*/
break;
case tx_ch2:
_DINT();
SendResult((unsigned char*) &wfs2, 2);
SendString("\r");
_EINT(); // Enable Interrupts
/*
SendChar((char)(wfs2>>8));
SendChar((char)(wfs2&0xff));
i++;
if (i < 0x400) {;}
else if (i == 0x5400) { TX_Mode = tx_off; i = 0; }
*/
break;
case tx_ch3:
_DINT();
SendResult((unsigned char*) &wfs3, 2);
SendString("\r");
_EINT(); // Enable Interrupts
/*
SendChar((char)(wfs3>>8));
SendChar((char)(wfs3&0xff));
i++;
if (i < 0x400) {;}
else if (i == 0x5400) { TX_Mode = tx_off; i = 0; }
*/
break;
case tx_temp:
SendString("\rTemp: ");
SendResult((unsigned char*) &temperature, 2);
SendString("\r");
break;
case tx_dump:
SendChar(0x0C);
SendString("Active Energy1: ");
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
energy.w[0] = ACTENERGY2_LO;
energy.w[1] = ACTENERGY2_HI;
SendString("Active Energy2: ");
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
energy.w[0] = REACTENERGY_LO;
energy.w[1] = REACTENERGY_HI;
SendString("Reactive Energy: ");
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
energy.w[0] = APPENERGY_LO;
energy.w[1] = APPENERGY_HI;
SendString("Apparent Energy: ");
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
value = V1RMS;
SendString("V(RMS): ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = IRMS_HI;
SendString("I(RMS): ");
SendResult((unsigned char*) &value, 2);
SendChar('.');
value = IRMS_LO;
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = VPEAK;
SendString("V(Peak): ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = IPEAK;
SendString("I(Peak): ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
// value = savedRET[20];//POWERFCT;
value = POWERFCT;
SendString("PF: ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = (unsigned int)((unsigned char)CAPIND);
SendString("CapInd: ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = MAINSPERIOD;
// value = savedRET[22];
SendString("f: ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
lvalue = ((LINECYCLCNT_LO) + ((unsigned long)LINECYCLCNT_HI << 16));
// lvalue = ((savedRET[28]) + ((unsigned long)savedRET[29] << 16));
SendString("Cycles: ");
SendResult((unsigned char*) &lvalue, 4);
SendChar('\r');
lvalue = ((NMBMEAS_LO) + ((unsigned long)NMBMEAS_HI << 16));
SendString("Num of Meas.: ");
SendResult((unsigned char*) &lvalue, 4);
SendChar('\r');
SendChar('\r');
break;
case tx_energy:
lvalue = (unsigned long)((float) energy.l * (s_parameters.EnergyRatio/1000));
SendString("Active Energy1 (mW): ");
//host_decu32(lvalue);
l_to_a(lvalue, strbuf);
// sprintf(strbuf, ldfs,lvalue);
SendString(strbuf);
SendChar('\r');
break;
case tx_cal:
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
TX_Mode = tx_off;
break;
case tx_values:
SendChar(0x0C);
SendString("Time: ");
SendResult((unsigned char*) &HOUR, 1);
SendString(":");
SendResult((unsigned char*) &MIN, 1);
SendString(":");
SendResult((unsigned char*) &SEC, 1);
SendString(" ");
SendResult((unsigned char*) &DAY, 1);
SendString(".");
SendResult((unsigned char*) &MONTH, 1);
SendString(".");
SendResult((unsigned char*) &YEAR, 1);
SendChar('\r');
lvalue = ((unsigned long) (V1RMS * (s_parameters.VRatio*1000))/1000);
SendString("V(RMS/mV): ");
//host_decu32(lvalue);
l_to_a(lvalue, strbuf);
// sprintf(strbuf, ldfs,lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = ((unsigned long) (IRMS_HI * s_parameters.IRatio*1000))/1000;
SendString("I(RMS/mA): ");
//host_decu32(lvalue);
l_to_a(lvalue, strbuf);
// sprintf(strbuf, ldfs,lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = ((unsigned long) (VPEAK * (s_parameters.VRatio*1000))/1000);
SendString("V(Peak/mV): ");
//host_decu32(lvalue);
l_to_a(lvalue, strbuf);
// sprintf(strbuf, ldfs,lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = ((unsigned long) (IPEAK * s_parameters.IRatio*1000))/1000;
SendString("I(peak/mA): ");
//host_decu32(lvalue);
l_to_a(lvalue, strbuf);
// sprintf(strbuf, ldfs,lvalue);
SendString(strbuf);
SendChar('\r');
value = POWERFCT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -