<commit_before>/*

   Copyright 2013 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.



*/


#define F_CPU 8000000UL		/* Clock Frequency = 8Mhz */

#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>

#include "Timer/timer.h"
#include "UART/uart.h"
#include "Modbus/modbus.h"

modbus_message_t msg;

int main(){

	uint8_t i = 0;
	uint8_t modbus_address = 65;
	uint8_t retval;
	uint8_t has_message = 0;
	
	/*tick_t*/ uint16_t t_last, t_current;
	
	uint8_t buffer[16];
	uint8_t bytes = 0;
	
	timer_init();
	uart_init();
	
	modbus_reset( &msg );
	
	DDRA = 0xFF;
	PORTA = 1;
	
	/*uart_listen();*/
	
	t_last = timer_get_fast();/*timer_get_time();*/
	while( 1 ){
		
		if( uart_has_data()  ){
			PORTA |= 0x10;
			buffer[ bytes ] = uart_recv();
			PORTA &= ~0x10;
			++bytes;
			
			t_last = timer_get_fast();/*timer_get_time();*/
			/*uart_listen();*/
			
			}
		t_current = timer_get_fast();
		
		if( (t_current - t_last > 1500) && (bytes > 0) ){
			
			
			/* 0xFF, 0x0F, 0xF0, 0x7f */
			/*
			PORTA &= ~0x04;
			
			if( buffer[0] == 0xFF ){
				PORTA |= 0x04;
				}
			
			_delay_us(100);
			PORTA &= ~0x04;
			_delay_us(100);
			
			if( buffer[1] == 0x0F ){
				PORTA |= 0x04;
				}
			
			_delay_us(100);
			PORTA &= ~0x04;
			_delay_us(100);
			
			if( buffer[2] == 0xF0 ){
				PORTA |= 0x04;
				}
			
			_delay_us(100);
			PORTA &= ~0x04;
			_delay_us(100);
			
			if( buffer[3] == 0x7F ){
				PORTA |= 0x04;
				}
			
			_delay_us(100);
			PORTA &= ~0x04;
			_delay_us(100);
			
			
			_delay_ms(0.3);
			
			buffer[0] = 0x41;
			buffer[1] = 0x42;
			buffer[2] = 0x43;
			buffer[3] = 0x44;
			buffer[4] = 0x45;
			*/
			
			/*PORTA |= 0x02;*/
			
			
			if( bytes == 8 ){
				
				PORTA |= 0x10;
				_delay_us(100);
				PORTA &= ~0x10;
				_delay_us(100);
				}
			
			for( i = 0 ; i < bytes ; ++i ){
				uart_send( buffer[i] );
				
				PORTA |= 0x04;
				uart_wait();
				PORTA &= ~0x04;
				_delay_us(80);
				}
			_delay_us(300);
			
			/*uart_listen();*/
			
			
			/*PORTA &= ~(0x02);*/
			
			bytes = 0;
			}



		}<commit_msg>Added modbus to the mix.<commit_after>/*

   Copyright 2013 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.



*/


#define F_CPU 8000000UL		/* Clock Frequency = 8Mhz */

#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>

#include "Timer/timer.h"
#include "UART/uart.h"
#include "Modbus/modbus.h"

modbus_message_t msg;

int main(){

	uint8_t i = 0;
	uint8_t modbus_address = 0x17;
	uint8_t retval;
	uint8_t has_message = 0;
	uint8_t recvd_byte;
	
	/*tick_t*/ uint16_t t_last, t_current;
	
	/*uint8_t buffer[16];*/
	uint8_t bytes = 0;
	
	timer_init();
	uart_init();
	
	modbus_reset( &msg );
	
	DDRA = 0xFF;
	PORTA = 1;
	
	/*uart_listen();*/
	
	t_last = timer_get_fast();/*timer_get_time();*/
	while( 1 ){
		
		if( uart_has_data()  ){
			PORTA |= 0x10;
			recvd_byte = uart_recv();
			modbus_append_byte( &msg, recvd_byte );
			
			PORTA &= ~0x10;
			++bytes;
			
			t_last = timer_get_fast();/*timer_get_time();*/
			/*uart_listen();*/
			
			}
		t_current = timer_get_fast();
		
		if( (t_current - t_last > 2100) && (bytes > 0) ){
			
			retval = modbus_handle_message( &msg, modbus_address );
			
			if( retval == MODBUS_OK ){
				for( i = 0 ; i < msg.length ; ++i ){
					uart_send( msg.buffer[i] );
					
					PORTA |= 0x04;
					uart_wait();
					PORTA &= ~0x04;
					_delay_us(80);
					}
				
				}
			else {
				uart_send( 0xDE );
				PORTA |= 0x04;
				uart_wait();
				PORTA &= ~0x04;
				_delay_us(80);
				
				uart_send( 0xAD );
				PORTA |= 0x04;
				uart_wait();
				PORTA &= ~0x04;
				_delay_us(80);
				
				}
				
			_delay_us(300);
			bytes = 0;
			
			modbus_reset( &msg );
			
			}



		}
{'fraction_non_alphanumeric': 0.1402127659574468, 'fraction_numerical': 0.0523404255319149, 'mean_word_length': 2.497767857142857, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2377890', 'n_tokens_mistral': 2373, 'n_tokens_neox': 1812, 'n_words': 451}