Firenet

Check-in [a0e1b6b712]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add longer lamp blink and blink on receive
Timelines: family | ancestors | descendants | both | NEWNET
Files: files | file ages | folders
SHA1:a0e1b6b712f04773d2cb981c001682458aca437b
User & Date: jim 2012-01-07 21:18:02
Context
2012-02-11
09:25
Update to fix Project check-in: 73e0072030 user: jim tags: NEWNET
2012-01-07
21:18
Add longer lamp blink and blink on receive check-in: a0e1b6b712 user: jim tags: NEWNET
10:45
[111b6a965d] invert LED check-in: ef08a74d95 user: jim tags: NEWNET
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Arduino/apps/HeadEnd/HeadEnd.ino.

20
21
22
23
24
25
26

27
28
29
30
31
32
33
..
47
48
49
50
51
52
53


54
55
56
57
58
59
60
...
102
103
104
105
106
107
108

109
110
111
112
113
114
115
...
136
137
138
139
140
141
142


143
144
145
146
147
148
149
...
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
...
215
216
217
218
219
220
221
222




223

  	Then the XMIT enable is set high and the data transmitted in one
  	batch.
  	XMIT is disabled after transmission.
  
  30-Dec-2011 Initial version [7e720cf520] Inventory problem
   1-Jan-2012 [55fd308482] Use LED on board
   6-Jan-2012 Invert LED state

*/
//-----------------------------------------------------------------------------
#include <SoftwareSerial.h>
#include "debug.h"

// States during run
#define STATE_IDLE	0
................................................................................
#define HDR_CHR		':'
#define TRLR_CHR	';'

// Set up second serial port 
SoftwareSerial fnet( PIN_RX,PIN_TX,false );

int state;



#define BUFFER_SIZE	64
char buffer[BUFFER_SIZE];
int bufpsn;

//****** DEBUGGING CODE *********
#ifdef DEBUG_ON
................................................................................
  // Set up serial ports
  Serial.begin(38400); 
  fnet.begin( 9600 );
  
  // Set up state
  
  state = STATE_IDLE;

  
  DEBUG_PRINT("\r\nHEAD END Test PGM V[ ");
  DEBUG_PRINT(__DATE__);
  DEBUG_PRINT(" ");
  DEBUG_PRINT(__TIME__);
  DEBUG_PRINTLN("]");
}
................................................................................
	// Main action:
	// (1) Data received from FNET -> Serial
	
	if( fnet.available() )
	{
		ch = fnet.read();
		Serial.write( ch );


	}
	
	// (2) Data received from Serial
	//	Form packet then send
	
	if( Serial.available() )
	{
................................................................................
							buffer[bufpsn++] = ch;
							
							// Send it out, enable xmit,send & disable
							// and then go to idle
							
							digitalWrite(PIN_XMIT,1);
							digitalWrite(PIN_LED,1);


							for( i=0; i<bufpsn; i++ )
							{
								fnet.write(buffer[i]);
							}
							digitalWrite(PIN_XMIT,0);
							digitalWrite(PIN_LED,0);
							state = STATE_IDLE;
							bufpsn = 0;
							break;
		}
		
		// Add checking here for bad packets
		// just ignore them and drop the
................................................................................
		
		if( bufpsn >= BUFFER_SIZE )
		{
			// Bad input, go to idle
			state = STATE_IDLE;
		}
	}
}













>







 







>
>







 







>







 







>
>







 







>






|







 







|
>
>
>
>
|
>
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
  	Then the XMIT enable is set high and the data transmitted in one
  	batch.
  	XMIT is disabled after transmission.
  
  30-Dec-2011 Initial version [7e720cf520] Inventory problem
   1-Jan-2012 [55fd308482] Use LED on board
   6-Jan-2012 Invert LED state
   7-Jan-2012 Make lamp pulse longer & pulse on received data
*/
//-----------------------------------------------------------------------------
#include <SoftwareSerial.h>
#include "debug.h"

// States during run
#define STATE_IDLE	0
................................................................................
#define HDR_CHR		':'
#define TRLR_CHR	';'

// Set up second serial port 
SoftwareSerial fnet( PIN_RX,PIN_TX,false );

int state;
long lamp;					// Time lamp was turned off
#define LAMP_TIME	100		// 100 ms lamp time

#define BUFFER_SIZE	64
char buffer[BUFFER_SIZE];
int bufpsn;

//****** DEBUGGING CODE *********
#ifdef DEBUG_ON
................................................................................
  // Set up serial ports
  Serial.begin(38400); 
  fnet.begin( 9600 );
  
  // Set up state
  
  state = STATE_IDLE;
  lamp = 0;
  
  DEBUG_PRINT("\r\nHEAD END Test PGM V[ ");
  DEBUG_PRINT(__DATE__);
  DEBUG_PRINT(" ");
  DEBUG_PRINT(__TIME__);
  DEBUG_PRINTLN("]");
}
................................................................................
	// Main action:
	// (1) Data received from FNET -> Serial
	
	if( fnet.available() )
	{
		ch = fnet.read();
		Serial.write( ch );
		digitalWrite(PIN_LED,1);
		lamp = millis();
	}
	
	// (2) Data received from Serial
	//	Form packet then send
	
	if( Serial.available() )
	{
................................................................................
							buffer[bufpsn++] = ch;
							
							// Send it out, enable xmit,send & disable
							// and then go to idle
							
							digitalWrite(PIN_XMIT,1);
							digitalWrite(PIN_LED,1);
							lamp = millis();

							for( i=0; i<bufpsn; i++ )
							{
								fnet.write(buffer[i]);
							}
							digitalWrite(PIN_XMIT,0);
							//digitalWrite(PIN_LED,0);
							state = STATE_IDLE;
							bufpsn = 0;
							break;
		}
		
		// Add checking here for bad packets
		// just ignore them and drop the
................................................................................
		
		if( bufpsn >= BUFFER_SIZE )
		{
			// Bad input, go to idle
			state = STATE_IDLE;
		}
	}
	
	// See if the lamp has been on long enough
	val = millis() - lamp;
	if( val > LAMP_TIME )
		digitalWrite(PIN_LED,0);
}