Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

probecoms.c File Reference

Glacsweb probecoms.c Main Base station probe communications package uses serial.c for rs232 access Copyright (C) 2004 Kirk Martinez The University of Southampton. More...

#include "log.h"
#include "serial.h"
#include "probecoms.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/time.h>
#include <time.h>

Functions

int check_id (int id)
 Check that a probe id is within accepted ranges.

void date_string (unsigned char *str)
 helpful function to make a date prefix for files

int dec2bcd (int dec)
 convert from decimal to BCD for dates etc.

void printPacket (glacsweb_packet *tempPacket)
 This function prints contents of a glacsweb packet to the standard output.

void set_packet (unsigned char size, unsigned char id, unsigned char cmd, unsigned char data[16], glacsweb_packet *tempPacket)
 This function sets the contents of a glacsweb_packet.

void send_packet (glacsweb_packet *p, SerialPort *sp)
 This function sends a packet over the serial port.

int send_packet_wait_reply (glacsweb_packet *TxPacket, glacsweb_packet *RxPacket, SerialPort *sp, unsigned char retries)
 This function sends a packet and waits for a reply packet.

int receive_packet (glacsweb_packet *RxPacket, SerialPort *sp)
 This function is responsible for receiving packet.

void probe_rtc_set_alarm (unsigned char id, int min, int hour, int date, SerialPort *sp)
 send a command to set the alarm on a probe.

void probe_rtc_get_alarm (unsigned char id, int *min, int *hour, int *date, SerialPort *sp)
 send a command to get the alarm of a probe.

void probe_sys_sleep (unsigned char id, SerialPort *sp)
 This is a wrapper function to put probe to sleep.

void probe_sys_loadparams (unsigned char id, SerialPort *sp)
 this is used to get it to reload settings into ram from eeprom locations.

int probe_eeprom_read16 (unsigned char id, int address, glacsweb_packet *rxpkt, SerialPort *sp)
 This function reads 16 bytes from the probe's external eeprom (where sensor data is!).

int probe_sys_eeprom_read (int id, unsigned char address, SerialPort *sp)
 This function reads an eeprom location in a probe.

int probe_sys_eeprom_write (int id, unsigned char address, unsigned char value, SerialPort *sp)
 This function writes to an eeprom location in a probe.

int probe_get_params (unsigned char id, int *ee_rd, int *ee_wr, SerialPort *sp)
 probe_get_params - gets the main parameters mainly used to read sensor data We should log the other data with an id and timestamp to logfile!! returns 0 on success, otherwise -1

void broadcast_sys_eeprom_write (unsigned char address, unsigned char value, unsigned int delay, unsigned char retries, SerialPort *sp)
 This function sends a broadcast command to all the probes to write to a particular location in the sys_eeprom.

void broadcast_sys_load_params (unsigned int delay, unsigned char retries, SerialPort *sp)
 This function sends a broadcast command to all the probes to load system variable with eeprom values in the RAM location.

void broadcast_rtc_set_time (unsigned int delay, unsigned char retries, SerialPort *sp)
 This function sends a broadcast command to all the probes to set RTC time to match time on BITSY.

void broadcast_rtc_set_date (unsigned int delay, unsigned char retries, SerialPort *sp)
 This function sends a broadcast command to all the probes to set RTC date to match date on BITSY.

void broadcast_rtc_set_alarm (int min, int hour, int date, unsigned int delay, unsigned char retries, SerialPort *sp)
 This function sends a broadcast command to all the probes to set RTC alarm.

int probe_get_batvolts (unsigned char id, float *value, SerialPort *sp)


Detailed Description

Glacsweb probecoms.c Main Base station probe communications package uses serial.c for rs232 access Copyright (C) 2004 Kirk Martinez The University of Southampton.


Function Documentation

void broadcast_rtc_set_alarm int  min,
int  hour,
int  date,
unsigned int  delay,
unsigned char  retries,
SerialPort sp
 

This function sends a broadcast command to all the probes to set RTC alarm.

Parameters:
min is the minute for the setting of the alarm
hour is the hour for the setting of the alarm
date is the date for the setting of the alarm.
delay is the time delay (micro seconds) required between each retry of the broadcast transmission.
retries is the number of times the packet needs to broadcasted.
*sp is the pointer to the SerialPort over which the transmission will take place.

void broadcast_rtc_set_date unsigned int  delay,
unsigned char  retries,
SerialPort sp
 

This function sends a broadcast command to all the probes to set RTC date to match date on BITSY.

The format of date is sent as day of week, day of month, month and year.

Parameters:
delay is the time delay (micro seconds) required between each retry of the broadcast transmission.
retries is the number of times the packet needs to broadcasted.
*sp is the pointer to the SerialPort over which the transmission will take place.

void broadcast_rtc_set_time unsigned int  delay,
unsigned char  retries,
SerialPort sp
 

This function sends a broadcast command to all the probes to set RTC time to match time on BITSY.

Parameters:
delay is the time delay (micro seconds) required between each retry of the broadcast transmission.
retries is the number of times the packet needs to broadcasted.
*sp is the pointer to the SerialPort over which the transmission will take place.

void broadcast_sys_eeprom_write unsigned char  address,
unsigned char  value,
unsigned int  delay,
unsigned char  retries,
SerialPort sp
 

This function sends a broadcast command to all the probes to write to a particular location in the sys_eeprom.

Parameters:
address is the 16 bit address location in the eerprom of the probe.
value is the actual value that needs to be written in the eeprom.
delay is the time delay (micro seconds) required between each retry of the broadcast transmission.
retries is the number of times the packet needs to broadcasted.
*sp is the pointer to the SerialPort over which the transmission will take place.

void broadcast_sys_load_params unsigned int  delay,
unsigned char  retries,
SerialPort sp
 

This function sends a broadcast command to all the probes to load system variable with eeprom values in the RAM location.

Parameters:
delay is the time delay (micro seconds) required between each retry of the broadcast transmission.
retries is the number of times the packet needs to broadcasted.
*sp is the pointer to the SerialPort over which the transmission will take place.

int check_id int  id  )  [static]
 

Check that a probe id is within accepted ranges.

Parameters:
id to check.
Returns:
zero if id is within accepted range, -1 otherwise.

void date_string unsigned char *  str  ) 
 

helpful function to make a date prefix for files

Parameters:
pointer to string where date will be put

int dec2bcd int  dec  ) 
 

convert from decimal to BCD for dates etc.

eg 040801

Parameters:
decimal int value to convert

void printPacket glacsweb_packet tempPacket  ) 
 

This function prints contents of a glacsweb packet to the standard output.

Parameters:
*tempPacket is a pointer to a glacsweb_packet structure.

int probe_eeprom_read16 unsigned char  id,
int  address,
glacsweb_packet rxpkt,
SerialPort sp
 

This function reads 16 bytes from the probe's external eeprom (where sensor data is!).

Parameters:
id is the value identifying the probe
address is the16bit address of the location in the EXTERNAL eeprom to be read from
*sp is the pointer to the SerialPort over which the transmission will take place.
Returns:
0 if successful, -1 if unsuccessful

void probe_rtc_get_alarm unsigned char  id,
int *  min,
int *  hour,
int *  date,
SerialPort sp
 

send a command to get the alarm of a probe.

Parameters:
id is a byte with the probe's ID
min,hour,date are pointers to ints to return the alarm time note returns are bcd so you have to print with x

void probe_rtc_set_alarm unsigned char  id,
int  min,
int  hour,
int  date,
SerialPort sp
 

send a command to set the alarm on a probe.

Parameters:
id is a byte with the probe's ID
min,hour,date are all ints with the alarm time note that decimal is entered but internally bcd is used eg min=10 is set as 0x10

int probe_sys_eeprom_read int  id,
unsigned char  address,
SerialPort sp
 

This function reads an eeprom location in a probe.

Parameters:
id is the value identifying the probe from which the data needs to be read
address is the 8 bit address location in the sys_eeprom of the probe
*sp is the pointer to the SerialPort over which the transmission will take place.
Returns:
byte read from the location in format int (May need Type casting to byte), Returns -1 if read was unsuccessful.

int probe_sys_eeprom_write int  id,
unsigned char  address,
unsigned char  value,
SerialPort sp
 

This function writes to an eeprom location in a probe.

Parameters:
id is the value identifying the probe to which data needs to be written
address is the 8 bit address location in the SYS eeprom of the probe where data needs writing
value is the byte long data that needs to be written
*sp is the pointer to the SerialPort over which the transmission will take place.
Returns:
byte read from the location in format int (May need Type casting to byte), Returns -1 if read was unsuccessful.

void probe_sys_loadparams unsigned char  id,
SerialPort sp
 

this is used to get it to reload settings into ram from eeprom locations.

eg for setting 28 29 2a 2b to a millisecond sleep timeout

void probe_sys_sleep unsigned char  id,
SerialPort sp
 

This is a wrapper function to put probe to sleep.

Parameters:
id is a byte value that hold the identity of the probe being put to sleep
*sp is the pointer to the SerialPort over which the transmission will take place.

int receive_packet glacsweb_packet RxPacket,
SerialPort sp
 

This function is responsible for receiving packet.

Parameters:
*RxPacket is the pointer to the packet that is to be received.
*sp is the pointer to the SerialPort over which the transmission will take place.
Returns:
- 0 if packet successfully received.
  • -1 if error in reading
  • -2 if timeout.

void send_packet glacsweb_packet p,
SerialPort sp
 

This function sends a packet over the serial port.

It only sends a packet and does not wait for a reply once the packet is sent. This function should be used for broadcast or INFO packets that do not expect a reply data from the probes.

Parameters:
*p is a pointer to a glacsweb_packet that needs to be sent
*sp is a pointer to the SerialPort over which the packet will be sent.

int send_packet_wait_reply glacsweb_packet TxPacket,
glacsweb_packet RxPacket,
SerialPort sp,
unsigned char  retries
 

This function sends a packet and waits for a reply packet.

It makes use of the functions send_packet(glacsweb_packet *p, SerialPort *sp) to send and receive_packet(glacs_packet *RxPacket, SerialPort *sp) to receive a reply. This function has a retry feature to it that enables re-transmission (sending and receiving) of the packet a specified number of times in case of failure.

Parameters:
*TxPacket is the pointer to the packet that is to be sent.
*RxPacket is the pointer to the packet that is to be received.
*sp is the pointer to the SerialPort over which the transmission will take place
retries is value signifying how many retries required for tranmissison incase of failure.
Returns:
0 if tranmission was successful. -1 if Unsuccessful after all retries

void set_packet unsigned char  size,
unsigned char  id,
unsigned char  cmd,
unsigned char  data[16],
glacsweb_packet tempPacket
 

This function sets the contents of a glacsweb_packet.

Parameters:
size is a value between 1 and 16 inclusive to determine size of packet data.
id is identity of receiver (probe) to which packet is to be sent.
cmd is a command (or info) to be sent to the receiver (or probe).
data is an array of 16 bytes representing data.
*tempPacket is the pointer to the actual packet that needs to be set with the parameters listed above.


Generated on Mon Aug 9 13:41:45 2004 for Glacsweb by doxygen 1.3.5