MODBUS laajempi esimerkki
mittari_jumapohja.c File Reference

Main State Machine. More...

#include <stdint.h>
#include <stdio.h>
#include "kosteus.h"
#include "sht11.h"
Include dependency graph for mittari_jumapohja.c:

Functions

int main (void)
 

Variables

unsigned char device_version [] = "$Revision: 248 $"
 
unsigned char modbuss_address
 
unsigned char message [MAX_LENGTH_OF_MESSAGE]
 
unsigned char response [MAX_LENGTH_OF_MESSAGE]
 
unsigned char response_in_ascii_hex [MAX_LENGTH_OF_MESSAGE *2]
 
unsigned char length_of_response = 0
 
unsigned char length_of_message = 0
 
unsigned char received_character
 
unsigned char previouse_received_character
 
volatile unsigned char receive_buffer [MAX_LENGTH_OF_BUFFER]
 
volatile unsigned char nro_characters_received = 0
 
volatile unsigned char nro_characters_to_be_sent
 
unsigned long int receive_timeout
 
unsigned char length_of_ascii_hex_response = 0
 
unsigned char datacount = 0
 
unsigned int start_address
 
unsigned int number_of_points
 
unsigned int sub_function
 
unsigned char query_type = 0
 
unsigned char laskuri = 0
 
volatile unsigned char transmit_buffer [MAX_LENGTH_OF_BUFFER]
 
unsigned char transmit_buffer_begin
 
unsigned char transmit_buffer_current_pos
 
int table [NRO_OF_SENSORS *2] = {0}
 
int lukemahum = 0x0000
 
int lukematemp = 0x0000
 
int anturi = 1
 
int tallenna = 0
 
unsigned char measurement_data [NRO_OF_SENSORS *4]
 
unsigned char real_time_data [NRO_OF_SENSORS *4]
 
int measurement_count =0
 
int measurement_number =0
 
int sensor_counter = 0
 
unsigned char state
 
unsigned char new_state
 
unsigned char error_condition
 
unsigned int boot_counter =0
 
unsigned int exception_error_counter =0
 
unsigned int bus_comm_error_counter =0
 
unsigned int first_start_indicator
 

Detailed Description

Main State Machine.


Function Documentation

int main ( void  )

State controls to main program flow

initialize HW ports for input and output

Todo:
Configure counter so, that timeout is 1 second
Todo:
Change the counter to count every 100th message
Todo:
This case is just for testing. To be modified to Report Slave ID

2 is Place of datacount value in the ModBus Response Message

Here is the call graph for this function:

Variable Documentation

int anturi = 1
unsigned int boot_counter =0
unsigned int bus_comm_error_counter =0
unsigned char datacount = 0
unsigned char device_version[] = "$Revision: 248 $"
Todo:
Too many global variables
unsigned char error_condition
unsigned int exception_error_counter =0
unsigned int first_start_indicator
unsigned char laskuri = 0
unsigned char length_of_ascii_hex_response = 0
unsigned char length_of_message = 0
unsigned char length_of_response = 0
int lukemahum = 0x0000
int lukematemp = 0x0000
int measurement_count =0
unsigned char measurement_data[NRO_OF_SENSORS *4]
int measurement_number =0
unsigned char message[MAX_LENGTH_OF_MESSAGE]

Totally received modbus frame

unsigned char modbuss_address
unsigned char new_state
volatile unsigned char nro_characters_received = 0
volatile unsigned char nro_characters_to_be_sent
unsigned int number_of_points
unsigned char previouse_received_character
unsigned char query_type = 0
unsigned char real_time_data[NRO_OF_SENSORS *4]
volatile unsigned char receive_buffer[MAX_LENGTH_OF_BUFFER]
unsigned long int receive_timeout
unsigned char received_character
unsigned char response[MAX_LENGTH_OF_MESSAGE]

Response frame to be sended to master

unsigned char response_in_ascii_hex[MAX_LENGTH_OF_MESSAGE *2]
int sensor_counter = 0
unsigned int start_address
unsigned char state

controlling main loop

unsigned int sub_function
int table[NRO_OF_SENSORS *2] = {0}
Todo:
Must be global??
int tallenna = 0
volatile unsigned char transmit_buffer[MAX_LENGTH_OF_BUFFER]
unsigned char transmit_buffer_begin
unsigned char transmit_buffer_current_pos