[Tinyos-2-commits] CVS: tinyos-2.x/apps/tosthreads/capps/SenseCompressForward/Sensor Makefile, NONE, 1.1 SenseStoreAndForward.c, NONE, 1.1 decompress.c, NONE, 1.1 volumes-at45db.xml, NONE, 1.1 volumes-stm25p.xml, NONE, 1.1
Kevin Klues
klueska at users.sourceforge.net
Thu Jun 12 08:11:42 PDT 2008
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/apps/tosthreads/capps/SenseCompressForward/Base Makefile, NONE, 1.1 ReceiveStoreDecompress.c, NONE, 1.1 volumes-at45db.xml, NONE, 1.1 volumes-stm25p.xml, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/apps/tosthreads/capps/SenseStoreAndForward Makefile, NONE, 1.1 SenseStoreAndForward.c, NONE, 1.1 volumes-at45db.xml, NONE, 1.1 volumes-stm25p.xml, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-2.x/apps/tosthreads/capps/SenseCompressForward/Sensor
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2426/tosthreads/capps/SenseCompressForward/Sensor
Added Files:
Makefile SenseStoreAndForward.c decompress.c
volumes-at45db.xml volumes-stm25p.xml
Log Message:
initial checkin of tosthreads related apps
--- NEW FILE: Makefile ---
TOSTHREAD_MAIN=SenseStoreAndForward.c
CFLAGS += -I..
CFLAGS += -I$(TOSDIR)/lib/tosthreads/sensorboards/tmote_onboard
ifneq ($(filter telosb tmote clean,$(MAKECMDGOALS)),)
include $(MAKERULES)
else
%:
@echo " Sorry, this application is only written to work with telos based motes equipped with onboard sensors.."
cthreads:
@:
dynthreads:
@:
endif
--- NEW FILE: SenseStoreAndForward.c ---
#include "tosthread.h"
#include "tosthread_amradio.h"
#include "tosthread_leds.h"
#include "tosthread_threadsync.h"
#include "tosthread_logstorage.h"
#include "tmote_onboard_sensors.h"
#include "StorageVolumes.h"
#include "lz.c"
#include "lz.h"
#define SAMPLING_PERIOD 100
#define SENDING_PERIOD 50
#define SENDING_INTERVAL 25
#define AM_SENSOR_DATA_MSG 0x25
#define NUM_RECORDS_TO_COMPRESS 50
#define NUM_SENSORS 4
#define TOTAL_NUM_RECORDS_TO_SEND 500
//Data structure for storing sensor data
typedef nx_struct sensor_data {
nx_uint32_t seq_no;
nx_uint16_t hum;
nx_uint16_t temp;
nx_uint16_t tsr;
nx_uint16_t par;
} sensor_data_t;
typedef nx_struct radio_data {
nx_uint8_t taskNum;
nx_uint16_t pktNum;
nx_uint8_t more;
nx_uint8_t data[0];
} radio_data_t;
//Initialize variables associated with each thread
tosthread_t humidity;
tosthread_t temperature;
tosthread_t total_solar;
tosthread_t photo_active;
tosthread_t store_handler;
tosthread_t send_handler;
message_t send_msg;
sensor_data_t storing_sensor_data;
mutex_t data_mutex;
mutex_t log_mutex;
barrier_t send_barrier;
barrier_t sense_barrier;
sensor_data_t compressing_sensor_data[NUM_RECORDS_TO_COMPRESS];
void humidity_thread(void* arg);
void temperature_thread(void* arg);
void total_solar_thread(void* arg);
void photo_active_thread(void* arg);
void store_thread(void* arg);
void send_thread(void* arg);
void tosthread_main(void* arg) {
mutex_init(&data_mutex);
mutex_init(&log_mutex);
barrier_reset(&send_barrier, NUM_SENSORS+1);
barrier_reset(&sense_barrier, NUM_SENSORS+1);
__nesc_hton_uint32((unsigned char *)&storing_sensor_data.seq_no, (unsigned long )0);
amRadioStart();
led0Toggle();
volumeLogErase(VOLUME_SENSORLOG);
volumeLogSeek(VOLUME_SENSORLOG, SEEK_BEGINNING);
led0Toggle();
tosthread_create(&humidity, humidity_thread, NULL, 200);
tosthread_create(&temperature, temperature_thread, NULL, 200);
tosthread_create(&total_solar, total_solar_thread, NULL, 200);
tosthread_create(&photo_active, photo_active_thread, NULL, 200);
tosthread_create(&store_handler, store_thread, NULL, 200);
tosthread_create(&send_handler, send_thread, NULL, 5000);
}
void read_sensor(error_t (*read)(uint16_t*), nx_uint16_t* nx_val) {
uint16_t val;
for(;;) {
(*read)(&val);
mutex_lock(&data_mutex);
// *nx_val = val;
__nesc_hton_uint16((unsigned char *)&*nx_val, val);
mutex_unlock(&data_mutex);
barrier_block(&send_barrier);
barrier_block(&sense_barrier);
}
}
void humidity_thread(void* arg) {
read_sensor(sensirionSht11_humidity_read, &(storing_sensor_data.hum));
}
void temperature_thread(void* arg) {
read_sensor(sensirionSht11_temperature_read, &(storing_sensor_data.temp));
}
void total_solar_thread(void* arg) {
read_sensor(hamamatsuS10871_tsr_read, &(storing_sensor_data.tsr));
}
void photo_active_thread(void* arg) {
read_sensor(hamamatsuS1087_par_read, &(storing_sensor_data.par));
}
void store_thread(void* arg) {
storage_len_t sensor_data_len;
bool sensor_records_lost;
//Only needed for nesC magic.... I hate this hack.....
unsigned long __nesc_temp43;
unsigned char *__nesc_temp42;
for(;;) {
barrier_block(&send_barrier);
barrier_reset(&send_barrier, NUM_SENSORS + 1);
mutex_lock(&log_mutex);
sensor_data_len = sizeof(sensor_data_t);
while( volumeLogAppend(VOLUME_SENSORLOG, &storing_sensor_data, &sensor_data_len, &sensor_records_lost) != SUCCESS );
mutex_unlock(&log_mutex);
//storing_sensor_data.seq_no++
(__nesc_temp42 = (unsigned char *)&storing_sensor_data.seq_no, __nesc_hton_uint32(__nesc_temp42, (__nesc_temp43 = __nesc_ntoh_uint32(__nesc_temp42)) + 1), __nesc_temp43);
led0Toggle();
//tosthread_sleep(SAMPLING_PERIOD);
barrier_block(&sense_barrier);
barrier_reset(&sense_barrier, NUM_SENSORS + 1);
}
}
uint8_t taskNum = 0;
void send_thread(void* arg) {
storage_len_t sensor_data_len;
uint8_t numRecords = 0;
uint8_t out[((NUM_RECORDS_TO_COMPRESS * sizeof(sensor_data_t) * 257 - 1) / 256) + 1 + 1];
for(;;) {
tosthread_sleep(SENDING_PERIOD);
while( volumeLogCurrentReadOffset(VOLUME_SENSORLOG) != volumeLogCurrentWriteOffset(VOLUME_SENSORLOG) ) {
sensor_data_len = sizeof(sensor_data_t);
mutex_lock(&log_mutex);
while( volumeLogRead(VOLUME_SENSORLOG, &(compressing_sensor_data[numRecords]), &sensor_data_len) != SUCCESS );
numRecords++;
mutex_unlock(&log_mutex);
if (numRecords == NUM_RECORDS_TO_COMPRESS) {
uint8_t pktNum = 0;
uint16_t outsize = 0, sendsize = 0, sendindex = 0;
radio_data_t *payload = NULL;
outsize = LZ_Compress((void *)compressing_sensor_data, out, NUM_RECORDS_TO_COMPRESS * sizeof(sensor_data_t));
while (outsize > 0) {
if (outsize > (TOSH_DATA_LENGTH - sizeof(radio_data_t))) {
sendsize = TOSH_DATA_LENGTH - sizeof(radio_data_t);
} else {
sendsize = outsize;
}
payload = (radio_data_t *) radioGetPayload(&send_msg, sizeof(radio_data_t) + sendsize);
payload->taskNum = taskNum;
payload->pktNum = pktNum;
payload->more = ((outsize - sendsize) > 0) ? TRUE : FALSE;
memcpy(payload->data, &(out[sendindex]), sendsize);
while( amRadioSend(AM_BROADCAST_ADDR, &send_msg, sizeof(radio_data_t) + sendsize, AM_SENSOR_DATA_MSG) != SUCCESS );
outsize -= sendsize;
sendindex += sendsize;
pktNum++;
led1Toggle();
tosthread_sleep(SENDING_INTERVAL);
}
taskNum++;
pktNum = 0;
numRecords = 0;
}
}
//led2Toggle();
}
}
--- NEW FILE: decompress.c ---
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include "bcl-1.2.0/src/lz.h"
#include "bcl-1.2.0/src/lz.c"
int main(int argc, char *argv[])
{
if (argc == 2) {
FILE *fp = fopen(argv[1], "rb");
if (fp == NULL) {
fprintf(stderr, "ERROR: Can't open input file, %s!\n", argv[1]);
} else {
fseek(fp, 0, SEEK_END);
{
long size = ftell(fp);
uint8_t in[size];
uint8_t out[size];
size_t in_size = 0;
rewind(fp);
in_size = fread(in, 1, size, fp);
printf("%d\n", in_size);
LZ_Uncompress(in, out, in_size);
{
int i = 0;
for (i = 0; i < 96; i++) {
printf("%d ", out[i]);
if ((i + 1) % 12 == 0) {
printf("\n");
}
}
}
}
}
} else {
printf("Usage: %s\n <file name>", argv[0]);
}
return 0;
}
--- NEW FILE: volumes-at45db.xml ---
<volume_table>
<volume name="SENSORLOG" size="262144" type="log" circular="true"/>
</volume_table>
--- NEW FILE: volumes-stm25p.xml ---
<volume_table>
<volume name="SENSORLOG" size="1048576" type="log" circular="true"/>
</volume_table>
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/apps/tosthreads/capps/SenseCompressForward/Base Makefile, NONE, 1.1 ReceiveStoreDecompress.c, NONE, 1.1 volumes-at45db.xml, NONE, 1.1 volumes-stm25p.xml, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/apps/tosthreads/capps/SenseStoreAndForward Makefile, NONE, 1.1 SenseStoreAndForward.c, NONE, 1.1 volumes-at45db.xml, NONE, 1.1 volumes-stm25p.xml, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-2-commits
mailing list