Changeset 56

Show
Ignore:
Timestamp:
11/03/09 08:09:41 (3 years ago)
Author:
icarus75
Message:

uc: serial.c clean-up + send() rewrite

Location:
flukso/trunk/uc
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • flukso/trunk/uc/main.c

    r53 r56  
    3737 
    3838// variable declarations 
     39uint8_t i; 
     40 
    3941volatile struct state aux[4] = {{false, false, START}, {false, false, START}, {false, false, START}, {false, false, START}}; 
    4042 
     
    112114  ADCSRA |= (1<<ADEN) | (1<<ADSC); 
    113115 
    114   printString("msg metervalues written to EEPROM (BROWN-OUT)\n"); 
     116  printString("msg BROWN-OUT\n"); 
    115117} 
    116118 
     
    120122    eeprom_write_block((const void*)&measurements[i].value, (void*)&EEPROM_measurements[i].value, 4); 
    121123 
    122   printString("msg metervalues written to EEPROM (WDT)\n"); 
     124  printString("msg WDT\n"); 
    123125} 
    124126 
     
    211213void send(const struct sensor *measurement) 
    212214{ 
    213   uint8_t i, length; 
    214   char buffer[49]; 
    215  
    216   // determine the length of value 
    217   ltoa(measurement->value, buffer, 10); 
    218   length = strlen(buffer); 
    219  
    220   strcpy(buffer, "pls "); 
    221   strcpy(&buffer[4], measurement->id); 
    222   strcpy(&buffer[36], ":"); 
    223   // insert leading 0's 
    224   for (i=0; i<10-length; i++) strcpy(&buffer[37+i], "0"); 
    225   ltoa(measurement->value, &buffer[47-length], 10); 
    226   strcpy(&buffer[47], "\n"); 
    227  
    228   printString(buffer); 
     215  uint8_t i = 46; 
     216  uint32_t value = measurement->value; 
     217  char pulse[49]; 
     218 
     219  // generate pulse message structure 
     220  strcpy(pulse, "pls "); 
     221  strcpy(&pulse[4], measurement->id); 
     222  strcpy(&pulse[36], ":0000000000\n"); 
     223 
     224  do {                              // generate digits in reverse order 
     225    pulse[i--] = '0' + value % 10;  // get next digit 
     226  } while ((value /= 10) > 0);      // delete it 
     227 
     228  printString(pulse); 
    229229 
    230230  // blink the green LED 
     
    258258  for (i=0; i<4; i++) _delay_ms(5000); 
    259259 
     260  serialFlush(); 
    260261  WDT_on(); 
    261262 
  • flukso/trunk/uc/main.h

    r55 r56  
    5151 
    5252// datastructures 
    53 uint8_t i; 
    54  
    5553struct state { 
    5654  boolean pulse; 
  • flukso/trunk/uc/wiring/serial.c

    r1 r56  
    2929// location to which to write the next incoming character and rx_buffer_tail 
    3030// is the index of the location from which to read. 
    31 #define RX_BUFFER_SIZE 128 
     31#define RX_BUFFER_SIZE 64 
    3232 
    3333unsigned char rx_buffer[RX_BUFFER_SIZE]; 
     
    129129} 
    130130 
    131 void printMode(int mode) 
    132 { 
    133         // do nothing, we only support serial printing, not lcd. 
    134 } 
    135  
    136131void printByte(unsigned char c) 
    137132{ 
    138133        serialWrite(c); 
    139 } 
    140  
    141 void printNewline() 
    142 { 
    143         printByte('\n'); 
    144134} 
    145135 
     
    195185        printIntegerInBase(n, 2); 
    196186} 
    197  
    198 /* Including print() adds approximately 1500 bytes to the binary size, 
    199  * so we replace it with the smaller and less-confusing printString(), 
    200  * printInteger(), etc. 
    201 void print(const char *format, ...) 
    202 { 
    203         char buf[256]; 
    204         va_list ap; 
    205          
    206         va_start(ap, format); 
    207         vsnprintf(buf, 256, format, ap); 
    208         va_end(ap); 
    209          
    210         printString(buf); 
    211 } 
    212 */ 
  • flukso/trunk/uc/wiring/wiring.h

    r1 r56  
    100100int serialRead(void); 
    101101void serialFlush(void); 
    102 void printMode(int); 
    103102void printByte(unsigned char c); 
    104 void printNewline(void); 
    105103void printString(const char *s); 
    106104void printInteger(long n);