repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
---|---|---|
hananiahhsu/OpenCAD | XUXUCAM/cam_newmaterial.h | #ifndef CAM_NEWMATERIAL_H
#define CAM_NEWMATERIAL_H
/*
************************************
*** @<NAME>
*** @2017.05.10
*** @NanJing,China
*** @<EMAIL>
************************************
*/
#include <QDialog>
#include <QDir>
#include "FileIO/cam_fileio.h"
namespace Ui {
class CAM_NewMaterial;
}
class CAM_NewMaterial : public QDialog
{
Q_OBJECT
public:
explicit CAM_NewMaterial(QWidget *parent = 0);
~CAM_NewMaterial();
private:
Ui::CAM_NewMaterial *ui;
void Init();
void closeEvent(QCloseEvent *event);
signals:
void CAM_NewMat_Close_Signal(QString name_mat,QString thick_mat);
void CAM_NewMat_New_Signal(QString name_mat,QString thick_mat);
void CAM_AddMat_Add_Signal(QString name_mat,QString thick_mat);
private slots:
void on_comboBox_2_choosed();//mat
void on_comboBox_choosed();//thick of mat
void on_lineEdit_changed();//input thick of mat
void on_pushbutton_new_clicked();//
void on_pushbutton_add_clicked();
public:
CAM_FileIO file_io;
QList<QList<QString>> p_all_mat_list;
QString qs_name_mat,qs_thick_mat;//name and thickness of mat
};
#endif // CAM_NEWMATERIAL_H
|
hananiahhsu/OpenCAD | XUXUCAM/CamCores/CamEng/cam_document.h | #ifndef CAM_DOCUMENT_H
#define CAM_DOCUMENT_H
/*
************************************
*** @<NAME>
*** @2017.05.10
*** @NanJing,China
*** @<EMAIL>
************************************
*/
#include "CamCores/CamEng/cam_pen.h"
#include <QString>
/*
************************************
*** @<NAME>
*** @2017.05.10
*** @NanJing,China
*** @<EMAIL>
************************************
*/
class Cam_Document
{
public:
Cam_Document();
virtual ~Cam_Document();
/********basic operation of docu*******/
virtual bool cam_save();
virtual bool cam_saveas(bool is_auto_save);
virtual bool cam_open(const QString file_name);
virtual bool cam_loadtemplate();
virtual void cam_newdoc();
public:
//record the state of doc
bool is_modified;
//name of auto saved
QString auto_save_file_name;
//Current filename(new)
QString cur_file_name;
//cur active cam pen
Cam_Pen *cam_pen;
//format of docu
//graphicsView for reading or saving cur view
};
#endif // CAM_DOCUMENT_H
|
hananiahhsu/OpenCAD | XUXUCAM/CamCores/CamEng/cam_blocklist.h | <reponame>hananiahhsu/OpenCAD
#ifndef CAM_BLOCKLIST_H
#define CAM_BLOCKLIST_H
/*
************************************
*** @<NAME>
*** @2017.05.10
*** @NanJing,China
*** @<EMAIL>
************************************
*/
class Cam_BlockList
{
public:
Cam_BlockList() {}
virtual ~Cam_BlockList();
public:
};
#endif // CAM_BLOCKLIST_H
|
hananiahhsu/OpenCAD | XUXUCAM/CamDxf/camswap.h | <reponame>hananiahhsu/OpenCAD<filename>XUXUCAM/CamDxf/camswap.h
#ifndef CAMSWAP_H
#define CAMSWAP_H
/*
************************************
*** @<NAME>
*** @2017.05.10
*** @NanJing,China
*** @<EMAIL>
************************************
*/
#include <QtGui>
#include <QWidget>
#include "CamDxf/qpointfwithparent.h"
/** we have to start with a random population .
CrossOver with Sushil J. Louis greedy crossOver
Mutate randomly by swapping 2 (or more cities positions)
Select the elite parents that will generate the new offsprings with Roulette Wheel Selection
**/
//swap the values
void swapVals(QPFWPVector &vect,int pos1,int pos2) ;
/// A chromose actually a possible route
class Chromosome
{
public:
Chromosome();
QPFWPVector elements;
/**
* create a new chromosome from a given set of points
* @param points a set of coordinates
* @return the newly created chromosome
*/
QPFWPVector createNew(QPFWPVector points);
int MySize;
virtual ~Chromosome();
double routeLength;
///@todo for now fitness=lenght change when switching to roulette selection...
double fitness;
/**
* set the chromosome elements (a.k.a the points definig the route)
* @param points the route elements
* @param random if set will take route points randomly, elsewhere the points are copied as is
*/
void setElements(QPFWPVector points,bool random);
/// create a chromosome of size by copying poiunts as its elments
void setElements(QPFWPVector points,int size=0);
/**
* set the chromosome fitness according to its route length
* @param fit
*/
void setFitness(double fit){this->fitness=fit;}
/**
* Calculate the total route length
*/
void calcRouteLength();
/**
*
* @return Chromosome route length
*/
double getRouteLength(){return routeLength;}
};
/// @todo: create a function that return the pop/chromosome size for brievty
/// A population is a set of chromosomes
class Popu
{
public:
/**
* Create a new population
*/
Popu();
void computeTotalRoute();
/**
* Sort the population according to its content fitness: The chromosome with the best fitness are placed on the top of the queue
*@todo: See if calling standard arrays function provideid by Qt is possible here
*/
void sortContent();
/**
* Creates a new Generation from the current Population (a.k.a @see content)
*/
void createNewGen();
/**
* Start GA optimization
* @param points unOptimizaed route
* @param randomtartupPop if set the created population is a random one
* @return Optimized route
*/
QPFWPVector init(QPFWPVector points,bool randomtartupPop=true);
void selectParents(Chromosome* parent1,Chromosome* parent2,int posd);
Chromosome cross(Chromosome parent1, Chromosome parent2);
Chromosome crossOver(Chromosome parent1, Chromosome parent2);
void selectTwoParents(Chromosome* p1,Chromosome* p2,int posd);
void mutateImprove(int pos);
void mutateImproveOffspring(Chromosome &toImprove,int pos);
/**
* Mutate the given Chromosome
* @param pos chromosome Position in the population
*/
void mutateImproveMe(int pos);
/**
* Given an offspring we mutate it at a certain rate and create the new population
* @param i the Chromosome position to mutate (in the genration)
*/
void mutate(int i);
QVector <Chromosome > newGen;
///
double totalRoute;
private:
///The population size : A common value is between 10 and 20
int popSize;
int Max_iter;
int chromoSize;
/// the Chromosome list a.k.a the population
QVector <Chromosome > content;
};
class Population
{
public:
Population(QPFWPVector points);
virtual ~Population();
QVector <Chromosome *> content;
double totalRoute;
int popSize;
void selectElite();
void mutate(Chromosome *offspring);
Chromosome *crossoverSimple(Chromosome *parent1, Chromosome *parent2);
Chromosome *crossover(Chromosome *parent1, Chromosome *parent2);
};
class GAThread : public QThread
{
Q_OBJECT
protected:
void run();
};
#endif // CAMSWAP_H
|
hananiahhsu/OpenCAD | XUXUCAM/camexpert.h | <reponame>hananiahhsu/OpenCAD
#ifndef CAMEXPERT_H
#define CAMEXPERT_H
/*
************************************
*** @<NAME>
*** @2017.05.10
*** @NanJing,China
*** @<EMAIL>
************************************
*/
#include <QMainWindow>
#include <QMdiArea>
#include <QSplitter>
#include <QTreeView>
#include "cam_importmat.h"
#include "cam_newmaterial.h"
#include "cam_newprt.h"
#include "cam_importprt.h"
#include <QStandardItem>
#include <QtGui>
#include <QWidget>
#include <QFileDialog>
#include <QVector>
#include <QDesktopWidget>
#include "CamDxf/camdxf.h"
#include "CamDxf/campart.h"
#include "CamDxf/camscene.h"
#include "StringOperation/stringoperation.h"
namespace Ui {
class CAMExpert;
}
//value of row
class RowData
{
public:
RowData(){}
~RowData(){}
public:
RowData(QString qs_0,QString qs_1,QString qs_2,QString qs_3,QString qs_4,QString qs_5,QString qs_6,QString qs_7)
{
row_v_0 = qs_0;
row_v_1 = qs_1;
row_v_2 = qs_2;
row_v_3 = qs_3;
row_v_4 = qs_4;
row_v_5 = qs_5;
row_v_6 = qs_6;
row_v_7 = qs_7;
}
public:
void RowData::operator=(const RowData& rd)
{
row_v_0 = rd.row_v_0;
row_v_1 = rd.row_v_1;
row_v_2 = rd.row_v_2;
row_v_3 = rd.row_v_3;
row_v_4 = rd.row_v_4;
row_v_5 = rd.row_v_5;
row_v_6 = rd.row_v_6;
row_v_7 = rd.row_v_7;
}
bool operator ==(const RowData& rd)
{
if(row_v_0 == rd.row_v_0 &&
row_v_1 == rd.row_v_1 &&
row_v_2 == rd.row_v_2 &&
row_v_3 == rd.row_v_3 &&
row_v_4 == rd.row_v_4 &&
row_v_5 == rd.row_v_5 &&
row_v_6 == rd.row_v_6 &&
row_v_7 == rd.row_v_7)
{
return true;
}
else
{
return false;
}
}
public:
QString row_v_0;
QString row_v_1;
QString row_v_2;
QString row_v_3;
QString row_v_4;
QString row_v_5;
QString row_v_6;
QString row_v_7;
};
//value of col
class ColData
{
QString col_v_0;
QString col_v_1;
QString col_v_2;
QString col_v_3;
QString col_v_4;
QString col_v_5;
QString col_v_6;
QString col_v_7;
};
class CAMExpert : public QMainWindow
{
Q_OBJECT
public:
explicit CAMExpert(QWidget *parent = 0);
~CAMExpert();
private:
Ui::CAMExpert *ui;
public:
//screen info params
int screen_w;
int screen_h;
//functions of scn
void GetScreenInfos();
//operation of strings
StringOperations st_op;
public:
QGraphicsView *plate_graphic_view;
QGraphicsView *plate_graphics_preview;
QGraphicsView *prt_view;//for preview of prt
Part *prt;
CamScene *plate_preView_scene;
CamScene *plate_scene;
CamScene *prt_preview_scene;
DL_Dxf *dl_dxf;
CamDxf cam_dxf;
public:
CAM_ImportMat *CAM_IMPORT_WIN;
CAM_NewMaterial *CAM_NEWMAT_WIN;
CAM_NewPrt *CAM_NEWPRT_WIN;
CAM_ImportPrt *CAM_IMPORTPRT_WIN;
QFileDialog *DXF_WIN;//USELESS
QList<WId> p_cam_impmat_win_list;
QList<WId> p_cam_newmat_win_list;
int cam_impmat_show_times=0;
int cam_newmat_show_times=0;
int cam_newprt_show_times = 0;
int cam_impprt_show_times = 0;
QString mat_name_from_NEWMAT;
QString mat_thick_from_NEWMAT;
QStandardItemModel * model_plate_tableView;
QStandardItemModel * model_prt_tableView;
public:
//All widgets and files
QIcon cam_newprt_win_icon;
QIcon cam_impprt_win_icon;
public:
//palette
QPalette errorText;
QPalette successText;
//Right menu for tableview of plate
QMenu *right_menu;
QAction *QA_del_row;
QAction *QA_copy_row;
QAction *QA_paste_row;
QAction *QA_cut_row;
QList<QModelIndex> TB_index_list;//store the indexes choosed by clicking
QList<QModelIndex> TB_cut_template;//for cut operation
QList<QModelIndex> TB_copy_template;//for copy
QList<RowData> TB_row_data_list;//set of clicked items
QList<RowData> TB_row_data_cut_list;//set of cutted items
QList<RowData> TB_row_data_cpy_list;//set of copied items
private:
// QSplitter *m_h_Spliter,*m_r_Splitter;
// QTreeView *m_left_treeView;
// QWidget *child_dialog_new_prt;
// QWidget *child_dialog_new_layout;
// QDialog *child_dialog_new_prt_01;
void CamSigSlotsManage();
void CamDockWinManage();
void CamEventMananger();
void CamListener();
void closeEvent(QCloseEvent *evnt);
void createRightMenu();
//delete,cut,copy and paste rows of tableView
void TableViewDelRow();
void TableViewCutRow();
void TableViewCopyRow();
void TableViewPasteRow();
//remove repeated index item of TB_index_list
void RemoveRepeatedIndex();
//Refresh the tableview of plate after editting
void RefreshTBIndex();
//create the scene
void CreateScene();
//layout the docks
void CamLayoutDocks();
public:
//Functions related
//open file with specific format such as Dxf...
void CamOpenDxfFile(QString qs_dxf);
private slots:
void on_new_order_triggered();
void on_quit_triggered();
void on_new_mat_triggered();
void on_new_layout_triggered();
void on_new_prt_triggered();
void on_save_order_triggered();
void on_history_order_triggered();
void on_import_2_triggered();
void on_export_2_triggered();
void on_run_triggered();
void on_send_triggered();
void on_print_preview_triggered();
void on_print_triggered();
void on_open_layout_triggered();
void on_print_layout_triggered();
void on_open_all_layout_triggered();
void on_equipments_triggered();
void on_materials_triggered();
void on_manufs_triggered();
void on_cost_triggered();
void on_calculator_triggered();
void on_about_triggered();
void on_help_files_triggered();
void on_Line_triggered();
void on_Arc_triggered();
void on_Text_triggered();
void on_Circle_triggered();
void on_Ellipse_triggered();
void on_Polygon_triggered();
void on_Copy_triggered();
void on_Dimension_triggered();
void on_Choose_triggered();
void on_Translation_triggered();
void on_Rotation_triggered();
void on_Delete_triggered();
void on_Offset_triggered();
void on_Line_Color_triggered();
void on_Line_Type_triggered();
void on_Line_Width_triggered();
//Dock of new material
void on_pushButton_NewMat_clicked();
void on_pushButton_importMat_clicked();
//Dock of new prt
void on_new_prt_btn_newprt_clicked();
void on_new_prt_btn_addprt_clicked();
//slot of Action for del,cut,copy and paste
void on_qa_del_row();
void on_qa_cut_row();
void on_qa_copy_row();
void on_qa_paste_row();
void on_tableView_item_clicked();
//self-defined slots
public slots:
//For Dock
void on_cam_importmat_win_destroy();
void on_cam_newmat_win_destroy();
void on_cam_newprt_win_destroyed();//6.6
void on_cam_impprt_win_destroyed();//6.6
//For TableView of plate
void on_cam_newmat_win_receiveData(QString qs_name,QString qs_thick);
//For opening dxf files
void on_cam_importmat_win_receiveData(QStringList dxf_list);
void on_cam_importmat_win_openfiles(QString file);
void on_cam_importprt_win_openfiles(QString file);
//For right menu of TableView of plate
void on_cam_right_menu_tableView(QPoint);
void on_cam_newprt_rev_params(QString name_mat,
QString len,
QString width,
QString mat,
QString thick_mat,
QString qty,
QString no,
bool is_rot);
protected:
//Event management
virtual void customEvent(QEvent * event,QObject * obj);
};
#endif // CAMEXPERT_H
|
miyamotok0105/deeplearning-learning-sample | src/cuda_sample/sample1/cuda_main.c | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include "sample.h"
double gettimeofday_sec()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec * 1e-6;
}
int main(int argc, char *argv[])
{
double t1,t2;
int n = 100;
if (argc > 1) {
n = atoi( argv[1] );
}
printf("n: %d\n", n);
t1 = gettimeofday_sec();
cuda_kernel_exec(n);
t2 = gettimeofday_sec();
printf("elapsed: %f sec.\n", t2-t1);
return 0;
}
|
miyamotok0105/deeplearning-learning-sample | src/cuda_sample/sample1/sample.h | #ifndef SAMPLE_H
#define SAMPLE_H
void cuda_kernel_exec(int n);
#endif /* SAMPLE_H */
|
janklab/FasterDatevec | Mcode/+jl/+time/+internal/fastdateparts_precalc_mex.c | #include "mex.h"
#include "matrix.h"
#include <stdio.h>
#include <math.h>
#include <stdint.h>
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
// Inputs
if (nrhs != 2) {
mexErrMsgIdAndTxt("jl:time:InvalidInput", "Exactly 2 inputs are required.");
}
const mxArray *mxInDatenums = prhs[0];
if (!mxIsDouble(mxInDatenums)) {
mexErrMsgIdAndTxt("jl:time:InvalidInput", "Input 1 must be a double (of datenums).");
}
double *inDatenums = mxGetDoubles(mxInDatenums);
const mxArray *mxConstants = prhs[1];
if (!mxIsCell(mxConstants)) {
mexErrMsgIdAndTxt("jl:time:InvalidInput", "Input 2 must be a cell.");
}
const mxArray *mxFirstPrecalcYear = mxGetCell(mxConstants, 0);
const mxArray *mxFirstPrecalcDatenum = mxGetCell(mxConstants, 2);
const mxArray *mxPrecalcDayDatenums = mxGetCell(mxConstants, 4);
const mxArray *mxPrecalcDayDatenumsInt32 = mxGetCell(mxConstants, 5);
const mxArray *mxPrecalcYear = mxGetCell(mxConstants, 6);
const mxArray *mxPrecalcMonth = mxGetCell(mxConstants, 7);
const mxArray *mxPrecalcDay = mxGetCell(mxConstants, 8);
const mxArray *mxPrecalcDateparts = mxGetCell(mxConstants, 10);
double firstPrecalcYear = mxGetScalar(mxFirstPrecalcYear);
double firstPrecalcDatenum = mxGetScalar(mxFirstPrecalcDatenum);
int32_t firstPrecalcDaypart = (int32_t) firstPrecalcDatenum;
int32_t *precalcDayDatenums = mxGetInt32s(mxPrecalcDayDatenums);
int16_t *precalcYear = mxGetInt16s(mxPrecalcYear);
uint8_t *precalcMonth = mxGetUint8s(mxPrecalcMonth);
uint8_t *precalcDay = mxGetUint8s(mxPrecalcDay);
uint16_t *precalcDateparts = mxGetUint16s(mxPrecalcDateparts);
uint16_t *precalc = precalcDateparts;
mwSize n = mxGetNumberOfElements(mxInDatenums);
// Outputs
mxArray *mxOutYear = mxCreateNumericMatrix(n, 1, mxINT16_CLASS, mxREAL);
mxArray *mxOutMonth = mxCreateNumericMatrix(n, 1, mxUINT8_CLASS, mxREAL);
mxArray *mxOutDay = mxCreateNumericMatrix(n, 1, mxUINT8_CLASS, mxREAL);
mxArray *mxOutHour = mxCreateNumericMatrix(n, 1, mxUINT8_CLASS, mxREAL);
mxArray *mxOutMinute = mxCreateNumericMatrix(n, 1, mxUINT8_CLASS, mxREAL);
mxArray *mxOutSeconds = mxCreateNumericMatrix(n, 1, mxDOUBLE_CLASS, mxREAL);
int16_t *year = mxGetInt16s(mxOutYear);
uint8_t *month = mxGetUint8s(mxOutMonth);
uint8_t *day = mxGetUint8s(mxOutDay);
uint8_t *hour = mxGetUint8s(mxOutHour);
uint8_t *minute = mxGetUint8s(mxOutMinute);
double *seconds = mxGetDoubles(mxOutSeconds);
// Logic
int16_t tmpYear;
uint8_t tmpMonth;
uint8_t tmpDay;
uint8_t tmpHour;
uint8_t tmpMinute;
double tmpSecond;
double microsOfDayWithFrac;
double secondsOfDayWithFrac;
double secondsOfDayDouble;
double fractionalSeconds;
uint64_t microsOfDay;
uint32_t secondsOfDay;
uint8_t hourOfDay;
uint32_t secondsOfHour;
uint8_t minuteOfHour;
uint32_t secondsOfMinute;
double secondsWithFrac;
for (size_t i = 0; i < n; i++) {
double dnum = inDatenums[i];
// Special condition handling
// TODO
double dayPartDouble = floor(dnum);
double timePart = dnum - dayPartDouble;
int32_t dayPart = (int32_t) dayPartDouble;
// Day part
size_t ixPrecalc = dayPart - firstPrecalcDaypart;
//year[i] = *(precalc + ixPrecalc*3 + 0);
//month[i] = *(precalc + ixPrecalc*3 + 1);
//day[i] = *(precalc + ixPrecalc*3 + 2);
year[i] = precalcYear[ixPrecalc];
month[i] = precalcMonth[ixPrecalc];
day[i] = precalcDay[ixPrecalc];
// Time part
secondsOfDayWithFrac = timePart * 86400; // 60 * 60 * 24
microsOfDay = (uint64_t) (secondsOfDayWithFrac * 1000000);
if (microsOfDay == 0) {
hour[i] = 0;
minute[i] = 0;
seconds[i] = 0.0;
continue;
}
secondsOfDayDouble = floor(secondsOfDayWithFrac);
fractionalSeconds = secondsOfDayWithFrac - secondsOfDayDouble;
secondsOfDay = (uint32_t) secondsOfDayDouble;
hourOfDay = secondsOfDay / 3600;
secondsOfHour = secondsOfDay - (hourOfDay * 3600);
minuteOfHour = secondsOfHour / 60;
secondsOfMinute = secondsOfHour - (minuteOfHour * 60);
secondsWithFrac = ((double) secondsOfMinute) + fractionalSeconds;
hour[i] = hourOfDay;
minute[i] = minuteOfHour;
seconds[i] = secondsWithFrac;
}
// Package return values
mxArray *mxOut1 = mxCreateCellMatrix(6, 1);
mxSetCell(mxOut1, 0, mxOutYear);
mxSetCell(mxOut1, 1, mxOutMonth);
mxSetCell(mxOut1, 2, mxOutDay);
mxSetCell(mxOut1, 3, mxOutHour);
mxSetCell(mxOut1, 4, mxOutMinute);
mxSetCell(mxOut1, 5, mxOutSeconds);
plhs[0] = mxOut1;
}
|
JasonElbert/LocalyticsAndroid | src/ios/Localytics.h | //
// Localytics.h
// Copyright (C) 2014 Char Software Inc., DBA Localytics
//
// This code is provided under the Localytics Modified BSD License.
// A copy of this license has been distributed in a file called LICENSE
// with this source code.
//
// Please visit www.localytics.com for more information.
//
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#define LOCALYTICS_LIBRARY_VERSION @"3.8.0"
typedef NS_ENUM(NSUInteger, LLInAppMessageDismissButtonLocation){
LLInAppMessageDismissButtonLocationLeft,
LLInAppMessageDismissButtonLocationRight
};
typedef NS_ENUM(NSInteger, LLProfileScope){
LLProfileScopeApplication,
LLProfileScopeOrganization
};
@protocol LLMessagingDelegate;
@protocol LLAnalyticsDelegate;
@class LLInboxCampaign;
@class LLInboxDetailViewController;
/**
@discussion The class which manages creating, collecting, & uploading a Localytics session.
Please see the following guides for information on how to best use this
library, sample code, and other useful information:
<ul>
<li><a href="http://wiki.localytics.com/index.php?title=Developer's_Integration_Guide">
Main Developer's Integration Guide</a></li>
</ul>
<strong>Best Practices</strong>
<ul>
<li>Integrate Localytics in <code>applicationDidFinishLaunching</code>.</li>
<li>Open your session and begin your uploads in <code>applicationDidBecomeActive</code>. This way the
upload has time to complete and it all happens before your users have a
chance to begin any data intensive actions of their own.</li>
<li>Close the session in <code>applicationWillResignActive</code>.</li>
<li>Do not call any Localytics functions inside a loop. Instead, calls
such as <code>tagEvent</code> should follow user actions. This limits the
amount of data which is stored and uploaded.</li>
<li>Do not instantiate a Localtyics object, instead use only the exposed class methods.</li>
</ul>
*/
@interface Localytics : NSObject
#pragma mark - SDK Integration
/** ---------------------------------------------------------------------------------------
* @name Localytics SDK Integration
* ---------------------------------------------------------------------------------------
*/
/** Auto-integrates the Localytic SDK into the application.
Use this method to automatically integrate the Localytics SDK in a single line of code. Automatic
integration is accomplished by proxing the AppDelegate and "inserting" a Localytics AppDelegate
behind the applications AppDelegate. The proxy will first call the applications AppDelegate and
then call the Localytics AppDelegate.
@param appKey The unique key for each application generated at www.localytics.com
@param launchOptions The launchOptions provided by application:DidFinishLaunchingWithOptions:
*/
+ (void)autoIntegrate:(NSString *)appKey launchOptions:(NSDictionary *)launchOptions;
/** Manually integrate the Localytic SDK into the application.
Use this method to manually integrate the Localytics SDK. The developer still has to make sure to
open and close the Localytics session as well as call upload to ensure data is uploaded to
Localytics
@param appKey The unique key for each application generated at www.localytics.com
@see openSession
@see closeSession
@see upload
*/
+ (void)integrate:(NSString *)appKey;
/** Opens the Localytics session.
The session time as presented on the website is the time between <code>open</code> and the
final <code>close</code> so it is recommended to open the session as early as possible, and close
it at the last moment. It is recommended that this call be placed in <code>applicationDidBecomeActive</code>.
<br>
If for any reason this is called more than once every subsequent open call will be ignored.
Resumes the Localytics session. When the App enters the background, the session is
closed and the time of closing is recorded. When the app returns to the foreground, the session
is resumed. If the time since closing is greater than BACKGROUND_SESSION_TIMEOUT, (15 seconds
by default) a new session is created, and uploading is triggered. Otherwise, the previous session
is reopened.
*/
+ (void)openSession;
/** Closes the Localytics session. This should be called in
<code>applicationWillResignActive</code>.
<br>
If close is not called, the session will still be uploaded but no
events will be processed and the session time will not appear. This is
because the session is not yet closed so it should not be used in
comparison with sessions which are closed.
*/
+ (void)closeSession;
/** Creates a low priority thread which uploads any Localytics data already stored
on the device. This should be done early in the process life in order to
guarantee as much time as possible for slow connections to complete. It is also reasonable
to upload again when the application is exiting because if the upload is cancelled the data
will just get uploaded the next time the app comes up.
*/
+ (void)upload;
#pragma mark - Event Tagging
/** ---------------------------------------------------------------------------------------
* @name Event Tagging
* ---------------------------------------------------------------------------------------
*/
/** Tag an event
@param eventName The name of the event which occurred.
@see tagEvent:attributes:customerValueIncrease:
*/
+ (void)tagEvent:(NSString *)eventName;
/** Tag an event with attributes
@param eventName The name of the event which occurred.
@param attributes An object/hash/dictionary of key-value pairs, contains
contextual data specific to the event.
@see tagEvent:attributes:customerValueIncrease:
*/
+ (void)tagEvent:(NSString *)eventName attributes:(NSDictionary *)attributes;
/** Allows a session to tag a particular event as having occurred. For
example, if a view has three buttons, it might make sense to tag
each button click with the name of the button which was clicked.
For another example, in a game with many levels it might be valuable
to create a new tag every time the user gets to a new level in order
to determine how far the average user is progressing in the game.
<br>
<strong>Tagging Best Practices</strong>
<ul>
<li>DO NOT use tags to record personally identifiable information.</li>
<li>The best way to use tags is to create all the tag strings as predefined
constants and only use those. This is more efficient and removes the risk of
collecting personal information.</li>
<li>Do not set tags inside loops or any other place which gets called
frequently. This can cause a lot of data to be stored and uploaded.</li>
</ul>
<br>
See the tagging guide at: http://wiki.localytics.com/
@param eventName The name of the event which occurred.
@param attributes (Optional) An object/hash/dictionary of key-value pairs, contains
contextual data specific to the event.
@param customerValueIncrease (Optional) Numeric value, added to customer lifetime value.
Integer expected. Try to use lowest possible unit, such as cents for US currency.
*/
+ (void)tagEvent:(NSString *)eventName attributes:(NSDictionary *)attributes customerValueIncrease:(NSNumber *)customerValueIncrease;
#pragma mark - Tag Screen Method
/** Allows tagging the flow of screens encountered during the session.
@param screenName The name of the screen
*/
+ (void)tagScreen:(NSString *)screenName;
#pragma mark - Custom Dimensions
/** ---------------------------------------------------------------------------------------
* @name Custom Dimensions
* ---------------------------------------------------------------------------------------
*/
/** Sets the value of a custom dimension. Custom dimensions are dimensions
which contain user defined data unlike the predefined dimensions such as carrier, model, and country.
Once a value for a custom dimension is set, the device it was set on will continue to upload that value
until the value is changed. To clear a value pass nil as the value.
The proper use of custom dimensions involves defining a dimension with less than ten distinct possible
values and assigning it to one of the four available custom dimensions. Once assigned this definition should
never be changed without changing the App Key otherwise old installs of the application will pollute new data.
@param value The value to set the custom dimension to
@param dimension The dimension to set the value of
@see valueForCustomDimension:
*/
+ (void)setValue:(NSString *)value forCustomDimension:(NSUInteger)dimension;
/** Gets the custom value for a given dimension. Avoid calling this on the main thread, as it
may take some time for all pending database execution.
@param dimension The custom dimension to return a value for
@return The current value for the given custom dimension
@see setValue:forCustomDimension:
*/
+ (NSString *)valueForCustomDimension:(NSUInteger)dimension;
#pragma mark - Identifiers
/** ---------------------------------------------------------------------------------------
* @name Identifiers
* ---------------------------------------------------------------------------------------
*/
/** Sets the value of a custom identifier. Identifiers are a form of key/value storage
which contain custom user data. Identifiers might include things like email addresses,
customer IDs, twitter handles, and facebook IDs. Once a value is set, the device it was set
on will continue to upload that value until the value is changed.
To delete a property, pass in nil as the value.
@param value The value to set the identifier to. To delete a propert set the value to nil
@param identifier The name of the identifier to have it's value set
@see valueForIdentifier:
*/
+ (void)setValue:(NSString *)value forIdentifier:(NSString *)identifier;
/** Gets the identifier value for a given identifier. Avoid calling this on the main thread, as it
may take some time for all pending database execution.
@param identifier The identifier to return a value for
@return The current value for the given identifier
@see setValue:forCustomDimension:
*/
+ (NSString *)valueForIdentifier:(NSString *)identifier;
/** This is an identifier helper method. This method acts the same as calling
[Localytics setValue:userId forIdentifier:@"customer_id"]
@param customerId The user id to set the 'customer_id' identifier to
*/
+ (void)setCustomerId:(NSString *)customerId;
/** Gets the customer id. Avoid calling this on the main thread, as it
may take some time for all pending database execution.
@return The current value for customer id
*/
+ (NSString *)customerId;
/** Stores the user's location. This will be used in all event and session calls.
If your application has already collected the user's location, it may be passed to Localytics
via this function. This will cause all events and the session close to include the location
information. It is not required that you call this function.
@param location The user's location.
*/
+ (void)setLocation:(CLLocationCoordinate2D)location;
#pragma mark - Profile
/** ---------------------------------------------------------------------------------------
* @name Profile
* ---------------------------------------------------------------------------------------
*/
/** Sets the value of a profile attribute.
@param value The value to set the profile attribute to. value can be one of the following: NSString,
NSNumber(long & int), NSDate, NSArray of Strings, NSArray of NSNumbers(long & int), NSArray of Date,
nil. Passing in a 'nil' value will result in that attribute being deleted from the profile
@param attribute The name of the profile attribute to be set
@param scope The scope of the attribute governs the visability of the profile attribute (application
only or organization wide)
*/
+ (void)setValue:(NSObject *)value forProfileAttribute:(NSString *)attribute withScope:(LLProfileScope)scope;
/** Sets the value of a profile attribute (scope: Application).
@param value The value to set the profile attribute to. value can be one of the following: NSString,
NSNumber(long & int), NSDate, NSArray of Strings, NSArray of NSNumbers(long & int), NSArray of Date,
nil. Passing in a 'nil' value will result in that attribute being deleted from the profile
@param attribute The name of the profile attribute to be set
*/
+ (void)setValue:(NSObject *)value forProfileAttribute:(NSString *)attribute;
/** Adds values to a profile attribute that is a set
@param values The value to be added to the profile attributes set
@param attribute The name of the profile attribute to have it's set modified
@param scope The scope of the attribute governs the visability of the profile attribute (application
only or organization wide)
*/
+ (void)addValues:(NSArray *)values toSetForProfileAttribute:(NSString *)attribute withScope:(LLProfileScope)scope;
/** Adds values to a profile attribute that is a set (scope: Application).
@param values The value to be added to the profile attributes set
@param attribute The name of the profile attribute to have it's set modified
*/
+ (void)addValues:(NSArray *)values toSetForProfileAttribute:(NSString *)attribute;
/** Removes values from a profile attribute that is a set
@param values The value to be removed from the profile attributes set
@param attribute The name of the profile attribute to have it's set modified
@param scope The scope of the attribute governs the visability of the profile attribute (application
only or organization wide)
*/
+ (void)removeValues:(NSArray *)values fromSetForProfileAttribute:(NSString *)attribute withScope:(LLProfileScope)scope;
/** Removes values from a profile attribute that is a set (scope: Application).
@param values The value to be removed from the profile attributes set
@param attribute The name of the profile attribute to have it's set modified
*/
+ (void)removeValues:(NSArray *)values fromSetForProfileAttribute:(NSString *)attribute;
/** Increment the value of a profile attribute.
@param value An NSInteger to be added to an existing profile attribute value.
@param attribute The name of the profile attribute to have it's value incremented
@param scope The scope of the attribute governs the visability of the profile attribute (application
only or organization wide)
*/
+ (void)incrementValueBy:(NSInteger)value forProfileAttribute:(NSString *)attribute withScope:(LLProfileScope)scope;
/** Increment the value of a profile attribute (scope: Application).
@param value An NSInteger to be added to an existing profile attribute value.
@param attribute The name of the profile attribute to have it's value incremented
*/
+ (void)incrementValueBy:(NSInteger)value forProfileAttribute:(NSString *)attribute;
/** Decrement the value of a profile attribute.
@param value An NSInteger to be subtracted from an existing profile attribute value.
@param attribute The name of the profile attribute to have it's value decremented
@param scope The scope of the attribute governs the visability of the profile attribute (application
only or organization wide)
*/
+ (void)decrementValueBy:(NSInteger)value forProfileAttribute:(NSString *)attribute withScope:(LLProfileScope)scope;
/** Decrement the value of a profile attribute (scope: Application).
@param value An NSInteger to be subtracted from an existing profile attribute value.
@param attribute The name of the profile attribute to have it's value decremented
*/
+ (void)decrementValueBy:(NSInteger)value forProfileAttribute:(NSString *)attribute;
/** Delete a profile attribute
@param attribute The name of the attribute to be deleted
@param scope The scope of the attribute governs the visability of the profile attribute (application
only or organization wide)
*/
+ (void)deleteProfileAttribute:(NSString *)attribute withScope:(LLProfileScope)scope;
/** Delete a profile attribute (scope: Application)
@param attribute The name of the attribute to be deleted
*/
+ (void)deleteProfileAttribute:(NSString *)attribute;
/** Convenience method to set a customer's email as both a profile attribute and
as a customer identifier (scope: Organization)
@param email Customer's email
*/
+ (void)setCustomerEmail:(NSString *)email;
/** Convenience method to set a customer's first name as both a profile attribute and
as a customer identifier (scope: Organization)
@param firstName Customer's first name
*/
+ (void)setCustomerFirstName:(NSString *)firstName;
/** Convenience method to set a customer's last name as both a profile attribute and
as a customer identifier (scope: Organization)
@param lastName Customer's last name
*/
+ (void)setCustomerLastName:(NSString *)lastName;
/** Convenience method to set a customer's full name as both a profile attribute and
as a customer identifier (scope: Organization)
@param fullName Customer's full name
*/
+ (void)setCustomerFullName:(NSString *)fullName;
#pragma mark - Push
/** ---------------------------------------------------------------------------------------
* @name Push
* ---------------------------------------------------------------------------------------
*/
/** Returns the device's APNS token if one has been set via setPushToken: previously.
@return The device's APNS token if one has been set otherwise nil
@see setPushToken:
*/
+ (NSString *)pushToken;
/** Stores the device's APNS token. This will be used in all event and session calls.
@param pushToken The devices APNS token returned by application:didRegisterForRemoteNotificationsWithDeviceToken:
@see pushToken
*/
+ (void)setPushToken:(NSData *)pushToken;
/** Used to record performance data for push notifications
@param notificationInfo The dictionary from either didFinishLaunchingWithOptions or
didReceiveRemoteNotification should be passed on to this method
*/
+ (void)handlePushNotificationOpened:(NSDictionary *)notificationInfo;
#pragma mark - In-App Message
/** ---------------------------------------------------------------------------------------
* @name In-App Message
* ---------------------------------------------------------------------------------------
*/
/**
@param url The URL to be handled
@return YES if the URL was successfully handled or NO if the attempt to handle the
URL failed.
*/
+ (BOOL)handleTestModeURL:(NSURL *)url;
/** Set the image to be used for dimissing an In-App message
@param image The image to be used for dismissing an In-App message. By default this is a
circle with an 'X' in the middle of it
*/
+ (void)setInAppMessageDismissButtonImage:(UIImage *)image;
/** Set the image to be used for dimissing an In-App message by providing the name of the
image to be loaded and used
@param imageName The name of an image to be loaded and used for dismissing an In-App
message. By default the image is a circle with an 'X' in the middle of it
*/
+ (void)setInAppMessageDismissButtonImageWithName:(NSString *)imageName;
/** Set the location of the dismiss button on an In-App msg
@param location The location of the button (left or right)
@see InAppDismissButtonLocation
*/
+ (void)setInAppMessageDismissButtonLocation:(LLInAppMessageDismissButtonLocation)location;
/** Returns the location of the dismiss button on an In-App msg
@return InAppDismissButtonLocation
@see InAppDismissButtonLocation
*/
+ (LLInAppMessageDismissButtonLocation)inAppMessageDismissButtonLocation;
+ (void)triggerInAppMessage:(NSString *)triggerName;
+ (void)triggerInAppMessage:(NSString *)triggerName withAttributes:(NSDictionary *)attributes;
+ (void)dismissCurrentInAppMessage;
#pragma mark - Inbox
/** Returns an array of all Inbox campaigns that are enabled and ready for display.
@return an array of LLInboxCampaign objects
*/
+ (NSArray<LLInboxCampaign *> *)inboxCampaigns;
/** Refresh inbox campaigns from the Localytics server.
@param completionBlock the block invoked with refresh is complete
*/
+ (void)refreshInboxCampaigns:(void (^)(NSArray<LLInboxCampaign *> *inboxCampaigns))completionBlock;
/** Set an Inbox campaign as read. Read state can be used to display opened but not disabled Inbox
campaigns differently (e.g. greyed out).
@param campaignId the campaign ID of the Inbox campaign.
@param read YES to mark the campaign as read, NO to mark it as unread
@see [LLInboxCampaign class]
*/
+ (void)setInboxCampaignId:(NSInteger)campaignId asRead:(BOOL)read;
/** Returns a inbox campaign detail view controller with the given inbox campaign data.
@return a LLInboxDetailViewController from a given LLInboxCampaign object
*/
+ (LLInboxDetailViewController *)inboxDetailViewControllerForCampaign:(LLInboxCampaign *)campaign;
#pragma mark - Developer Options
/** ---------------------------------------------------------------------------------------
* @name Developer Options
* ---------------------------------------------------------------------------------------
*/
/** Returns whether the Localytics SDK is set to emit logging information
@return YES if logging is enabled, NO otherwise
*/
+ (BOOL)isLoggingEnabled;
/** Set whether Localytics SDK should emit logging information. By default the Localytics SDK
is set to not to emit logging information. It is recommended that you only enable logging
for debugging purposes.
@param loggingEnabled Set to YES to enable logging or NO to disable it
*/
+ (void)setLoggingEnabled:(BOOL)loggingEnabled;
/** Returns whether or not an IDFA is collected and sent to Localytics
@return YES if an IDFA is collected, NO otherwise
@see setCollectAdvertisingIdentifier
*/
+ (BOOL)isCollectingAdvertisingIdentifier;
/** Set whether or not an IDFA is collected and sent to Localytics
@param collectAdvertisingIdentifier When set to YES an IDFA is collected. No prevents the IDFA
from being collected. By default an IDFA is collected
@see isCollectingAdvertisingIdentifier
*/
+ (void)setCollectAdvertisingIdentifier:(BOOL)collectAdvertisingIdentifier;
/** Returns whether or not the application will collect user data.
@return YES if the user is opted out, NO otherwise. Default is NO
@see setOptedOut:
*/
+ (BOOL)isOptedOut;
/** Allows the application to control whether or not it will collect user data.
Even if this call is used, it is necessary to continue calling upload(). No new data will be
collected, so nothing new will be uploaded but it is necessary to upload an event telling the
server this user has opted out.
@param optedOut YES if the user is opted out, NO otherwise.
@see isOptedOut
*/
+ (void)setOptedOut:(BOOL)optedOut;
/** Returns whether the Localytics SDK is currently in test mode or not. When in test mode
a small Localytics tab will appear on the left side of the screen which enables a developer
to see/test all the campaigns currently available to this customer.
@return YES if test mode is enabled, NO otherwise
*/
+ (BOOL)isTestModeEnabled;
/** Set whether Localytics SDK should enter test mode or not. When set to YES the a small
Localytics tab will appear on the left side of the screen, enabling a developer to see/test
all campaigns currently available to this customer.
Setting testModeEnabled to NO will cause Localytics to exit test mode, if it's currently
in it.
@param enabled Set to YES to enable test mode, NO to disable test mode
*/
+ (void)setTestModeEnabled:(BOOL)enabled;
/** Returns the session time out interval. If a user backgrounds the app and then foregrounds
the app before the session timeout interval expires then the session will be considered as
resuming. If the user returns after the time out interval expires the old session willl be
closed and a new session will be initiated.
@return the session time out interval (defaults to 15 seconds)
*/
+ (NSTimeInterval)sessionTimeoutInterval;
/** Sets the session time out interval. If a user backgrounds the app and then foregrounds
the app before the session time out interval expires then the session will be considered as
resuming. If the user returns after the time out interval expires the old session willl be
closed and a new session will be initiated.
@param timeoutInterval The session time out interval
*/
+ (void)setSessionTimeoutInterval:(NSTimeInterval)timeoutInterval;
/** Returns the install id
@return the install id as an NSString
*/
+ (NSString *)installId;
/** Returns the version of the Localytics SDK
@return the version of the Localytics SDK as an NSString
*/
+ (NSString *)libraryVersion;
/** Returns the app key currently set in Localytics
@return the app key currently set in Localytics as an NSString
*/
+ (NSString *)appKey;
/** Returns the analytics API hostname
@return the analyics API hostname currently set in Localytics as an NSString
*/
+ (NSString *)analyticsHost;
/** Sets the analytics API hostname
@param analyticsHost The hostname for analytics API requests
*/
+ (void)setAnalyticsHost:(NSString *)analyticsHost;
/** Returns the messaging API hostname
@return the messaging API hostname currently set in Localytics as an NSString
*/
+ (NSString *)messagingHost;
/** Sets the messaging API hostname
@param messagingHost The hostname for messaging API requests
*/
+ (void)setMessagingHost:(NSString *)messagingHost;
/** Returns the profiles API hostname
@return the profiles API hostname currently set in Localytics as an NSString
*/
+ (NSString *)profilesHost;
/** Sets the profiles API hostname
@param profilesHost The hostname for profiles API requests
*/
+ (void)setProfilesHost:(NSString *)profilesHost;
/** Returns the manifest API hostname
@return the manifest API hostname currently set in Localytics as an NSString
*/
+ (NSString *)manifestHost;
/** Sets the manifest API hostname
@param manifestHost The hostname for manifest API requests
*/
+ (void)setManifestHost:(NSString *)manifestHost;
#pragma mark - In-App Message Delegate
/** ---------------------------------------------------------------------------------------
* @name In-App Message Delegate
* ---------------------------------------------------------------------------------------
*/
/** Add a Messaging delegate
@param delegate An object that implements the LLMessagingDelegate and is called
when an In-App message will display, did display, will hide, and did hide. Multiple objects
can be delegates, and each one will receive callbacks.
@see LLMessagingDelegate
*/
+ (void)addMessagingDelegate:(id<LLMessagingDelegate>)delegate;
/** Remove a Messaging delegate
@param delegate The delegate previously added that now being removed
@see LLMessagingDelegate
*/
+ (void)removeMessagingDelegate:(id<LLMessagingDelegate>)delegate;
/** Returns whether the ADID parameter is added to In-App call to action URLs
@return YES if parameter is added, NO otherwise
*/
+ (BOOL)isInAppAdIdParameterEnabled;
/** Set whether ADID parameter is added to In-App call to action URLs. By default
the ADID parameter will be added to call to action URLs.
@param enabled Set to YES to enable the ADID parameter or NO to disable it
*/
+ (void)setInAppAdIdParameterEnabled:(BOOL)enabled;
#pragma mark - Analytics Delegate
/** ---------------------------------------------------------------------------------------
* @name Analytics Delegate
* ---------------------------------------------------------------------------------------
*/
/** Add an Analytics delegate
@param delegate An object implementing the LLAnalyticsDelegate protocol. Multiple objects
can be delegates, and each one will receive callbacks.
@see LLAnalyticsDelegate
*/
+ (void)addAnalyticsDelegate:(id<LLAnalyticsDelegate>)delegate;
/** Remove an Analytics delegate
@param delegate The delegate previously added that now being removed
@see LLAnalyticsDelegate
*/
+ (void)removeAnalyticsDelegate:(id<LLAnalyticsDelegate>)delegate;
#pragma mark - WatchKit
/** ---------------------------------------------------------------------------------------
* @name WatchKit
* ---------------------------------------------------------------------------------------
*/
/** Handle calls to the SDK from a WatchKit Extension app
Call this in the UIApplicationDelegate's application:handleWatchKitExtensionRequest:reply:
method.
@param userInfo the userInfo provided by application:handleWatchKitExtensionRequest:reply:
@param reply The reply provided by application:handleWatchKitExtensionRequest:reply:
@return YES if the Localytics SDK has handled replying to the WatchKit Extension; NO otherwise
*/
+ (BOOL)handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *replyInfo))reply;
@end
@protocol LLAnalyticsDelegate <NSObject>
@optional
- (void)localyticsSessionWillOpen:(BOOL)isFirst isUpgrade:(BOOL)isUpgrade isResume:(BOOL)isResume;
- (void)localyticsSessionDidOpen:(BOOL)isFirst isUpgrade:(BOOL)isUpgrade isResume:(BOOL)isResume;
- (void)localyticsDidTagEvent:(NSString *)eventName
attributes:(NSDictionary *)attributes
customerValueIncrease:(NSNumber *)customerValueIncrease;
- (void)localyticsSessionWillClose;
@end
@protocol LLMessagingDelegate <NSObject>
@optional
- (void)localyticsWillDisplayInAppMessage;
- (void)localyticsDidDisplayInAppMessage;
- (void)localyticsWillDismissInAppMessage;
- (void)localyticsDidDismissInAppMessage;
@end
@protocol LLInboxCampaignsRefreshingDelegate <NSObject>
@optional
- (void)localyticsDidBeginRefreshingInboxCampaigns;
- (void)localyticsDidFinishRefreshingInboxCampaigns;
@end
/**
* A base campaign class containing information relevant to all campaign types
*/
@interface LLCampaignBase : NSObject
/**
* The unique campaign id.
*/
@property (nonatomic, assign, readonly) NSInteger campaignId;
/**
* The campaign name
*/
@property (nonatomic, copy, readonly) NSString *name;
/**
* The attributes associated with the campaign.
*/
@property (nonatomic, copy, readonly) NSDictionary *attributes;
@end
/**
* A base campaign class containing information relevant to campaigns which
* include a web component.
*
* @see LLInboxCampaign
*/
@interface LLWebViewCampaign : LLCampaignBase
@end
/**
* The campaign class containing information relevant to a single inbox campaign.
*
* @see LLWebViewCampaign
* @see LLCampaignBase
*/
@interface LLInboxCampaign : LLWebViewCampaign
/**
* The flag indicating whether the campaign has been read.
*
* Note: Changing this value will automatically update the inbox campaign record
* in the Localytics database.
*/
@property (nonatomic, assign, getter=isRead) BOOL read;
/**
* The preview title text.
*/
@property (nonatomic, copy, readonly) NSString *titleText;
/**
* The preview description text.
*/
@property (nonatomic, copy, readonly) NSString *summaryText;
/**
* The remote url of the thumbnail.
*/
@property (nonatomic, copy, readonly) NSURL *thumbnailUrl;
/**
* Value indicating if the campaign has a creative.
*/
@property (nonatomic, assign, readonly) BOOL hasCreative;
/**
* The sort order of the campaign.
*/
@property (nonatomic, assign, readonly) NSInteger sortOrder;
/**
* The received date of the campaign.
*/
@property (nonatomic, assign, readonly) NSTimeInterval receivedDate;
@end
/**
* UIViewController class that loads inbox campaigns and displays them in a UITableView.
* This class also handles marking inbox campaigns as read and displaying the inbox
* campaign's full creative when it is tapped by pushing an LLInboxDetailViewController
* onto the UINavigationController stack.
*
* By default this class uses custom UITableViewCells which include an unread indicator, title text,
* summary text (when available), thumbnail image (when available), and created time text.
*
* Customization options:
* - Empty campaigns view, @see property emptyCampaignsView
* - Show UIActivityIndicatorView while loading campaigns, @see property showsActivityIndicatorView
* - UITableViewCells, override tableView:cellForRowAtIndexPath:
* - Full creative display, override tableView:didSelectRowAtIndexPath:, Note: You must also handle
* setting the LLInboxCampaign to be read and checking the existense of the creativeUrl property of
* the LLInboxCampaign object.
*
* @see LLInboxDetailViewController
*/
@interface LLInboxViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, LLInboxCampaignsRefreshingDelegate>
/**
* The UITableView that shows the inbox campaigns.
*/
@property (nonatomic, strong) UITableView *tableView;
/**
* The UIView to show when there are no inbox campaigns to display.
*
* Note: All subviews of this view should include appropriate Auto Layout constraints because this
* view's leading edge, top edge, trailing edge, and bottom edge will be constrained to match
* the main view in LLInboxViewController.
*/
@property (nonatomic, strong) UIView *emptyCampaignsView;
/**
* Flag indicating whether a UIActivityIndicatorView should be shown will campaigns are loading.
*/
@property (nonatomic, assign) BOOL showsActivityIndicatorView;
/**
* Flag indicating whether thumbnail images are automatically downloaded and loading into LLInboxThumbnailCell.
* Defaults to YES. Set this property to NO to manually manage thumbnail downloading and caching (such as through
* a 3rd party networking library).
*/
@property (nonatomic, assign) BOOL downloadsThumbnails;
/**
* The font of the UITableViewCell textLabel. Default is 16 point system bold.
*/
@property (nonatomic, strong) UIFont *textLabelFont;
/**
* The color of the UITableViewCell textLabel. Default is black.
*/
@property (nonatomic, strong) UIColor *textLabelColor;
/**
* The font of the UITableViewCell detailTextLabel. Default is 14 point system.
*/
@property (nonatomic, strong) UIFont *detailTextLabelFont;
/**
* The color of the UITableViewCell detailTextLabel. Default is black.
*/
@property (nonatomic, strong) UIColor *detailTextLabelColor;
/**
* The font of the UITableViewCell timeTextLabel. Default is 10 point system.
*/
@property (nonatomic, strong) UIFont *timeTextLabelFont;
/**
* The color of the UITableViewCell timeTextLabel. Default is gray.
*/
@property (nonatomic, strong) UIColor *timeTextLabelColor;
/**
* The color of the UITableViewCell unread indicator. Default is #007AFF.
*/
@property (nonatomic, strong) UIColor *unreadIndicatorColor;
/**
* The color of the UITablviewCell background
*/
@property (nonatomic, strong) UIColor *cellBackgroundColor;
/**
* The UIView to show when a creative fails to load in a detail view. This property is used to set the
* creativeLoadErrorView of LLInboxDetailViewControllers created when the user opens a campaign.
* If this property is not set, a gray 'X' will be shown in the center of the view.
*
* Note: All subviews of this view should include appropriate Auto Layout constraints because this
* view's leading edge, top edge, trailing edge, and bottom edge will be constrained to match
* the main view in LLInboxDetailViewController.
*/
@property (nonatomic, strong) UIView *creativeLoadErrorView;
/**
* Returns the inbox campaign for an index path (useful for overriding tableView:cellForRowAtIndexPath:)
*
* @return An LLInboxCampaign object for the index path.
*/
- (LLInboxCampaign *)campaignForRowAtIndexPath:(NSIndexPath *)indexPath;
@end
/**
* UIViewController class that displays an inbox campaign's full creative. This class also handles tagging
* impression events when a call to action is tapped within the creative or when the UIViewController is
* dismissed.
*
* Customization options:
* - Error view, @see errorView
*
* @see LLInboxViewController
*/
@interface LLInboxDetailViewController : UIViewController
/**
* The inbox campaign being displayed
*/
@property (nonatomic, strong, readonly) LLInboxCampaign *campaign;
/**
* The UIView to show when the full creative fails to load. If this property is not set, a gray 'X' will
* be shown in the center of the view.
*
* Note: All subviews of this view should include appropriate Auto Layout constraints because this
* view's leading edge, top edge, trailing edge, and bottom edge will be constrained to match
* the main view in LLInboxDetailViewController.
*/
@property (nonatomic, strong) UIView *creativeLoadErrorView;
@end
|
JasonElbert/LocalyticsAndroid | src/ios/LocalyticsPlugin.h | //
// LocalyticsPlugin.h
//
// Copyright 2015 Localytics. All rights reserved.
//
#import <Cordova/CDVPlugin.h>
@interface LocalyticsPlugin : CDVPlugin
- (void)integrate:(CDVInvokedUrlCommand *)command;
- (void)autoIntegrate:(CDVInvokedUrlCommand *)command;
- (void)openSession:(CDVInvokedUrlCommand *)command;
- (void)closeSession:(CDVInvokedUrlCommand *)command;
- (void)upload:(CDVInvokedUrlCommand *)command;
- (void)tagEvent:(CDVInvokedUrlCommand *)command;
- (void)tagScreen:(CDVInvokedUrlCommand *)command;
- (void)setCustomDimension:(CDVInvokedUrlCommand *)command;
- (void)getCustomDimension:(CDVInvokedUrlCommand *)command;
- (void)setOptedOut:(CDVInvokedUrlCommand *)command;
- (void)isOptedOut:(CDVInvokedUrlCommand *)command;
- (void)setProfileAttribute:(CDVInvokedUrlCommand *)command;
- (void)addProfileAttributesToSet:(CDVInvokedUrlCommand *)command;
- (void)removeProfileAttributesFromSet:(CDVInvokedUrlCommand *)command;
- (void)incrementProfileAttribute:(CDVInvokedUrlCommand *)command;
- (void)decrementProfileAttribute:(CDVInvokedUrlCommand *)command;
- (void)deleteProfileAttribute:(CDVInvokedUrlCommand *)command;
- (void)setIdentifier:(CDVInvokedUrlCommand *)command;
- (void)setCustomerId:(CDVInvokedUrlCommand *)command;
- (void)setCustomerFullName:(CDVInvokedUrlCommand *)command;
- (void)setCustomerFirstName:(CDVInvokedUrlCommand *)command;
- (void)setCustomerLastName:(CDVInvokedUrlCommand *)command;
- (void)setCustomerEmail:(CDVInvokedUrlCommand *)command;
- (void)setLocation:(CDVInvokedUrlCommand *)command;
- (void)registerPush:(CDVInvokedUrlCommand *)command;
- (void)setPushDisabled:(CDVInvokedUrlCommand *)command;
- (void)isPushDisabled:(CDVInvokedUrlCommand *)command;
- (void)setTestModeEnabled:(CDVInvokedUrlCommand *)command;
- (void)isTestModeEnabled:(CDVInvokedUrlCommand *)command;
- (void)setInAppMessageDismissButtonImageWithName:(CDVInvokedUrlCommand *)command;
- (void)setInAppMessageDismissButtonLocation:(CDVInvokedUrlCommand *)command;
- (void)getInAppMessageDismissButtonLocation:(CDVInvokedUrlCommand *)command;
- (void)triggerInAppMessage:(CDVInvokedUrlCommand *)command;
- (void)dismissCurrentInAppMessage:(CDVInvokedUrlCommand *)command;
- (void)setLoggingEnabled:(CDVInvokedUrlCommand *)command;
- (void)isLoggingEnabled:(CDVInvokedUrlCommand *)command;
- (void)setSessionTimeoutInterval:(CDVInvokedUrlCommand *)command;
- (void)getSessionTimeoutInterval:(CDVInvokedUrlCommand *)command;
- (void)getInstallId:(CDVInvokedUrlCommand *)command;
- (void)getAppKey:(CDVInvokedUrlCommand *)command;
- (void)getLibraryVersion:(CDVInvokedUrlCommand *)command;
@end |
WarZhan/Graphics-Demo | Solar/Angel.h | <reponame>WarZhan/Graphics-Demo
//////////////////////////////////////////////////////////////////////////////
//
// --- Angel.h ---
//
// The main header file for all examples from Angel 6th Edition
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __ANGEL_H__
#define __ANGEL_H__
//----------------------------------------------------------------------------
//
// --- Include system headers ---
//
#include <cmath> // 包含C++数学库
#include <iostream> // 包含C++标准输入输出库
// Define M_PI in the case it's not defined in the math header file
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
//----------------------------------------------------------------------------
//
// --- Include OpenGL header files and helpers ---
//
// The location of these files vary by operating system. We've included
// copies of open-soruce project headers in the "GL" directory local
// this this "include" directory.
//
#ifdef __APPLE__ // include Mac OS X verions of headers
# include <OpenGL/OpenGL.h>
# include <GLUT/glut.h>
#else // non-Mac OS X operating systems
# include <GL/glew.h>
# include <GL/freeglut.h>
# include <GL/freeglut_ext.h>
#pragma comment (lib, "glew32.lib") // Zou Kun额外增加,用于链接glew库
#endif // __APPLE__
// Define a helpful macro for handling offsets into buffer objects
// 定义buffer对象偏移量宏,主要实现类型转化
#define BUFFER_OFFSET( offset ) ((GLvoid*) (offset))
//----------------------------------------------------------------------------
//
// --- Include our class libraries and constants ---
//
namespace Angel
{
struct Shader
{
const char* filename; // shader文件名
GLenum type; // shader类型
GLchar* source; // shader程序字符串
}; // 定义Shader结构体数组shaders
// 声明加载顶点和片元shader的函数,此函数定义于InitShader.cpp中
GLuint InitShader(const char* vertexShaderFile, const char* fragmentShaderFile);
// 定义最小浮点数,防止被0除
const GLfloat DivideByZeroTolerance = GLfloat(1.0e-07);
// 角度转弧度的系数
const GLfloat DegreesToRadians = M_PI / 180.0;
} // namespace Angel
/*包含自定义的头文件*/
#include "vec.h"
#include "mat.h"
// 打印输出宏,其中#x表示将x转为字符数组
#define Print(x) do { std::cerr << #x " = " << (x) << std::endl; } while(0)
// 使用Angel命名空间
using namespace Angel;
#endif // __ANGEL_H__
|
onezens/HttpsDemo | HttpsDemo/ViewController.h | //
// ViewController.h
// HttpsDemo
//
// Created by leaf on 2017/8/15.
// Copyright © 2017年 cc.onezen. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
|
onezens/HttpsDemo | HttpsDemo/UIAHttps.h | <reponame>onezens/HttpsDemo<gh_stars>0
//
// UIAHttps.h
// UIADemo
//
// Created by zhangchao on 16/12/13.
// Copyright © 2016年 王龙. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIAHttps : NSObject
+ (UIAHttps *)shared;
- (void)POST:(NSString *)urlString
Dictionary:(NSDictionary *)dic
progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
- (void)get:(NSString *)url params:(NSDictionary *)params success:(void (^)(id obj))success failure:(void (^)(NSError * err))failure;
@end
NS_ASSUME_NONNULL_END
|
pjcollins/java.interop | src/java-interop/java-interop-gc-bridge-mono.c | #include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <inttypes.h>
#include "java-interop.h"
#include "java-interop-gc-bridge.h"
#include "java-interop-mono.h"
#ifdef __linux__
#include <unistd.h>
#endif /* !defined (__linux__) */
#if defined (ANDROID)
#include "logger.h"
#endif /* !defined (ANDROID) */
#include <dlfcn.h>
typedef struct MonoJavaGCBridgeInfo {
MonoClass *klass;
MonoClassField *handle;
MonoClassField *handle_type;
MonoClassField *refs_added;
MonoClassField *weak_handle;
} MonoJavaGCBridgeInfo;
#define NUM_GC_BRIDGE_TYPES (4)
struct JavaInteropGCBridge {
JavaVM *jvm;
MonoClass *BridgeProcessing_type;
MonoClassField *BridgeProcessing_field;
int BridgeProcessing_vtables_count, BridgeProcessing_vtables_length;
MonoDomain **BridgeProcessing_domains;
MonoVTable **BridgeProcessing_vtables;
int num_bridge_types;
MonoJavaGCBridgeInfo mono_java_gc_bridge_info [NUM_GC_BRIDGE_TYPES];
int gc_disabled;
int gc_gref_count;
int gc_weak_gref_count;
jobject Runtime_instance;
jmethodID Runtime_gc;
jclass WeakReference_class;
jmethodID WeakReference_init;
jmethodID WeakReference_get;
jclass GCUserPeerable_class;
jmethodID GCUserPeerable_add;
jmethodID GCUserPeerable_clear;
FILE *gref_log, *lref_log;
char *gref_path, *lref_path;
int gref_log_level, lref_log_level;
int gref_cleanup, lref_cleanup;
};
typedef char* (*MonoThreadGetNameUtf8)(MonoThread*);
typedef int32_t (*MonoThreadGetManagedId)(MonoThread*);
static MonoThreadGetManagedId _mono_thread_get_managed_id;
static MonoThreadGetNameUtf8 _mono_thread_get_name_utf8;
static void
lookup_optional_mono_thread_functions (void)
{
void *h = dlopen (NULL, RTLD_LAZY);
if (!h)
return;
_mono_thread_get_managed_id = dlsym (h, "mono_thread_get_managed_id");
_mono_thread_get_name_utf8 = dlsym (h, "mono_thread_get_name_utf8");
}
static jobject
lref_to_gref (JNIEnv *env, jobject lref)
{
jobject g;
if (lref == 0)
return 0;
g = (*env)->NewGlobalRef (env, lref);
(*env)->DeleteLocalRef (env, lref);
return g;
}
static JNIEnv*
ensure_jnienv (JavaInteropGCBridge *bridge)
{
JavaVM *jvm = bridge->jvm;
JNIEnv *env;
if ((*bridge->jvm)->GetEnv (bridge->jvm, (void**)&env, JNI_VERSION_1_6) != JNI_OK || env == NULL) {
mono_thread_attach (mono_domain_get ());
(*jvm)->GetEnv (jvm, (void**)&env, JNI_VERSION_1_6);
}
return env;
}
static int
java_interop_gc_bridge_destroy (JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return -1;
JNIEnv *env = ensure_jnienv (bridge);
if (env != NULL) {
(*env)->DeleteGlobalRef (env, bridge->Runtime_instance);
(*env)->DeleteGlobalRef (env, bridge->WeakReference_class);
(*env)->DeleteGlobalRef (env, bridge->GCUserPeerable_class);
bridge->Runtime_instance = NULL;
bridge->WeakReference_class = NULL;
bridge->GCUserPeerable_class = NULL;
}
if (bridge->gref_log != NULL && bridge->gref_cleanup) {
fclose (bridge->gref_log);
}
bridge->gref_log = NULL;
free (bridge->gref_path);
bridge->gref_path = NULL;
if (bridge->lref_log != NULL && bridge->lref_cleanup) {
fclose (bridge->lref_log);
}
bridge->lref_log = NULL;
free (bridge->lref_path);
bridge->lref_path = NULL;
free (bridge->BridgeProcessing_domains);
free (bridge->BridgeProcessing_vtables);
bridge->BridgeProcessing_domains = NULL;
bridge->BridgeProcessing_vtables = NULL;
bridge->BridgeProcessing_vtables_count = 0;
bridge->BridgeProcessing_vtables_length = 0;
return 0;
}
static char*
ji_realpath (const char *path)
{
if (path == NULL)
return NULL;
char *rp = realpath (path, NULL);
if (rp == NULL) {
return strdup (path);
}
return rp;
}
static FILE *
open_log_file (const char *path, FILE *alt, const char *alt_path, const char *envVar, int *cleanup, char **rpath)
{
path = path ? path : getenv (envVar);
if (path == NULL)
return NULL;
*cleanup = 0;
if (strlen (path) == 0)
return stdout;
char *rp = ji_realpath (path);
if (rp != NULL && alt_path != NULL && strcmp (rp, alt_path) == 0) {
free (rp);
return alt;
}
FILE *f = fopen (path, "w");
if (f == NULL) {
free (rp);
return NULL;
}
if (rpath) {
*rpath = rp;
} else {
free (rp);
}
*cleanup = 1;
return f;
}
JavaInteropGCBridge*
java_interop_gc_bridge_new (JavaVM *jvm)
{
if (jvm == NULL)
return NULL;
lookup_optional_mono_thread_functions ();
JavaInteropGCBridge bridge = {0};
bridge.jvm = jvm;
JNIEnv *env;
if ((*jvm)->GetEnv (jvm, (void**) &env, JNI_VERSION_1_6) != JNI_OK)
return NULL;
jobject Runtime_class = (*env)->FindClass (env, "java/lang/Runtime");
if (Runtime_class != NULL) {
bridge.Runtime_gc = (*env)->GetMethodID (env, Runtime_class, "gc", "()V");
jmethodID Runtime_getRuntime = (*env)->GetStaticMethodID (env, Runtime_class, "getRuntime", "()Ljava/lang/Runtime;");
bridge.Runtime_instance = Runtime_getRuntime
? lref_to_gref (env, (*env)->CallStaticObjectMethod (env, Runtime_class, Runtime_getRuntime))
: NULL;
(*env)->DeleteLocalRef (env, Runtime_class);
}
jobject WeakReference_class = (*env)->FindClass (env, "java/lang/ref/WeakReference");
if (WeakReference_class != NULL) {
bridge.WeakReference_init = (*env)->GetMethodID (env, WeakReference_class, "<init>", "(Ljava/lang/Object;)V");
bridge.WeakReference_get = (*env)->GetMethodID (env, WeakReference_class, "get", "()Ljava/lang/Object;");
bridge.WeakReference_class = lref_to_gref (env, WeakReference_class);
}
jobject GCUserPeerable_class = (*env)->FindClass (env, "com/xamarin/java_interop/GCUserPeerable");
if (GCUserPeerable_class) {
bridge.GCUserPeerable_add = (*env)->GetMethodID (env, GCUserPeerable_class, "jiAddManagedReference", "(Ljava/lang/Object;)V");
bridge.GCUserPeerable_clear = (*env)->GetMethodID (env, GCUserPeerable_class, "jiClearManagedReferences", "()V");
bridge.GCUserPeerable_class = lref_to_gref (env, GCUserPeerable_class);
fflush (stdout);
}
JavaInteropGCBridge *p = calloc (1, sizeof (JavaInteropGCBridge));
if (p == NULL || bridge.jvm == NULL ||
bridge.Runtime_instance == NULL || bridge.Runtime_gc == NULL ||
bridge.WeakReference_class == NULL || bridge.WeakReference_init == NULL || bridge.WeakReference_get == NULL) {
java_interop_gc_bridge_destroy (&bridge);
free (p);
return NULL;
}
*p = bridge;
p->gref_log = open_log_file (NULL, NULL, NULL, "JAVA_INTEROP_GREF_LOG", &p->gref_cleanup, &p->gref_path);
p->lref_log = open_log_file (NULL, p->gref_log, p->gref_path, "JAVA_INTEROP_LREF_LOG", &p->lref_cleanup, &p->lref_path);
return p;
}
int
java_interop_gc_bridge_free (JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return -1;
int r = java_interop_gc_bridge_destroy (bridge);
free (bridge);
return r;
}
int
java_interop_gc_bridge_enable (JavaInteropGCBridge *bridge, int enable)
{
if (!bridge)
return -1;
bridge->gc_disabled = !enable;
return 0;
}
int
java_interop_gc_bridge_set_bridge_processing_field (
JavaInteropGCBridge *bridge,
struct JavaInterop_System_RuntimeTypeHandle type_handle,
const char *field_name)
{
if (bridge == NULL || type_handle.value == NULL || field_name == NULL)
return -1;
MonoType *type = type_handle.value;
bridge->BridgeProcessing_type = mono_class_from_mono_type (type);
bridge->BridgeProcessing_field = mono_class_get_field_from_name (bridge->BridgeProcessing_type, field_name);
return 0;
}
int
java_interop_gc_bridge_register_bridgeable_type (
JavaInteropGCBridge *bridge,
struct JavaInterop_System_RuntimeTypeHandle type_handle)
{
if (bridge == NULL || type_handle.value == NULL)
return -1;
if (bridge->num_bridge_types >= NUM_GC_BRIDGE_TYPES)
return -1;
MonoType *type = type_handle.value;
int i = bridge->num_bridge_types;
MonoJavaGCBridgeInfo *info = &bridge->mono_java_gc_bridge_info [i];
info->klass = mono_class_from_mono_type (type);
info->handle = mono_class_get_field_from_name (info->klass, "handle");
info->handle_type = mono_class_get_field_from_name (info->klass, "handle_type");
info->refs_added = mono_class_get_field_from_name (info->klass, "refs_added");
info->weak_handle = mono_class_get_field_from_name (info->klass, "weak_handle");
if (info->klass == NULL || info->handle == NULL || info->handle_type == NULL ||
info->refs_added == NULL || info->weak_handle == NULL)
return -1;
bridge->num_bridge_types++;
return 0;
}
int
java_interop_gc_bridge_get_gref_count (JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return -1;
return bridge->gc_gref_count;
}
int
java_interop_gc_bridge_get_weak_gref_count (JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return -1;
return bridge->gc_weak_gref_count;
}
int
java_interop_gc_bridge_gref_set_log_file (
JavaInteropGCBridge *bridge,
const char *gref_log_file)
{
if (bridge == NULL)
return -1;
if (bridge->gref_log && bridge->gref_cleanup) {
fclose (bridge->gref_log);
}
bridge->gref_log = open_log_file (gref_log_file, bridge->lref_log, bridge->lref_path, "JAVA_INTEROP_GREF_LOG", &bridge->gref_cleanup, &bridge->gref_path);
return 0;
}
FILE*
java_interop_gc_bridge_gref_get_log_file (
JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return NULL;
return bridge->gref_log;
}
int
java_interop_gc_bridge_gref_set_log_level (
JavaInteropGCBridge *bridge,
int level)
{
if (bridge == NULL)
return -1;
bridge->gref_log_level = level;
return 0;
}
void
java_interop_gc_bridge_gref_log_message (
JavaInteropGCBridge *bridge,
int level,
const char *message)
{
if (!bridge || !bridge->gref_log || bridge->gref_log_level < level)
return;
fprintf (bridge->gref_log, "%s", message);
fflush (bridge->gref_log);
}
int
java_interop_gc_bridge_lref_set_log_file (
JavaInteropGCBridge *bridge,
const char *lref_log_file)
{
if (bridge == NULL)
return -1;
if (bridge->lref_log && bridge->lref_cleanup) {
fclose (bridge->lref_log);
}
bridge->lref_log = open_log_file (lref_log_file, bridge->gref_log, bridge->gref_path, "JAVA_INTEROP_LREF_LOG", &bridge->lref_cleanup, &bridge->lref_path);
return 0;
}
FILE*
java_interop_gc_bridge_lref_get_log_file (
JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return NULL;
return bridge->lref_log;
}
int
java_interop_gc_bridge_lref_set_log_level (
JavaInteropGCBridge *bridge,
int level)
{
if (bridge == NULL)
return -1;
bridge->lref_log_level = level;
return 0;
}
void
java_interop_gc_bridge_lref_log_message (
JavaInteropGCBridge *bridge,
int level,
const char *message)
{
if (!bridge || !bridge->lref_log || bridge->lref_log_level < level)
return;
fprintf (bridge->lref_log, "%s", message);
fflush (bridge->lref_log);
}
static void
log_gref (JavaInteropGCBridge *bridge, const char *format, ...)
{
va_list args;
if (!bridge->gref_log)
return;
va_start (args, format);
vfprintf (bridge->gref_log, format, args);
fflush (bridge->gref_log);
va_end (args);
}
static char
get_object_ref_type (JNIEnv *env, void *handle)
{
jobjectRefType value;
if (handle == NULL)
return 'I';
value = (*env)->GetObjectRefType (env, handle);
switch (value) {
case JNIInvalidRefType: return 'I';
case JNILocalRefType: return 'L';
case JNIGlobalRefType: return 'G';
case JNIWeakGlobalRefType: return 'W';
default: return '*';
}
}
static int
gref_inc (JavaInteropGCBridge *bridge)
{
return __sync_add_and_fetch (&bridge->gc_gref_count, 1);
}
static int
gref_dec (JavaInteropGCBridge *bridge)
{
return __sync_sub_and_fetch (&bridge->gc_gref_count, 1);
}
#if defined (ANDROID)
#define WRITE_ANDROID_MESSAGE_RETURN(ret, category, format, ...) do { \
if ((log_categories & category) == 0) \
return ret; \
log_info (category, format, __VA_ARGS__); \
} while (0)
#else /* ndef ANDROID */
#define WRITE_ANDROID_MESSAGE_RETURN(ret, category, format, ...) do { \
} while (0)
#endif /* ndef ANDROID */
#define WRITE_LOG_MESSAGE_RETURN(ret, category, to, from, format, ...) do { \
WRITE_ANDROID_MESSAGE_RETURN(ret, category, format, __VA_ARGS__); \
if (!to) \
return ret; \
fprintf (to, format "\n", __VA_ARGS__); \
fprintf (to, "%s\n", from); \
fflush (to); \
} while (0)
int
java_interop_gc_bridge_gref_log_new (
JavaInteropGCBridge *bridge,
jobject curHandle,
char curType,
jobject newHandle,
char newType,
const char *thread_name,
int64_t thread_id,
const char *from)
{
if (!bridge)
return -1;
int c = gref_inc (bridge);
WRITE_LOG_MESSAGE_RETURN(c, LOG_GREF, bridge->gref_log, from,
"+g+ grefc %i gwrefc %i obj-handle %p/%c -> new-handle %p/%c from thread '%s'(%" PRId64 ")",
c,
bridge->gc_weak_gref_count,
curHandle,
curType,
newHandle,
newType,
thread_name,
thread_id);
return c;
}
int
java_interop_gc_bridge_gref_log_delete (
JavaInteropGCBridge *bridge,
jobject handle,
char type,
const char *thread_name,
int64_t thread_id,
const char *from)
{
if (!bridge)
return -1;
int c = gref_dec (bridge);
WRITE_LOG_MESSAGE_RETURN(c, LOG_GREF, bridge->gref_log, from,
"-g- grefc %i gwrefc %i handle %p/%c from thread '%s'(%" PRId64 ")",
c,
bridge->gc_weak_gref_count,
handle,
type,
thread_name,
thread_id);
return c;
}
void
java_interop_gc_bridge_lref_log_new (
JavaInteropGCBridge *bridge,
int lref_count,
jobject curHandle,
char curType,
jobject newHandle,
char newType,
const char *thread_name,
int64_t thread_id,
const char *from)
{
if (!bridge)
return;
if (newHandle) {
WRITE_LOG_MESSAGE_RETURN(, LOG_LREF, bridge->lref_log, from,
"+l+ lrefc %i obj-handle %p/%c -> new-handle %p/%c from thread '%s'(%" PRId64 ")",
lref_count,
curHandle,
curType,
newHandle,
newType,
thread_name,
thread_id);
}
else {
WRITE_LOG_MESSAGE_RETURN(, LOG_LREF, bridge->lref_log, from,
"+l+ lrefc %i handle %p/%c from thread '%s'(%" PRId64 ")",
lref_count,
curHandle,
curType,
thread_name,
thread_id);
}
}
void
java_interop_gc_bridge_lref_log_delete (
JavaInteropGCBridge *bridge,
int lref_count,
jobject handle,
char type,
const char *thread_name,
int64_t thread_id,
const char *from)
{
if (!bridge)
return;
WRITE_LOG_MESSAGE_RETURN(, LOG_LREF, bridge->lref_log, from,
"-l- lrefc %i handle %p/%c from thread '%s'(%" PRId64 ")",
lref_count,
handle,
type,
thread_name,
thread_id);
}
int
java_interop_gc_bridge_weak_gref_log_new (
JavaInteropGCBridge *bridge,
jobject curHandle,
char curType,
jobject newHandle,
char newType,
const char *thread_name,
int64_t thread_id,
const char *from)
{
if (!bridge)
return -1;
int c = ++bridge->gc_weak_gref_count;
WRITE_LOG_MESSAGE_RETURN(c, LOG_GREF, bridge->gref_log, from,
"+w+ grefc %i gwrefc %i obj-handle %p/%c -> new-handle %p/%c from thread '%s'(%" PRId64 ")",
bridge->gc_gref_count,
bridge->gc_weak_gref_count,
curHandle,
curType,
newHandle,
newType,
thread_name,
thread_id);
return c;
}
int
java_interop_gc_bridge_weak_gref_log_delete (
JavaInteropGCBridge *bridge,
jobject handle,
char type,
const char *thread_name,
int64_t thread_id,
const char *from)
{
if (!bridge)
return -1;
int c = bridge->gc_weak_gref_count--;
WRITE_LOG_MESSAGE_RETURN(c, LOG_GREF, bridge->gref_log, from,
"-w- grefc %i gwrefc %i handle %p/%c from thread '%s'(%" PRId64 ")",
bridge->gc_gref_count,
bridge->gc_weak_gref_count,
handle,
type,
thread_name,
thread_id);
return c;
}
static int
get_gc_bridge_index (JavaInteropGCBridge *bridge, MonoClass *klass)
{
int i;
int f = 0;
for (i = 0; i < NUM_GC_BRIDGE_TYPES; ++i) {
MonoClass *k = bridge->mono_java_gc_bridge_info [i].klass;
if (k == NULL) {
f++;
continue;
}
if (klass == k || mono_class_is_subclass_of (klass, k, 0))
return i;
}
return f == NUM_GC_BRIDGE_TYPES
? (int) -NUM_GC_BRIDGE_TYPES
: -1;
}
static MonoJavaGCBridgeInfo *
get_gc_bridge_info_for_class (JavaInteropGCBridge *bridge, MonoClass *klass)
{
int i;
if (klass == NULL)
return NULL;
i = get_gc_bridge_index (bridge, klass);
if (i < 0)
return NULL;
return &bridge->mono_java_gc_bridge_info [i];
}
static MonoJavaGCBridgeInfo *
get_gc_bridge_info_for_object (JavaInteropGCBridge *bridge, MonoObject *object)
{
if (object == NULL)
return NULL;
return get_gc_bridge_info_for_class (bridge, mono_object_get_class (object));
}
typedef mono_bool (*MonodroidGCTakeRefFunc) (JavaInteropGCBridge *bridge, JNIEnv *env, MonoObject *obj, const char *thread_name, int64_t thread_id);
static MonodroidGCTakeRefFunc take_global_ref;
static MonodroidGCTakeRefFunc take_weak_global_ref;
static mono_bool
take_global_ref_java (JavaInteropGCBridge *bridge, JNIEnv *env, MonoObject *obj, const char *thread_name, int64_t thread_id)
{
MonoJavaGCBridgeInfo *bridge_info = get_gc_bridge_info_for_object (bridge, obj);
if (bridge_info == NULL)
return 0;
void *weak;
mono_field_get_value (obj, bridge_info->weak_handle, &weak);
void *handle = (*env)->CallObjectMethod (env, weak, bridge->WeakReference_get);
log_gref (bridge, "*try_take_global_2_1 obj=%p -> wref=%p handle=%p\n", obj, weak, handle);
if (handle) {
void *h = (*env)->NewGlobalRef (env, handle);
(*env)->DeleteLocalRef (env, handle);
handle = h;
java_interop_gc_bridge_gref_log_new (bridge, weak, get_object_ref_type (env, weak),
handle, get_object_ref_type (env, handle), thread_name, thread_id, "take_global_ref_java");
}
java_interop_gc_bridge_weak_gref_log_delete (bridge, weak, get_object_ref_type (env, weak), thread_name, thread_id, "take_global_ref_java");
(*env)->DeleteGlobalRef (env, weak);
weak = NULL;
mono_field_set_value (obj, bridge_info->weak_handle, &weak);
mono_field_set_value (obj, bridge_info->handle, &handle);
int type = JNIGlobalRefType;
mono_field_set_value (obj, bridge_info->handle_type, &type);
return handle != NULL;
}
static mono_bool
take_weak_global_ref_java (JavaInteropGCBridge *bridge, JNIEnv *env, MonoObject *obj, const char *thread_name, int64_t thread_id)
{
MonoJavaGCBridgeInfo *bridge_info = get_gc_bridge_info_for_object (bridge, obj);
if (bridge_info == NULL)
return 0;
void *handle;
mono_field_get_value (obj, bridge_info->handle, &handle);
jobject weaklocal = (*env)->NewObject (env, bridge->WeakReference_class, bridge->WeakReference_init, handle);
void *weakglobal = (*env)->NewGlobalRef (env, weaklocal);
(*env)->DeleteLocalRef (env, weaklocal);
log_gref (bridge, "*take_weak_2_1 obj=%p -> wref=%p handle=%p\n", obj, weakglobal, handle);
java_interop_gc_bridge_weak_gref_log_new (bridge, handle, get_object_ref_type (env, handle),
weakglobal, get_object_ref_type (env, weakglobal), thread_name, thread_id, "take_weak_global_ref_2_1_compat");
java_interop_gc_bridge_gref_log_delete (bridge, handle, get_object_ref_type (env, handle), thread_name, thread_id, "take_weak_global_ref_2_1_compat");
(*env)->DeleteGlobalRef (env, handle);
mono_field_set_value (obj, bridge_info->weak_handle, &weakglobal);
return 1;
}
static mono_bool
take_global_ref_jni (JavaInteropGCBridge *bridge, JNIEnv *env, MonoObject *obj, const char *thread_name, int64_t thread_id)
{
MonoJavaGCBridgeInfo *bridge_info = get_gc_bridge_info_for_object (bridge, obj);
if (bridge_info == NULL)
return 0;
void *weak;
mono_field_get_value (obj, bridge_info->handle, &weak);
void *handle = (*env)->NewGlobalRef (env, weak);
log_gref (bridge, "*try_take_global obj=%p -> wref=%p handle=%p\n", obj, weak, handle);
if (handle) {
java_interop_gc_bridge_gref_log_new (bridge, weak, get_object_ref_type (env, weak),
handle, get_object_ref_type (env, handle),
thread_name, thread_id,
"take_global_ref_jni");
}
java_interop_gc_bridge_weak_gref_log_delete (bridge, weak, 'W',
thread_name, thread_id, "take_global_ref_jni");
(*env)->DeleteWeakGlobalRef (env, weak);
mono_field_set_value (obj, bridge_info->handle, &handle);
int type = JNIGlobalRefType;
mono_field_set_value (obj, bridge_info->handle_type, &type);
return handle != NULL;
}
static mono_bool
take_weak_global_ref_jni (JavaInteropGCBridge *bridge, JNIEnv *env, MonoObject *obj, const char *thread_name, int64_t thread_id)
{
MonoJavaGCBridgeInfo *bridge_info = get_gc_bridge_info_for_object (bridge, obj);
if (bridge_info == NULL)
return 0;
void *handle;
mono_field_get_value (obj, bridge_info->handle, &handle);
log_gref (bridge, "*take_weak obj=%p; handle=%p\n", obj, handle);
void *weak = (*env)->NewWeakGlobalRef (env, handle);
java_interop_gc_bridge_weak_gref_log_new (bridge, handle, get_object_ref_type (env, handle),
weak, get_object_ref_type (env, weak),
thread_name, thread_id, "take_weak_global_ref_jni");
java_interop_gc_bridge_gref_log_delete (bridge, handle, get_object_ref_type (env, handle),
thread_name, thread_id, "take_weak_global_ref_jni");
(*env)->DeleteGlobalRef (env, handle);
mono_field_set_value (obj, bridge_info->handle, &weak);
int type = JNIWeakGlobalRefType;
mono_field_set_value (obj, bridge_info->handle_type, &type);
return 1;
}
static jmethodID
get_add_reference_method (JavaInteropGCBridge *bridge, JNIEnv *env, jobject obj, MonoClass *mclass)
{
if (!obj)
return NULL;
if (bridge->GCUserPeerable_class && (*env)->IsInstanceOf (env, obj, bridge->GCUserPeerable_class)) {
return bridge->GCUserPeerable_add;
}
jclass klass = (*env)->GetObjectClass (env, obj);
jmethodID add = (*env)->GetMethodID (env, klass, "monodroidAddReference", "(Ljava/lang/Object;)V");
if (!add)
(*env)->ExceptionClear (env);
(*env)->DeleteLocalRef (env, klass);
return add;
}
static mono_bool
add_reference (JavaInteropGCBridge *bridge, JNIEnv *env, MonoObject *obj, MonoJavaGCBridgeInfo *bridge_info, MonoObject *reffed_obj)
{
MonoClass *klass = mono_object_get_class (obj);
void *handle;
mono_field_get_value (obj, bridge_info->handle, &handle);
jmethodID add_method_id = get_add_reference_method (bridge, env, handle, klass);
if (add_method_id) {
void *reffed_handle;
mono_field_get_value (reffed_obj, bridge_info->handle, &reffed_handle);
(*env)->CallVoidMethod (env, handle, add_method_id, reffed_handle);
#if DEBUG
if (bridge->gref_log_level > 1)
log_gref (bridge,
"added reference for object of class %s.%s to object of class %s.%s\n",
mono_class_get_namespace (klass),
mono_class_get_name (klass),
mono_class_get_namespace (mono_object_get_class (reffed_obj)),
mono_class_get_name (mono_object_get_class (reffed_obj)));
#endif
return 1;
}
#if DEBUG
if (bridge->gref_log_level > 1)
log_gref (bridge,
"Missing monodroidAddReference method for object of class %s.%s\n",
mono_class_get_namespace (klass),
mono_class_get_name (klass));
#endif
return 0;
}
static void
set_bridge_processing (JavaInteropGCBridge *bridge, mono_bool value)
{
int count = bridge->BridgeProcessing_vtables_count;
for (int i = 0; i < count; ++i) {
MonoVTable *v = bridge->BridgeProcessing_vtables [i];
if (!v) {
continue;
}
mono_field_static_set_value (v, bridge->BridgeProcessing_field, &value);
}
}
static void
gc_prepare_for_java_collection (JavaInteropGCBridge *bridge, JNIEnv *env, int num_sccs, MonoGCBridgeSCC **sccs, int num_xrefs, MonoGCBridgeXRef *xrefs, const char *thread_name, int64_t thread_id)
{
set_bridge_processing (bridge, 1);
int ref_val = 1;
/* add java refs for items on the list which reference each other */
for (int i = 0; i < num_sccs; i++) {
MonoGCBridgeSCC *scc = sccs [i];
MonoJavaGCBridgeInfo *bridge_info = NULL;
/* start at the second item, ref j from j-1 */
for (int j = 1; j < scc->num_objs; j++) {
bridge_info = get_gc_bridge_info_for_object (bridge, scc->objs [j-1]);
if (bridge_info != NULL && add_reference (bridge, env, scc->objs [j-1], bridge_info, scc->objs [j])) {
mono_field_set_value (scc->objs [j-1], bridge_info->refs_added, &ref_val);
}
}
/* ref the first from the last */
if (scc->num_objs > 1) {
bridge_info = get_gc_bridge_info_for_object (bridge, scc->objs [scc->num_objs-1]);
if (bridge_info != NULL && add_reference (bridge, env, scc->objs [scc->num_objs-1], bridge_info, scc->objs [0])) {
mono_field_set_value (scc->objs [scc->num_objs-1], bridge_info->refs_added, &ref_val);
}
}
}
/* add the cross scc refs */
for (int i = 0; i < num_xrefs; i++) {
MonoJavaGCBridgeInfo *bridge_info = get_gc_bridge_info_for_object (bridge, sccs [xrefs [i].src_scc_index]->objs [0]);
if (bridge_info != NULL && add_reference (bridge, env, sccs [xrefs [i].src_scc_index]->objs [0], bridge_info, sccs [xrefs [i].dst_scc_index]->objs [0])) {
mono_field_set_value (sccs [xrefs [i].src_scc_index]->objs [0], bridge_info->refs_added, &ref_val);
}
}
// switch to weak refs
for (int i = 0; i < num_sccs; i++)
for (int j = 0; j < sccs [i]->num_objs; j++)
take_weak_global_ref (bridge, env, sccs [i]->objs [j], thread_name, thread_id);
}
static jmethodID
get_clear_references_method (JavaInteropGCBridge *bridge, JNIEnv *env, jobject obj)
{
if (!obj)
return NULL;
if (bridge->GCUserPeerable_class && (*env)->IsInstanceOf (env, obj, bridge->GCUserPeerable_class)) {
return bridge->GCUserPeerable_clear;
}
jclass klass = (*env)->GetObjectClass (env, obj);
jmethodID clear = (*env)->GetMethodID (env, klass, "monodroidClearReferences", "()V");
if (!clear)
(*env)->ExceptionClear (env);
(*env)->DeleteLocalRef (env, klass);
return clear;
}
static void
gc_cleanup_after_java_collection (JavaInteropGCBridge *bridge, JNIEnv *env, int num_sccs, MonoGCBridgeSCC **sccs, const char *thread_name, int64_t thread_id)
{
int total = 0;
int alive = 0;
for (int i = 0; i < num_sccs; i++)
for (int j = 0; j < sccs [i]->num_objs; j++, total++)
take_global_ref (bridge, env, sccs [i]->objs [j], thread_name, thread_id);
/* clear the cross references on any remaining items */
for (int i = 0; i < num_sccs; i++) {
sccs [i]->is_alive = 0;
for (int j = 0; j < sccs [i]->num_objs; j++) {
MonoObject *obj = sccs [i]->objs [j];
MonoJavaGCBridgeInfo *bridge_info = get_gc_bridge_info_for_object (bridge, obj);
if (bridge_info == NULL)
continue;
jobject jref;
mono_field_get_value (obj, bridge_info->handle, &jref);
if (jref) {
alive++;
if (j > 0)
assert (sccs [i]->is_alive);
sccs [i]->is_alive = 1;
int refs_added;
mono_field_get_value (obj, bridge_info->refs_added, &refs_added);
if (refs_added) {
jmethodID clear_method_id = get_clear_references_method (bridge, env, jref);
if (clear_method_id) {
(*env)->CallVoidMethod (env, jref, clear_method_id);
} else {
#if DEBUG
if (bridge->gref_log_level > 1) {
MonoClass *klass = mono_object_get_class (obj);
log_gref (bridge,
"Missing monodroidClearReferences method for object of class %s.%s\n",
mono_class_get_namespace (klass),
mono_class_get_name (klass));
}
#endif
}
}
} else {
assert (!sccs [i]->is_alive);
}
}
}
#if DEBUG
log_gref (bridge, "GC cleanup summary: %d objects tested - resurrecting %d.\n", total, alive);
#endif
set_bridge_processing (bridge, 0);
}
static void
java_gc (JavaInteropGCBridge *bridge, JNIEnv *env)
{
(*env)->CallVoidMethod (env, bridge->Runtime_instance, bridge->Runtime_gc);
}
int
java_interop_gc_bridge_add_current_app_domain (JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return -1;
if (bridge->BridgeProcessing_type == NULL)
return -1;
MonoDomain *domain = mono_domain_get ();
if (domain == NULL)
return -1;
int count = bridge->BridgeProcessing_vtables_count;
for (int i = 0; i < count; ++i) {
MonoDomain **domains = bridge->BridgeProcessing_domains;
MonoVTable **vtables = bridge->BridgeProcessing_vtables;
if (domains [i] == NULL) {
domains [i] = domain;
vtables [i] = mono_class_vtable (domain, bridge->BridgeProcessing_type);
return 0;
}
}
if (bridge->BridgeProcessing_vtables_count == bridge->BridgeProcessing_vtables_length) {
int new_length = bridge->BridgeProcessing_vtables_length + 1;
MonoDomain **new_domains = calloc (new_length, sizeof (MonoDomain*));
MonoVTable **new_vtbles = calloc (new_length, sizeof (MonoVTable*));
if (new_domains == NULL || new_vtbles == NULL) {
free (new_domains);
free (new_vtbles);
return -1;
}
bridge->BridgeProcessing_vtables_length = new_length;
memcpy (new_domains, bridge->BridgeProcessing_domains, bridge->BridgeProcessing_vtables_count);
memcpy (new_vtbles, bridge->BridgeProcessing_vtables, bridge->BridgeProcessing_vtables_count);
free (bridge->BridgeProcessing_domains);
free (bridge->BridgeProcessing_vtables);
bridge->BridgeProcessing_domains = new_domains;
bridge->BridgeProcessing_vtables = new_vtbles;
}
int i = bridge->BridgeProcessing_vtables_count++;
bridge->BridgeProcessing_domains [i] = domain;
bridge->BridgeProcessing_vtables [i] = mono_class_vtable (domain, bridge->BridgeProcessing_type);
return 0;
}
int
java_interop_gc_bridge_remove_current_app_domain (JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return -1;
MonoDomain *domain = mono_domain_get ();
if (domain == NULL)
return -1;
int count = bridge->BridgeProcessing_vtables_count;
for (int i = 0; i < count; ++i) {
if (bridge->BridgeProcessing_domains [i] == domain) {
bridge->BridgeProcessing_domains [i] = NULL;
bridge->BridgeProcessing_vtables [i] = NULL;
return 0;
}
}
return -1;
}
static JavaInteropGCBridge *mono_bridge;
JavaInteropGCBridge*
java_interop_gc_bridge_get_current (void)
{
return mono_bridge;
}
int
java_interop_gc_bridge_set_current_once (JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return -1;
mono_bridge = bridge;
return 0;
}
static MonoGCBridgeObjectKind
gc_bridge_class_kind (MonoClass *klass)
{
int i;
if (mono_bridge->gc_disabled)
return GC_BRIDGE_TRANSPARENT_CLASS;
i = get_gc_bridge_index (mono_bridge, klass);
if (i == -NUM_GC_BRIDGE_TYPES) {
log_gref (mono_bridge,
"asked if a class %s.%s is a bridge before we inited GC Bridge Types!\n",
mono_class_get_namespace (klass),
mono_class_get_name (klass));
return GC_BRIDGE_TRANSPARENT_CLASS;
}
if (i >= 0) {
return GC_BRIDGE_TRANSPARENT_BRIDGE_CLASS;
}
return GC_BRIDGE_TRANSPARENT_CLASS;
}
static mono_bool
gc_is_bridge_object (MonoObject *object)
{
void *handle;
MonoJavaGCBridgeInfo *bridge_info = get_gc_bridge_info_for_object (mono_bridge, object);
if (bridge_info == NULL)
return 0;
mono_field_get_value (object, bridge_info->handle, &handle);
if (handle == NULL) {
#if DEBUG
MonoClass *mclass = mono_object_get_class (object);
log_gref (mono_bridge,
"object of class %s.%s with null handle\n",
mono_class_get_namespace (mclass),
mono_class_get_name (mclass));
#endif
return 0;
}
return 1;
}
static char *
get_thread_name (void)
{
if (_mono_thread_get_name_utf8) {
MonoThread *thread = mono_thread_current ();
return _mono_thread_get_name_utf8 (thread);
}
return strdup ("finalizer");
}
static int64_t
get_thread_id (void)
{
if (_mono_thread_get_managed_id) {
MonoThread *thread = mono_thread_current ();
return _mono_thread_get_managed_id (thread);
}
#if __linux__
int64_t tid = gettid ();
#else
int64_t tid = (int64_t) pthread_self ();
#endif
return tid;
}
static void
gc_cross_references (int num_sccs, MonoGCBridgeSCC **sccs, int num_xrefs, MonoGCBridgeXRef *xrefs)
{
if (mono_bridge->gc_disabled)
return;
JavaInteropGCBridge *bridge = mono_bridge;
char *thread_name = get_thread_name ();
int64_t thread_id = get_thread_id ();
#if DEBUG
if (bridge->gref_log_level > 1) {
log_gref (bridge, "cross references callback invoked with %d sccs and %d xrefs.\n", num_sccs, num_xrefs);
for (int i = 0; i < num_sccs; ++i) {
log_gref (bridge, "group %d with %d objects\n", i, sccs [i]->num_objs);
for (int j = 0; j < sccs [i]->num_objs; ++j) {
MonoObject *obj = sccs [i]->objs [j];
MonoClass *klass = mono_object_get_class (obj);
log_gref (bridge,
"\tobj %p [%s::%s]\n",
obj,
mono_class_get_namespace (klass),
mono_class_get_name (klass));
}
}
for (int i = 0; i < num_xrefs; ++i)
log_gref (bridge, "xref [%d] %d -> %d\n", i, xrefs [i].src_scc_index, xrefs [i].dst_scc_index);
}
#endif
JNIEnv *env = ensure_jnienv (bridge);
if (env != NULL) {
gc_prepare_for_java_collection (bridge, env, num_sccs, sccs, num_xrefs, xrefs, thread_name, thread_id);
java_gc (bridge, env);
gc_cleanup_after_java_collection (bridge, env, num_sccs, sccs, thread_name, thread_id);
}
free (thread_name);
}
int
java_interop_gc_bridge_register_hooks (JavaInteropGCBridge *bridge, int weak_ref_kind)
{
if (bridge == NULL)
return -1;
if (mono_bridge != bridge)
return -1;
const char *message = NULL;
MonoGCBridgeCallbacks bridge_cbs = {0};
switch (weak_ref_kind) {
case JAVA_INTEROP_GC_BRIDGE_USE_WEAK_REFERENCE_KIND_JAVA:
message = "Using java.lang.ref.WeakReference for JNI Weak References.";
take_global_ref = take_global_ref_java;
take_weak_global_ref = take_weak_global_ref_java;
break;
case JAVA_INTEROP_GC_BRIDGE_USE_WEAK_REFERENCE_KIND_JNI:
message = "Using JNIEnv::NewWeakGlobalRef() for JNI Weak References.";
take_global_ref = take_global_ref_jni;
take_weak_global_ref = take_weak_global_ref_jni;
break;
default:
return -1;
}
log_gref (mono_bridge, "%s\n", message);
bridge_cbs.bridge_version = SGEN_BRIDGE_VERSION;
bridge_cbs.bridge_class_kind = gc_bridge_class_kind;
bridge_cbs.is_bridge_object = gc_is_bridge_object;
bridge_cbs.cross_references = gc_cross_references;
mono_gc_register_bridge_callbacks (&bridge_cbs);
return 0;
}
int
java_interop_gc_bridge_wait_for_bridge_processing (JavaInteropGCBridge *bridge)
{
if (bridge == NULL)
return -1;
mono_gc_wait_for_bridge_processing ();
return 0;
}
|
pjcollins/java.interop | src/java-interop/java-interop.c | <gh_stars>0
#include <stdlib.h>
#include <string.h>
#include "java-interop.h"
char*
java_interop_strdup (const char* value)
{
return strdup (value);
}
void
java_interop_free (void *p)
{
free (p);
}
|
pjcollins/java.interop | src/java-interop/java-interop.h | #ifndef INC_JAVA_INTEROP_H
#define INC_JAVA_INTEROP_H
#include <stdint.h>
#if defined(_MSC_VER)
#define MONO_API_EXPORT __declspec(dllexport)
#define MONO_API_IMPORT __declspec(dllimport)
#else /* defined(_MSC_VER */
#ifdef __GNUC__
#define MONO_API_EXPORT __attribute__ ((visibility ("default")))
#else
#define MONO_API_EXPORT
#endif
#define MONO_API_IMPORT
#endif /* !defined(_MSC_VER) */
#if defined(MONO_DLL_EXPORT)
#define MONO_API MONO_API_EXPORT
#elif defined(MONO_DLL_IMPORT)
#define MONO_API MONO_API_IMPORT
#else /* !defined(MONO_DLL_IMPORT) && !defined(MONO_API_IMPORT) */
#define MONO_API
#endif /* MONO_DLL_EXPORT... */
#ifdef __cplusplus
#define JAVA_INTEROP_BEGIN_DECLS extern "C" {
#define JAVA_INTEROP_END_DECLS }
#else /* ndef __cplusplus */
#define JAVA_INTEROP_BEGIN_DECLS
#define JAVA_INTEROP_END_DECLS
#endif /* ndef __cplusplus */
JAVA_INTEROP_BEGIN_DECLS
MONO_API char *java_interop_strdup (const char* value);
MONO_API void java_interop_free (void *p);
JAVA_INTEROP_END_DECLS
#endif /* ndef INC_JAVA_INTEROP_H */
|
pjcollins/java.interop | src/java-interop/java-interop-mono.h | #ifndef INC_JAVA_INTEROP_MONO_H
#define INC_JAVA_INTEROP_MONO_H
#include "java-interop.h"
#if defined (ANDROID)
#include "dylib-mono.h"
#include "monodroid-glue.h"
#define mono_class_from_mono_type (mono.mono_class_from_mono_type)
#define mono_class_from_name (mono.mono_class_from_name)
#define mono_class_get_field_from_name (mono.mono_class_get_field_from_name)
#define mono_class_get_name (mono.mono_class_get_name)
#define mono_class_get_namespace (mono.mono_class_get_namespace)
#define mono_class_is_subclass_of (mono.mono_class_is_subclass_of)
#define mono_class_vtable (mono.mono_class_vtable)
#define mono_domain_get (mono.mono_domain_get)
#define mono_field_get_value (mono.mono_field_get_value)
#define mono_field_set_value (mono.mono_field_set_value)
#define mono_field_static_set_value (mono.mono_field_static_set_value)
#define mono_object_get_class (mono.mono_object_get_class)
#define mono_thread_attach (mono.mono_thread_attach)
#define mono_thread_current (mono.mono_thread_current)
#define mono_gc_register_bridge_callbacks (mono.mono_gc_register_bridge_callbacks)
#define mono_gc_wait_for_bridge_processing (mono.mono_gc_wait_for_bridge_processing)
#else /* !defined (ANDROID) */
#include <mono/metadata/assembly.h>
#include <mono/metadata/class.h>
#include <mono/metadata/object.h>
#include <mono/metadata/sgen-bridge.h>
#include <mono/metadata/threads.h>
#include <mono/utils/mono-counters.h>
#include <mono/utils/mono-dl-fallback.h>
#endif /* !defined (ANDROID) */
JAVA_INTEROP_BEGIN_DECLS
JAVA_INTEROP_END_DECLS
#endif /* ndef INC_JAVA_INTEROP_MONO_H */
|
pjcollins/java.interop | src/java-interop/java-interop-mono.c | #include "java-interop-mono.h"
|
dayananth/TwitterClient | TwitterClient/MessageComposeController.h | //
// MessageComposeController.h
// TwitterClient
//
// Created by <NAME> on 11/8/15.
// Copyright © 2015 <NAME>. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Tweet.h"
@class MessageComposeController;
@protocol MessageComposeControllerDelegate <NSObject>
-(void) MessageComposeController: (MessageComposeController *) MessageComposeController didPostMessage:(Tweet*) tweet;
@end
@interface MessageComposeController : UIViewController
@property (nonatomic, weak) id<MessageComposeControllerDelegate> delegate;
@property (strong, nonatomic) Tweet *inReplyToTweet;
@end
|
dayananth/TwitterClient | TwitterClient/TwitterClient.h | <gh_stars>0
//
// TwitterClient.h
// TwitterClient
//
// Created by <NAME> on 11/4/15.
// Copyright © 2015 <NAME>. All rights reserved.
//
#import <BDBOAuth1Manager/BDBOAuth1RequestOperationManager.h>
#import "Tweet.h"
#import "User.h"
@interface TwitterClient : BDBOAuth1RequestOperationManager
+ (TwitterClient *)sharedInstance;
-(void)loginWithCompletion:(void (^) (User *user, NSError *error))completion;
-(void) openURL:(NSURL* )url;
-(void) homeTimeLineWithParams: (NSDictionary *) params completion:(void (^) (NSArray *tweets, NSError *error)) completion;
-(void) sendTweet: (NSDictionary *) params completion:(void (^) (Tweet *tweet, NSError *error)) completion;
-(void) retweet: (NSNumber *) tweetID completion:(void (^) (Tweet *tweet, NSError *error)) completion;
-(void) favourite: (NSNumber *) tweetID completion:(void (^) (Tweet *tweet, NSError *error)) completion;
@end
|
dayananth/TwitterClient | TwitterClient/LoginViewController.h | //
// LoginViewController.h
// TwitterClient
//
// Created by <NAME> on 11/4/15.
// Copyright © 2015 <NAME>. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController
@end
|
dayananth/TwitterClient | Tweet.h | //
// Tweet.h
// TwitterClient
//
// Created by <NAME> on 11/5/15.
// Copyright © 2015 <NAME>. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "User.h"
@interface Tweet : NSObject
@property (nonatomic, strong) NSNumber *twetID;
@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) NSDate *createdAt;
@property (nonatomic, strong) NSString *formattedDate;
@property (nonatomic, strong) User *user;
@property long noOfReTweets;
@property long noOfLikes;
@property long inReplyTo;
-(id) initWithDictionary: (NSDictionary *)dictionary;
+(NSArray *) tweetsWithArray: (NSArray *) tweetsArray;
@end
|
dayananth/TwitterClient | TwitterClient/TweetDetailViewController.h | <gh_stars>1-10
//
// TweetDetailViewController.h
// TwitterClient
//
// Created by <NAME> on 11/8/15.
// Copyright © 2015 <NAME>. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Tweet.h"
@class TweetDetailViewController;
@protocol TweetDetailViewControllerDelegate <NSObject>
-(void) TweetDetailViewController: (TweetDetailViewController *) TweetDetailViewController didReply:(Tweet*) tweet;
@end
@interface TweetDetailViewController : UIViewController
@property (nonatomic, strong) Tweet *tweet;
@property (nonatomic, weak) id<TweetDetailViewControllerDelegate> delegate;
-(id) initWithTweet: (Tweet *) tweet;
- (IBAction)onReply:(id)sender;
- (IBAction)onRetweet:(id)sender;
- (IBAction)onLike:(id)sender;
@end
|
dayananth/TwitterClient | User.h | <filename>User.h
//
// User.h
// TwitterClient
//
// Created by <NAME> on 11/5/15.
// Copyright © 2015 <NAME>. All rights reserved.
//
#import <Foundation/Foundation.h>
extern NSString * const UserDidLoginNotification;
extern NSString * const UserDidLogoutNotification;
@interface User : NSObject
-(id) initWithDictionary: (NSDictionary *)dictionary;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *screenName;
@property (nonatomic, strong) NSString *profileImageUrl;
@property (nonatomic, strong) NSString *tagLine;
+ (User *)currentUser;
+ (void)setCurrentUser: (User *) user;
+ (void) logout;
@end
|
dayananth/TwitterClient | TwitterClient/TweetsViewController.h | //
// TweetsViewController.h
// TwitterClient
//
// Created by <NAME> on 11/6/15.
// Copyright © 2015 <NAME>. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TweetsViewController : UIViewController
@end
|
dayananth/TwitterClient | TwitterClient/TweetCell.h | <reponame>dayananth/TwitterClient<filename>TwitterClient/TweetCell.h
//
// TweetCell.h
// TwitterClient
//
// Created by <NAME> on 11/7/15.
// Copyright © 2015 <NAME>. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Tweet.h"
@interface TweetCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *profileImageView;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *TweetLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeStampLabel;
@property (nonatomic, strong) Tweet *tweet;
-(void) setTweet: (Tweet *) tweet;
@end
|
tinyos-io/tinyos-3.x-contrib | uob/tossdr/tos/lib/tossdr/sim_tossdr.c | <reponame>tinyos-io/tinyos-3.x-contrib<filename>uob/tossdr/tos/lib/tossdr/sim_tossdr.c
/*
* "Copyright (c) 2005 Stanford University. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the following two paragraphs and the author appear in all
* copies of this software.
*
* IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY
* HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
* Implementation of all of the basic TOSSDR primitives and utility
* functions.
*
* @author <NAME>
* @date Nov 22 2005
*/
// $Id: sim_tossdr.c,v 1.3 2010/03/26 15:17:01 mab-cn Exp $
#include <sim_tossdr.h>
#include <sim_event_queue.h>
#include <sim_mote.h>
#include <stdlib.h>
#include <sys/time.h>
static sim_time_t sim_ticks;
static unsigned long current_node;
static int sim_seed;
static int __nesc_nido_resolve(int mote, char* varname, uintptr_t* addr, size_t* size);
void sim_init() __attribute__ ((C, spontaneous)) {
sim_queue_init();
sim_log_init();
sim_log_commit_change();
{
struct timeval tv;
gettimeofday(&tv, NULL);
// Need to make sure we don't pass zero to seed simulation.
// But in case some weird timing factor causes usec to always
// be zero, default to tv_sec. Note that the explicit
// seeding call also has a check for zero. Thanks to Konrad
// Iwanicki for finding this. -pal
if (tv.tv_usec != 0) {
sim_random_seed(tv.tv_usec);
}
else {
sim_random_seed(tv.tv_sec);
}
}
}
void sim_end() __attribute__ ((C, spontaneous)) {
sim_queue_init();
}
int sim_random() __attribute__ ((C, spontaneous)) {
uint32_t mlcg,p,q;
uint64_t tmpseed;
tmpseed = (uint64_t)33614U * (uint64_t)sim_seed;
q = tmpseed; /* low */
q = q >> 1;
p = tmpseed >> 32 ; /* hi */
mlcg = p + q;
if (mlcg & 0x80000000) {
mlcg = mlcg & 0x7FFFFFFF;
mlcg++;
}
sim_seed = mlcg;
return mlcg;
}
void sim_random_seed(int seed) __attribute__ ((C, spontaneous)) {
// A seed of zero wedges on zero, so use 1 instead.
if (seed == 0) {
seed = 1;
}
sim_seed = seed;
}
sim_time_t sim_time() __attribute__ ((C, spontaneous)) {
return sim_ticks;
}
void sim_set_time(sim_time_t t) __attribute__ ((C, spontaneous)) {
sim_ticks = t;
}
sim_time_t sim_ticks_per_sec() __attribute__ ((C, spontaneous)) {
return 10000000000ULL;
}
unsigned long sim_node() __attribute__ ((C, spontaneous)) {
return current_node;
}
void sim_set_node(unsigned long node) __attribute__ ((C, spontaneous)) {
current_node = node;
TOS_NODE_ID = node;
}
bool sim_run_next_event() __attribute__ ((C, spontaneous)) {
bool result = FALSE;
if (!sim_queue_is_empty()) {
sim_event_t* event = sim_queue_pop();
sim_set_time(event->time);
sim_set_node(event->mote);
// Need to test whether function pointers are for statically
// allocted events that are zeroed out on reboot
dbg("Tossdr", "CORE: popping event 0x%p for %i at %llu with handler %p... ", event, sim_node(), sim_time(), event->handle);
if ((sim_mote_is_on(event->mote) || event->force) &&
event->handle != NULL) {
result = TRUE;
dbg_clear("Tossdr", " mote is on (or forced event), run it.\n");
event->handle(event);
}
else {
dbg_clear("Tossdr", "\n");
}
/*if (event->cleanup != NULL) {
event->cleanup(event);
}*/ //mab: FIXME: if commented leaking, but running
}
return result;
}
int sim_print_time(char* buf, int len, sim_time_t ftime) __attribute__ ((C, spontaneous)) {
int hours;
int minutes;
int seconds;
sim_time_t secondBillionths;
secondBillionths = (ftime % sim_ticks_per_sec());
if (sim_ticks_per_sec() > (sim_time_t)1000000000) {
secondBillionths /= (sim_ticks_per_sec() / (sim_time_t)1000000000);
}
else {
secondBillionths *= ((sim_time_t)1000000000 / sim_ticks_per_sec());
}
seconds = (int)(ftime / sim_ticks_per_sec());
minutes = seconds / 60;
hours = minutes / 60;
seconds %= 60;
minutes %= 60;
buf[len-1] = 0;
return snprintf(buf, len - 1, "%i:%i:%i.%09llu", hours, minutes, seconds, secondBillionths);
}
int sim_print_now(char* buf, int len) __attribute__ ((C, spontaneous)) {
return sim_print_time(buf, len, sim_time());
}
char simTimeBuf[128];
char* sim_time_string() __attribute__ ((C, spontaneous)) {
sim_print_now(simTimeBuf, 128);
return simTimeBuf;
}
void sim_add_channel(char* channel, FILE* file) __attribute__ ((C, spontaneous)) {
sim_log_add_channel(channel, file);
}
bool sim_remove_channel(char* channel, FILE* file) __attribute__ ((C, spontaneous)) {
return sim_log_remove_channel(channel, file);
}
|
tinyos-io/tinyos-3.x-contrib | vu/tos/lib/remotecontrol/RemoteControl.h | /*
* Copyright (c) 2009, Vanderbilt University
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Author: <NAME>
*
**/
#if !defined(__REMOTECONTROL_H__)
#define __REMOTECONTROL_H__
enum {
APPID_REMOTECONTROL = 0x5e,
AM_REMOTECONTROL = 0x5e,
};
typedef nx_struct reply
{
nx_uint16_t nodeId;
nx_uint16_t seqNum;
nx_uint8_t unique_delimiter[0];
nx_uint16_t ret;
} reply_t;
typedef nx_struct RemoteControlMsg
{
nx_uint16_t seqNum; // sequence number (incremeneted at the base station)
nx_uint16_t target; // node id of final destination, or 0xFFFF for all, or 0xFF?? or a group of nodes
nx_uint16_t source;
nx_uint8_t dataType; // what kind of command is this
nx_uint8_t appId; // app id of final destination
nx_uint8_t data[0]; // variable length data packet
} remotecontrol_t;
#endif /* __REMOTECONTROL_H__ */
|
tinyos-io/tinyos-3.x-contrib | berkeley/blip-2.0/support/sdk/c/blip/lib6lowpan/lib6lowpan-includes.h | <gh_stars>1-10
#ifndef _LIB6LOWPAN_INCLUDES_H
#define _LIB6LOWPAN_INCLUDES_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <Ieee154.h>
#ifdef PC
#include "blip-pc-includes.h"
// typedef uint16_t ieee154_saddr_t;
typedef uint16_t hw_pan_t;
enum {
HW_BROADCAST_ADDR = 0xffff,
};
#else
#include "blip-tinyos-includes.h"
#endif
#include "nwbyte.h"
#include "iovec.h"
#include "6lowpan.h"
#endif
|
tinyos-io/tinyos-3.x-contrib | berkeley/blip-2.0/support/sdk/c/blip/lib6lowpan/lib6lowpan_frag.c |
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "6lowpan.h"
#include "Ieee154.h"
#include "ip.h"
#include "lib6lowpan.h"
#include "nwbyte.h"
#include "ip_malloc.h"
#include "iovec.h"
int lowpan_recon_complete(struct lowpan_reconstruct *recon,
struct ip6_packet_headers *hdrs);
int lowpan_recon_start(struct ieee154_frame_addr *frame_addr,
struct lowpan_reconstruct *recon,
uint8_t *pkt, size_t len) {
uint8_t *unpack_point, *unpack_end;
struct packed_lowmsg msg;
msg.data = pkt;
msg.len = len;
msg.headers = getHeaderBitmap(&msg);
if (msg.headers == LOWMSG_NALP) return -1;
/* remove the 6lowpan headers from the payload */
unpack_point = getLowpanPayload(&msg);
len -= (unpack_point - pkt);
/* set up the reconstruction, or just fill in the packet length */
if (hasFrag1Header(&msg)) {
getFragDgramTag(&msg, &recon->r_tag);
getFragDgramSize(&msg, &recon->r_size);
} else {
recon->r_size = LIB6LOWPAN_MAX_LEN + LOWPAN_LINK_MTU;
}
recon->r_buf = malloc(recon->r_size);
if (!recon->r_buf) return -1;
memset(recon->r_buf, 0, recon->r_size);
/* unpack the first fragment */
unpack_end = lowpan_unpack_headers(recon->r_buf, recon->r_size,
frame_addr,
unpack_point, len);
if (!unpack_end) {
free(recon->r_buf);
return -1;
}
if (!hasFrag1Header(&msg)) {
recon->r_size = (unpack_end - recon->r_buf);
}
recon->r_bytes_rcvd = unpack_end - recon->r_buf;
/* done, updated all the fields */
/* reconstruction is complete if r_bytes_rcvd == r_size */
return 0;
}
int lowpan_recon_add(struct lowpan_reconstruct *recon,
uint8_t *pkt, size_t len) {
struct packed_lowmsg msg;
uint8_t *buf;
msg.data = pkt;
msg.len = len;
msg.headers = getHeaderBitmap(&msg);
if (msg.headers == LOWMSG_NALP) return -1;
if (!hasFragNHeader(&msg)) {
return -1;
}
buf = getLowpanPayload(&msg);
len -= (buf - pkt);
if (recon->r_size < recon->r_bytes_rcvd + len) return -1;
/* just need to copy the new payload in and return */
memcpy(recon->r_buf + recon->r_bytes_rcvd, buf, len);
recon->r_bytes_rcvd += len;
return 0;
}
int lowpan_frag_get(uint8_t *frag, size_t len,
struct ip6_packet *packet,
struct ieee154_frame_addr *frame,
struct lowpan_ctx *ctx) {
uint8_t *buf, *lowpan_buf, *ieee_buf = frag;
uint16_t extra_payload;
/* pack 802.15.4 */
buf = lowpan_buf = pack_ieee154_header(frag, len, frame);
if (ctx->offset == 0) {
int offset;
/* pack the IPv6 header */
buf = lowpan_pack_headers(packet, frame, buf, len - (buf - frag));
if (!buf) return -1;
/* pack the next headers */
offset = pack_nhc_chain(&buf, len - (buf - ieee_buf), packet);
if (offset < 0) return -2;
/* copy the rest of the payload into this fragment */
extra_payload = ntohs(packet->ip6_hdr.ip6_plen) - offset;
/* may need to fragment -- insert a FRAG1 header if so */
if (extra_payload > len - (buf - ieee_buf)) {
struct packed_lowmsg lowmsg;
memmove(lowpan_buf + LOWMSG_FRAG1_LEN,
lowpan_buf,
buf - lowpan_buf);
lowmsg.data = lowpan_buf;
lowmsg.len = LOWMSG_FRAG1_LEN;
lowmsg.headers = 0;
setupHeaders(&lowmsg, LOWMSG_FRAG1_HDR);
setFragDgramSize(&lowmsg, ntohs(packet->ip6_hdr.ip6_plen) + sizeof(struct ip6_hdr));
setFragDgramTag(&lowmsg, ctx->tag);
lowpan_buf += LOWMSG_FRAG1_LEN;
buf += LOWMSG_FRAG1_LEN;
extra_payload = len - (buf - ieee_buf);
extra_payload -= (extra_payload % 8);
}
if (iov_read(packet->ip6_data, offset, extra_payload, buf) != extra_payload) {
return -3;
}
ctx->offset = offset + extra_payload + sizeof(struct ip6_hdr);
return (buf - frag) + extra_payload;
} else {
struct packed_lowmsg lowmsg;
buf = lowpan_buf = pack_ieee154_header(frag, len, frame);
/* setup the FRAGN header */
lowmsg.data = lowpan_buf;
lowmsg.len = LOWMSG_FRAGN_LEN;
lowmsg.headers = 0;
setupHeaders(&lowmsg, LOWMSG_FRAGN_HDR);
if (setFragDgramSize(&lowmsg, ntohs(packet->ip6_hdr.ip6_plen) + sizeof(struct ip6_hdr)))
return -5;
if (setFragDgramTag(&lowmsg, ctx->tag))
return -6;
if (setFragDgramOffset(&lowmsg, ctx->offset / 8))
return -7;
buf += LOWMSG_FRAGN_LEN;
extra_payload = ntohs(packet->ip6_hdr.ip6_plen) + sizeof(struct ip6_hdr) - ctx->offset;
if (extra_payload > len - (buf - ieee_buf)) {
extra_payload = len - (buf - ieee_buf);
extra_payload -= (extra_payload % 8);
}
/* { */
/* int i; */
/* for (i = 0; i < extra_payload; i++) { */
/* buf[i] = i; */
/* } */
/* } */
if (iov_read(packet->ip6_data, ctx->offset - sizeof(struct ip6_hdr), extra_payload, buf) != extra_payload) {
return -4;
}
ctx->offset += extra_payload;
if (extra_payload == 0) return 0;
else return (lowpan_buf - ieee_buf) + LOWMSG_FRAGN_LEN + extra_payload;
}
}
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/chips/mcs51/io8051.h | /*
* Copyright (c) 2007 University of Copenhagen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of University of Copenhagen nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
* OF COPENHAGEN OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
*
* This file defines properties shared among 8051 variants. Chip
* specific additions are found in the directories for those chips
*
* The special function register definitions are created in a slightly
* odd way in order to allow special attributes to pass through nescc
* unchanged and then be modified by a mangle script later.
*
* For Keil the sfr/sbit definitions cannot be created inside a
* function body - they have to be made outside (see "Cx51 User" under
* sfr/bit types).
*
* The __attribute(()) will be removed by the mangle script and
* the content x will be used to construct:
* sfr at x ...
*
* Alternative to stay within ANSI-C one could imagine using a
* structure with bit fields say struct { int P0:1 }, however the
* silly architecture of the 8051 forces us to controll whether code
* using direct or indirect addressing is generated. I can't se how
* this could be done using ANSI-C.
*
* The above scheme allows nescc to parse the code and sdcc to to
* generate the appropriate code.
*
* Interrupt definitions are moved to the include file for each architectore as
* no lowest commen denominator could be found. See mcs51hardware.h for more.
*
* @author <NAME> <<EMAIL>>
* @author <NAME>
* @author <NAME>
*
*/
#ifndef _H_io8051_H
#define _H_io8051_H
#include <byteorder.h>
uint8_t volatile P0 __attribute((sfrAT0x80));
uint8_t volatile SP __attribute((sfrAT0x81));
uint8_t volatile DPL __attribute((sfrAT0x82));
uint8_t volatile DPH __attribute((sfrAT0x83));
uint8_t volatile DPL1 __attribute((sfrAT0x84));
uint8_t volatile DPH1 __attribute((sfrAT0x85));
// 0x86 used differently by CC2430/nRF24E1
uint8_t volatile PCON __attribute((sfrAT0x87));
uint8_t volatile TCON __attribute((sfrAT0x88));
uint8_t volatile TMOD __attribute((sfrAT0x89));
uint8_t volatile TL0 __attribute((sfrAT0x8A));
uint8_t volatile TL1 __attribute((sfrAT0x8B));
uint8_t volatile TH0 __attribute((sfrAT0x8C));
uint8_t volatile TH1 __attribute((sfrAT0x8D));
uint8_t volatile CKCON __attribute((sfrAT0x8E));
uint8_t volatile P1 __attribute((sfrAT0x90));
uint8_t volatile EXIF __attribute((sfrAT0x91));
uint8_t volatile MPAGE __attribute((sfrAT0x92));
uint8_t volatile SCON __attribute((sfrAT0x98));
uint8_t volatile SBUF __attribute((sfrAT0x99));
uint8_t volatile T2CON __attribute((sfrAT0xC8));
uint8_t volatile RCAP2L __attribute((sfrAT0xCA));
uint8_t volatile RCAP2H __attribute((sfrAT0xCB));
uint8_t volatile TL2 __attribute((sfrAT0xCC));
uint8_t volatile TH2 __attribute((sfrAT0xCD));
uint8_t volatile PSW __attribute((sfrAT0xD0));
uint8_t volatile EICON __attribute((sfrAT0xD8));
uint8_t volatile ACC __attribute((sfrAT0xE0));
uint8_t volatile B __attribute((sfrAT0xF0));
// Interrupt control at 0xE8 is used differently
uint8_t volatile EIP __attribute((sfrAT0xF8));
uint8_t volatile P1_ALT __attribute((sfrAT0x97));
uint8_t volatile P2 __attribute((sfrAT0xA0));
uint8_t volatile ADCCON __attribute((sfrAT0xA1));
uint8_t volatile ADCDATAH __attribute((sfrAT0xA2));
uint8_t volatile ADCDATAL __attribute((sfrAT0xA3));
uint8_t volatile ADCSTATIC __attribute((sfrAT0xA4));
uint8_t volatile PWMCON __attribute((sfrAT0xA9));
uint8_t volatile PWMDUTY __attribute((sfrAT0xAA));
uint8_t volatile REGX_MSB __attribute((sfrAT0xAB));
uint8_t volatile REGX_LSB __attribute((sfrAT0xAC));
uint8_t volatile REGX_CTRL __attribute((sfrAT0xAD));
uint8_t volatile RSTREAS __attribute((sfrAT0xB1));
uint8_t volatile SPI_DATA __attribute((sfrAT0xB2));
uint8_t volatile SPI_CTRL __attribute((sfrAT0xB3));
uint8_t volatile SPICLK __attribute((sfrAT0xB4));
uint8_t volatile TICK_DV __attribute((sfrAT0xB5));
uint8_t volatile CK_CTRL __attribute((sfrAT0xB6));
/* BIT Registers */
/* PSW */
uint8_t volatile CY __attribute((sbitAT0xD7));
uint8_t volatile AC __attribute((sbitAT0xD6));
uint8_t volatile F0 __attribute((sbitAT0xD5));
uint8_t volatile RS1 __attribute((sbitAT0xD4));
uint8_t volatile RS0 __attribute((sbitAT0xD3));
uint8_t volatile OV __attribute((sbitAT0xD2));
uint8_t volatile F1 __attribute((sbitAT0xD1));
uint8_t volatile P __attribute((sbitAT0xD0));
/* TCON */
uint8_t volatile TF1 __attribute((sbitAT0x8F));
uint8_t volatile TR1 __attribute((sbitAT0x8E));
uint8_t volatile TF0 __attribute((sbitAT0x8D));
uint8_t volatile TR0 __attribute((sbitAT0x8C));
uint8_t volatile IE1 __attribute((sbitAT0x8B));
uint8_t volatile IT1 __attribute((sbitAT0x8A));
uint8_t volatile IE0 __attribute((sbitAT0x89));
uint8_t volatile IT0 __attribute((sbitAT0x88));
/* IE */
/* The interupt mask register definition seems to be common, but the
semantics of the bits other than "disable/enble all" (bit 7, EA) seems
to vary. On chipcon this register is name IE0EN
*/
uint8_t volatile IE __attribute((sfrAT0A8));
norace uint8_t volatile EA __attribute((sbitAT0xAF));
/* IP */
uint8_t volatile PT2 __attribute((sbitAT0xBD));
uint8_t volatile PS __attribute((sbitAT0xBC));
uint8_t volatile PT1 __attribute((sbitAT0xBB));
uint8_t volatile PX1 __attribute((sbitAT0xBA));
uint8_t volatile PT0 __attribute((sbitAT0xB9));
uint8_t volatile PX0 __attribute((sbitAT0xB8));
/* P0 bit adressable locations */
uint8_t volatile P0_0 __attribute((sbitAT0x80));
uint8_t volatile P0_1 __attribute((sbitAT0x81));
uint8_t volatile P0_2 __attribute((sbitAT0x82));
uint8_t volatile P0_3 __attribute((sbitAT0x83));
uint8_t volatile P0_4 __attribute((sbitAT0x84));
uint8_t volatile P0_5 __attribute((sbitAT0x85));
uint8_t volatile P0_6 __attribute((sbitAT0x86));
uint8_t volatile P0_7 __attribute((sbitAT0x87));
/* P0 alternate functions */
uint8_t volatile T1 __attribute((sbitAT0x86));
uint8_t volatile T0 __attribute((sbitAT0x85));
uint8_t volatile INT1 __attribute((sbitAT0x84));
uint8_t volatile INT0 __attribute((sbitAT0x83));
/* P1 bit adressable locations */
uint8_t volatile P1_0 __attribute((sbitAT0x90));
uint8_t volatile P1_1 __attribute((sbitAT0x91));
uint8_t volatile P1_2 __attribute((sbitAT0x92));
uint8_t volatile P1_3 __attribute((sbitAT0x93));
uint8_t volatile P1_4 __attribute((sbitAT0x94));
uint8_t volatile P1_5 __attribute((sbitAT0x95));
uint8_t volatile P1_6 __attribute((sbitAT0x96));
uint8_t volatile P1_7 __attribute((sbitAT0x97));
/* P1 alternate functions*/
uint8_t volatile T2 __attribute((sbitAT0x90));
/* P2 bit adressable locations */
/* On some platforms (eg. cc2430) not all are available */
uint8_t volatile P2_0 __attribute((sbitAT0xA0));
uint8_t volatile P2_1 __attribute((sbitAT0xA1));
uint8_t volatile P2_2 __attribute((sbitAT0xA2));
uint8_t volatile P2_3 __attribute((sbitAT0xA3));
uint8_t volatile P2_4 __attribute((sbitAT0xA4));
uint8_t volatile P2_5 __attribute((sbitAT0xA5));
uint8_t volatile P2_6 __attribute((sbitAT0xA6));
uint8_t volatile P2_7 __attribute((sbitAT0xA7));
/* SCON */
uint8_t volatile SM0 __attribute((sbitAT0x9F));
uint8_t volatile SM1 __attribute((sbitAT0x9E));
uint8_t volatile SM2 __attribute((sbitAT0x9D));
uint8_t volatile REN __attribute((sbitAT0x9C));
uint8_t volatile TB8 __attribute((sbitAT0x9B));
uint8_t volatile RB8 __attribute((sbitAT0x9A));
uint8_t volatile TI __attribute((sbitAT0x99));
uint8_t volatile RI __attribute((sbitAT0x98));
/* T2CON */
uint8_t volatile TF2 __attribute((sbitAT0xCF));
uint8_t volatile EXF2 __attribute((sbitAT0xCE));
uint8_t volatile RCLK __attribute((sbitAT0xCD));
uint8_t volatile TCLK __attribute((sbitAT0xCC));
uint8_t volatile EXEN2 __attribute((sbitAT0xCB));
uint8_t volatile TR2 __attribute((sbitAT0xCA));
uint8_t volatile C_T2 __attribute((sbitAT0xC9));
uint8_t volatile CP_RL2 __attribute((sbitAT0xC8));
/* EICON */
uint8_t volatile SMOD1 __attribute((sbitAT0xDF));
uint8_t volatile WDTI __attribute((sbitAT0xDB));
/* EIE */
uint8_t volatile EWDI __attribute((sbitAT0xEC));
uint8_t volatile EX5 __attribute((sbitAT0xEB));
uint8_t volatile EX4 __attribute((sbitAT0xEA));
uint8_t volatile EX3 __attribute((sbitAT0xE9));
uint8_t volatile EX2 __attribute((sbitAT0xE8));
/* EIP */
uint8_t volatile PWDI __attribute((sbitAT0xFC));
uint8_t volatile PX5 __attribute((sbitAT0xFB));
uint8_t volatile PX4 __attribute((sbitAT0xFA));
uint8_t volatile PX3 __attribute((sbitAT0xF9));
uint8_t volatile PX2 __attribute((sbitAT0xF8));
/* RADIO */
uint8_t volatile PWR_UP __attribute((sbitAT0xA7));
uint8_t volatile DR2 __attribute((sbitAT0xA6));
uint8_t volatile CE __attribute((sbitAT0xA6));
uint8_t volatile CLK2 __attribute((sbitAT0xA5));
uint8_t volatile DOUT2 __attribute((sbitAT0xA4));
uint8_t volatile CS __attribute((sbitAT0xA3));
uint8_t volatile DR1 __attribute((sbitAT0xA2));
uint8_t volatile CLK1 __attribute((sbitAT0xA1));
uint8_t volatile DATA __attribute((sbitAT0xA0));
#endif // _H_io8051_H
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/driver/get_configuration.c | <reponame>tinyos-io/tinyos-3.x-contrib<gh_stars>1-10
/* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 <NAME> <<EMAIL>>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "libusb_driver.h"
NTSTATUS get_configuration(libusb_device_t *dev,
unsigned char *configuration, int *ret,
int timeout)
{
NTSTATUS status = STATUS_SUCCESS;
URB urb;
DEBUG_PRINT_NL();
DEBUG_MESSAGE("get_configuration(): timeout %d", timeout);
memset(&urb, 0, sizeof(URB));
urb.UrbHeader.Function = URB_FUNCTION_GET_CONFIGURATION;
urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_CONFIGURATION_REQUEST);
urb.UrbControlGetConfigurationRequest.TransferBufferLength = 1;
urb.UrbControlGetConfigurationRequest.TransferBuffer = configuration;
status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
if(!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
{
DEBUG_ERROR("get_configuration(): getting configuration failed: "
"status: 0x%x, urb-status: 0x%x",
status, urb.UrbHeader.Status);
*ret = 0;
}
else
{
DEBUG_MESSAGE("get_configuration(): current configuration is: %d",
*configuration);
*ret = urb.UrbControlGetConfigurationRequest.TransferBufferLength;
}
return status;
}
|
tinyos-io/tinyos-3.x-contrib | rincon/tos/lib/Nmea/NmeaCoordinates.h | /*
* Copyright (c) 2008 Rincon Research Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the Rincon Research Corporation nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* RINCON RESEARCH OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE
*/
/**
* TODO:Add documentation here.
*
* @author <NAME>
*/
#ifndef NMEA_COORDINATES_H
#define NMEA_COORDINATES_H
typedef uint8_t nmea_cardinal_t;//North, South, East, West -- ONLY
enum {
SOUTH = 0x53,//hex ASCII for 'S'
NORTH = 0x4E,//hex ASCII for 'N'
EAST = 0x45,//hex ASCII for 'E'
WEST = 0x57,//hex ASCII for 'W'
};
typedef struct nmea_coordinate {
/** Stored as an integer value */
uint8_t degree;
/**
* Measured from 0-60* minutes with 3 decimal places of accuracy
* stored as an integer (divide by 1000 to get actual value)
* *Actual values will range from 0 to 59999.
*/
uint16_t minute;
/** NORTH, SOUTH, EAST, or WEST (from the above enums) */
nmea_cardinal_t direction;
} nmea_coordinate_t;
/** degree should be from 0-90, direction should only be NORTH or SOUTH */
typedef nmea_coordinate_t nmea_latitude_t;
/** degree should be from 0-180, direction should only be EAST or WEST */
typedef nmea_coordinate_t nmea_longitude_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/tos/platforms/turtlenet/hardware.h | <reponame>tinyos-io/tinyos-3.x-contrib<filename>eon/tos/platforms/turtlenet/hardware.h
/*
* Copyright (c) 2005-2006, Ecole Polytechnique Federale de Lausanne (EPFL)
* and Shockfish SA, Switzerland.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Ecole Polytechnique Federale de Lausanne (EPFL)
* and Shockfish SA, nor the names of its contributors may be used to
* endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ========================================================================
*/
/*
* Platform definitions for tinynode platform
*
* @author <NAME>
* @author <NAME>
* @author <NAME>
*
*/
#ifndef _H_hardware_h
#define _H_hardware_h
#include "msp430hardware.h"
// XE1205 radio
TOSH_ASSIGN_PIN(NSS_DATA, 1, 0);
TOSH_ASSIGN_PIN(DATA, 5, 7);
TOSH_ASSIGN_PIN(NSS_CONFIG, 1, 4);
TOSH_ASSIGN_PIN(IRQ0, 2, 0);
TOSH_ASSIGN_PIN(IRQ1, 2, 1);
TOSH_ASSIGN_PIN(SW_RX, 2, 6);
TOSH_ASSIGN_PIN(SW_TX, 2, 7);
TOSH_ASSIGN_PIN(POR, 3, 0);
TOSH_ASSIGN_PIN(SCK, 3, 3);
TOSH_ASSIGN_PIN(SW0, 3, 4);
TOSH_ASSIGN_PIN(SW1, 3, 5);
// LED
TOSH_ASSIGN_PIN(RED_LED, 1, 5); // on tinynode
TOSH_ASSIGN_PIN(RED_LED2, 1, 6); // external, for compatibility with Mica
TOSH_ASSIGN_PIN(GREEN_LED, 2, 3);
TOSH_ASSIGN_PIN(YELLOW_LED, 2, 4);
// TOSH_ASSIGN_PIN(RED_LED2, 1, 5); // external, for compatibility with Mica
// TOSH_ASSIGN_PIN(GREEN_LED, 1, 3);
// TOSH_ASSIGN_PIN(YELLOW_LED, 1, 2);
// Other IO
TOSH_ASSIGN_PIN(TEMPE, 5, 4); // optional temperature sensor
TOSH_ASSIGN_PIN(NVSUPE, 5, 5); // voltage supply monitor
TOSH_ASSIGN_PIN(NREGE, 5, 6); // voltage regulator enable
// UART0 pins (shared with XE1205 radio)
TOSH_ASSIGN_PIN(STE0, 3, 0);
TOSH_ASSIGN_PIN(SIMO0, 3, 1);
TOSH_ASSIGN_PIN(SOMI0, 3, 2);
TOSH_ASSIGN_PIN(UCLK0, 3, 3);
TOSH_ASSIGN_PIN(UTXD0, 3, 4);
TOSH_ASSIGN_PIN(URXD0, 3, 5);
// UART1 pins
TOSH_ASSIGN_PIN(STE1, 5, 0);
TOSH_ASSIGN_PIN(SIMO1, 5, 1);
TOSH_ASSIGN_PIN(SOMI1, 5, 2);
TOSH_ASSIGN_PIN(UCLK1, 5, 3);
TOSH_ASSIGN_PIN(UTXD1, 3, 6);
TOSH_ASSIGN_PIN(URXD1, 3, 7);
// ADC
TOSH_ASSIGN_PIN(TEMP, 6, 0); // channel 0: optional temperature sensor
TOSH_ASSIGN_PIN(VSUP, 6, 1); // channel 1: supply monitor
TOSH_ASSIGN_PIN(ADC2, 6, 2);
TOSH_ASSIGN_PIN(ADC3, 6, 3);
TOSH_ASSIGN_PIN(ADC4, 6, 4);
TOSH_ASSIGN_PIN(ADC5, 6, 5);
TOSH_ASSIGN_PIN(ADC6, 6, 6);
TOSH_ASSIGN_PIN(ADC7, 6, 7);
// External FLASH
TOSH_ASSIGN_PIN(NFL_RST, 4, 6);
TOSH_ASSIGN_PIN(NFL_CS, 4, 7);
TOSH_ASSIGN_PIN(FLASH_RST, 4, 6);
TOSH_ASSIGN_PIN(FLASH_CS, 4, 7);
// PROGRAMMING PINS (tri-state)
TOSH_ASSIGN_PIN(PROG_RX, 1, 1);
TOSH_ASSIGN_PIN(PROG_TX, 2, 2);
// Oscillator resistance
TOSH_ASSIGN_PIN(ROSC, 2, 5);
// unused
TOSH_ASSIGN_PIN(P12, 1, 2);
TOSH_ASSIGN_PIN(P13, 1, 3);
TOSH_ASSIGN_PIN(P16, 1, 6);
TOSH_ASSIGN_PIN(P23, 2, 3);
TOSH_ASSIGN_PIN(P24, 2, 4);
TOSH_ASSIGN_PIN(P40, 4, 0);
TOSH_ASSIGN_PIN(P41, 4, 1);
// unconnected
TOSH_ASSIGN_PIN(NOT_CONNECTED1, 1, 7);
TOSH_ASSIGN_PIN(NOT_CONNECTED2, 4, 2);
TOSH_ASSIGN_PIN(NOT_CONNECTED3, 4, 3);
TOSH_ASSIGN_PIN(NOT_CONNECTED4, 4, 4);
TOSH_ASSIGN_PIN(NOT_CONNECTED5, 4, 5);
void TOSH_SET_PIN_DIRECTIONS(void)
{
//LEDS
TOSH_CLR_RED_LED_PIN();
TOSH_MAKE_RED_LED_OUTPUT();
// XE1205 radio
// TOSH_SET_NSS_DATA_PIN();
// TOSH_MAKE_NSS_DATA_OUTPUT();
// TOSH_CLR_DATA_PIN();
// TOSH_MAKE_DATA_OUTPUT();
// TOSH_SET_NSS_CONFIG_PIN();
// TOSH_MAKE_NSS_CONFIG_OUTPUT();
// TOSH_CLR_IRQ0_PIN();
// TOSH_MAKE_IRQ0_OUTPUT();
// TOSH_CLR_IRQ1_PIN();
// TOSH_MAKE_IRQ1_OUTPUT();
// TOSH_CLR_SW_RX_PIN();
// TOSH_MAKE_SW_RX_OUTPUT();
// TOSH_CLR_SW_TX_PIN();
// TOSH_MAKE_SW_TX_OUTPUT();
TOSH_MAKE_POR_INPUT();
// SPI0
TOSH_CLR_SCK_PIN();
TOSH_MAKE_SCK_OUTPUT();
// antenna switch
// TOSH_CLR_SW0_PIN();
// TOSH_MAKE_SW0_OUTPUT();
// TOSH_CLR_SW1_PIN();
// TOSH_MAKE_SW1_OUTPUT();
// optional temperature sensor
TOSH_CLR_TEMPE_PIN();
TOSH_MAKE_TEMPE_OUTPUT();
TOSH_MAKE_TEMP_INPUT();
TOSH_SEL_TEMP_MODFUNC();
// voltage supply monitor
TOSH_SET_NVSUPE_PIN();
TOSH_MAKE_NVSUPE_INPUT();
TOSH_MAKE_VSUP_INPUT();
TOSH_SEL_VSUP_MODFUNC();
// voltage regulator
TOSH_SET_NREGE_PIN(); // disable regulator for low power mode
TOSH_MAKE_NREGE_OUTPUT();
//UART PINS
TOSH_MAKE_UTXD1_INPUT();
TOSH_MAKE_URXD1_INPUT();
TOSH_SEL_UTXD1_IOFUNC();
// External FLASH
TOSH_SET_FLASH_RST_PIN();
TOSH_MAKE_FLASH_RST_OUTPUT();
TOSH_SET_FLASH_CS_PIN();
TOSH_MAKE_FLASH_CS_OUTPUT();
//PROG PINS
TOSH_MAKE_PROG_RX_INPUT();
TOSH_MAKE_PROG_TX_INPUT();
// ROSC PIN
TOSH_SET_ROSC_PIN();
TOSH_MAKE_ROSC_OUTPUT();
// set unconnected pins to avoid instability
TOSH_SET_NOT_CONNECTED1_PIN();
TOSH_SET_NOT_CONNECTED2_PIN();
TOSH_SET_NOT_CONNECTED3_PIN();
TOSH_SET_NOT_CONNECTED4_PIN();
TOSH_SET_NOT_CONNECTED5_PIN();
TOSH_MAKE_NOT_CONNECTED1_OUTPUT();
TOSH_MAKE_NOT_CONNECTED2_OUTPUT();
TOSH_MAKE_NOT_CONNECTED3_OUTPUT();
TOSH_MAKE_NOT_CONNECTED4_OUTPUT();
TOSH_MAKE_NOT_CONNECTED5_OUTPUT();
}
#endif // _H_hardware_h
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/platforms/c8051F340TB/hardware.h | /*
* Copyright (c) 2008 Polaric
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of Polaric nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL POLARIC OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
*
* @author <NAME> <<EMAIL>>
*/
#ifndef HARDWARE_H
#define HARDWARE_H
#include <iocip51.h>
#include <mcs51hardware.h>
#endif //HARDWARE_H
|
tinyos-io/tinyos-3.x-contrib | ethz/tinynode184/tos/chips/msp430/msp430regtypes.h |
/* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
//@author <NAME> <<EMAIL>>
#ifndef _H_msp430regtypes_h
#define _H_msp430regtypes_h
/*
To generate the primary contents of this file seen below, in
mspgcc/msp430/include/, execute the following command:
find . | xargs perl -ne '
BEGIN { %t = qw(b uint8_t w uint16_t); }
if( /\bsfr([bw])\s*\(\s*(\w+)/ && length($2) > 1 ) {
$r{$2} = $t{$1};
print "#define TYPE_$2 $t{$1}\n" if /\bsfr([bw])\s*\(\s*(\w+)/;
} elsif( /^#define\s+(\w+)\s+(\w+)\s+$/ ) {
print "#define TYPE_$1 $r{$2}\n" if $r{$2};
}
' | sort -u
*/
#define TYPE_ACTL uint16_t
#define TYPE_ADAT uint16_t
#define TYPE_ADC10AE uint8_t
#define TYPE_ADC10CTL0 uint16_t
#define TYPE_ADC10CTL1 uint16_t
#define TYPE_ADC10DTC0 uint8_t
#define TYPE_ADC10DTC1 uint8_t
#define TYPE_ADC10MEM uint16_t
#define TYPE_ADC10SA uint16_t
#define TYPE_ADC12CTL0 uint16_t
#define TYPE_ADC12CTL1 uint16_t
#define TYPE_ADC12IE uint16_t
#define TYPE_ADC12IFG uint16_t
#define TYPE_ADC12IV uint16_t
#define TYPE_ADC12MCTL0 uint8_t
#define TYPE_ADC12MCTL1 uint8_t
#define TYPE_ADC12MCTL10 uint8_t
#define TYPE_ADC12MCTL11 uint8_t
#define TYPE_ADC12MCTL12 uint8_t
#define TYPE_ADC12MCTL13 uint8_t
#define TYPE_ADC12MCTL14 uint8_t
#define TYPE_ADC12MCTL15 uint8_t
#define TYPE_ADC12MCTL2 uint8_t
#define TYPE_ADC12MCTL3 uint8_t
#define TYPE_ADC12MCTL4 uint8_t
#define TYPE_ADC12MCTL5 uint8_t
#define TYPE_ADC12MCTL6 uint8_t
#define TYPE_ADC12MCTL7 uint8_t
#define TYPE_ADC12MCTL8 uint8_t
#define TYPE_ADC12MCTL9 uint8_t
#define TYPE_ADC12MEM0 uint16_t
#define TYPE_ADC12MEM1 uint16_t
#define TYPE_ADC12MEM10 uint16_t
#define TYPE_ADC12MEM11 uint16_t
#define TYPE_ADC12MEM12 uint16_t
#define TYPE_ADC12MEM13 uint16_t
#define TYPE_ADC12MEM14 uint16_t
#define TYPE_ADC12MEM15 uint16_t
#define TYPE_ADC12MEM2 uint16_t
#define TYPE_ADC12MEM3 uint16_t
#define TYPE_ADC12MEM4 uint16_t
#define TYPE_ADC12MEM5 uint16_t
#define TYPE_ADC12MEM6 uint16_t
#define TYPE_ADC12MEM7 uint16_t
#define TYPE_ADC12MEM8 uint16_t
#define TYPE_ADC12MEM9 uint16_t
#define TYPE_AEN uint16_t
#define TYPE_AIN uint16_t
#define TYPE_BCSCTL1 uint8_t
#define TYPE_BCSCTL2 uint8_t
#define TYPE_BTCNT1 uint8_t
#define TYPE_BTCNT2 uint8_t
#define TYPE_BTCTL uint8_t
#define TYPE_CACTL1 uint8_t
#define TYPE_CACTL2 uint8_t
#define TYPE_CAPD uint8_t
#define TYPE_CBCTL uint8_t
#define TYPE_CCR0 uint16_t
#define TYPE_CCR1 uint16_t
#define TYPE_CCR2 uint16_t
#define TYPE_CCTL0 uint16_t
#define TYPE_CCTL1 uint16_t
#define TYPE_CCTL2 uint16_t
#define TYPE_DAC12CTL0 uint16_t
#define TYPE_DAC12IFG uint16_t
#define TYPE_DAC12_0CTL uint16_t
#define TYPE_DAC12_0DAT uint16_t
#define TYPE_DAC12_1CTL uint16_t
#define TYPE_DAC12_1DAT uint16_t
#define TYPE_DCOCTL uint8_t
#define TYPE_DMA0CTL uint16_t
#define TYPE_DMA0DA uint16_t
#define TYPE_DMA0SA uint16_t
#define TYPE_DMA0SZ uint16_t
#define TYPE_DMA1CTL uint16_t
#define TYPE_DMA1DA uint16_t
#define TYPE_DMA1SA uint16_t
#define TYPE_DMA1SZ uint16_t
#define TYPE_DMA2CTL uint16_t
#define TYPE_DMA2DA uint16_t
#define TYPE_DMA2SA uint16_t
#define TYPE_DMA2SZ uint16_t
#define TYPE_DMACTL0 uint16_t
#define TYPE_DMACTL1 uint16_t
#define TYPE_EPCTL uint8_t
#define TYPE_ESPCTL uint16_t
#define TYPE_FCTL1 uint16_t
#define TYPE_FCTL2 uint16_t
#define TYPE_FCTL3 uint16_t
#define TYPE_FLL_CTL0 uint8_t
#define TYPE_FLL_CTL1 uint8_t
#define TYPE_I2CDCTL uint8_t
#define TYPE_I2CDR uint8_t
#define TYPE_I2CIE uint8_t
#define TYPE_I2CIFG uint8_t
#define TYPE_I2CIV uint16_t
#define TYPE_I2CNDAT uint8_t
#define TYPE_I2COA uint16_t
#define TYPE_I2CPSC uint8_t
#define TYPE_I2CSA uint16_t
#define TYPE_I2CSCLH uint8_t
#define TYPE_I2CSCLL uint8_t
#define TYPE_I2CTCTL uint8_t
#define TYPE_IE1 uint8_t
#define TYPE_IE2 uint8_t
#define TYPE_UC1IE uint8_t
#define TYPE_IFG1 uint8_t
#define TYPE_IFG2 uint8_t
#define TYPE_UC1IFG uint8_t
#define TYPE_LCDCTL uint8_t
#define TYPE_LCDM1 uint8_t
#define TYPE_LCDM10 uint8_t
#define TYPE_LCDM11 uint8_t
#define TYPE_LCDM12 uint8_t
#define TYPE_LCDM13 uint8_t
#define TYPE_LCDM14 uint8_t
#define TYPE_LCDM15 uint8_t
#define TYPE_LCDM16 uint8_t
#define TYPE_LCDM17 uint8_t
#define TYPE_LCDM18 uint8_t
#define TYPE_LCDM19 uint8_t
#define TYPE_LCDM2 uint8_t
#define TYPE_LCDM20 uint8_t
#define TYPE_LCDM3 uint8_t
#define TYPE_LCDM4 uint8_t
#define TYPE_LCDM5 uint8_t
#define TYPE_LCDM6 uint8_t
#define TYPE_LCDM7 uint8_t
#define TYPE_LCDM8 uint8_t
#define TYPE_LCDM9 uint8_t
#define TYPE_LCDMA uint8_t
#define TYPE_LCDMB uint8_t
#define TYPE_LCDMC uint8_t
#define TYPE_LCDMD uint8_t
#define TYPE_LCDME uint8_t
#define TYPE_LCDMF uint8_t
#define TYPE_MAC uint16_t
#define TYPE_MACS uint16_t
#define TYPE_MBCTL uint16_t
#define TYPE_MBIN0 uint16_t
#define TYPE_MBIN1 uint16_t
#define TYPE_MBOUT0 uint16_t
#define TYPE_MBOUT1 uint16_t
#define TYPE_ME1 uint8_t
#define TYPE_ME2 uint8_t
#define TYPE_MPY uint16_t
#define TYPE_MPYS uint16_t
#define TYPE_OA0CTL0 uint8_t
#define TYPE_OA0CTL1 uint8_t
#define TYPE_OA1CTL0 uint8_t
#define TYPE_OA1CTL1 uint8_t
#define TYPE_OA2CTL0 uint8_t
#define TYPE_OA2CTL1 uint8_t
#define TYPE_OP2 uint16_t
#define TYPE_PORT_OUT uint8_t
#define TYPE_PORT_IN uint8_t
#define TYPE_PORT_DIR uint8_t
#define TYPE_PORT_SEL uint8_t
#define TYPE_P0DIR uint8_t
#define TYPE_P0IE uint8_t
#define TYPE_P0IES uint8_t
#define TYPE_P0IFG uint8_t
#define TYPE_P0IN uint8_t
#define TYPE_P0OUT uint8_t
#define TYPE_P1DIR uint8_t
#define TYPE_P1IE uint8_t
#define TYPE_P1IES uint8_t
#define TYPE_P1IFG uint8_t
#define TYPE_P1IN uint8_t
#define TYPE_P1OUT uint8_t
#define TYPE_P1SEL uint8_t
#define TYPE_P2DIR uint8_t
#define TYPE_P2IE uint8_t
#define TYPE_P2IES uint8_t
#define TYPE_P2IFG uint8_t
#define TYPE_P2IN uint8_t
#define TYPE_P2OUT uint8_t
#define TYPE_P2SEL uint8_t
#define TYPE_P3DIR uint8_t
#define TYPE_P3IN uint8_t
#define TYPE_P3OUT uint8_t
#define TYPE_P3SEL uint8_t
#define TYPE_P4DIR uint8_t
#define TYPE_P4IN uint8_t
#define TYPE_P4OUT uint8_t
#define TYPE_P4SEL uint8_t
#define TYPE_P5DIR uint8_t
#define TYPE_P5IN uint8_t
#define TYPE_P5OUT uint8_t
#define TYPE_P5SEL uint8_t
#define TYPE_P6DIR uint8_t
#define TYPE_P6IN uint8_t
#define TYPE_P6OUT uint8_t
#define TYPE_P6SEL uint8_t
#define TYPE_RESHI uint16_t
#define TYPE_RESLO uint16_t
#define TYPE_RET0 uint16_t
#define TYPE_RET1 uint16_t
#define TYPE_RET10 uint16_t
#define TYPE_RET11 uint16_t
#define TYPE_RET12 uint16_t
#define TYPE_RET13 uint16_t
#define TYPE_RET14 uint16_t
#define TYPE_RET15 uint16_t
#define TYPE_RET16 uint16_t
#define TYPE_RET17 uint16_t
#define TYPE_RET18 uint16_t
#define TYPE_RET19 uint16_t
#define TYPE_RET2 uint16_t
#define TYPE_RET20 uint16_t
#define TYPE_RET21 uint16_t
#define TYPE_RET22 uint16_t
#define TYPE_RET23 uint16_t
#define TYPE_RET24 uint16_t
#define TYPE_RET25 uint16_t
#define TYPE_RET26 uint16_t
#define TYPE_RET27 uint16_t
#define TYPE_RET28 uint16_t
#define TYPE_RET29 uint16_t
#define TYPE_RET3 uint16_t
#define TYPE_RET30 uint16_t
#define TYPE_RET31 uint16_t
#define TYPE_RET4 uint16_t
#define TYPE_RET5 uint16_t
#define TYPE_RET6 uint16_t
#define TYPE_RET7 uint16_t
#define TYPE_RET8 uint16_t
#define TYPE_RET9 uint16_t
#define TYPE_RXBUF uint8_t
#define TYPE_RXBUF0 uint8_t
#define TYPE_RXBUF1 uint8_t
#define TYPE_RXBUF_0 uint8_t
#define TYPE_RXBUF_1 uint8_t
#define TYPE_SCFI0 uint8_t
#define TYPE_SCFI1 uint8_t
#define TYPE_SCFQCTL uint8_t
#define TYPE_SD16CCTL0 uint16_t
#define TYPE_SD16CCTL1 uint16_t
#define TYPE_SD16CCTL2 uint16_t
#define TYPE_SD16CTL uint16_t
#define TYPE_SD16INCTL0 uint8_t
#define TYPE_SD16INCTL1 uint8_t
#define TYPE_SD16INCTL2 uint8_t
#define TYPE_SD16IV uint16_t
#define TYPE_SD16MEM0 uint16_t
#define TYPE_SD16MEM1 uint16_t
#define TYPE_SD16MEM2 uint16_t
#define TYPE_SD16PRE0 uint8_t
#define TYPE_SD16PRE1 uint8_t
#define TYPE_SD16PRE2 uint8_t
#define TYPE_SIFCNT uint16_t
#define TYPE_SIFCTL0 uint16_t
#define TYPE_SIFCTL1 uint16_t
#define TYPE_SIFCTL2 uint16_t
#define TYPE_SIFCTL3 uint16_t
#define TYPE_SIFCTL4 uint16_t
#define TYPE_SIFDACR0 uint16_t
#define TYPE_SIFDACR1 uint16_t
#define TYPE_SIFDACR2 uint16_t
#define TYPE_SIFDACR3 uint16_t
#define TYPE_SIFDACR4 uint16_t
#define TYPE_SIFDACR5 uint16_t
#define TYPE_SIFDACR6 uint16_t
#define TYPE_SIFDACR7 uint16_t
#define TYPE_SIFDEBUG uint16_t
#define TYPE_SIFTPSMV uint16_t
#define TYPE_SIFTSM0 uint16_t
#define TYPE_SIFTSM1 uint16_t
#define TYPE_SIFTSM10 uint16_t
#define TYPE_SIFTSM11 uint16_t
#define TYPE_SIFTSM12 uint16_t
#define TYPE_SIFTSM13 uint16_t
#define TYPE_SIFTSM14 uint16_t
#define TYPE_SIFTSM15 uint16_t
#define TYPE_SIFTSM16 uint16_t
#define TYPE_SIFTSM17 uint16_t
#define TYPE_SIFTSM18 uint16_t
#define TYPE_SIFTSM19 uint16_t
#define TYPE_SIFTSM2 uint16_t
#define TYPE_SIFTSM20 uint16_t
#define TYPE_SIFTSM21 uint16_t
#define TYPE_SIFTSM22 uint16_t
#define TYPE_SIFTSM23 uint16_t
#define TYPE_SIFTSM3 uint16_t
#define TYPE_SIFTSM4 uint16_t
#define TYPE_SIFTSM5 uint16_t
#define TYPE_SIFTSM6 uint16_t
#define TYPE_SIFTSM7 uint16_t
#define TYPE_SIFTSM8 uint16_t
#define TYPE_SIFTSM9 uint16_t
#define TYPE_SUMEXT uint16_t
#define TYPE_SVSCTL uint8_t
#define TYPE_TA0CCR0 uint16_t
#define TYPE_TA0CCR1 uint16_t
#define TYPE_TA0CCR2 uint16_t
#define TYPE_TA0CCTL0 uint16_t
#define TYPE_TA0CCTL1 uint16_t
#define TYPE_TA0CCTL2 uint16_t
#define TYPE_TA0CTL uint16_t
#define TYPE_TA0IV uint16_t
#define TYPE_TA0R uint16_t
#define TYPE_TA1CCR0 uint16_t
#define TYPE_TA1CCR1 uint16_t
#define TYPE_TA1CCR2 uint16_t
#define TYPE_TA1CCR3 uint16_t
#define TYPE_TA1CCR4 uint16_t
#define TYPE_TA1CCTL0 uint16_t
#define TYPE_TA1CCTL1 uint16_t
#define TYPE_TA1CCTL2 uint16_t
#define TYPE_TA1CCTL3 uint16_t
#define TYPE_TA1CCTL4 uint16_t
#define TYPE_TA1CTL uint16_t
#define TYPE_TA1IV uint16_t
#define TYPE_TACCR0 uint16_t
#define TYPE_TACCR1 uint16_t
#define TYPE_TACCR2 uint16_t
#define TYPE_TACCTL0 uint16_t
#define TYPE_TACCTL1 uint16_t
#define TYPE_TACCTL2 uint16_t
#define TYPE_TACTL uint16_t
#define TYPE_TAIV uint16_t
#define TYPE_TAR uint16_t
#define TYPE_TAR1 uint16_t
#define TYPE_TBCCR0 uint16_t
#define TYPE_TBCCR1 uint16_t
#define TYPE_TBCCR2 uint16_t
#define TYPE_TBCCR3 uint16_t
#define TYPE_TBCCR4 uint16_t
#define TYPE_TBCCR5 uint16_t
#define TYPE_TBCCR6 uint16_t
#define TYPE_TBCCTL0 uint16_t
#define TYPE_TBCCTL1 uint16_t
#define TYPE_TBCCTL2 uint16_t
#define TYPE_TBCCTL3 uint16_t
#define TYPE_TBCCTL4 uint16_t
#define TYPE_TBCCTL5 uint16_t
#define TYPE_TBCCTL6 uint16_t
#define TYPE_TBCTL uint16_t
#define TYPE_TBIV uint16_t
#define TYPE_TBR uint16_t
#define TYPE_TCCTL uint8_t
#define TYPE_TPCNT1 uint8_t
#define TYPE_TPCNT2 uint8_t
#define TYPE_TPCTL uint8_t
#define TYPE_TPD uint8_t
#define TYPE_TPE uint8_t
#define TYPE_TXBUF uint8_t
#define TYPE_TXBUF0 uint8_t
#define TYPE_TXBUF1 uint8_t
#define TYPE_TXBUF_0 uint8_t
#define TYPE_TXBUF_1 uint8_t
#define TYPE_U0BR0 uint8_t
#define TYPE_U0BR1 uint8_t
#define TYPE_U0CTL uint8_t
#define TYPE_U0MCTL uint8_t
#define TYPE_U0RCTL uint8_t
#define TYPE_U0RXBUF uint8_t
#define TYPE_U0TCTL uint8_t
#define TYPE_U0TXBUF uint8_t
#define TYPE_U1BR0 uint8_t
#define TYPE_U1BR1 uint8_t
#define TYPE_U1CTL uint8_t
#define TYPE_U1MCTL uint8_t
#define TYPE_U1RCTL uint8_t
#define TYPE_U1RXBUF uint8_t
#define TYPE_U1TCTL uint8_t
#define TYPE_U1TXBUF uint8_t
#define TYPE_UBR0 uint8_t
#define TYPE_UBR00 uint8_t
#define TYPE_UBR01 uint8_t
#define TYPE_UBR0_0 uint8_t
#define TYPE_UBR0_1 uint8_t
#define TYPE_UBR1 uint8_t
#define TYPE_UBR10 uint8_t
#define TYPE_UBR11 uint8_t
#define TYPE_UBR1_0 uint8_t
#define TYPE_UBR1_1 uint8_t
#define TYPE_UCTL uint8_t
#define TYPE_UCTL0 uint8_t
#define TYPE_UCTL1 uint8_t
#define TYPE_UCTL_0 uint8_t
#define TYPE_UCTL_1 uint8_t
#define TYPE_UMCTL uint8_t
#define TYPE_UMCTL0 uint8_t
#define TYPE_UMCTL1 uint8_t
#define TYPE_UMCTL_0 uint8_t
#define TYPE_UMCTL_1 uint8_t
#define TYPE_URCTL uint8_t
#define TYPE_URCTL0 uint8_t
#define TYPE_URCTL1 uint8_t
#define TYPE_URCTL_0 uint8_t
#define TYPE_URCTL_1 uint8_t
#define TYPE_UTCTL uint8_t
#define TYPE_UTCTL0 uint8_t
#define TYPE_UTCTL1 uint8_t
#define TYPE_UTCTL_0 uint8_t
#define TYPE_UTCTL_1 uint8_t
#define TYPE_WDTCTL uint16_t
#endif//_H_msp430regtypes_h
|
tinyos-io/tinyos-3.x-contrib | berkeley/apps/BlinkSPOT/EnergyMsg.h | enum
{
AM_ENERGYMSG = 13,
};
typedef struct EnergyMsg
{
uint16_t src;
uint32_t base;
uint32_t energy;
} EnergyMsg_t;
|
tinyos-io/tinyos-3.x-contrib | diku/freescale/tos/chips/hcs08/uart/Hcs08Uart.h | /* Copyright (c) 2007, <NAME> <<EMAIL>>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the University of Copenhagen nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
@author <NAME> <<EMAIL>>
*/
#ifndef _H_Hsc08Uart_h
#define _H_Hsc08Uart_h
enum {
//The SCIxBD register is only 13 bits
HCS08UART_BD_MAX = 8191,
//SCIxC1
HCS08UART_LOOPS = 0x80,
HCS08UART_SCISWAI = 0x40,
HCS08UART_RSRC = 0x20,
HCS08UART_M = 0x10,
HCS08UART_WAKE = 0x8,
HCS08UART_ILT = 0x4,
HCS08UART_PE = 0x2,
HCS08UART_PT = 0x1,
//SCIxC2
HCS08UART_TIE = 0x80,
HCS08UART_TCIE = 0x40,
HCS08UART_RIE = 0x20,
HCS08UART_ILIE = 0x10,
HCS08UART_TE = 0x8,
HCS08UART_RE = 0x4,
HCS08UART_RWU = 0x2,
HCS08UART_SBK = 0x1,
//SCIxC3
HCS08UART_R8 = 0x80,
HCS08UART_T8 = 0x40,
HCS08UART_TXDIR = 0x20,
HCS08UART_ORIE = 0x8,
HCS08UART_NEIE = 0x4,
HCS08UART_FEIE = 0x2,
HCS08UART_PEIE = 0x1,
//SCIxS1
HCS08UART_TDRE = 0x80,
HCS08UART_TC = 0x40,
HCS08UART_RDRF = 0x20,
HCS08UART_IDLE = 0x10,
HCS08UART_OR = 0x8,
HCS08UART_NF = 0x4,
HCS08UART_FE = 0x2,
HCS08UART_PF = 0x1,
//SCIxS2
HCS08UART_RAF = 0x1,
};
#endif//_H_Hsc08Uart_h |
tinyos-io/tinyos-3.x-contrib | kth/tkn154-gts/tos/platforms/telosb/mac/tkn154/TKN154_platform.h | <reponame>tinyos-io/tinyos-3.x-contrib
/*
* Copyright (c) 2008, Technische Universitaet Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitaet Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* - Revision -------------------------------------------------------------
* $Revision: 1.2 $
* $Date: 2011/04/20 08:49:20 $
* @author <NAME> <<EMAIL>>
* ========================================================================
*/
/**
* @author <NAME> <<EMAIL>>
* @author <NAME> <<EMAIL>>
* @modified 2010/10/01
*/
#ifndef __TKN154_platform_H
#define __TKN154_platform_H
/****************************************************
* The following constants define guard times on Tmote Sky / TelosB.
* All values are in symbol time (1 symbol = 16 us) and assume the
* default system configuration (MCLK running at 4 MHz)
*/
enum {
// the expected maximum time between calling a transmit() operation and
// the radio putting the first byte on the channel assuming no CSMA-CA
IEEE154_RADIO_TX_DELAY = 200,
// the expected maximum time between calling a receive() operation and the
// the radio actually being put in receive mode
IEEE154_RADIO_RX_DELAY = 200,
// defines at what time the MAC payload for a beacon frame is assembled before
// the next scheduled beacon transmission time; the value must be smaller than
// the beacon interval plus the time for preparing the Tx operation
BEACON_PAYLOAD_UPDATE_INTERVAL = 2500,
};
// Defines the time to power the CC2420 radio from "Power Down" mode to "Idle"
// mode. The actual start up time of the oscillator is 860 us (with default
// capacitor, see CC2420 datasheet), but our constant must also include
// software latency (task posting, etc.) + shutting the radio down
// -> we keep it conservative, otherwise we may lose beacons
// NOTE: if this constant is not defined, the radio will never be powered down
// during inactive period, but always stay in idle (which consumes more energy).
#endif
|
tinyos-io/tinyos-3.x-contrib | shimmer/apps/SimpleAccelGyro/SimpleAccelGyro.h | #ifndef SYNCD_TIMING_H
#define SYNCD_TIMING_H
#include "AM.h"
typedef nx_struct simple_send_msg {
nx_uint16_t counter;
nx_uint8_t message[TOSH_DATA_LENGTH-2]; // 114 bytes - 2 byte counter
} simple_send_msg_t;
enum {
BASE_STATION_ADDRESS = 0,
AM_SYNCD_TIMING_MSG = 0x7F,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | diku/common/lib/compression/huffman.h | <gh_stars>1-10
#define CODESET "../../tools/compression/huffman/huffman_codes.h"
#include "../../tools/compression/huffman/huffman_comp.c"
|
tinyos-io/tinyos-3.x-contrib | cotsbots/tos/lib/SlotMsg.h | <filename>cotsbots/tos/lib/SlotMsg.h
/*
* Author: <NAME>
* Date last modified: 10/2/2003
*
*/
// The message type for Slot-Ring Protocol Management (SlotManager)
/**
* @author <NAME>
*/
enum {
MAX_NODES_IN_RING = 8
};
typedef struct SlotMsg {
int16_t src;
uint8_t sync;
int16_t table[MAX_NODES_IN_RING];
int16_t tickLength; // in milliseconds
} SlotMsg;
typedef struct NewTickMsg {
int16_t tickLength; // in milliseconds
} NewTickMsg;
typedef struct StartMsg {
int16_t tickLength;
int16_t numPackets;
} StartMsg;
typedef struct TestMsg {
int16_t src;
uint16_t seqno;
} TestMsg;
enum {
AM_SLOTMSG = 131,
AM_TICKMSG = 132,
AM_TESTMSG = 133,
AM_STARTMSG = 134
};
|
tinyos-io/tinyos-3.x-contrib | timetossim/tinyos-2.x/tools/cgram/examples/check_time3.c | inline int check_time(sim_time_t avr_time){
//printf("%lld",sim_time());
sim_time_t temp=((sim_time_t)avr_time * sim_ticks_per_sec());
temp /= 7372800ULL;
sim_set_time(sim_time()+temp);
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/client/sfaccess/tinystream.h | <filename>eon/eon/src/client/sfaccess/tinystream.h
#ifndef _TINYSTREAM_H_
#define _TINYSTREAM_H_
#include "teloscomm.h"
#include "tinyrely.h"
int tinystream_init(const char* host, int port);
int tinystream_close();
int tinystream_connect(int addr);
int tinystream_close_connection(int id);
int tinystream_read(int id, uint8_t *buf, int length);
int tinystream_write(int id, const uint8_t *buf, int length);
//allow you to peek at the next byte in the buffer
int tinystream_peek(int id, uint8_t *byte);
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/util/collect/platform.h | <gh_stars>1-10
#ifndef PLATFORM_H
#define PLATFORM_H
#define AVRMOTE 1
#define TELOS 2
#define MICAZ 3
#define EYES 4
#define TINYNODE 5
#if !defined(__CYGWIN__)
#include <inttypes.h>
#else //__CYGWIN
#include <sys/types.h>
// Earlier cygwins do not define uint8_t & co
#ifndef _STDINT_H
#ifndef __uint32_t_defined
#define __uint32_t_defined
typedef u_int32_t uint32_t;
#endif
#endif
#endif //__CYGWIN
extern uint32_t platform;
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/tos/chips/bc4/d_bt.h | //
// Date init 14.12.2004
//
// Revision date $Date: 2007/12/18 21:48:12 $
//
// Filename $Workfile:: d_bt.h $
//
// Version $Revision: 1.1 $
//
// Archive $Archive:: /LMS2006/Sys01/Main/Firmware/Source/d_bt.h $
//
// Platform C
//
#ifndef D_BT_H
#define D_BT_H
#define STREAM_MODE 1
#define CMD_MODE 2
#endif
|
tinyos-io/tinyos-3.x-contrib | usc/senzip/SenZip_v1.0/SenZipApp/SenZipApp.h | #ifndef SENZIPAPP_H
#define SENZIPAPP_H
#define BASE_ID 127
#define SINK_NODE_ID 0
#define NUM_MEASUREMENTS 3
#define SAMPLE_PERIOD 2000
enum {
AM_BASE_MSG = 37,
};
enum {
START = 1,
};
typedef nx_struct base_msg {
nx_int16_t data[NUM_MEASUREMENTS];
nx_uint8_t type;
nx_uint8_t src;
nx_uint8_t parent;
nx_uint8_t seq;
nx_int16_t max;
nx_int16_t min;
} base_msg_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | osu/platforms/psi/chips/msp430/usart/Msp430PSI.h | /**
* Copyright (c) 2007 - The Ohio State University.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs, and the author attribution appear in all copies of this
* software.
*
* IN NO EVENT SHALL THE OHIO STATE UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE OHIO STATE
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE OHIO STATE UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE OHIO STATE UNIVERSITY HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
@author
<NAME> <<EMAIL>>
<NAME> <<EMAIL>>
$Date: 2007/10/20 18:20:54 $
Porting TinyOS to Intel PSI motes
*/
#ifndef _H_Msp430PSI_h
#define _H_Msp430PSI_h
#define SPI_CS1_INT 0x08
#define SPI_NIRQ 0x10
#define STATE_SEND 1
#define STATE_RECV 2
#endif
|
tinyos-io/tinyos-3.x-contrib | csm/tos/lib/tossim/SerialPacket.h | <filename>csm/tos/lib/tossim/SerialPacket.h
/*
* "Copyright (c) 2005 Stanford University. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the following two paragraphs and the author appear in all
* copies of this software.
*
* IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* STANFORD UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND STANFORD UNIVERSITY
* HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS."
*/
/**
*
* Injecting packets into TOSSIM.
*
* @author <NAME>
* @author <NAME>
* @date July 15 2007
*/
#ifndef SERIAL_PACKET_H_INCLUDED
#define SERIAL_PACKET_H_INCLUDED
#include <sim_serial_packet.h>
class SerialPacket {
public:
SerialPacket();
SerialPacket(sim_serial_packet_t* msg);
~SerialPacket();
void setDestination(int dest);
int destination();
void setLength(int len);
int length();
void setType(int type);
int type();
char* data();
void setData(char* data, int len);
int maxLength();
sim_serial_packet_t* getPacket();
void deliver(int node, long long int t);
void deliverNow(int node);
private:
int allocated;
sim_serial_packet_t* msgPtr;
};
#endif
|
tinyos-io/tinyos-3.x-contrib | cedt/tos/lib/tossim/sim_energy_estimate.c | /**
* "Copyright (c) 2007 CENTRE FOR ELECTRONICS AND DESIGN TECHNOLOGY,IISc.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the following two paragraphs and the author appear in all
* copies of this software.
*
* IN NO EVENT SHALL CENTRE FOR ELECTRONICS AND DESIGN TECHNOLOGY,IISc BE LIABLE TO
* ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF CENTRE FOR ELECTRONICS AND DESIGN TECHNOLOGY,IISc HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* CENTRE FOR ELECTRONICS AND DESIGN TECHNOLOGY,IISc SPECIFICALLY DISCLAIMS
* ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND CENTRE FOR ELECTRONICS
* AND DESIGN TECHNOLOGY,IISc HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/
/**
*
* @author <NAME>
* @author <NAME>
*/
#include <stdio.h>
#include <tos.h>
#include <sim_energy_estimate.h>
sim_energy_t node_energy[TOSSIM_MAX_NODES];
void sim_energy_estimator_init()
{
int i;
//printf("Initializing node_power variables to zero\n");
for (i=0; i< TOSSIM_MAX_NODES; i++) {
node_energy[i].MCUEnergy.idle = 0.0;
node_energy[i].MCUEnergy.adc = 0.0;
node_energy[i].MCUEnergy.extStandby = 0.0;
node_energy[i].MCUEnergy.save = 0.0;
node_energy[i].MCUEnergy.standby = 0.0;
node_energy[i].MCUEnergy.down = 0.0;
node_energy[i].MCUEnergy.on = 0.0;
node_energy[i].MCUEnergy.total = 0.0;
node_energy[i].LedEnergy.led0 = 0.0;
node_energy[i].LedEnergy.led1 = 0.0;
node_energy[i].LedEnergy.led2 = 0.0;
node_energy[i].LedEnergy.total = 0.0;
node_energy[i].RadioEnergy.core = 0.0;
node_energy[i].RadioEnergy.coreBias = 0.0;
node_energy[i].RadioEnergy.coreBiasSyn = 0.0;
node_energy[i].RadioEnergy.tx = 0.0;
node_energy[i].RadioEnergy.rx = 0.0;
node_energy[i].RadioEnergy.rxPacket = 0.0;
node_energy[i].RadioEnergy.total = 0.0;
node_energy[i].MemEnergy.write = 0.0;
node_energy[i].MemEnergy.read = 0.0;
node_energy[i].MemEnergy.total = 0.0;
node_energy[i].total = 0.0;
}
}
void sim_update_cpuIdleEnergy(double val) {
node_energy[sim_node()].MCUEnergy.idle += val;
node_energy[sim_node()].MCUEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cpuAdcEnergy(double val) {
node_energy[sim_node()].MCUEnergy.adc += val;
node_energy[sim_node()].MCUEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cpuExtStandbyEnergy(double val) {
node_energy[sim_node()].MCUEnergy.extStandby += val;
node_energy[sim_node()].MCUEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cpuSaveEnergy(double val) {
node_energy[sim_node()].MCUEnergy.save += val;
node_energy[sim_node()].MCUEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cpuStandbyEnergy(double val) {
node_energy[sim_node()].MCUEnergy.standby += val;
node_energy[sim_node()].MCUEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cpuPowerDownEnergy(double val) {
node_energy[sim_node()].MCUEnergy.down += val;
node_energy[sim_node()].MCUEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cpuOnEnergy(double val) {
node_energy[sim_node()].MCUEnergy.on += val;
}
void sim_update_led0Energy(double val) {
node_energy[sim_node()].LedEnergy.led0 += val;
node_energy[sim_node()].LedEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_led1Energy(double val) {
node_energy[sim_node()].LedEnergy.led1 += val;
node_energy[sim_node()].LedEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_led2Energy(double val) {
node_energy[sim_node()].LedEnergy.led2 += val;
node_energy[sim_node()].LedEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cyrsOscEnergy(double val) {
node_energy[sim_node()].RadioEnergy.core += val;
node_energy[sim_node()].RadioEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cyrsOscBiasEnergy(double val) {
node_energy[sim_node()].RadioEnergy.coreBias += val;
node_energy[sim_node()].RadioEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_cyrsOscBiasSynEnergy(double val) {
node_energy[sim_node()].RadioEnergy.coreBiasSyn += val;
node_energy[sim_node()].RadioEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_radioTxEnergy(double val) {
node_energy[sim_node()].RadioEnergy.tx += val;
node_energy[sim_node()].RadioEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_radioRxEnergy(double val) {
node_energy[sim_node()].RadioEnergy.rx += val;
node_energy[sim_node()].RadioEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_radioRxPacketEnergy(double val) {
node_energy[sim_node()].RadioEnergy.rxPacket += val;
}
void sim_update_memWriteEnergy(double val) {
node_energy[sim_node()].MemEnergy.write += val;
node_energy[sim_node()].MemEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_update_memReadEnergy(double val) {
node_energy[sim_node()].MemEnergy.read += val;
node_energy[sim_node()].MemEnergy.total += val;
node_energy[sim_node()].total += val;
}
void sim_node_energy(int node) {
char str[20];
FILE *fp;
sprintf(str,"Node_%d_Energy",node);
fp = fopen(str,"w");
if(fp == NULL) {
fprintf(fp,"ERROR in writing the Energy to a file\n");
return;
}
fprintf(fp,"Node %d Energy Status\n",node);
fprintf(fp,"***************************************\n");
fprintf(fp,"Total Node Energy = %4.8f J\n",node_energy[node].total);
fprintf(fp,"Total MCU Energy = %4.8f J\n",node_energy[node].MCUEnergy.total);
fprintf(fp,"Total Leds Energy = %4.8f J\n",node_energy[node].LedEnergy.total);
fprintf(fp,"Total Radio Energy = %4.8f J\n",node_energy[node].RadioEnergy.total);
fprintf(fp,"Total Flash Energy = %4.8f J\n",node_energy[node].MemEnergy.total);
fprintf(fp,"****************************************\n");
fprintf(fp,"Energy spent in Detail \n");
fprintf(fp,"------ AT128 MCU Energy-----------\n");
// fprintf(fp,"MCUPower.Active = %4.8f J\n",node_energy[node].MCUEnergy.on);
fprintf(fp,"Idle \t\t= %4.8f J\n",node_energy[node].MCUEnergy.idle);
fprintf(fp,"ADC_NR \t\t= %4.8f J\n",node_energy[node].MCUEnergy.adc);
fprintf(fp,"ExtStandby \t= %4.8f J\n",node_energy[node].MCUEnergy.extStandby);
fprintf(fp,"Save \t\t= %4.8f J\n",node_energy[node].MCUEnergy.save);
fprintf(fp,"Standby \t= %4.8f J\n",node_energy[node].MCUEnergy.standby);
fprintf(fp,"Down \t\t= %4.8f J\n",node_energy[node].MCUEnergy.down);
fprintf(fp,"-----------Leds Energy-----------\n");
fprintf(fp,"led0 \t\t= %4.8f J\n",node_energy[node].LedEnergy.led0);
fprintf(fp,"led1 \t\t= %4.8f J\n",node_energy[node].LedEnergy.led1);
fprintf(fp,"led2 \t\t= %4.8f J\n",node_energy[node].LedEnergy.led2);
fprintf(fp,"--------CC1000 Radio Energy--------\n");
fprintf(fp,"Core \t\t= %4.8f J\n",node_energy[node].RadioEnergy.core);
fprintf(fp,"CoreBias \t= %4.8f J\n",node_energy[node].RadioEnergy.coreBias);
fprintf(fp,"CoreBiasSyn \t= %4.8f J\n",node_energy[node].RadioEnergy.coreBiasSyn);
fprintf(fp,"Tx \t\t= %4.8f J\n",node_energy[node].RadioEnergy.tx);
fprintf(fp,"Rx(Total) \t= %4.8f J\n",node_energy[node].RadioEnergy.rx);
fprintf(fp,"Rx(Packet Only) = %4.8f J\n",node_energy[node].RadioEnergy.rxPacket);
fprintf(fp,"--------- AT45DB Flash -------------\n");
fprintf(fp,"Read \t\t= %4.8f J\n",node_energy[node].MemEnergy.read);
fprintf(fp,"Write \t\t= %4.8f J\n",node_energy[node].MemEnergy.write);
fprintf(fp,"****************************************\n");
fclose(fp);
}
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/tinyos2/fluxconsumptionpredictor.h | #ifndef FLUXSOURCEPREDICTOR_H_INCLUDED
#define FLUXSOURCEPREDICTOR_H_INCLUDED
int32_t predict_consumption(uint8_t hours, uint8_t state);
{
return 5; //TODO come back to this
}
#endif
|
tinyos-io/tinyos-3.x-contrib | berkeley/acme/tos/sensorboards/ACme/ADE7753.h | /**********************
* types and register defs for ADE7753 energy meter
* @author <NAME> <<EMAIL>>
*/
// Register addresses
#define ADE7753_GAIN 0x0F
#define ADE7753_AENERGY 0x02
#define ADE7753_RAENERGY 0x03
#define ADE7753_MODE 0x09
#define ADE7753_IRMS 0x16
// Register values
// Gain for CH2 is 2 and CH1 is 16 at 0.5 scale
#define ADE7753_GAIN_VAL 0x24
// MSB enabled for no-creep
#define ADE7753_MODE_VAL 0x800C
|
tinyos-io/tinyos-3.x-contrib | eon/apps/server-e/mImpl.c | <gh_stars>1-10
#include "mImpl.h"
#include "mImpl.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
const uint8_t minPathState[NUMPATHS] =
{ STATE_BASE, STATE_BASE, STATE_BASE, STATE_BASE, STATE_BASE, STATE_BASE,
STATE_BASE, STATE_TEXT, STATE_TEXT, STATE_TEXT, STATE_TEXT, STATE_IMAGE_THUMB, STATE_IMAGE_THUMB,
STATE_IMAGE_THUMB, STATE_IMAGE_THUMB, STATE_IMAGE_THUMB, STATE_IMAGE_THUMB, STATE_IMAGE_THUMB,
STATE_IMAGE_THUMB };
#include "mImpl.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
int socket_in_use[1024];
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
void closeSocket(int socket) {
close(socket);
if (socket > -1) {
if (socket < 1024)
socket_in_use[socket] = 2;
else
printf("ERR, socket to large\n");
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
void init (int argc, char **argv)
{
int i;
for (i=0; i<1024; i++)
socket_in_use[i] = 2;
}
// IN: [uint16_t connid]
// OUT: []
int CloseZigbee (CloseZigbee_in * in, CloseZigbee_out * out)
{
return 0;
}
// IN: [uint16_t connid, uint16_t port_num, uint8_t type, request_t request]
// OUT: []
int StargatePage (StargatePage_in * in, StargatePage_out * out)
{
return 0;
}
// IN: [uint16_t connid, int socket]
// OUT: [uint16_t connid]
int CloseWifi (CloseWifi_in * in, CloseWifi_out * out)
{
closeSocket(in->socket);
return 0;
}
// IN: [uint16_t connid, uint8_t type, request_t request]
// OUT: [uint16_t connid, uint8_t type, char* data, int size]
int ReadText (ReadText_in * in, ReadText_out * out)
{
out->connid = in->connid;
out->type = in->type;
int file_size = -1; // file size in bytes -1 by default
// first we get the file size...
//struct stat *buf = (struct stat *) malloc (sizeof(struct stat));
struct stat buf;
stat(in->request, &buf);
file_size = buf.st_size;
if (file_size <= 0)
{
printf("SrvImage: error... invalid file size\n");
free (buf);
return -1;
}
out->size = file_size;
// open the file
int fd = open(in->request, O_RDONLY);
// now map the file
out->data = mmap(0, file_size, PROT_READ, MAP_SHARED, fd, 0);
close(fd);
return 0;
}
// IN: [uint16_t connid, uint8_t type, request_t request]
void SorryErr (ReadText_in * in, int err)
{
}
// IN: [uint16_t connid, uint8_t type, char* data, int size]
// OUT: [uint16_t connid]
int SendZigbee (SendZigbee_in * in, SendZigbee_out * out)
{
out->connid = in->connid;
return 0;
}
// IN: [uint16_t connid, uint16_t port_num, uint8_t type, request_t request]
// OUT: [uint16_t connid, int socket, uint8_t type, char* filename]
int StargateListen (StargateListen_in * in, StargateListen_out * out)
{
out->connid = in->connid;
out->type = in->type;
int bind_socket = -1;
out->connid = in->connid;
out->type = in->type;
out->filename = in->request;
struct sockaddr_in server_addr;
bind_socket = socket(AF_INET, SOCK_STREAM, 0);
int val = 1;
if (setsockopt(bind_socket, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0)
{
perror("setsockopt: ");
exit(1);
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = in->port_num;
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
if ((bind(bind_socket,(struct sockaddr*) &server_addr, sizeof(struct sockaddr))) < 0) {
perror("Bind: ");
return -1;
}
if (listen(bind_socket,50000)<0) {
perror("Listen : ");
return -1;
}
printf ("listening on address %s, port %d\n", server_addr.sin_addr.s_addr, in->port_num);
struct timeval select_timeout;
select_timeout.tv_sec = 0;
select_timeout.tv_usec = 10*1000; // Half a second... too short?
fd_set read_fds;
FD_ZERO(&read_fds);
FD_SET(bind_socket, &read_fds);
int max = bind_socket;
int sel;
if ( sel=select(max+1, &read_fds, NULL, NULL, &select_timeout) > 0)
{
socklen_t length = sizeof(struct sockaddr);
out->socket = accept(bind_socket, (struct sockaddr *)&server_addr,&length);
int optval = 1;
if (setsockopt (out->socket, SOL_TCP, TCP_NODELAY, &optval, sizeof (optval)) < 0)
{
perror("setsockopt");
}
socket_in_use[out->socket] = 1;
}
else
{
return -1;
}
return 0;
return 0;
}
// IN: [uint16_t connid, int socket, uint8_t type, char* filename]
// OUT: [uint16_t connid, int socket, uint8_t type, char* data, int size]
int ReadData (ReadData_in * in, ReadData_out * out)
{
out->connid = in->connid;
out->type = in->type;
out->socket = in->socket;
out->connid = in->connid;
out->type = in->type;
int file_size = -1; // file size in bytes -1 by default
// first we get the file size...
//struct stat *buf = (struct stat *) malloc (sizeof(struct stat));
struct stat buf;
stat(in->filename, &buf);
file_size = buf.st_size;
if (file_size <= 0)
{
printf("SrvImage: error... invalid file size\n");
free (buf);
return -1;
}
out->size = file_size;
// open the file
int fd = open(in->filename, O_RDONLY);
// now map the file
out->data = mmap(0, file_size, PROT_READ, MAP_SHARED, fd, 0);
return 0;
}
// IN: [uint16_t connid, int socket, uint8_t type, char* data, int size]
// OUT: [uint16_t connid, int socket]
int SendWifi (SendWifi_in * in, SendWifi_out * out)
{
out->connid = in->connid;
out->socket = in->socket;
// now we send...
char *content = "image/jpeg";
char hdrs[256];
sprintf(hdrs, "HTTP/1.1 200 OK\r\nContent-type: %s\r\nServer: eFlux 0.1\r\nConnection: close\r\nContent-Length: %d\r\n\r\n",
content, in->size);
int header_len = strlen(hdrs);
int written = write(in->socket, hdrs, header_len);
while (written < header_len)
{
if (written < 0)
{
perror("Writing");
closeSocket(in->socket);
//int munmap(void *start, size_t length);
munmap(in->data, in->size);
return -1;
}
written += write(in->socket,
hdrs+written,
header_len-written);
}
written = write(in->socket, in->data, in->size);
while (written < in->size)
{
if (written < 0)
{
perror("Writing");
closeSocket(in->socket);
munmap(in->data, in->size);
return -1;
}
written += write(in->socket,
in->data + written,
in->size - written);
}
munmap(in->data, in->size);
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | stanford-sing/s4-tinyos-2.x/tos/lib/bvr/topology-old.h | /* Topology file. Ids 1 to 5 are beacons.
* Parameters: n:256 nodes
* Author: <NAME>
*/
#ifndef TOPOLOGY_H
#define TOPOLOGY_H
enum {
N_NODES = 256,
N_ROOT_BEACONS = 5,
DIAMETER = 10,
INVALID_BEACON_ID = 0xff,
};
uint8_t hc_root_beacon_id[N_NODES] = {
0xff, 0, 1, 2, 3, 4, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
#endif
|
tinyos-io/tinyos-3.x-contrib | antlab-polimi/sensors/sdram.h | <gh_stars>1-10
/*
* Copyright (c) 2006 Stanford University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the Stanford University nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author <NAME> (<EMAIL>)
*/
/* modified for Robbie's new SDRAM section
* RMK
*/
#ifndef _SDRAM_H_
#define _SDRAM_H_
#define VGA_SIZE_RGB (640*480*2)
#define QVGA_SIZE_YUV (320*240*2)
#define DPCM_SIZE (320*240)
uint32_t base_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
uint32_t jpeg_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
uint32_t buf1_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
uint32_t buf2_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
uint32_t buf3_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
#define BASE_FRAME_ADDRESS base_f
#define JPEG_FRAME_ADDRESS jpeg_f
#define BUF1_FRAME_ADDRESS buf1_f
#define BUF2_FRAME_ADDRESS buf2_f
#define BUF3_FRAME_ADDRESS buf3_f
/*
* DPCM Structures
*/
// blocco buffer 1
uint32_t base1_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
uint32_t dpcm1_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
#define BASE1_FRAME_ADDRESS base1_f
#define DPCM1_FRAME_ADDRESS dpcm1_f
// blocco buffer 2
uint32_t base2_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
uint32_t dpcm2_f[VGA_SIZE_RGB] __attribute__((section(".sdram")));
#define BASE2_FRAME_ADDRESS base2_f
#define DPCM2_FRAME_ADDRESS dpcm2_f
// blocco buffer 3
uint32_t base3_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm3_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE3_FRAME_ADDRESS base3_f
#define DPCM3_FRAME_ADDRESS dpcm3_f
// blocco buffer 4
uint32_t base4_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm4_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE4_FRAME_ADDRESS base4_f
#define DPCM4_FRAME_ADDRESS dpcm4_f
/*
// blocco buffer 5
uint32_t base5_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm5_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE5_FRAME_ADDRESS base5_f
#define DPCM5_FRAME_ADDRESS dpcm5_f
// blocco buffer 6
uint32_t base6_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm6_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE6_FRAME_ADDRESS base6_f
#define DPCM6_FRAME_ADDRESS dpcm6_f
// blocco buffer 7
uint32_t base7_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm7_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE7_FRAME_ADDRESS base7_f
#define DPCM7_FRAME_ADDRESS dpcm7_f
// blocco buffer 8
uint32_t base8_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm8_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE8_FRAME_ADDRESS base8_f
#define DPCM8_FRAME_ADDRESS dpcm8_f
// blocco buffer 9
uint32_t base9_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm9_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE9_FRAME_ADDRESS base9_f
#define DPCM9_FRAME_ADDRESS dpcm9_f
// blocco buffer 10
uint32_t base10_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm10_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE10_FRAME_ADDRESS base10_f
#define DPCM10_FRAME_ADDRESS dpcm10_f
// blocco buffer 11
uint32_t base11_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm11_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE11_FRAME_ADDRESS base11_f
#define DPCM11_FRAME_ADDRESS dpcm11_f
// blocco buffer 12
uint32_t base12_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm12_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE12_FRAME_ADDRESS base12_f
#define DPCM12_FRAME_ADDRESS dpcm12_f
// blocco buffer 13
uint32_t base13_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm13_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE13_FRAME_ADDRESS base13_f
#define DPCM13_FRAME_ADDRESS dpcm13_f
// blocco buffer 14
uint32_t base14_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm14_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE14_FRAME_ADDRESS base14_f
#define DPCM14_FRAME_ADDRESS dpcm14_f
// blocco buffer 15
uint32_t base15_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm15_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE15_FRAME_ADDRESS base15_f
#define DPCM15_FRAME_ADDRESS dpcm15_f
// blocco buffer 16
uint32_t base16_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm16_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE16_FRAME_ADDRESS base16_f
#define DPCM16_FRAME_ADDRESS dpcm16_f
// blocco buffer 17
uint32_t base17_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm17_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE17_FRAME_ADDRESS base17_f
#define DPCM17_FRAME_ADDRESS dpcm17_f
// blocco buffer 18
uint32_t base18_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm18_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE18_FRAME_ADDRESS base18_f
#define DPCM18_FRAME_ADDRESS dpcm18_f
// blocco buffer 19
uint32_t base19_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm19_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE19_FRAME_ADDRESS base19_f
#define DPCM19_FRAME_ADDRESS dpcm19_f
// blocco buffer 20
uint32_t base20_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
uint32_t dpcm20_f[QVGA_SIZE_YUV] __attribute__((section(".sdram")));
#define BASE20_FRAME_ADDRESS base20_f
#define DPCM20_FRAME_ADDRESS dpcm20_f
*/
#endif //_SDRAM_H_
|
tinyos-io/tinyos-3.x-contrib | berkeley/apps/AIIT_tutorials/6_Readings/PrintCounterReading.h |
#ifndef PRINT_SERIAL_H
#define PRINT_SERIAL_H
#include "message.h"
typedef nx_struct print_counter_reading_msg {
nx_uint8_t flag;
nx_uint16_t nodeid;
nx_uint16_t counter;
nx_uint16_t voltage_reading;
} print_counter_reading_msg_t;
enum {
AM_PRINT_COUNTER_READING_MSG = 0x0D,
FLAG_COUNTER = 0x01,
FLAG_VOLTAGE_READING = 0x02,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | tcd/powertossim-z/tinyos_files/tinyos-2.0.2/tos/chips/atm128/adc/Atm128Adc.h | // $Id: Atm128Adc.h,v 1.1 2014/11/26 19:31:33 carbajor Exp $
/*
* Copyright (c) 2004-2005 Crossbow Technology, Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS BE LIABLE TO
* ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS.
*/
// @author <NAME> <<EMAIL>>
// @author <NAME> <<EMAIL>>
#ifndef _H_Atm128ADC_h
#define _H_Atm128ADC_h
//================== 8 channel 10-bit ADC ==============================
/* Voltage Reference Settings */
enum {
ATM128_ADC_VREF_OFF = 0, //!< VR+ = AREF and VR- = GND
ATM128_ADC_VREF_AVCC = 1,//!< VR+ = AVcc and VR- = GND
ATM128_ADC_VREF_RSVD,
ATM128_ADC_VREF_2_56 = 3,//!< VR+ = 2.56V and VR- = GND
};
/* Voltage Reference Settings */
enum {
ATM128_ADC_RIGHT_ADJUST = 0,
ATM128_ADC_LEFT_ADJUST = 1,
};
/* ADC Multiplexer Settings */
enum {
ATM128_ADC_SNGL_ADC0 = 0,
ATM128_ADC_SNGL_ADC1,
ATM128_ADC_SNGL_ADC2,
ATM128_ADC_SNGL_ADC3,
ATM128_ADC_SNGL_ADC4,
ATM128_ADC_SNGL_ADC5,
ATM128_ADC_SNGL_ADC6,
ATM128_ADC_SNGL_ADC7,
ATM128_ADC_DIFF_ADC00_10x,
ATM128_ADC_DIFF_ADC10_10x,
ATM128_ADC_DIFF_ADC00_200x,
ATM128_ADC_DIFF_ADC10_200x,
ATM128_ADC_DIFF_ADC22_10x,
ATM128_ADC_DIFF_ADC32_10x,
ATM128_ADC_DIFF_ADC22_200x,
ATM128_ADC_DIFF_ADC32_200x,
ATM128_ADC_DIFF_ADC01_1x,
ATM128_ADC_DIFF_ADC11_1x,
ATM128_ADC_DIFF_ADC21_1x,
ATM128_ADC_DIFF_ADC31_1x,
ATM128_ADC_DIFF_ADC41_1x,
ATM128_ADC_DIFF_ADC51_1x,
ATM128_ADC_DIFF_ADC61_1x,
ATM128_ADC_DIFF_ADC71_1x,
ATM128_ADC_DIFF_ADC02_1x,
ATM128_ADC_DIFF_ADC12_1x,
ATM128_ADC_DIFF_ADC22_1x,
ATM128_ADC_DIFF_ADC32_1x,
ATM128_ADC_DIFF_ADC42_1x,
ATM128_ADC_DIFF_ADC52_1x,
ATM128_ADC_SNGL_1_23,
ATM128_ADC_SNGL_GND,
};
/* ADC Multiplexer Selection Register */
typedef struct
{
uint8_t mux : 5; //!< Analog Channel and Gain Selection Bits
uint8_t adlar : 1; //!< ADC Left Adjust Result
uint8_t refs : 2; //!< Reference Selection Bits
} Atm128Admux_t;
/* ADC Prescaler Settings */
/* Note: each platform must define ATM128_ADC_PRESCALE to the smallest
prescaler which guarantees full A/D precision. */
enum {
ATM128_ADC_PRESCALE_2 = 0,
ATM128_ADC_PRESCALE_2b,
ATM128_ADC_PRESCALE_4,
ATM128_ADC_PRESCALE_8,
ATM128_ADC_PRESCALE_16,
ATM128_ADC_PRESCALE_32,
ATM128_ADC_PRESCALE_64,
ATM128_ADC_PRESCALE_128,
// This special value is used to ask the platform for the prescaler
// which gives full precision.
ATM128_ADC_PRESCALE
};
/* ADC Enable Settings */
enum {
ATM128_ADC_ENABLE_OFF = 0,
ATM128_ADC_ENABLE_ON,
};
/* ADC Start Conversion Settings */
enum {
ATM128_ADC_START_CONVERSION_OFF = 0,
ATM128_ADC_START_CONVERSION_ON,
};
/* ADC Free Running Select Settings */
enum {
ATM128_ADC_FREE_RUNNING_OFF = 0,
ATM128_ADC_FREE_RUNNING_ON,
};
/* ADC Interrupt Flag Settings */
enum {
ATM128_ADC_INT_FLAG_OFF = 0,
ATM128_ADC_INT_FLAG_ON,
};
/* ADC Interrupt Enable Settings */
enum {
ATM128_ADC_INT_ENABLE_OFF = 0,
ATM128_ADC_INT_ENABLE_ON,
};
/* ADC Multiplexer Selection Register */
typedef struct
{
uint8_t adps : 3; //!< ADC Prescaler Select Bits
uint8_t adie : 1; //!< ADC Interrupt Enable
uint8_t adif : 1; //!< ADC Interrupt Flag
uint8_t adfr : 1; //!< ADC Free Running Select
uint8_t adsc : 1; //!< ADC Start Conversion
uint8_t aden : 1; //!< ADC Enable
} Atm128Adcsra_t;
typedef uint8_t Atm128_ADCH_t; //!< ADC data register high
typedef uint8_t Atm128_ADCL_t; //!< ADC data register low
// The resource identifier string for the ADC subsystem
#define UQ_ATM128ADC_RESOURCE "atm128adc.resource"
#endif //_H_Atm128ADC_h
|
tinyos-io/tinyos-3.x-contrib | diku/sensinode/tos/platforms/micro4/platform.h | <reponame>tinyos-io/tinyos-3.x-contrib
/* Changes the clock frequency from the default 4 MHz to 1 MHz */
#ifndef __4MHz__
#ifndef __1MHz__
#define __1MHz__
#endif
#endif
/* old TOSH_uwait - more precise than the new TOS2 timers */
inline void TOSH_uwait(uint16_t u)
{
uint16_t i;
// 1MHz clock - not 4
#ifdef __1MHz__
u /= 8;
#endif
if (u < 500)
for (i=2; i < u; i++) {
asm volatile("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
::);
}
else
for (i=0; i < u; i++) {
asm volatile("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
::);
}
}
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/chips/mcs51/sys/select.h | /*
* Dummy to prevent inclution of system includes (that Keil don't like)
*/
#ifndef _SYS_SELECT_H
#define _SYS_SELECT_H 1
#endif _SYS_SELECT_H |
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/driver/claim_interface.c | /* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 <NAME> <<EMAIL>>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "libusb_driver.h"
NTSTATUS claim_interface(libusb_device_t *dev, int interface)
{
DEBUG_MESSAGE("claim_interface(): interface %d", interface);
if(!dev->config.value)
{
DEBUG_ERROR("claim_interface(): device is not configured");
return STATUS_INVALID_DEVICE_STATE;
}
if(interface >= LIBUSB_MAX_NUMBER_OF_INTERFACES)
{
DEBUG_ERROR("claim_interface(): interface number %d too high",
interface);
return STATUS_INVALID_PARAMETER;
}
if(!dev->config.interfaces[interface].valid)
{
DEBUG_ERROR("claim_interface(): interface %d does not exist", interface);
return STATUS_INVALID_PARAMETER;
}
if(dev->config.interfaces[interface].claimed)
{
DEBUG_ERROR("claim_interface(): could not claim interface %d, "
"interface is already claimed", interface);
return STATUS_DEVICE_BUSY;
}
dev->config.interfaces[interface].claimed = TRUE;
return STATUS_SUCCESS;
}
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/driver/set_feature.c | /* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 <NAME> <<EMAIL>>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "libusb_driver.h"
NTSTATUS set_feature(libusb_device_t *dev, int recipient, int index,
int feature, int timeout)
{
NTSTATUS status = STATUS_SUCCESS;
URB urb;
DEBUG_PRINT_NL();
DEBUG_MESSAGE("set_feature(): recipient %02d", recipient);
DEBUG_MESSAGE("set_feature(): index %04d", index);
DEBUG_MESSAGE("set_feature(): feature %04d", feature);
DEBUG_MESSAGE("set_feature(): timeout %d", timeout);
memset(&urb, 0, sizeof(struct _URB_CONTROL_FEATURE_REQUEST));
switch(recipient)
{
case USB_RECIP_DEVICE:
urb.UrbHeader.Function = URB_FUNCTION_SET_FEATURE_TO_DEVICE;
break;
case USB_RECIP_INTERFACE:
urb.UrbHeader.Function = URB_FUNCTION_SET_FEATURE_TO_INTERFACE;
break;
case USB_RECIP_ENDPOINT:
urb.UrbHeader.Function = URB_FUNCTION_SET_FEATURE_TO_ENDPOINT;
break;
case USB_RECIP_OTHER:
urb.UrbHeader.Function = URB_FUNCTION_SET_FEATURE_TO_OTHER;
urb.UrbControlFeatureRequest.Index = 0;
break;
default:
DEBUG_ERROR("set_feature(): invalid recipient");
return STATUS_INVALID_PARAMETER;
}
urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_FEATURE_REQUEST);
urb.UrbControlFeatureRequest.FeatureSelector = (USHORT)feature;
urb.UrbControlFeatureRequest.Index = (USHORT)index;
status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
if(!NT_SUCCESS(status) || !USBD_SUCCESS(urb.UrbHeader.Status))
{
DEBUG_ERROR("set_feature(): setting feature failed: status: 0x%x, "
"urb-status: 0x%x", status, urb.UrbHeader.Status);
}
return status;
}
|
tinyos-io/tinyos-3.x-contrib | uob/tossdr/tos/lib/tossdr/tossim_sync_impl.c | /*
When included into a TOSSIM application this module will allow
using the C++/Python TossimSync interface run simulation events in
"real-world" time.
!!Assumes sim_time_t is in nano-seconds.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <sim_tossdr.h>
#include <sim_event_queue.h>
/* Automatically set on first invocation of wait_until_real_time() */
sim_time_t sync_start_time = 0;
/* Static compensation for overhead/resolution limitations. It would
be really neat if this adjusted dynamically... */
#define SKIP_TIME 3000000ULL
/*
Return real-world time.
*/
sim_time_t sim_get_real_time() {
struct timeval tv;
if(gettimeofday(&tv, NULL) == 0) {
return (sim_time_t)tv.tv_sec * sim_ticks_per_sec() +
(sim_time_t)tv.tv_usec * 10000;
} else { /* failure */
perror("gettimeofday() failed");
return 0;
}
}
sim_time_t sim_get_sync_start() {
return sync_start_time;
}
void sim_set_sync_start(sim_time_t time) {
sync_start_time = time;
}
/*
Synchronize the with current world time. This takes into account how
long the simulator has been running to sync. right back up.
*/
void sim_sync_start_to_now() {
sim_set_sync_start(sim_get_real_time() - sim_time());
}
/*
Wait until "real time" is >= event_time ("sim time").
*/
static void sim_wait_until_real_time(sim_time_t event_time) {
struct timespec req;
sim_time_t wait_time;
if (sync_start_time == 0)
sim_sync_start_to_now();
wait_time = event_time - (sim_get_real_time() - sync_start_time) - SKIP_TIME;
/* event now or in the past, run (right) away! */
if (wait_time <= 0)
return;
/* there should be a way to clean up these conversion */
/* and what is with the /10? */
req.tv_sec = wait_time / sim_ticks_per_sec();
req.tv_nsec = (wait_time - req.tv_sec * sim_ticks_per_sec()) / 10;
WAITMORE:
if (nanosleep(&req, &req) == -1) {
/* this might be better handled with a re-computation of the
real time remaining: it could be a long interruption --
nanosleep modifies req (2nd arg). */
if (EINTR == errno)
goto WAITMORE;
else
perror("nanosleep() failed");
}
}
/*
Run the next TOSSIM event at the correct "real world" time (or
pretty darn close to it). If the event is in the past in runs
right away.
The queue pop and insert are slightly ugly but, using this
approach removes the need to modify or use sim_run_next_event()
code. The overhead the operation adds is NOT SIGNIFICANT, but it
MAY change the order of events.
*/
bool sim_wait_until_next_event() {
sim_event_t* evt;
if (sim_queue_is_empty())
return 0;
evt = sim_queue_pop();
//fprintf(stderr, "sync_impl %x\n", evt), fflush(stderr);
sim_queue_insert(evt);
//fprintf(stderr, "wait until %d\n", evt->time), fflush(stderr);
sim_wait_until_real_time(evt->time);
return 1;
}
#ifdef __cplusplus
}
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/misc/src/libusb-win32/libusb-win32-src-0.1.12.1/src/inf_wizard.c | <gh_stars>1-10
/* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2006 <NAME> <<EMAIL>>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef __GNUC__
#define _WIN32_IE 0x0400
#define WINVER 0x0500
#endif
#define INITGUID
#include <windows.h>
#include <commdlg.h>
#include <dbt.h>
#include <stdio.h>
#include <stdlib.h>
#include <initguid.h>
#include <commctrl.h>
#include <setupapi.h>
#include "registry.h"
#define __INF_WIZARD_C__
#include "inf_wizard_rc.rc"
#define _STRINGIFY(x) #x
#define STRINGIFY(x) _STRINGIFY(x)
DEFINE_GUID(GUID_DEVINTERFACE_USB_HUB, 0xf18a0e88, 0xc30c, 0x11d0, 0x88, \
0x15, 0x00, 0xa0, 0xc9, 0x06, 0xbe, 0xd8);
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, \
0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
const char cat_file_content[] =
"This file will contain the digital signature of the files to be installed\n"
"on the system.\n"
"This file will be provided by Microsoft upon certification of your "
"drivers.\n";
const char info_text_0[] =
"This program will create an .inf file for your device.\n\n"
"Before clicking \"Next\" make sure that your device is connected to the "
"system.\n";
const char info_text_1[] =
"An .inf and .cat file has been created successfully for the following "
"device:\n\n";
const char list_header_text[] =
"Select your device from the list of detected devices below.\n"
"If your device isn't listed then either connect it or just click \"Next\"\n"
"and enter your device description manually\n";
const char inf_header[] =
"[Version]\n"
"Signature = \"$Chicago$\"\n"
"provider = %manufacturer%\n"
"DriverVer = " STRINGIFY(INF_DATE) "," STRINGIFY(INF_VERSION) "\n";
const char inf_body[] =
"Class = LibUsbDevices\n"
"ClassGUID = {EB781AAF-9C70-4523-A5DF-642A87ECA567}\n"
"\n"
"[ClassInstall]\n"
"AddReg=libusb_class_install_add_reg\n"
"\n"
"[ClassInstall32]\n"
"AddReg=libusb_class_install_add_reg\n"
"\n"
"[libusb_class_install_add_reg]\n"
"HKR,,,,\"LibUSB-Win32 Devices\"\n"
"HKR,,Icon,,\"-20\"\n"
"\n"
"[Manufacturer]\n"
"%manufacturer%=Devices,NT,NTAMD64\n"
"\n"
";--------------------------------------------------------------------------\n"
"; Files\n"
";--------------------------------------------------------------------------\n"
"\n"
"[SourceDisksNames]\n"
"1 = \"Libusb-Win32 Driver Installation Disk\",,\n"
"\n"
"[SourceDisksFiles]\n"
"libusb0.sys = 1,,\n"
"libusb0.dll = 1,,\n"
"libusb0_x64.sys = 1,,\n"
"libusb0_x64.dll = 1,,\n"
"\n"
"[DestinationDirs]\n"
"libusb_files_sys = 10,system32\\drivers\n"
"libusb_files_sys_x64 = 10,system32\\drivers\n"
"libusb_files_dll = 10,system32\n"
"libusb_files_dll_wow64 = 10,syswow64\n"
"libusb_files_dll_x64 = 10,system32\n"
"\n"
"[libusb_files_sys]\n"
"libusb0.sys\n"
"\n"
"[libusb_files_sys_x64]\n"
"libusb0.sys,libusb0_x64.sys\n"
"\n"
"[libusb_files_dll]\n"
"libusb0.dll\n"
"\n"
"[libusb_files_dll_wow64]\n"
"libusb0.dll\n"
"\n"
"[libusb_files_dll_x64]\n"
"libusb0.dll,libusb0_x64.dll\n"
"\n"
";--------------------------------------------------------------------------\n"
"; Device driver\n"
";--------------------------------------------------------------------------\n"
"\n"
"[LIBUSB_DEV]\n"
"CopyFiles = libusb_files_sys, libusb_files_dll\n"
"AddReg = libusb_add_reg\n"
"\n"
"[LIBUSB_DEV.NT]\n"
"CopyFiles = libusb_files_sys, libusb_files_dll\n"
"\n"
"[LIBUSB_DEV.NTAMD64]\n"
"CopyFiles = libusb_files_sys_x64, libusb_files_dll_wow64, libusb_files_dll_x64\n"
"\n"
"[LIBUSB_DEV.HW]\n"
"DelReg = libusb_del_reg_hw\n"
"AddReg = libusb_add_reg_hw\n"
"\n"
"[LIBUSB_DEV.NT.HW]\n"
"DelReg = libusb_del_reg_hw\n"
"AddReg = libusb_add_reg_hw\n"
"\n"
"[LIBUSB_DEV.NTAMD64.HW]\n"
"DelReg = libusb_del_reg_hw\n"
"AddReg = libusb_add_reg_hw\n"
"\n"
"[LIBUSB_DEV.NT.Services]\n"
"AddService = libusb0, 0x00000002, libusb_add_service\n"
"\n"
"[LIBUSB_DEV.NTAMD64.Services]\n"
"AddService = libusb0, 0x00000002, libusb_add_service\n"
"\n"
"[libusb_add_reg]\n"
"HKR,,DevLoader,,*ntkern\n"
"HKR,,NTMPDriver,,libusb0.sys\n"
"\n"
"; Older versions of this .inf file installed filter drivers. They are not\n"
"; needed any more and must be removed\n"
"[libusb_del_reg_hw]\n"
"HKR,,LowerFilters\n"
"HKR,,UpperFilters\n"
"\n"
"; Device properties\n"
"[libusb_add_reg_hw]\n"
"HKR,,SurpriseRemovalOK, 0x00010001, 1\n"
"\n"
";--------------------------------------------------------------------------\n"
"; Services\n"
";--------------------------------------------------------------------------\n"
"\n"
"[libusb_add_service]\n"
"DisplayName = \"LibUsb-Win32 - Kernel Driver "
STRINGIFY(INF_DATE) ", " STRINGIFY(INF_VERSION) "\"\n"
"ServiceType = 1\n"
"StartType = 3\n"
"ErrorControl = 0\n"
"ServiceBinary = %12%\\libusb0.sys\n"
"\n"
";--------------------------------------------------------------------------\n"
"; Devices\n"
";--------------------------------------------------------------------------\n"
"\n";
const char strings_header[] =
"\n"
";--------------------------------------------------------------------------\n"
"; Strings\n"
";--------------------------------------------------------------------------\n"
"\n"
"[Strings]\n";
typedef struct {
int vid;
int pid;
char description[MAX_PATH];
char manufacturer[MAX_PATH];
} device_context_t;
BOOL CALLBACK dialog_proc_0(HWND dialog, UINT message,
WPARAM w_param, LPARAM l_param);
BOOL CALLBACK dialog_proc_1(HWND dialog, UINT message,
WPARAM w_param, LPARAM l_param);
BOOL CALLBACK dialog_proc_2(HWND dialog, UINT message,
WPARAM w_param, LPARAM l_param);
BOOL CALLBACK dialog_proc_3(HWND dialog, UINT message,
WPARAM w_param, LPARAM l_param);
static void device_list_init(HWND list);
static void device_list_refresh(HWND list);
static void device_list_add(HWND list, device_context_t *device);
static void device_list_clean(HWND list);
static int save_file(HWND dialog, device_context_t *device);
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev_instance,
LPSTR cmd_line, int cmd_show)
{
int next_dialog;
device_context_t device;
LoadLibrary("comctl32.dll");
InitCommonControls();
memset(&device, 0, sizeof(device));
next_dialog = ID_DIALOG_0;
while(next_dialog)
{
switch(next_dialog)
{
case ID_DIALOG_0:
next_dialog = (int)DialogBoxParam(instance,
MAKEINTRESOURCE(next_dialog),
NULL, (DLGPROC)dialog_proc_0,
(LPARAM)&device);
break;
case ID_DIALOG_1:
next_dialog = (int)DialogBoxParam(instance,
MAKEINTRESOURCE(next_dialog),
NULL, (DLGPROC)dialog_proc_1,
(LPARAM)&device);
break;
case ID_DIALOG_2:
next_dialog = (int)DialogBoxParam(instance,
MAKEINTRESOURCE(next_dialog),
NULL, (DLGPROC)dialog_proc_2,
(LPARAM)&device);
break;
case ID_DIALOG_3:
next_dialog = (int)DialogBoxParam(instance,
MAKEINTRESOURCE(next_dialog),
NULL, (DLGPROC)dialog_proc_3,
(LPARAM)&device);
break;
default:
;
}
}
return 0;
}
BOOL CALLBACK dialog_proc_0(HWND dialog, UINT message,
WPARAM w_param, LPARAM l_param)
{
switch(message)
{
case WM_INITDIALOG:
SetWindowText(GetDlgItem(dialog, ID_INFO_TEXT), info_text_0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(w_param))
{
case ID_BUTTON_NEXT:
EndDialog(dialog, ID_DIALOG_1);
return TRUE ;
case ID_BUTTON_CANCEL:
case IDCANCEL:
EndDialog(dialog, 0);
return TRUE ;
}
}
return FALSE;
}
BOOL CALLBACK dialog_proc_1(HWND dialog, UINT message,
WPARAM w_param, LPARAM l_param)
{
static HDEVNOTIFY notification_handle_hub = NULL;
static HDEVNOTIFY notification_handle_dev = NULL;
DEV_BROADCAST_HDR *hdr = (DEV_BROADCAST_HDR *) l_param;
DEV_BROADCAST_DEVICEINTERFACE dev_if;
static device_context_t *device = NULL;
HWND list = GetDlgItem(dialog, ID_LIST);
LVITEM item;
switch(message)
{
case WM_INITDIALOG:
device = (device_context_t *)l_param;
memset(device, 0, sizeof(*device));
SetWindowText(GetDlgItem(dialog, ID_LIST_HEADER_TEXT), list_header_text);
device_list_init(list);
device_list_refresh(list);
dev_if.dbcc_size = sizeof(dev_if);
dev_if.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
dev_if.dbcc_classguid = GUID_DEVINTERFACE_USB_HUB;
notification_handle_hub = RegisterDeviceNotification(dialog, &dev_if, 0);
dev_if.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
notification_handle_dev = RegisterDeviceNotification(dialog, &dev_if, 0);
return TRUE;
case WM_DEVICECHANGE:
switch(w_param)
{
case DBT_DEVICEREMOVECOMPLETE:
if(hdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
device_list_refresh(list);
break;
case DBT_DEVICEARRIVAL:
if(hdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
device_list_refresh(list);
break;
default:
;
}
return TRUE;
case WM_COMMAND:
switch(LOWORD(w_param))
{
case ID_BUTTON_NEXT:
if(notification_handle_hub)
UnregisterDeviceNotification(notification_handle_hub);
if(notification_handle_dev)
UnregisterDeviceNotification(notification_handle_dev);
memset(&item, 0, sizeof(item));
item.mask = LVIF_TEXT | LVIF_PARAM;
item.iItem = ListView_GetNextItem(list, -1, LVNI_SELECTED);
memset(device, 0, sizeof(*device));
if(item.iItem >= 0)
{
if(ListView_GetItem(list, &item))
{
if(item.lParam)
{
memcpy(device, (void *)item.lParam, sizeof(*device));
}
}
}
if(!device->vid)
{
device->vid = 0x12AB;
device->pid = 0x12AB;
}
if(!device->manufacturer[0])
strcpy(device->manufacturer, "Insert manufacturer name");
if(!device->description[0])
strcpy(device->description, "Insert device description");
if(notification_handle_hub)
UnregisterDeviceNotification(notification_handle_hub);
if(notification_handle_dev)
UnregisterDeviceNotification(notification_handle_dev);
device_list_clean(list);
EndDialog(dialog, ID_DIALOG_2);
return TRUE;
case ID_BUTTON_BACK:
device_list_clean(list);
if(notification_handle_hub)
UnregisterDeviceNotification(notification_handle_hub);
if(notification_handle_dev)
UnregisterDeviceNotification(notification_handle_dev);
EndDialog(dialog, ID_DIALOG_0);
return TRUE ;
case ID_BUTTON_CANCEL:
case IDCANCEL:
device_list_clean(list);
if(notification_handle_hub)
UnregisterDeviceNotification(notification_handle_hub);
if(notification_handle_dev)
UnregisterDeviceNotification(notification_handle_dev);
EndDialog(dialog, 0);
return TRUE ;
}
}
return FALSE;
}
BOOL CALLBACK dialog_proc_2(HWND dialog, UINT message,
WPARAM w_param, LPARAM l_param)
{
static device_context_t *device = NULL;
char tmp[MAX_PATH];
switch(message)
{
case WM_INITDIALOG:
device = (device_context_t *)l_param;
if(device)
{
memset(tmp, 0, sizeof(tmp));
sprintf(tmp, "0x%04X", device->vid);
SetWindowText(GetDlgItem(dialog, ID_TEXT_VID), tmp);
memset(tmp, 0, sizeof(tmp));
sprintf(tmp, "0x%04X", device->pid);
SetWindowText(GetDlgItem(dialog, ID_TEXT_PID), tmp);
SetWindowText(GetDlgItem(dialog, ID_TEXT_MANUFACTURER),
device->manufacturer);
SetWindowText(GetDlgItem(dialog, ID_TEXT_DEV_NAME),
device->description);
}
return TRUE;
case WM_COMMAND:
switch(LOWORD(w_param))
{
case ID_BUTTON_NEXT:
memset(device, 0, sizeof(*device));
GetWindowText(GetDlgItem(dialog, ID_TEXT_MANUFACTURER),
device->manufacturer, sizeof(tmp));
GetWindowText(GetDlgItem(dialog, ID_TEXT_DEV_NAME),
device->description, sizeof(tmp));
GetWindowText(GetDlgItem(dialog, ID_TEXT_VID), tmp, sizeof(tmp));
sscanf(tmp, "0x%04x", &device->vid);
GetWindowText(GetDlgItem(dialog, ID_TEXT_PID), tmp, sizeof(tmp));
sscanf(tmp, "0x%04x", &device->pid);
if(save_file(dialog, device))
EndDialog(dialog, ID_DIALOG_3);
return TRUE ;
case ID_BUTTON_BACK:
EndDialog(dialog, ID_DIALOG_1);
return TRUE ;
case ID_BUTTON_CANCEL:
case IDCANCEL:
EndDialog(dialog, 0);
return TRUE ;
}
}
return FALSE;
}
BOOL CALLBACK dialog_proc_3(HWND dialog, UINT message,
WPARAM w_param, LPARAM l_param)
{
static device_context_t *device = NULL;
char tmp[MAX_PATH];
switch(message)
{
case WM_INITDIALOG:
device = (device_context_t *)l_param;
sprintf(tmp,
"%s\n"
"Vendor ID:\t\t 0x%04X\n\n"
"Product ID:\t\t 0x%04X\n\n"
"Device description:\t %s\n\n"
"Manufacturer:\t\t %s\n\n",
info_text_1,
device->vid,
device->pid,
device->description,
device->manufacturer);
SetWindowText(GetDlgItem(dialog, ID_INFO_TEXT), tmp);
return TRUE;
case WM_COMMAND:
switch(LOWORD(w_param))
{
case ID_BUTTON_NEXT:
case IDCANCEL:
EndDialog(dialog, 0);
return TRUE ;
}
}
return FALSE;
}
static void device_list_init(HWND list)
{
LVCOLUMN lvc;
ListView_SetExtendedListViewStyle(list, LVS_EX_FULLROWSELECT);
memset(&lvc, 0, sizeof(lvc));
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
lvc.fmt = LVCFMT_LEFT;
lvc.cx = 70;
lvc.iSubItem = 0;
lvc.pszText = "Vendor ID";
ListView_InsertColumn(list, 1, &lvc);
lvc.cx = 70;
lvc.iSubItem = 1;
lvc.pszText = "Product ID";
ListView_InsertColumn(list, 2, &lvc);
lvc.cx = 250;
lvc.iSubItem = 2;
lvc.pszText = "Description";
ListView_InsertColumn(list, 3, &lvc);
}
static void device_list_refresh(HWND list)
{
HDEVINFO dev_info;
SP_DEVINFO_DATA dev_info_data;
int dev_index = 0;
device_context_t *device;
char tmp[MAX_PATH];
device_list_clean(list);
dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
dev_index = 0;
dev_info = SetupDiGetClassDevs(NULL, "USB", NULL,
DIGCF_ALLCLASSES | DIGCF_PRESENT);
if(dev_info == INVALID_HANDLE_VALUE)
{
return;
}
while(SetupDiEnumDeviceInfo(dev_info, dev_index, &dev_info_data))
{
if(usb_registry_match(dev_info, &dev_info_data))
{
device = (device_context_t *) malloc(sizeof(device_context_t));
memset(device, 0, sizeof(*device));
usb_registry_get_property(SPDRP_HARDWAREID, dev_info,
&dev_info_data,
tmp, sizeof(tmp) - 1);
sscanf(tmp + sizeof("USB\\VID_") - 1, "%04x", &device->vid);
sscanf(tmp + sizeof("USB\\VID_XXXX&PID_") - 1, "%04x", &device->pid);
usb_registry_get_property(SPDRP_DEVICEDESC, dev_info,
&dev_info_data,
tmp, sizeof(tmp) - 1);
strcpy(device->description, tmp);
usb_registry_get_property(SPDRP_MFG, dev_info,
&dev_info_data,
tmp, sizeof(tmp) - 1);
strcpy(device->manufacturer, tmp);
device_list_add(list, device);
}
dev_index++;
}
SetupDiDestroyDeviceInfoList(dev_info);
}
static void device_list_add(HWND list, device_context_t *device)
{
LVITEM item;
char vid[32];
char pid[32];
memset(&item, 0, sizeof(item));
memset(vid, 0, sizeof(vid));
memset(pid, 0, sizeof(pid));
sprintf(vid, "0x%04X", device->vid);
sprintf(pid, "0x%04X", device->pid);
item.mask = LVIF_TEXT | LVIF_PARAM;
item.lParam = (LPARAM)device;
ListView_InsertItem(list, &item);
ListView_SetItemText(list, 0, 0, vid);
ListView_SetItemText(list, 0, 1, pid);
ListView_SetItemText(list, 0, 2, device->description);
}
static void device_list_clean(HWND list)
{
LVITEM item;
memset(&item, 0, sizeof(LVITEM));
while(ListView_GetItem(list, &item))
{
if(item.lParam)
free((void *)item.lParam);
ListView_DeleteItem(list, 0);
memset(&item, 0, sizeof(LVITEM));
}
}
static int save_file(HWND dialog, device_context_t *device)
{
OPENFILENAME open_file;
char inf_name[MAX_PATH];
char inf_path[MAX_PATH];
char cat_name[MAX_PATH];
char cat_path[MAX_PATH];
char cat_name_x64[MAX_PATH];
char cat_path_x64[MAX_PATH];
char error[MAX_PATH];
FILE *file;
memset(&open_file, 0, sizeof(open_file));
strcpy(inf_path, "your_file.inf");
open_file.lStructSize = sizeof(OPENFILENAME);
open_file.hwndOwner = dialog;
open_file.lpstrFile = inf_path;
open_file.nMaxFile = sizeof(inf_path);
open_file.lpstrFilter = "*.inf\0*.inf\0";
open_file.nFilterIndex = 1;
open_file.lpstrFileTitle = inf_name;
open_file.nMaxFileTitle = sizeof(inf_name);
open_file.lpstrInitialDir = NULL;
open_file.Flags = OFN_PATHMUSTEXIST;
open_file.lpstrDefExt = "inf";
if(GetSaveFileName(&open_file))
{
strcpy(cat_path, inf_path);
strcpy(cat_name, inf_name);
strcpy(cat_path_x64, inf_path);
strcpy(cat_name_x64, inf_name);
strcpy(strstr(cat_path, ".inf"), ".cat");
strcpy(strstr(cat_name, ".inf"), ".cat");
strcpy(strstr(cat_path_x64, ".inf"), "_x64.cat");
strcpy(strstr(cat_name_x64, ".inf"), "_x64.cat");
file = fopen(inf_path, "w");
if(file)
{
fprintf(file, "%s", inf_header);
fprintf(file, "CatalogFile = %s\n", cat_name);
fprintf(file, "CatalogFile.NT = %s\n", cat_name);
fprintf(file, "CatalogFile.NTAMD64 = %s\n\n", cat_name_x64);
fprintf(file, "%s", inf_body);
fprintf(file, "[Devices]\n");
fprintf(file, "\"%s\"=LIBUSB_DEV, USB\\VID_%04x&PID_%04x\n\n",
device->description,
device->vid, device->pid);
fprintf(file, "[Devices.NT]\n");
fprintf(file, "\"%s\"=LIBUSB_DEV, USB\\VID_%04x&PID_%04x\n\n",
device->description,
device->vid, device->pid);
fprintf(file, "[Devices.NTAMD64]\n");
fprintf(file, "\"%s\"=LIBUSB_DEV, USB\\VID_%04x&PID_%04x\n\n",
device->description,
device->vid, device->pid);
fprintf(file, strings_header);
fprintf(file, "manufacturer = \"%s\"\n", device->manufacturer);
fclose(file);
}
else
{
sprintf(error, "Error: unable to open file: %s", inf_name);
MessageBox(dialog, error, "Error",
MB_OK | MB_APPLMODAL | MB_ICONWARNING);
}
file = fopen(cat_path, "w");
if(file)
{
fprintf(file, "%s", cat_file_content);
fclose(file);
}
else
{
sprintf(error, "Error: unable to open file: %s", cat_name);
MessageBox(dialog, error, "Error",
MB_OK | MB_APPLMODAL | MB_ICONWARNING);
}
file = fopen(cat_path_x64, "w");
if(file)
{
fprintf(file, "%s", cat_file_content);
fclose(file);
}
else
{
sprintf(error, "Error: unable to open file: %s", cat_name_x64);
MessageBox(dialog, error, "Error",
MB_OK | MB_APPLMODAL | MB_ICONWARNING);
}
return TRUE;
}
return FALSE;
}
|
tinyos-io/tinyos-3.x-contrib | rincon/apps/BlackbookBridge/BDictionaryBridge/Link_BDictionary.h | <filename>rincon/apps/BlackbookBridge/BDictionaryBridge/Link_BDictionary.h
/*
* Copyright (c) 2005-2006 Rincon Research Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the Rincon Research Corporation nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE
*/
/**
* Automatically generated header file for BDictionary
*/
#ifndef LINK_BDICTIONARY_H
#define LINK_BDICTIONARY_H
#include "message.h"
#define BDICTIONARY_BYTE_ARRAY_LENGTH (TOSH_DATA_LENGTH-13)
typedef nx_struct BDictionaryMsg {
nx_uint8_t bool0;
nx_uint8_t short0;
nx_uint8_t short1;
nx_uint16_t int0;
nx_uint32_t long0;
nx_uint32_t long1;
nx_uint8_t byteArray[BDICTIONARY_BYTE_ARRAY_LENGTH];
} BDictionaryMsg;
enum {
BDICTIONARY_CMD_OPEN = 0,
BDICTIONARY_REPLY_OPEN = 1,
BDICTIONARY_CMD_ISOPEN = 2,
BDICTIONARY_REPLY_ISOPEN = 3,
BDICTIONARY_CMD_CLOSE = 4,
BDICTIONARY_REPLY_CLOSE = 5,
BDICTIONARY_CMD_GETFILELENGTH = 6,
BDICTIONARY_REPLY_GETFILELENGTH = 7,
BDICTIONARY_CMD_GETTOTALKEYS = 8,
BDICTIONARY_REPLY_GETTOTALKEYS = 9,
BDICTIONARY_CMD_INSERT = 10,
BDICTIONARY_REPLY_INSERT = 11,
BDICTIONARY_CMD_RETRIEVE = 12,
BDICTIONARY_REPLY_RETRIEVE = 13,
BDICTIONARY_CMD_REMOVE = 14,
BDICTIONARY_REPLY_REMOVE = 15,
BDICTIONARY_CMD_GETFIRSTKEY = 16,
BDICTIONARY_REPLY_GETFIRSTKEY = 17,
BDICTIONARY_CMD_GETLASTKEY = 18,
BDICTIONARY_REPLY_GETLASTKEY = 19,
BDICTIONARY_CMD_GETNEXTKEY = 20,
BDICTIONARY_REPLY_GETNEXTKEY = 21,
BDICTIONARY_CMD_ISFILEDICTIONARY = 22,
BDICTIONARY_REPLY_ISFILEDICTIONARY = 23,
BDICTIONARY_EVENT_OPENED = 24,
BDICTIONARY_EVENT_CLOSED = 25,
BDICTIONARY_EVENT_INSERTED = 26,
BDICTIONARY_EVENT_RETRIEVED = 27,
BDICTIONARY_EVENT_REMOVED = 28,
BDICTIONARY_EVENT_NEXTKEY = 29,
BDICTIONARY_EVENT_FILEISDICTIONARY = 30,
BDICTIONARY_EVENT_TOTALKEYS = 31,
};
enum {
AM_BDICTIONARYMSG = 0xB2,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/client/sfaccess/tinystream.c | <reponame>tinyos-io/tinyos-3.x-contrib
#include "tinystream.h"
#include <string.h>
#include <unistd.h>
#define TS_BUFSIZE 5000
uint8_t ts_buffer[TS_BUFSIZE];
pthread_mutex_t read_mutex = {0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __LOCK_INITIALIZER};
int bufhead = 0;
int buftail = 0;
bool all_abort = FALSE;
bool pushbyte(uint8_t data);
bool popbyte(uint8_t *data);
//recv callback
void tinystream_cb(int id, uint8_t *data, int length)
{
int i, count;
bool result = FALSE;
pthread_mutex_lock(&read_mutex);
for (i=0; i < length; i++)
{
result = FALSE;
count = 0;
while (!result)
{
result = pushbyte(data[i]);
if (!result)
{
pthread_mutex_unlock(&read_mutex);
count++;
usleep(50000);//rest 50ms
if (count > 100)
{
dbg(TSRC,"Callback probably deadlocked.\n");
}
pthread_mutex_lock(&read_mutex);
}
}
}
pthread_mutex_unlock(&read_mutex);
}
bool pushbyte(uint8_t data)
{
unsigned int nextbyte;
nextbyte = (buftail + 1) % TS_BUFSIZE;
if (nextbyte == bufhead)
{
//full
dbg(TSRC,"buffer full!\n");
return FALSE;
}
ts_buffer[buftail] = data;
buftail = nextbyte;
dbg(TSRC,"(< %02x)",data);
return TRUE;
}
bool popbyte(uint8_t *data)
{
if (bufhead == buftail)
{
//empty
return FALSE;
}
*data = ts_buffer[bufhead];
bufhead = (bufhead + 1) % TS_BUFSIZE;
dbg(TSRC,"(> %02x)",*data);
return TRUE;
}
bool peekbyte(uint8_t *data)
{
if (bufhead == buftail)
{
//empty
return FALSE;
}
*data = ts_buffer[bufhead];
return TRUE;
}
int tinystream_init(const char* host, int port)
{
all_abort = FALSE;
pthread_mutex_lock(&read_mutex);
memset(&ts_buffer, 0, sizeof(ts_buffer));
bufhead = 0;
buftail = 0;
pthread_mutex_unlock(&read_mutex);
return tinyrely_init(host,port);
}
int tinystream_close()
{
all_abort = TRUE;
return tinyrely_destroy();
}
int tinystream_connect(int address)
{
return tinyrely_connect(tinystream_cb, address);
}
int tinystream_read(int id, uint8_t *buf, int length)
{
int i, count;
bool result = FALSE;
pthread_mutex_lock(&read_mutex);
dbg(TSRC,"tstream_read(%i)...",length);
for (i=0; i < length; i++)
{
result = FALSE;
count = 0;
while (!result)
{
result = popbyte(&buf[i]);
if (!result)
{
pthread_mutex_unlock(&read_mutex);
if (all_abort)
{
return -1;
}
count++;
usleep(50000);//rest 50ms
if (count > 200 && i > 0)
{
dbg(TSRC,"tinyrely_read probably dead.\n");
}
pthread_mutex_lock(&read_mutex);
} else {
dbg(TSRC," %02x ",buf[i]);
}
}
}
dbg(TSRC,"...\n");
pthread_mutex_unlock(&read_mutex);
return 0;
}
int tinystream_peek(int id, uint8_t *abyte)
{
bool result = FALSE;
pthread_mutex_lock(&read_mutex);
result = FALSE;
while (!result)
{
result = peekbyte(abyte);
if (!result)
{
pthread_mutex_unlock(&read_mutex);
if (all_abort)
{
return -1;
}
usleep(50000);//rest 50ms
pthread_mutex_lock(&read_mutex);
}
}
pthread_mutex_unlock(&read_mutex);
return 0;
}
int tinystream_write(int id, const uint8_t *buf, int length)
{
return tinyrely_send(id, buf, length);
}
int tinystream_close_connection(int id)
{
return tinyrely_close(id);
}
|
tinyos-io/tinyos-3.x-contrib | intelmote2/support/sdk/c/camera_cmd/cmd_msg.h | <reponame>tinyos-io/tinyos-3.x-contrib<filename>intelmote2/support/sdk/c/camera_cmd/cmd_msg.h
/**
* This file is automatically generated by mig. DO NOT EDIT THIS FILE.
* This file defines the layout of the 'cmd_msg' message type.
*/
#ifndef CMD_MSG_H
#define CMD_MSG_H
#include <message.h>
enum {
/** The default size of this message type in bytes. */
CMD_MSG_SIZE = 7,
/** The Active Message type associated with this message. */
CMD_MSG_AM_TYPE = 4,
/* Field node_id: type uint16_t, offset (bits) 0, size (bits) 16 */
/** Offset (in bytes) of the field 'node_id' */
CMD_MSG_NODE_ID_OFFSET = 0,
/** Offset (in bits) of the field 'node_id' */
CMD_MSG_NODE_ID_OFFSETBITS = 0,
/** Size (in bytes) of the field 'node_id' */
CMD_MSG_NODE_ID_SIZE = 2,
/** Size (in bits) of the field 'node_id' */
CMD_MSG_NODE_ID_SIZEBITS = 16,
/* Field cmd: type uint8_t, offset (bits) 16, size (bits) 8 */
/** Offset (in bytes) of the field 'cmd' */
CMD_MSG_CMD_OFFSET = 2,
/** Offset (in bits) of the field 'cmd' */
CMD_MSG_CMD_OFFSETBITS = 16,
/** Size (in bytes) of the field 'cmd' */
CMD_MSG_CMD_SIZE = 1,
/** Size (in bits) of the field 'cmd' */
CMD_MSG_CMD_SIZEBITS = 8,
/* Field val1: type uint16_t, offset (bits) 24, size (bits) 16 */
/** Offset (in bytes) of the field 'val1' */
CMD_MSG_VAL1_OFFSET = 3,
/** Offset (in bits) of the field 'val1' */
CMD_MSG_VAL1_OFFSETBITS = 24,
/** Size (in bytes) of the field 'val1' */
CMD_MSG_VAL1_SIZE = 2,
/** Size (in bits) of the field 'val1' */
CMD_MSG_VAL1_SIZEBITS = 16,
/* Field val2: type uint16_t, offset (bits) 40, size (bits) 16 */
/** Offset (in bytes) of the field 'val2' */
CMD_MSG_VAL2_OFFSET = 5,
/** Offset (in bits) of the field 'val2' */
CMD_MSG_VAL2_OFFSETBITS = 40,
/** Size (in bytes) of the field 'val2' */
CMD_MSG_VAL2_SIZE = 2,
/** Size (in bits) of the field 'val2' */
CMD_MSG_VAL2_SIZEBITS = 16,
};
/**
* Return the value of the field 'node_id'
*/
uint16_t cmd_msg_node_id_get(tmsg_t *msg);
/**
* Set the value of the field 'node_id'
*/
void cmd_msg_node_id_set(tmsg_t *msg, uint16_t value);
/**
* Return the value of the field 'cmd'
*/
uint8_t cmd_msg_cmd_get(tmsg_t *msg);
/**
* Set the value of the field 'cmd'
*/
void cmd_msg_cmd_set(tmsg_t *msg, uint8_t value);
/**
* Return the value of the field 'val1'
*/
uint16_t cmd_msg_val1_get(tmsg_t *msg);
/**
* Set the value of the field 'val1'
*/
void cmd_msg_val1_set(tmsg_t *msg, uint16_t value);
/**
* Return the value of the field 'val2'
*/
uint16_t cmd_msg_val2_get(tmsg_t *msg);
/**
* Set the value of the field 'val2'
*/
void cmd_msg_val2_set(tmsg_t *msg, uint16_t value);
#endif
|
tinyos-io/tinyos-3.x-contrib | nxtmote/tos/chips/bc4/Bc4.h | <reponame>tinyos-io/tinyos-3.x-contrib
/*
* Copyright (c) 2007 nxtmote project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the project nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE
*
* @author <NAME>
*/
#ifndef __BC4_H__
#define __BC4_H__
/**
* Bc4 header.
*/
typedef nx_struct bc4_header_t {
nxle_uint8_t length;
nxle_uint16_t destpan; // Keeping it
nxle_uint16_t dest;
nx_uint8_t btdest[SIZE_OF_BDADDR]; // bt
nxle_uint16_t src;
nx_uint8_t btsrc[SIZE_OF_BDADDR]; // bt
nxle_uint8_t type;
} bc4_header_t;
/**
* bc4 Packet Footer
*/
typedef nx_struct bc4_footer_t {
} bc4_footer_t;
/**
* BC4 Packet metadata.
* It has the full BT address.
*/
typedef nx_struct bc4_metadata_t {
} bc4_metadata_t;
//typedef nx_struct bc4_packet_t {
// bc4_header_t packet;
// nx_uint8_t data[];
//} bc4_packet_t;
#ifndef TOSH_DATA_LENGTH
#define TOSH_DATA_LENGTH 28
#endif
enum {
// size of the header not including the length byte
BC4_HEADER_SIZE = sizeof( bc4_header_t ),// - 1,
BC4_FOOTER_SIZE = 0,
// MDU
BC4_PACKET_SIZE = BC4_HEADER_SIZE + TOSH_DATA_LENGTH + BC4_FOOTER_SIZE
};
#endif
|
tinyos-io/tinyos-3.x-contrib | diku/mcs51/tos/chips/cip51/spi/spi.h | <filename>diku/mcs51/tos/chips/cip51/spi/spi.h
/*
* Copyright (c) 2008 Polaric
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of Polaric nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL POLARIC OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
*
* This file defines the allowed SPI settings
*
* @author <NAME> <<EMAIL>>
*
*/
#ifndef _H_SPI_H
#define _H_SPI_H
/**
* Bit numbers for SPI
*/
enum {
SPI_4WIRE = 0, // 1, SPI 4WIRE, 0=> SPI3 WIRE
SPI_AUTO_SS = 1, // 1, SPI hardware controls slave select
SPI_MASTER = 2, // 1, SPI Master, 0 SPI slave
SPI_INTERRUPT = 3 // 1, Enable SPI interrupt
};
#endif _H_SPI_H
|
tinyos-io/tinyos-3.x-contrib | stanford-lgl/tos/chips/ov7670/SCCB.h | /*
* Copyright (c) 2006 Stanford University.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the Stanford University nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @brief Driver module for the OmniVision OV7670 Camera
* @author
* <NAME> (<EMAIL>)
* <NAME> (<EMAIL>)
*/
/**
* @brief Ported to TOS2
* @author <NAME> (<EMAIL>)
*/
#ifndef _OV7670SCCB_H
#define _OV7670SCCB_H
#define OV7670SCCB_SCLK_PIN 0x0010 // PIOE4
#define OV7670SCCB_SDATA_PIN 0x0008 // PIOE3
#define OV7670SCCB_SCCB_MODE GPPME
#define OV7670SCCB_SCCB_IN GPPIE
#define OV7670SCCB_SCCB_OUT GPPOE
#define sdata_out() { _GPIO_setaltfn(56,0);GPDR(56) |= _GPIO_bit(56); }/*call SIOD.makeOutput(); }*/
#define sdata_in() { _GPIO_setaltfn(56,0);GPDR(56) &= ~(_GPIO_bit(56)); }/*call SIOD.makeInput(); }*/
#define sdata_set() { GPSR(56) |= _GPIO_bit(56); } /*call SIOD.set(); }*/
#define sdata_clr() { GPCR(56) |= _GPIO_bit(56); } /*call SIOD.clr(); }*/
#define sdata_get() { ((GPLR(56) & _GPIO_bit(56)) != 0); } /*call SIOD.get(); }*/
#define sclock_out() { _GPIO_setaltfn(57,0);GPDR(57) |= _GPIO_bit(57); }/*call SIOD.makeOutput(); }*/
#define sclock_set() { GPSR(57) |= _GPIO_bit(57); } /*call SIOD.set(); }*/
#define sclock_clr() { GPCR(57) |= _GPIO_bit(57); } /*call SIOD.clr(); }*/
#define pwdn_out() { _GPIO_setaltfn(82,0);GPDR(82) |= _GPIO_bit(82); }/*call SIOD.makeOutput(); }*/
#define pwdn_in() { _GPIO_setaltfn(82,0);GPDR(82) &= ~(_GPIO_bit(82)); }/*call SIOD.makeInput(); }*/
#define pwdn_set() { GPSR(82) |= _GPIO_bit(82); } /*call SIOD.set(); }*/
#define pwdn_clr() { GPCR(82) |= _GPIO_bit(82); } /*call SIOD.clr(); }*/
#define pwdn_get() { ((GPLR(82) & _GPIO_bit(82)) != 0); } /*call SIOD.get(); }*/
#define reset_out() { _GPIO_setaltfn(83,0);GPDR(83) |= _GPIO_bit(83); }/*call SIOD.makeOutput(); }*/
#define reset_in() { _GPIO_setaltfn(83,0);GPDR(83) &= ~(_GPIO_bit(83)); }/*call SIOD.makeInput(); }*/
#define reset_set() { GPSR(83) |= _GPIO_bit(83); } /*call SIOD.set(); }*/
#define reset_clr() { GPCR(83) |= _GPIO_bit(83); } /*call SIOD.clr(); }*/
#define reset_get() { ((GPLR(83) & _GPIO_bit(83)) != 0); } /*call SIOD.get(); }*/
#define led_out() { _GPIO_setaltfn(106,0);GPDR(106) |= _GPIO_bit(106); }/*call SIOD.makeOutput(); }*/
#define led_in() { _GPIO_setaltfn(106,0);GPDR(106) &= ~(_GPIO_bit(106)); }/*call SIOD.makeInput(); }*/
#define led_set() { GPSR(106) |= _GPIO_bit(106); } /*call SIOD.set(); }*/
#define led_clr() { GPCR(106) |= _GPIO_bit(106); } /*call SIOD.clr(); }*/
#define led_get() { ((GPLR(106) & _GPIO_bit(106)) != 0); } /*call SIOD.get(); }*/
//#define sccb_delay() { uint8_t i=20; while (--i != 0) asm volatile("nop"); }
#define sccb_delay() { asm volatile ("nop" ::); asm volatile ("nop" ::); asm volatile ("nop" ::); }
//#define sccb_delay() { uint32_t start = OSCR0; while ( (OSCR0 - start) < 5); }
#endif /* _OV7670SCCB_H */
|
tinyos-io/tinyos-3.x-contrib | uob/tossdr/ucla/gnuradio-802.15.4-demodulation/src/lib/ucla_delay_cc.h | <reponame>tinyos-io/tinyos-3.x-contrib
/* -*- c++ -*- */
/*
* Copyright 2004 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef INCLUDED_UCLA_DELAY_CC_H
#define INCLUDED_UCLA_DELAY_CC_H
#include <gr_sync_block.h>
#include <gr_io_signature.h>
#include <gr_types.h>
class ucla_delay_cc;
typedef boost::shared_ptr<ucla_delay_cc> ucla_delay_cc_sptr;
// public constructor
ucla_delay_cc_sptr ucla_make_delay_cc (const int delay);
/*!
* \brief Delay Block.
* \ingroup ucla
*
* The block takes one complex stream as input and outputs a complex
* stream where the Q-Phase is delayed by delay. This can be used to
* transform a QPSK signal to a O-QPSK one.
*
*/
class ucla_delay_cc : public gr_sync_block
{
public:
~ucla_delay_cc ();
int work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
protected:
ucla_delay_cc (const int delay);
private:
unsigned int d_delay;
friend ucla_delay_cc_sptr ucla_make_delay_cc (const int delay);
};
#endif /* INCLUDED_UCLA_DELAY_CC_H */
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/stargate/sfaccess/tinyrely.h | #ifndef _TINYRELY_H_
#define _TINYRELY_H_
#include "teloscomm.h"
#include <stdint.h>
#include <pthread.h>
typedef uint8_t bool;
#define TRUE 1
#define FALSE 0
#ifndef TOSH_DATA_LENGTH
#define TOSH_DATA_LENGTH 60
#endif
#ifndef RELY_HEADER_LENGTH
#define RELY_HEADER_LENGTH 6
#endif
#ifndef RELY_PAYLOAD_LENGTH
#define RELY_PAYLOAD_LENGTH (TOSH_DATA_LENGTH-RELY_HEADER_LENGTH)
#endif
#ifndef RELY_MAX_CONNECTIONS
#define RELY_MAX_CONNECTIONS 5
#endif
#ifndef RELY_UID_INVALID
#define RELY_UID_INVALID 0
#endif
#ifndef RELY_IDX_INVALID
#define RELY_IDX_INVALID -1
#endif
#define RELY_TIME_STEP 300
#define RELY_CONN_TIMEOUT 15000 //reset connection if no
#define RELY_SEND_TIMEOUT 100 // * RELY_ACKTIMER ms
#define RELY_RESEND_TIMEOUT 20 // * RELY_ACKTIMER ms
#define RELY_REQ_TIMEOUT 5000
#define RELY_GRANULARITY 200
#define RELY_ACKTIMER 5
#define RELY_TIMEOUT_COUNT ((RELY_REQ_TIMEOUT / RELY_GRANULARITY)+1)
typedef void (*recv_callback_t)(int id, uint8_t *data, int length);
typedef struct ConnStr {
bool valid;
pthread_mutex_t mutex;
pthread_mutex_t rxmutex;
bool pending;
bool sending;
bool resending;
bool full;
bool closing;
uint8_t count;
uint8_t suid;
uint8_t duid;
uint16_t addr;
uint8_t txseq;
uint8_t rxseq;
recv_callback_t callback;
} ConnStr;
enum {
CONN_TYPE_REQUEST=0,
CONN_TYPE_ACK = 1,
CONN_TYPE_CLOSE = 2
};
enum {
RELY_OK = 0,
RELY_DUP = 1,
RELY_FULL= 2,
RELY_ERR = 3
};
enum {
AM_TINYRELYCONNECT = 0xE0,
AM_TINYRELYMSG = 0xE1,
AM_TINYRELYACK = 0xE2
};
#define CONNMSGSIZE 6
#define RELYMSGSIZE (6 + RELY_PAYLOAD_LENGTH)
#define ACKMSGSIZE 6
enum {
TOS_BCAST_ADDR = 0xffff,
TOS_UART_ADDR = 0x007e,
};
int tinyrely_init(const char* host, int port);
int tinyrely_destroy();
int tinyrely_connect(recv_callback_t callback);
int tinyrely_send(int id, const uint8_t *data, int length);
int tinyrely_close(int id);
#endif
|
tinyos-io/tinyos-3.x-contrib | gems/wmtp/tinyos/tos/lib/net/wmtp/Wmtp.h | /*
* WMTP - Wireless Modular Transport Protocol
*
* Copyright (c) 2008 <NAME> and IT - Instituto de Telecomunicacoes
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Address:
* Instituto Superior Tecnico - Taguspark Campus
* Av. Prof. Dr. <NAME>, 2744-016 Porto Salvo
*
* E-Mail:
* <EMAIL>
*/
/**
* WMTP Protocol.
*
* This component implements the WMTP transport protocol.
*
* @author <NAME> <<EMAIL>>
* @author <NAME> <<EMAIL>> (port to TinyOS 2.x)
**/
#ifndef __WMTP_H__
#define __WMTP_H__
#include "WmtpMsgs.h"
#include <stdio.h>
#include "AM.h"
//#include "TosTime.h"
// TagRouter
#define MAX_TAG_ASSOCIATIONS 10
#define NUM_QOS_CONNECTIONS 4
#define NUM_REGISTERED_SERVICES 2
// Core
#define NUM_CONNECTION_SPECIFICATIONS 10
#define NUM_QUEUE_ELEMENTS 10
#define LOCAL_MANAGEMENT_DATA_PERIOD 1024
#define QOS_RESERVATION_TREE_MAX_DEPTH 8
#define QOS_RESERVATION_TREE_SHORTEST_DELAY_MIN_DEPTH 2
#define NUM_LOCAL_MANAGEMENT_DATA_HANDLERS (WMTP_LOCALPART_SRCROUTEDCONN + 1)
#define NUM_CONN_MANAGEMENT_DATA_HANDLERS (WMTP_CONNPART_WMTPRELIABILITY + 1)
#define NUM_FEATURE_CONFIGURATION_HANDLERS (WMTP_CONFPART_WMTPRELIABILITY + 1)
// Features
#define WMTP_USEQUEUEAVAILABILITYSHAPER
#define WMTP_USETHROTTLING
#define WMTP_USEFLOWCONTROL
#define WMTP_USECONGESTIONCONTROL
#define WMTP_USEFAIRNESS
#define WMTP_USEWMTPRELIABILITY
// Routers and Connection Establishment Handlers
//#define WMTP_USETOSMULTIHOPROUTER
#define WMTP_USEDECREMENTADDRESSROUTER
#define WMTP_USESOURCEROUTEDCONNECTIONS
// Service Specifications
#define WMTP_USEPACKETSINKSERVICESPECIFICATION
#define WMTP_USESINKIDSERVICESPECIFICATION
// QoS Indicators
#define WMTP_USESTATISTICALQOSINDICATOR
// Dependencies
#ifdef WMTP_USESOURCEROUTEDCONNECTIONS
#define WMTP_USETAGROUTER
#endif // #ifdef WMTP_USESOURCEROUTEDCONNECTIONS
#ifdef WMTP_USEDECREMENTADDRESSROUTER
#define NUM_PENDING_CONNECTION_REQUESTS 4
#endif // #ifdef WMTP_USEDECREMENTADDRESSROUTER
typedef uint8_t WmtpApplicationID_t;
typedef struct {
WmtpApplicationID_t ApplicationID;
uint8_t Connectionless;
uint8_t ConnectionOriented;
uint8_t ServiceType;
union {
#ifdef WMTP_USEPACKETSINKSERVICESPECIFICATION
struct {
} PacketSink;
#endif // #ifdef WMTP_USEPACKETSINKSERVICESPECIFICATION
#ifdef WMTP_USESINKIDSERVICESPECIFICATION
struct {
uint8_t Value;
} SinkID;
#endif // #ifdef WMTP_USESINKIDSERVICESPECIFICATION
} ServiceData;
} WmtpServiceSpecification_t;
enum {
#ifdef WMTP_USESOURCEROUTEDCONNECTIONS
WMTP_PATHTYPE_SOURCEROUTEDCONNECTION = 0,
#endif // #ifdef WMTP_USESOURCEROUTEDCONNECTIONS
#ifdef WMTP_USETOSMULTIHOPROUTER
WMTP_PATHTYPE_TOSMULTIHOP = 1,
#endif // #ifdef WMTP_USETOSMULTIHOPROUTER
#ifdef WMTP_USEDECREMENTADDRESSROUTER
WMTP_PATHTYPE_DECREMENTADDRESS = 2,
#endif // #ifdef WMTP_USEDECREMENTADDRESSROUTER
#if defined( WMTP_USETOSMULTIHOPROUTER )
WMTP_PATHTYPE_DEFAULT = WMTP_PATHTYPE_TOSMULTIHOP,
#elif defined( WMTP_USESOURCEROUTEDCONNECTIONS )
WMTP_PATHTYPE_DEFAULT = WMTP_PATHTYPE_SOURCEROUTEDCONNECTION,
#elif defined( WMTP_USEDECREMENTADDRESSROUTER )
WMTP_PATHTYPE_DEFAULT = WMTP_PATHTYPE_DECREMENTADDRESS,
#endif
};
#ifdef WMTP_USESOURCEROUTEDCONNECTIONS
enum {
WMTP_SOURCEROUTEDCONNECTION_MAXHOPS = 5,
};
#endif // #ifdef WMTP_USESOURCEROUTEDCONNECTIONS
typedef struct {
uint8_t PathType;
union {
#ifdef WMTP_USESOURCEROUTEDCONNECTIONS
struct {
WmtpServiceSpecification_t ServiceSpecification;
uint8_t NumHops;
uint16_t Hops[WMTP_SOURCEROUTEDCONNECTION_MAXHOPS];
} SourceRoutedConnection;
#endif // #ifdef WMTP_USESOURCEROUTEDCONNECTIONS
#ifdef WMTP_USETOSMULTIHOPROUTER
struct {
} TOSMultihop;
#endif // #ifdef WMTP_USETOSMULTIHOPROUTER
#ifdef WMTP_USEDECREMENTADDRESSROUTER
struct {
} DecrementAddressRouter;
#endif // #ifdef WMTP_USEDECREMENTADDRESSROUTER
} PathData;
} WmtpPathSpecification_t;
enum {
#ifdef WMTP_USEWMTPRELIABILITY
WMTP_RELIABILITYHANDLER_WMTPRELIABILITY = 0,
#endif // #ifdef WMTP_USEWMTPRELIABILITY
WMTP_RELIABILITYHANDLER_NONE = 255,
};
typedef struct {
#ifdef WMTP_USEQUEUEAVAILABILITYSHAPER
struct {
uint8_t Active;
} QueueAvailabilityShaper;
#endif // #ifdef WMTP_USEQUEUEAVAILABILITYSHAPER
#ifdef WMTP_USETHROTTLING
struct {
// The minimum packet period.
// Set to 0 to deactivate throttling.
uint16_t Period;
} Throttling;
#endif // #ifdef WMTP_USETHROTTLING
#ifdef WMTP_USEFLOWCONTROL
struct {
// Minimum packet periods.
// Set to 0 to deactivate flow control.
// Local period is set by remote node.
uint16_t LocalPeriod;
// Remote period is set by local node.
uint16_t RemotePeriod;
} FlowControl;
#endif // #ifdef WMTP_USEFLOWCONTROL
#ifdef WMTP_USECONGESTIONCONTROL
struct {
uint8_t Active;
} CongestionControl;
#endif // #ifdef WMTP_USECONGESTIONCONTROL
#ifdef WMTP_USEFAIRNESS
struct {
uint8_t SinkID:7;
// Set to 0 to deactivate fairness.
uint8_t Weight;
} Fairness;
#endif // #ifdef WMTP_USEFAIRNESS
uint8_t ReliabilityHandlerID;
union {
#ifdef WMTP_USEWMTPRELIABILITY
struct {
} WmtpReliability;
#endif // #ifdef WMTP_USEWMTPRELIABILITY
} Reliability;
} WmtpFeatureSpecification_t;
typedef struct {
// Maximum end-to-end delay. Set to 0 to deactivate delay constraints.
uint16_t MaxDelay;
// Maximum sending period. Set to 0 to deactivate throughput constraints.
uint16_t MaxPeriod;
// Preferred sending period.
uint16_t PreferredPeriod;
} WmtpQoSSpecification_t;
#if defined( WMTP_USETAGROUTER ) || defined( WMTP_USETOSMULTIHOPROUTER ) || defined( WMTP_USEDECREMENTADDRESSROUTER )
enum {
#ifdef WMTP_USETAGROUTER
WMTP_ROUTERTYPE_TAGROUTER = 0,
#endif // #ifdef WMTP_USETAGROUTER
#ifdef WMTP_USETOSMULTIHOPROUTER
WMTP_ROUTERTYPE_TOSMULTIHOP = 1,
#endif // #ifdef WMTP_USETOSMULTIHOPROUTER
#ifdef WMTP_USEDECREMENTADDRESSROUTER
WMTP_ROUTERTYPE_DECREMENTADDRESSROUTER = 2,
#endif // #ifdef WMTP_USEDECREMENTADDRESSROUTER
};
#endif // #if defined( WMTP_USETAGROUTER ) || defined( WMTP_USETOSMULTIHOPROUTER ) || defined( WMTP_USEDECREMENTADDRESSROUTER )
typedef struct {
uint8_t RouterType;
union {
#ifdef WMTP_USETAGROUTER
struct {
uint8_t OutgoingTag;
} TagRouter;
#endif // #ifdef WMTP_USETAGROUTER
#ifdef WMTP_USETOSMULTIHOPROUTER
struct {
} TOSMultihop;
#endif // #ifdef WMTP_USETOSMULTIHOPROUTER
#ifdef WMTP_USEDECREMENTADDRESSROUTER
struct {
} DecrementAddressRouter;
#endif // #ifdef WMTP_USEDECREMENTADDRESSROUTER
} RouterData;
} WmtpRouterSpecification_t;
typedef union {
#ifdef WMTP_USETHROTTLING
struct {
uint32_t WakeUpTime;
} Throttling;
#endif // #ifdef WMTP_USETHROTTLING
#ifdef WMTP_USEFLOWCONTROL
struct {
uint32_t WakeUpTime;
} FlowControl;
#endif // #ifdef WMTP_USEFLOWCONTROL
#ifdef WMTP_USEFAIRNESS
struct {
uint32_t WakeUpTime;
} Fairness;
#endif // #ifdef WMTP_USEFAIRNESS
} WmtpConnectionScratchPad_t;
enum {
WMTP_QOSPRIORITY_NONE = 255,
};
struct WmtpQueueElement_t;
typedef struct {
WmtpPathSpecification_t PathSpecification;
WmtpFeatureSpecification_t FeatureSpecification;
WmtpQoSSpecification_t QoSSpecification;
WmtpRouterSpecification_t RouterSpecification;
uint8_t IsLocal;
uint8_t IsConnectionOriented;
uint8_t IsTemporary;
WmtpApplicationID_t ApplicationID;
uint8_t TrafficShaperState[((uniqueCount( "WmtpTrafficShaper" ) - 1) / 8) + 1];
WmtpConnectionScratchPad_t ScratchPad[uniqueCount( "WMTPConnectionScratchPad" )];
uint8_t QoSPriority;
struct WmtpQueueElement_t *QoSReservedQueueElement;
} WmtpConnectionSpecification_t;
typedef union {
#ifdef WMTP_USEWMTPRELIABILITY
struct {
uint16_t PrevHop;
uint8_t NumTimesSent;
uint32_t TimeOutTime;
uint8_t NextHopAcked;
uint8_t PrevHopDropped;
} WmtpReliability;
#endif // #ifdef WMTP_USEWMTPRELIABILITY
} WmtpPacketScratchPad_t;
#define WMTP_MAXCONNECTIONPARTS 5
#define WMTP_MAXCONNECTIONLOCALPARTSIZE TOSH_DATA_LENGTH
typedef struct WmtpQueueElement_t {
WmtpConnectionSpecification_t *ConnectionSpecification;
uint16_t NextHop;
uint8_t TrafficShaperState[((uniqueCount( "WmtpTrafficShaper" ) - 1) / 8) + 1];
WmtpPacketScratchPad_t ScratchPad[uniqueCount( "WMTPPacketScratchPad" )];
uint8_t NumConnectionParts;
WmtpConnectionPart_t *ConnectionParts[WMTP_MAXCONNECTIONPARTS];
// Contains the routing data, any connection parts, as well as the payload.
uint8_t ConnectionLocalPartSize;
uint8_t ConnectionLocalPart[WMTP_MAXCONNECTIONLOCALPARTSIZE];
} WmtpQueueElement_t;
#define WMTP_MAXPAYLOADSIZE 25
typedef struct {
char Data[WMTP_MAXPAYLOADSIZE];
} WmtpPayload_t;
typedef struct {
uint16_t PreviousAddress;
uint8_t PreviousTag;
uint16_t NextAddress;
uint8_t NextTag;
WmtpConnectionSpecification_t *ConnectionSpecification;
uint32_t UsageTimeOut;
//tos_time_t TimeOutTime;
uint32_t TimeOutTime;
bool Activated;
} TagAssociation_t;
#endif // #define __WMTP_H__
|
tinyos-io/tinyos-3.x-contrib | intelmote2/support/sdk/c/camera_cmd/camera_cmd.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include "serialsource.h"
#ifndef NO_JPEG
#include "jpeglib.h"
#endif
#include "camera_cmd.h"
#include "img_stat.h"
#include "cmd_msg.h"
#include "status.h"
#include "bigmsg_frame_part.h"
#include "tinyos_macros.h"
#include "jpeghdr.h"
#include "jpegTOS.h"
#include "jpegUncompress.h"
#include "quanttables.h"
//#include <syslog.h>
int has_forked = 0;
int is_parent_proc = 1; // used to track whether this is the parent of child thread
// when forking during progressive jpg downloads
unsigned char first_packets_mask=255;
void write_img_file(img_stat_t *is, packet_buffer_t *pkt_buf, char *filename);
long tv_udiff(struct timeval *start, struct timeval *end)
{
return (end->tv_sec - start->tv_sec)*1000000L + (end->tv_usec - start->tv_usec);
}
int do_fork() {
//printf("do_fork (pid %d, has_forked %d, is_parent_proc %d)\n",getpid(), has_forked, is_parent_proc);
int pID = fork();
if (pID == 0)
is_parent_proc = 0;
else
nice(10); // give child process enough cycles to render the page
//printf("do_forked (pid %d, has_forked %d, is_parent_proc %d)\n",getpid(), has_forked, is_parent_proc);
return 1;
}
void comm_init(char* host, int port)
{
sf_fd = open_sf_source(host, port);
if (sf_fd==-1){
fprintf(stderr, "Couldn't open serial forwarder at %s:%d\n", host, port);
exit(1);
}
}
int send_packet(unsigned char *packet, int count)
{
return write_sf_packet(sf_fd, packet, count);
}
void* read_packet(int *len)
{
struct timeval deadline;
deadline.tv_sec = 3;
deadline.tv_usec = 0;
fd_set fds;
FD_ZERO(&fds);
FD_SET(sf_fd, &fds);
int cnt = select(sf_fd+1, &fds, NULL, NULL, &deadline);
if (cnt <= 0)
return NULL;
return read_sf_packet(sf_fd, len);
}
unsigned char cmd_packet[8+CMD_MSG_SIZE];
void init_cmd_packet(int node_id, int cmd_type, int val1, int val2)
{
unsigned char am=CMD_MSG_AM_TYPE;
unsigned char len=CMD_MSG_SIZE;
memset(cmd_packet,0,sizeof(cmd_packet));
cmd_packet[1]=0xFF;
cmd_packet[2]=0xFF;
cmd_packet[3]=0xFF;
cmd_packet[4]=0xFF;
cmd_packet[5]=len;
cmd_packet[7]=am;
tmsg_t *tmsg = new_tmsg((void *)&cmd_packet[8], len);
cmd_msg_node_id_set(tmsg, node_id);
cmd_msg_cmd_set(tmsg,cmd_type);
cmd_msg_node_id_set(tmsg, node_id);
cmd_msg_val1_set(tmsg,val1);
cmd_msg_val2_set(tmsg,val2);
free_tmsg(tmsg);
}
int send_img_cmd(int node_id, int img_type)
//types: ~0x01 - bw, 0x01 - col
// ~0x02 - raw, 0x02 -jpg
// e.g. 2 = bw_jpg, 3 = col_jpg
{
init_cmd_packet( node_id, img_type, 0, 0);
return send_packet(cmd_packet, sizeof(cmd_packet));
}
int send_img_part_cmd(int node_id, int idx, int num_parts)
{
init_cmd_packet( node_id, 5, idx, num_parts);
return send_packet( cmd_packet, sizeof(cmd_packet));
}
//Sends a request to camera nodes to return its parent and ETX in the CTP collection tree.
int send_CTP_info_cmd(int node_id){
init_cmd_packet(node_id, 8, 5, 0);
return send_packet( cmd_packet, sizeof(cmd_packet));
}
//Listens for a single command packet with CTP routing information
const unsigned char *receive_ctp_info_packet()
{
//listen for one second
time_t t;
t = time(NULL);
while( ((time(NULL))-t) <3 ){
int len;
const unsigned char *packet = read_packet(&len);
//if am check fails, try to receive next packet
if (packet)
{
if( (len<9) || (packet[7]!=STATUS_AM_TYPE))
{
free((void *)packet);
}
else
{
return packet;
}
}
}
//printf("No packet received in 1 sec!, %d vs %d",t,time(NULL));
return NULL;
}
//Debugging,, no data returned, just displayed on the standard output.
int receive_ctp_info_pckts()
{
time_t t;
int node_id, seqNo, parent, ETX;
t = time(NULL);
printf("Waiting for Routing Info.\n");
while( ((time(NULL))-t) <20 ){ //Wait 10 seconds for routing information
const unsigned char *packet = receive_ctp_info_packet();
if (!packet)
break;
//Extract sender, parent, and ETX from the packet and display
tmsg_t *ctp_info = new_tmsg((void *)&packet[8], STATUS_SIZE);
node_id=status_node_id_get(ctp_info);
seqNo=status_seqNo_get(ctp_info);
parent=status_parent_get(ctp_info);
ETX=status_ETX_get(ctp_info);
free_tmsg(ctp_info);
printf("Routing info for node: %d, parent: %d, ETX: %d.\n", node_id, parent, ETX);
}
return 0;
}
void (*callback_function)(int, char *) = NULL;
int receive_img_stat_packet(int session_id, img_stat_t *is)
{
//i do it with time deadline here - want to wait for the right img_stat,
//even if there is other traffic in the air
struct timeval start;
gettimeofday(&start,0);
const unsigned char *packet = NULL;
int len;
while(1) // 1 sec
{
packet = read_packet(&len);
if (packet)
{
// printf("am type: %d, looking for: %d\n",packet[7],IMG_STAT_AM_TYPE);
if (len<9 || packet[7]!=IMG_STAT_AM_TYPE)
free((void *)packet);
else
{
tmsg_t *img_stat_msg = new_tmsg((void *)&packet[8], len);
if (img_stat_node_id_get(img_stat_msg) == session_id)
{
is->node_id = img_stat_node_id_get(img_stat_msg);
is->type = img_stat_type_get(img_stat_msg);
is->data_size = img_stat_data_size_get(img_stat_msg);
is->width = img_stat_width_get(img_stat_msg);
is->height = img_stat_height_get(img_stat_msg);
free_tmsg(img_stat_msg);
free((void *)packet);
return 0;
}
free_tmsg(img_stat_msg);
free((void *)packet);
}
}
struct timeval now;
gettimeofday(&now,0);
if (tv_udiff(&start,&now)>5000000L) // 5 sec
return -1;
}
//printf("No packet received in 1 sec!\n");
return -1;
}
int tmp=0;
const unsigned char *receive_img_packet()
{
//listen for one second
struct timeval start;
gettimeofday(&start,0);
while(1){
int len;
const unsigned char *packet = read_packet(&len);
//if am check fails, try to receive next packet
if (packet)
{
//printf("am type: %d, looking for: %d\n",packet[7],BIGMSG_FRAME_PART_AM_TYPE);
if( (len<9) || (packet[7]!=BIGMSG_FRAME_PART_AM_TYPE))
free((void *)packet);
else
return packet;
}
struct timeval now;
gettimeofday(&now,0);
if (tv_udiff(&start,&now)>1000000L) // 1 sec
return NULL;
}
return NULL;
}
int receive_img_packets(img_stat_t *is, packet_buffer_t *pkt_buf, char *filename, int max_part_id)
{
int session_id = is->node_id;
int part_id=0;
int iter = 1;
int inc_amt = (pkt_buf->num_packets / 5);
while (part_id<max_part_id){
const unsigned char *packet = receive_img_packet();
if (!packet)
{
free((void *)packet);
break;
}
tmsg_t *bigmsg = new_tmsg((void *)&packet[8], BIGMSG_FRAME_PART_SIZE);
//printf("session id: %d, looking for: %d\n",bigmsg_frame_part_node_id_get(bigmsg),session_id );
if (bigmsg_frame_part_node_id_get(bigmsg) != session_id) // ignore messages not meant for us
{
free_tmsg(bigmsg);
free((void *)packet);
continue;
}
part_id = bigmsg_frame_part_part_id_get(bigmsg);
if (part_id<8)
first_packets_mask &= ~(1<<part_id);
const unsigned char *buf = &packet[8+bigmsg_frame_part_buf_offset(0)];
//printf("part id: %d, max: %d\n", part_id, pkt_buf->num_packets);
if (part_id>=pkt_buf->num_packets)
{
free_tmsg(bigmsg);
free((void *)packet);
return -1;
}
memcpy(&pkt_buf->data[part_id*pkt_buf->packet_size], buf, pkt_buf->packet_size);
pkt_buf->is_received[part_id] = 1;
if (callback_function!=NULL)
{
int percentage = (part_id*100)/(pkt_buf->num_packets);
percentage = (percentage>=100)?99:percentage;
if(is->is_progressive && part_id >= iter*inc_amt)
{
iter++;
is->data_size=part_id*64;
if (!first_packets_mask)
write_img_file(is, pkt_buf, filename);
//syslog(0,"receive: callback(1)(pid %d)\n",getpid());
callback_function(percentage, filename);
if (!has_forked)
{
has_forked = do_fork();
if (is_parent_proc)
{
//syslog(0,"stopping parent process(pid %d)\n",getpid());
free_tmsg(bigmsg);
free((void *)packet);
return 0;
}
}
}
else if (!is->is_progressive)
{
//printf("receive: callback(2)(pid %d)\n",getpid());
callback_function(percentage, filename);
}
}
free_tmsg(bigmsg);
free((void *)packet);
}
//printf("receive: done(pid %d)\n",getpid());
return 0;
}
int reliable_receive_img_packets(img_stat_t *is, char *filename, void (*_callback)(int, char *))
{
packet_buffer_t pkt_buf;
pkt_buf.packet_size = 64;
pkt_buf.num_packets = is->data_size/64+((is->data_size%64==0)?0:1);
int pkt_buf_size=(pkt_buf.packet_size+1)*pkt_buf.num_packets;
unsigned char *p_buffer = (unsigned char*)calloc(pkt_buf_size, sizeof(char));
memset(p_buffer, 0, pkt_buf_size);
pkt_buf.is_received=p_buffer;
pkt_buf.data=&p_buffer[pkt_buf.num_packets];
callback_function = _callback;
int retries = 10;
int part_idx = 0;
first_packets_mask = 255;
//syslog(0,"receive_img_packets attmpt 1");
receive_img_packets(is, &pkt_buf, filename, pkt_buf.num_packets-1);
//syslog(0,"receive_img_packets attmpt 1 done");
--retries;
while (retries>0 && part_idx<pkt_buf.num_packets
&& (!is_parent_proc||!is->is_progressive)){
if (!pkt_buf.is_received[part_idx]){
//syslog(0,"query missing packets");
send_img_part_cmd(is->node_id, part_idx, 10);
//syslog(0, "receive_img_packets, attempt %d",11-retries);
receive_img_packets(is, &pkt_buf, filename,part_idx+9);
//syslog(0, "receive_img_packets, attempt %d done",11-retries);
--retries;
}
else
++part_idx;
}
if (is->is_progressive && is_parent_proc) {
//syslog(0,"reliable_receive: exiting parent process!(pid %d)\n",getpid());
free(p_buffer);
//exit(0);
return 0;
}
else
{
//syslog(0, "reliable_receive: callback!(pid %d)\n",getpid());
is->data_size=part_idx*64;
if (!first_packets_mask)
write_img_file(is, &pkt_buf, filename);
callback_function(100, filename);
if (!is_parent_proc)
exit(0);
}
free(p_buffer);
return part_idx;
}
int packets2col_img(packet_buffer_t *pkt_buf,
unsigned char *img_buffer, int width, int height){
int idx;
int packet_buf_size = pkt_buf->packet_size*pkt_buf->num_packets;
for (idx=0; idx<packet_buf_size; idx+=2){
unsigned char byte = pkt_buf->data[idx];
unsigned char byte2 = pkt_buf->data[idx+1];
unsigned char byteR = (byte2&0xF8)>>3;
unsigned char byteG = ((byte2&0x07)<<3) | ((byte&0xE0)>>5);
unsigned char byteB = byte&0x1F;
img_buffer[idx/2*3] =byteR<<3;
img_buffer[idx/2*3+1]=byteG<<2;
img_buffer[idx/2*3+2]=byteB<<3;
}
return 0;
}
int save_img_pnm(char *filebase, unsigned char *img_buffer, int width, int height, int is_color){
FILE *fd;
int i,j,k;
char *filename = (char *)calloc(strlen(filebase)+5,sizeof(char));
char *ext = is_color?".ppm":".pgm";
strcpy(filename, filebase);
strcat(filename,ext);
if (!(fd = fopen(filename, "w"))) {
fprintf(stderr, "Can't open data: %s\n", strerror(errno));
free(filename);
return -1;
}
free(filename);
if (!is_color)
fprintf(fd, "P2\r\n320 240\r\n255\r\n");
else
fprintf(fd, "P3\r\n320 240\r\n255\r\n");
int pixels_width = is_color?3:1;
for (i=0; i<height; i++){
for (j=0; j<width; j++)
for (k=0; k<pixels_width; k++){
unsigned char byte = img_buffer[i*width*pixels_width+j*pixels_width+k];
fprintf(fd, "%d ", byte);
}
fprintf(fd,"\r\n");
}
fclose(fd);
return 0;
}
#ifndef NO_JPEG
int save_img_jpg(char *filebase, unsigned char *img_buffer, int width, int height, int is_color){
FILE *fd;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPROW row_pointer[1];
int row_stride = is_color?width*3:width;
char *filename = (char *)calloc(strlen(filebase)+5,sizeof(char));
char *ext = ".jpg";
strcpy(filename, filebase);
strcat(filename,ext);
if ((fd = fopen(filename, "wb")) == NULL) {
fprintf(stderr, "can't open %s\n", filename);
return -1;
}
free(filename);
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, fd);
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = is_color?3:1;
cinfo.in_color_space = is_color?JCS_RGB:JCS_GRAYSCALE;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, 90, TRUE);
jpeg_start_compress(&cinfo, TRUE);
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = & img_buffer[cinfo.next_scanline * row_stride];
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
fclose(fd);
jpeg_destroy_compress(&cinfo);
return 0;
}
#endif
void write_img_file(img_stat_t *is, packet_buffer_t *pkt_buf, char *filename){
//fprintf(stderr,"rendering at %d %%: %s\n", percentage, filename);
unsigned char *img_buffer = (unsigned char*)calloc(is->width*is->height*3,sizeof(char));
if (is->type&IMG_TYPE_JPG)
{
code_header_t header;
//printf("decoding data size %d\n",is->data_size);
decodeJpegBytes(pkt_buf->data, is->data_size, img_buffer, &header);
//printf("jpg decoded header: W=%d H=%d qual=%d COL=%d size=%d\n",header.width, header.height, header.quality, header.is_color, header.totalSize);
#ifndef NO_JPEG
save_img_jpg(filename, img_buffer, header.width, header.height, header.is_color);
#else
save_img_pnm(filename, img_buffer, header.width, header.height, header.is_color);
#endif
}
else if(is->type&IMG_TYPE_COL)
{
packets2col_img(pkt_buf, img_buffer, is->width, is->height);
save_img_pnm(filename, img_buffer, is->width, is->height, 1);
#ifndef NO_JPEG
save_img_jpg(filename, img_buffer, is->width, is->height, 1);
#endif
}
else
{
save_img_pnm(filename, pkt_buf->data, is->width, is->height, 0);
#ifndef NO_JPEG
save_img_jpg(filename, pkt_buf->data, is->width, is->height, 0);
#endif
}
free(img_buffer);
}
int receive_img(int session_id, int progressive, char * filename, void (*_callback)(int, char *))
{
img_stat_t is;
//syslog(0,"receving image");
if (receive_img_stat_packet(session_id, &is)!=0)
return -1;
is.is_progressive=progressive;
//printf("img stat: id: %d, type: %d, progress: %d, size: %d\n", is.node_id, is.type, is.is_progressive, is.data_size);
//syslog(0,"img from node: %d, progressive: %d", is.node_id, is.is_progressive);
reliable_receive_img_packets(&is, filename, _callback);
//syslog(0,"reliable_receive done!");
return 0;
}
|
tinyos-io/tinyos-3.x-contrib | berkeley/acme/apps/ACMeterApp/EnergyMsg.h | <filename>berkeley/acme/apps/ACMeterApp/EnergyMsg.h<gh_stars>1-10
enum
{
AM_ENERGYMSG = 8,
};
typedef nx_struct EnergyMsg
{
nx_uint16_t src;
nx_uint32_t energy;
} EnergyMsg_t;
enum
{
AM_SWITCHMSG = 9,
};
typedef nx_struct SwitchMsg
{
nx_uint8_t nodeID;
nx_uint16_t toggle;
} SwitchMsg_t;
|
tinyos-io/tinyos-3.x-contrib | crypto/tos/system/trivium.h | <gh_stars>1-10
/*
* Copyright (c) 2009 Centre for Electronics Design and Technology (CEDT),
* Indian Institute of Science (IISc) and Laboratory for Cryptologic
* Algorithms (LACAL), Ecole Polytechnique Federale de Lausanne (EPFL).
*
* Author: <NAME> <<EMAIL>>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of INSERT_AFFILIATION_NAME_HERE nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD
* UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*
* Implementation of the Trivium Stream cipher designed by
* <NAME> and <NAME>
* following the implementation avalaible at
* http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/trivium/
*
* Warning of the original version:
*
* *** WARNING ***
*
* This implementation uses the following ordering of the key and iv
* bits during initialization:
*
* (s_1,s_2,...,s_93) <- (K_80,...,K_1,0,...,0)
* (s_94,s_95,...,s_177) <- (IV_80,...,IV_1,0,...,0)
* (s_178,s_279,...,s_288) <- (0,...,0,1,1,1)
*
* This ordering is more natural than the reversed one used in the
* original specs (as pointed out by both <NAME> and <NAME>).
*
*/
#ifndef TRIVIUM_H
#define TRIVIUM_H
/*
* Compilation done for 8-bit microcontroller by default.
*/
#if ! defined(SIXTEEN_BIT_MICROCONTROLLER) && ! defined(EIGHT_BIT_MICROCONTROLLER)
#define EIGHT_BIT_MICROCONTROLLER
#endif
/*
* 16-bit definitions.
*/
#ifdef SIXTEEN_BIT_MICROCONTROLLER
#define WORD 16
#define KEYLENGTH 5
#define IVLENGTH 5
#define GEN_WORD 4
typedef uint16_t uint_t;
typedef int16_t int_t;
#endif
/*
* 8-bit definitions.
*/
#ifdef EIGHT_BIT_MICROCONTROLLER
#define WORD 8
#define KEYLENGTH 10
#define IVLENGTH 10
#define GEN_WORD 8
typedef uint8_t uint_t;
typedef int8_t int_t;
#endif
/*
* Boolean operations
*/
#define OR(a, b) ((a) | (b))
#define AND(a, b) ((a) & (b))
#define XOR(a, b) ((a) ^ (b))
#define SL(m, i) ((m) << (i))
#define SR(m, i) ((m) >> (i))
/*
* Macros to access useful bits of the internal state
* of the algorithm.
*/
#ifdef EIGHT_BIT_MICROCONTROLLER
#define S1_66_1 OR( SL( s1[7] , 2 ) , SR( s1[8] , 6))
#define S1_66_2 OR( SL( s1[6] , 2 ) , SR( s1[7] , 6))
#define S1_66_3 OR( SL( s1[5] , 2 ) , SR( s1[6] , 6))
#define S1_66_4 OR( SL( s1[4] , 2 ) , SR( s1[5] , 6))
#define S1_66_5 OR( SL( s1[3] , 2 ) , SR( s1[4] , 6))
#define S1_66_6 OR( SL( s1[2] , 2 ) , SR( s1[3] , 6))
#define S1_66_7 OR( SL( s1[1] , 2 ) , SR( s1[2] , 6))
#define S1_66_8 OR( SL( s1[0] , 2 ) , SR( s1[1] , 6))
#define S1_69_1 OR( SL( s1[7] , 5 ) , SR( s1[8] , 3))
#define S1_69_2 OR( SL( s1[6] , 5 ) , SR( s1[7] , 3))
#define S1_69_3 OR( SL( s1[5] , 5 ) , SR( s1[6] , 3))
#define S1_69_4 OR( SL( s1[4] , 5 ) , SR( s1[5] , 3))
#define S1_69_5 OR( SL( s1[3] , 5 ) , SR( s1[4] , 3))
#define S1_69_6 OR( SL( s1[2] , 5 ) , SR( s1[3] , 3))
#define S1_69_7 OR( SL( s1[1] , 5 ) , SR( s1[2] , 3))
#define S1_69_8 OR( SL( s1[0] , 5 ) , SR( s1[1] , 3))
#define S1_91_1 OR( SL( s1[10] , 3 ) , SR( s1[11] , 5))
#define S1_91_2 OR( SL( s1[9] , 3 ) , SR( s1[10] , 5))
#define S1_91_3 OR( SL( s1[8] , 3 ) , SR( s1[9] , 5))
#define S1_91_4 OR( SL( s1[7] , 3 ) , SR( s1[8] , 5))
#define S1_91_5 OR( SL( s1[6] , 3 ) , SR( s1[7] , 5))
#define S1_91_6 OR( SL( s1[5] , 3 ) , SR( s1[6] , 5))
#define S1_91_7 OR( SL( s1[4] , 3 ) , SR( s1[5] , 5))
#define S1_91_8 OR( SL( s1[3] , 3 ) , SR( s1[4] , 5))
#define S1_92_1 OR( SL( s1[10] , 4 ) , SR( s1[11] , 4))
#define S1_92_2 OR( SL( s1[9] , 4 ) , SR( s1[10] , 4))
#define S1_92_3 OR( SL( s1[8] , 4 ) , SR( s1[9] , 4))
#define S1_92_4 OR( SL( s1[7] , 4 ) , SR( s1[8] , 4))
#define S1_92_5 OR( SL( s1[6] , 4 ) , SR( s1[7] , 4))
#define S1_92_6 OR( SL( s1[5] , 4 ) , SR( s1[6] , 4))
#define S1_92_7 OR( SL( s1[4] , 4 ) , SR( s1[5] , 4))
#define S1_92_8 OR( SL( s1[3] , 4 ) , SR( s1[4] , 4))
#define S1_93_1 OR( SL( s1[10] , 5 ) , SR( s1[11] , 3))
#define S1_93_2 OR( SL( s1[9] , 5 ) , SR( s1[10] , 3))
#define S1_93_3 OR( SL( s1[8] , 5 ) , SR( s1[9] , 3))
#define S1_93_4 OR( SL( s1[7] , 5 ) , SR( s1[8] , 3))
#define S1_93_5 OR( SL( s1[6] , 5 ) , SR( s1[7] , 3))
#define S1_93_6 OR( SL( s1[5] , 5 ) , SR( s1[6] , 3))
#define S1_93_7 OR( SL( s1[4] , 5 ) , SR( s1[5] , 3))
#define S1_93_8 OR( SL( s1[3] , 5 ) , SR( s1[4] , 3))
#define S2_69_1 OR( SL( s2[7] , 5 ) , SR( s2[8] , 3))
#define S2_69_2 OR( SL( s2[6] , 5 ) , SR( s2[7] , 3))
#define S2_69_3 OR( SL( s2[5] , 5 ) , SR( s2[6] , 3))
#define S2_69_4 OR( SL( s2[4] , 5 ) , SR( s2[5] , 3))
#define S2_69_5 OR( SL( s2[3] , 5 ) , SR( s2[4] , 3))
#define S2_69_6 OR( SL( s2[2] , 5 ) , SR( s2[3] , 3))
#define S2_69_7 OR( SL( s2[1] , 5 ) , SR( s2[2] , 3))
#define S2_69_8 OR( SL( s2[0] , 5 ) , SR( s2[1] , 3))
#define S2_78_1 OR( SL( s2[8] , 6 ) , SR( s2[9] , 2))
#define S2_78_2 OR( SL( s2[7] , 6 ) , SR( s2[8] , 2))
#define S2_78_3 OR( SL( s2[6] , 6 ) , SR( s2[7] , 2))
#define S2_78_4 OR( SL( s2[5] , 6 ) , SR( s2[6] , 2))
#define S2_78_5 OR( SL( s2[4] , 6 ) , SR( s2[5] , 2))
#define S2_78_6 OR( SL( s2[3] , 6 ) , SR( s2[4] , 2))
#define S2_78_7 OR( SL( s2[2] , 6 ) , SR( s2[3] , 2))
#define S2_78_8 OR( SL( s2[1] , 6 ) , SR( s2[2] , 2))
#define S2_82_1 OR( SL( s2[9] , 2 ) , SR( s2[10] , 6))
#define S2_82_2 OR( SL( s2[8] , 2 ) , SR( s2[9] , 6))
#define S2_82_3 OR( SL( s2[7] , 2 ) , SR( s2[8] , 6))
#define S2_82_4 OR( SL( s2[6] , 2 ) , SR( s2[7] , 6))
#define S2_82_5 OR( SL( s2[5] , 2 ) , SR( s2[6] , 6))
#define S2_82_6 OR( SL( s2[4] , 2 ) , SR( s2[5] , 6))
#define S2_82_7 OR( SL( s2[3] , 2 ) , SR( s2[4] , 6))
#define S2_82_8 OR( SL( s2[2] , 2 ) , SR( s2[3] , 6))
#define S2_83_1 OR( SL( s2[9] , 3 ) , SR( s2[10] , 5))
#define S2_83_2 OR( SL( s2[8] , 3 ) , SR( s2[9] , 5))
#define S2_83_3 OR( SL( s2[7] , 3 ) , SR( s2[8] , 5))
#define S2_83_4 OR( SL( s2[6] , 3 ) , SR( s2[7] , 5))
#define S2_83_5 OR( SL( s2[5] , 3 ) , SR( s2[6] , 5))
#define S2_83_6 OR( SL( s2[4] , 3 ) , SR( s2[5] , 5))
#define S2_83_7 OR( SL( s2[3] , 3 ) , SR( s2[4] , 5))
#define S2_83_8 OR( SL( s2[2] , 3 ) , SR( s2[3] , 5))
#define S2_84_1 OR( SL( s2[9] , 4 ) , SR( s2[10] , 4))
#define S2_84_2 OR( SL( s2[8] , 4 ) , SR( s2[9] , 4))
#define S2_84_3 OR( SL( s2[7] , 4 ) , SR( s2[8] , 4))
#define S2_84_4 OR( SL( s2[6] , 4 ) , SR( s2[7] , 4))
#define S2_84_5 OR( SL( s2[5] , 4 ) , SR( s2[6] , 4))
#define S2_84_6 OR( SL( s2[4] , 4 ) , SR( s2[5] , 4))
#define S2_84_7 OR( SL( s2[3] , 4 ) , SR( s2[4] , 4))
#define S2_84_8 OR( SL( s2[2] , 4 ) , SR( s2[3] , 4))
#define S3_66_1 OR( SL( s3[7] , 2 ) , SR( s3[8] , 6))
#define S3_66_2 OR( SL( s3[6] , 2 ) , SR( s3[7] , 6))
#define S3_66_3 OR( SL( s3[5] , 2 ) , SR( s3[6] , 6))
#define S3_66_4 OR( SL( s3[4] , 2 ) , SR( s3[5] , 6))
#define S3_66_5 OR( SL( s3[3] , 2 ) , SR( s3[4] , 6))
#define S3_66_6 OR( SL( s3[2] , 2 ) , SR( s3[3] , 6))
#define S3_66_7 OR( SL( s3[1] , 2 ) , SR( s3[2] , 6))
#define S3_66_8 OR( SL( s3[0] , 2 ) , SR( s3[1] , 6))
#define S3_87_1 OR( SL( s3[9] , 7 ) , SR( s3[10] , 1))
#define S3_87_2 OR( SL( s3[8] , 7 ) , SR( s3[9] , 1))
#define S3_87_3 OR( SL( s3[7] , 7 ) , SR( s3[8] , 1))
#define S3_87_4 OR( SL( s3[6] , 7 ) , SR( s3[7] , 1))
#define S3_87_5 OR( SL( s3[5] , 7 ) , SR( s3[6] , 1))
#define S3_87_6 OR( SL( s3[4] , 7 ) , SR( s3[5] , 1))
#define S3_87_7 OR( SL( s3[3] , 7 ) , SR( s3[4] , 1))
#define S3_87_8 OR( SL( s3[2] , 7 ) , SR( s3[3] , 1))
#define S3_109_1 OR( SL( s3[12] , 5 ) , SR( s3[13] , 3))
#define S3_109_2 OR( SL( s3[11] , 5 ) , SR( s3[12] , 3))
#define S3_109_3 OR( SL( s3[10] , 5 ) , SR( s3[11] , 3))
#define S3_109_4 OR( SL( s3[9] , 5 ) , SR( s3[10] , 3))
#define S3_109_5 OR( SL( s3[8] , 5 ) , SR( s3[9] , 3))
#define S3_109_6 OR( SL( s3[7] , 5 ) , SR( s3[8] , 3))
#define S3_109_7 OR( SL( s3[6] , 5 ) , SR( s3[7] , 3))
#define S3_109_8 OR( SL( s3[5] , 5 ) , SR( s3[6] , 3))
#define S3_110_1 OR( SL( s3[12] , 6 ) , SR( s3[13] , 2))
#define S3_110_2 OR( SL( s3[11] , 6 ) , SR( s3[12] , 2))
#define S3_110_3 OR( SL( s3[10] , 6 ) , SR( s3[11] , 2))
#define S3_110_4 OR( SL( s3[9] , 6 ) , SR( s3[10] , 2))
#define S3_110_5 OR( SL( s3[8] , 6 ) , SR( s3[9] , 2))
#define S3_110_6 OR( SL( s3[7] , 6 ) , SR( s3[8] , 2))
#define S3_110_7 OR( SL( s3[6] , 6 ) , SR( s3[7] , 2))
#define S3_110_8 OR( SL( s3[5] , 6 ) , SR( s3[6] , 2))
#define S3_111_1 OR( SL( s3[12] , 7 ) , SR( s3[13] , 1))
#define S3_111_2 OR( SL( s3[11] , 7 ) , SR( s3[12] , 1))
#define S3_111_3 OR( SL( s3[10] , 7 ) , SR( s3[11] , 1))
#define S3_111_4 OR( SL( s3[9] , 7 ) , SR( s3[10] , 1))
#define S3_111_5 OR( SL( s3[8] , 7 ) , SR( s3[9] , 1))
#define S3_111_6 OR( SL( s3[7] , 7 ) , SR( s3[8] , 1))
#define S3_111_7 OR( SL( s3[6] , 7 ) , SR( s3[7] , 1))
#define S3_111_8 OR( SL( s3[5] , 7 ) , SR( s3[6] , 1))
#endif
#ifdef SIXTEEN_BIT_MICROCONTROLLER
#define S1_66_1 OR( SL( s1[3] , 2) , SR( s1[4] , 14))
#define S1_66_2 OR( SL( s1[2] , 2) , SR( s1[3] , 14))
#define S1_66_3 OR( SL( s1[1] , 2) , SR( s1[2] , 14))
#define S1_66_4 OR( SL( s1[0] , 2) , SR( s1[1] , 14))
#define S1_69_1 OR( SL( s1[3] , 5) , SR( s1[4] , 11))
#define S1_69_2 OR( SL( s1[2] , 5) , SR( s1[3] , 11))
#define S1_69_3 OR( SL( s1[1] , 5) , SR( s1[2] , 11))
#define S1_69_4 OR( SL( s1[0] , 5) , SR( s1[1] , 11))
#define S1_91_1 OR( SL( s1[4] , 11) , SR( s1[5] , 5))
#define S1_91_2 OR( SL( s1[3] , 11) , SR( s1[4] , 5))
#define S1_91_3 OR( SL( s1[2] , 11) , SR( s1[3] , 5))
#define S1_91_4 OR( SL( s1[1] , 11) , SR( s1[2] , 5))
#define S1_92_1 OR( SL( s1[4] , 12) , SR( s1[5] , 4))
#define S1_92_2 OR( SL( s1[3] , 12) , SR( s1[4] , 4))
#define S1_92_3 OR( SL( s1[2] , 12) , SR( s1[3] , 4))
#define S1_92_4 OR( SL( s1[1] , 12) , SR( s1[2] , 4))
#define S1_93_1 OR( SL( s1[4] , 13) , SR( s1[5] , 3))
#define S1_93_2 OR( SL( s1[3] , 13) , SR( s1[4] , 3))
#define S1_93_3 OR( SL( s1[2] , 13) , SR( s1[3] , 3))
#define S1_93_4 OR( SL( s1[1] , 13) , SR( s1[2] , 3))
#define S2_69_1 OR( SL( s2[3] , 5) , SR( s2[4] , 11))
#define S2_69_2 OR( SL( s2[2] , 5) , SR( s2[3] , 11))
#define S2_69_3 OR( SL( s2[1] , 5) , SR( s2[2] , 11))
#define S2_69_4 OR( SL( s2[0] , 5) , SR( s2[1] , 11))
#define S2_78_1 OR( SL( s2[3] , 14) , SR( s2[4] , 2))
#define S2_78_2 OR( SL( s2[2] , 14) , SR( s2[3] , 2))
#define S2_78_3 OR( SL( s2[1] , 14) , SR( s2[2] , 2))
#define S2_78_4 OR( SL( s2[0] , 14) , SR( s2[1] , 2))
#define S2_82_1 OR( SL( s2[4] , 2 ) , SR( s2[5] , 14))
#define S2_82_2 OR( SL( s2[3] , 2 ) , SR( s2[4] , 14))
#define S2_82_3 OR( SL( s2[2] , 2 ) , SR( s2[3] , 14))
#define S2_82_4 OR( SL( s2[1] , 2 ) , SR( s2[2] , 14))
#define S2_83_1 OR( SL( s2[4] , 3 ) , SR( s2[5] , 13))
#define S2_83_2 OR( SL( s2[3] , 3 ) , SR( s2[4] , 13))
#define S2_83_3 OR( SL( s2[2] , 3 ) , SR( s2[3] , 13))
#define S2_83_4 OR( SL( s2[1] , 3 ) , SR( s2[2] , 13))
#define S2_84_1 OR( SL( s2[4] , 4 ) , SR( s2[5] , 12))
#define S2_84_2 OR( SL( s2[3] , 4 ) , SR( s2[4] , 12))
#define S2_84_3 OR( SL( s2[2] , 4 ) , SR( s2[3] , 12))
#define S2_84_4 OR( SL( s2[1] , 4 ) , SR( s2[2] , 12))
#define S3_66_1 OR( SL( s3[3] , 2 ) , SR( s3[4] , 14))
#define S3_66_2 OR( SL( s3[2] , 2 ) , SR( s3[3] , 14))
#define S3_66_3 OR( SL( s3[1] , 2 ) , SR( s3[2] , 14))
#define S3_66_4 OR( SL( s3[0] , 2 ) , SR( s3[1] , 14))
#define S3_87_1 OR( SL( s3[4] , 7 ) , SR( s3[5] , 9))
#define S3_87_2 OR( SL( s3[3] , 7 ) , SR( s3[4] , 9))
#define S3_87_3 OR( SL( s3[2] , 7 ) , SR( s3[3] , 9))
#define S3_87_4 OR( SL( s3[1] , 7 ) , SR( s3[2] , 9))
#define S3_109_1 OR( SL( s3[5] , 13 ) , SR( s3[6] , 3))
#define S3_109_2 OR( SL( s3[4] , 13 ) , SR( s3[5] , 3))
#define S3_109_3 OR( SL( s3[3] , 13 ) , SR( s3[4] , 3))
#define S3_109_4 OR( SL( s3[2] , 13 ) , SR( s3[3] , 3))
#define S3_110_1 OR( SL( s3[5] , 14 ) , SR( s3[6] , 2))
#define S3_110_2 OR( SL( s3[4] , 14 ) , SR( s3[5] , 2))
#define S3_110_3 OR( SL( s3[3] , 14 ) , SR( s3[4] , 2))
#define S3_110_4 OR( SL( s3[2] , 14 ) , SR( s3[3] , 2))
#define S3_111_1 OR( SL( s3[5] , 15 ) , SR( s3[6] , 1))
#define S3_111_2 OR( SL( s3[4] , 15 ) , SR( s3[5] , 1))
#define S3_111_3 OR( SL( s3[3] , 15 ) , SR( s3[4] , 1))
#define S3_111_4 OR( SL( s3[2] , 15 ) , SR( s3[3] , 1))
#endif
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/stargatehelper/SolarSrc.h | <gh_stars>1-10
#ifndef SOLARSRC_H_INCLUDED
#define SOLARSRC_H_INCLUDED
#define _NUMEPOCHS 6
#define _HISTORYLENGTH 5
#define _DAYLENGTH (24*60)
#define _EPOCHLENGTH (_DAYLENGTH / _NUMEPOCHS)
#endif
|
tinyos-io/tinyos-3.x-contrib | diku/common/tools/compression/buffer.c | /**************************************************************************
*
* buffer.c
*
* An implementation of the most basic buffer manipulation functions,
* needed for the compression algorithms.
*
* This file is licensed under the GNU GPL.
*
* (C) 2005, <NAME> <<EMAIL>>
*
*/
#include "buffer.h"
#ifdef HAVE_ASSERT
# include <assert.h>
#else
# define assert(x)
#endif
uint8_t membuffer[MEMBUFSIZE] __attribute((xdata));
uint8_t *buf_pos;
uint8_t write_bits_used;
void reset_buffer()
{
buf_pos = membuffer;
write_bits_used = 0;
*buf_pos = 0;
}
uint8_t *get_unwritten()
{
if (write_bits_used) {
return buf_pos + 1;
} else {
return buf_pos;
}
}
uint8_t *get_buffer()
{
return membuffer;
}
uint16_t bits_left()
{
uint16_t res = MEMBUFSIZE * 8; // Entire memory
res -= (buf_pos - membuffer) * 8; // Bytes used.
res -= write_bits_used; // The unused bits left in the buffer.
assert(res <= MEMBUFSIZE * 8);
return res;
}
void write_bits(uint8_t data, uint8_t len)
{
uint16_t buffer;
assert(len <= 8);
assert(write_bits_used < 8);
assert(buf_pos >= membuffer && buf_pos < membuffer + MEMBUFSIZE);
if (write_bits_used == 0) {
buffer = 0;
} else {
buffer = ((uint16_t)*buf_pos) << 8;
}
buffer |= (uint16_t)data << (16 - len - write_bits_used);
write_bits_used += len;
while (write_bits_used >= 8) {
*buf_pos++ = buffer >> 8;
buffer <<= 8;
write_bits_used -= 8;
}
assert(write_bits_used < 8);
if (write_bits_used) {
assert(buf_pos >= membuffer && buf_pos < membuffer + MEMBUFSIZE);
*buf_pos = (uint8_t)(buffer >> 8);
}
}
|
tinyos-io/tinyos-3.x-contrib | berkeley/blip-2.0/support/sdk/c/blip/interface/logging.c | /*
* "Copyright (c) 2008 The Regents of the University of California.
* All rights reserved."
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <stdarg.h>
#include "logging.h"
loglevel_t log_level;
FILE *log_dest;
const char *log_names[5] = {"DEBUG",
"INFO",
"WARN",
"ERROR",
"FATAL"};
/* buffers for log history */
static int log_size, log_end;
static char log_history[LOGHISTSIZ][LOGLINESIZ];
#define LOG_INCR do { \
log_end = (log_end + 1) % LOGHISTSIZ; \
log_size = (log_size < LOGHISTSIZ) ? (log_size + 1) : log_size; \
} while (0);
static int timestamp(char *buf, int len){
struct timeval tv;
struct tm *ltime;
int rv = 0;
gettimeofday(&tv, NULL);
// automatically calls tzset()
ltime = localtime(&tv.tv_sec);
rv += snprintf(buf, len, ISO8601_FMT(ltime, &tv));
rv += snprintf(buf + rv, len - rv, ": ");
return rv;
}
loglevel_t log_setlevel(loglevel_t l) {
loglevel_t old_lvl = log_level;
log_level = l;
return old_lvl;
}
loglevel_t log_getlevel() {
return log_level;
}
void log_init() {
log_level = LOGLVL_INFO;
log_dest = stderr;
log_end = log_size = 0;
}
void log_addentry(char *buf) {
strncpy(log_history[log_end], buf, LOGLINESIZ);
log_history[log_end][LOGLINESIZ-1] = '\0';
LOG_INCR;
}
void log_log (loglevel_t level, const char *fmt, ...) {
char buf[1024];
int buf_used = 0;
va_list ap;
va_start(ap, fmt);
if (log_level > level) return;
buf_used += timestamp(buf, 1024 - buf_used);
buf_used += snprintf(buf + buf_used, 1024 - buf_used, "%s: ", log_names[level]);
buf_used += vsnprintf(buf + buf_used, 1024 - buf_used, fmt, ap);
fputs(buf, log_dest);
log_addentry(buf);
va_end(ap);
}
void log_fatal_perror(const char *msg) {
char buf[1024];
int in_errno = errno;
if (in_errno < 0) return;
timestamp(buf, 1024);
fputs(buf, log_dest);
fprintf(log_dest, "%s: ", log_names[LOGLVL_FATAL]);
if (msg != NULL) fprintf(log_dest, "%s: ", msg);
fprintf(log_dest, "%s\n", strerror(in_errno));
}
void log_clear (loglevel_t level, const char *fmt, ...) {
char buf[1024];
if (log_level > level) return;
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, 1024, fmt, ap);
fputs(buf, log_dest);
log_addentry(buf);
va_end(ap);
}
/* print char* in hex format */
void log_dump_serial_packet(unsigned char *packet, const int len) {
int i;
if (log_level > LOGLVL_DEBUG) return;
printf("[%d]\t", len);
if (!packet)
return;
for (i = 0; i < len; i++) {
if ((i % 16) == 0 && i) printf("\n\t");
printf("%02x ", packet[i]);
}
putchar('\n');
}
#if 0
void log_show_log(int fd, int argc, char **argv) {
VTY_HEAD;
int n = 10, i, start_point;
if (argc == 2) {
n = atoi(argv[1]);
}
if (n == 0 || n > log_size) {
n = log_size;
}
start_point = (log_end - n);
if (start_point < 0) start_point += LOGHISTSIZ;
for (i = 0; i < n; i++) {
int idx = (start_point + i) % LOGHISTSIZ;
VTY_printf("%s", log_history[idx]);
VTY_flush();
}
VTY_flush();
}
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/tinyos2/eon_network.h | <reponame>tinyos-io/tinyos-3.x-contrib
#ifndef EON_NETWORK_H_INCLUDED
#define EON_NETWORK_H_INCLUDED
#include "message.h"
/*enum
{
AM_BEACONMSG = 4,
//AM_ACCEPTMSG = 5,
AM_PREDATA = 8,
AM_OFFERMSG = 9,
AM_DATAMSG = 11,
AM_DATAACK = 12,
AM_ARCHIVEMSG = 13,
AM_ACKMSG = 14,
AM_COLLECTMSG = 15,
AM_STATUSMSG = 16,
AM_ACTIVATEMSG = 17,
};*/
typedef struct BeaconMsg
{
uint16_t src_addr; //the beaconers address
uint16_t src_delay; //the beaconers delay to the base station
uint16_t bw; //the maximum number of packets that the beaconer might send you
} BeaconMsg_t;
typedef struct OfferMsg
{
uint16_t addr; //the responders address
uint16_t delay; //the responders delay to the base station
uint16_t bw; //the maximum number of packets that the responder might recv from you
} OfferMsg_t;
typedef struct AckMsg{
uint8_t src;
uint8_t idx;
uint16_t addr;
uint16_t min_id;
uint16_t max_id;
}AckMsg_t;
#define DATA_MSG_HDR_LEN 6
#define DATA_MSG_DATA_LEN (TOSH_DATA_LENGTH-DATA_MSG_HDR_LEN)
#define MAX_CONSECUTIVE_DATA_TIMEOUTS 5
#define RECV_MSG_TIMEOUT_MS 1000
#define INTERESTED_ROUNDS 3
#define INTERESTED_INTERVAL 1000
#define SEND_TIMEOUT_MS 1000
#define MAX_CONSECUTIVE_TIMEOUTS 5
#define RECV_ACK_TIMEOUT_MS 1000
#define BUNDLE_ACK_HEADER_LENGTH 6
#define BUNDLE_ACK_DATA_LENGTH TOSH_DATA_LENGTH - BUNDLE_ACK_HEADER_LENGTH
#define PACKET_DATA_LENGTH 30
#define PACKET_HEADER_LENGTH 1
#define CHUNK_DATA_LENGTH (PACKET_DATA_LENGTH - PACKET_HEADER_LENGTH)
#define CHUNK_HEADER_LENGTH 6
#define CHUNK_PAYLOAD_LENGTH (CHUNK_DATA_LENGTH - CHUNK_HEADER_LENGTH)
typedef nx_struct DataMsg
{
nx_uint16_t src_addr;
nx_uint8_t offerid;
nx_uint8_t last;
nx_uint8_t length;
nx_uint16_t sequence;
nx_uint8_t data[DATA_MSG_DATA_LEN];
}DataMsg_t;
typedef struct eon_message
{
uint8_t data[PACKET_DATA_LENGTH];
uint8_t length;
} eon_message_t;
#endif // EON_NETWORK_H_INCLUDED
|
tinyos-io/tinyos-3.x-contrib | tcd/tinyhop/tos/lib/TinyHop-v.1.0/TinyHop.h | <reponame>tinyos-io/tinyos-3.x-contrib
/*
* Copyright (c) 2009 Trinity College Dublin.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the Trinity College Dublin nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRINITY
* COLLEGE DUBLIN OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author <NAME> <carbajor {tcd.ie}>
* @date February 13 2009
* Computer Science
* Trinity College Dublin
*/
/****************************************************************/
/* TinyHop: */
/* An end-to-end on-demand reliable ad hoc routing protocol */
/* for Wireless Sensor Networks intended for P2P communication */
/*--------------------------------------------------------------*/
/* This version has been tested with TinyOS 2.1.0 and 2.1.1 */
/****************************************************************/
#ifndef _TOS_TINYHOP_H
#define _TOS_TINYHOP_H
#include "AM.h"
#include "message.h"
//DEFINE TRANSMISSION POWER FOR THE ROUTING PROTOCOL
#ifndef ROUTING_RFPOWER
#define ROUTING_RFPOWER CC2420_DEF_RFPOWER
#endif
#include <qsort.c>
void qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *));
enum {
AM_TOS_HOPPINGMSG = 249
};
enum {
EMPTY = 0xffff
};
enum {
SEND_QUEUE_SIZE = 8, //20
ACK_QUEUE_SIZE = 1,
ACK_NEW_QUEUE_SIZE = 1
};
enum {
ROUTE_TABLE_SIZE = 25, //50
MAX_NUM_MOTES=15, //50
MAX_SEQUENCE_MOTE=32535,
MAX_MEMORY_FILTER=20,
MAX_PACKETS_ACKED_FILTER=20,
MAX_ROUTING_FREQ=32535
};
enum {
NEW_ROUTE=0,
ACK_NEW_ROUTE=1,
ACK_OF_ACK_NEW_ROUTE=2,
DISCOVERY_ACK_NEW_ROUTE=3,
ACK_DISCOVERY_ACK_NEW_ROUTE=4,
FOLLOW_ROUTE=5,
ACK_FOLLOW_ROUTE=6,
BROADCAST = 7
};
enum{
//TIME_RTX_NEW_ROUTE=350, //That's in Milliseconds
//TIME_RTX_FOLLOW_ROUTE=150, //That's in Milliseconds
//TIME_RTX_ACK_NEW_ROUTE=30 //That's in Milliseconds
//For topologies larger than 32 nodes
TIME_RTX_NEW_ROUTE=800, //That's in Milliseconds
TIME_RTX_FOLLOW_ROUTE=500, //That's in Milliseconds
TIME_RTX_ACK_NEW_ROUTE=30 //That's in Milliseconds
};
enum{
MAX_NUM_FOLLOWING_TRIALS=2, //Maximum number of resending trials if the msg is already following a route
MAX_NUM_NEW_ROUTE_TRIALS=2, //Maximum number of resending trials if the msg it is discovering a route
MAX_RE_DISCOVERY_TRIALS=1, //Maximum number of retrials if a discovery process for an ack new route has failed
MAX_TRIALS_ACK_NEW_ROUTE=1 //Maximum number of retrials in sending the ACK_NEW_ROUTE packet,
//if an ACK_OF_ACK_NEW ROUTE or a SNOOP packet is not received
};
/********************************************************************************************************************/
/* Tupla Mote_Address-Sequence */
/********************************************************************************************************************/
typedef struct AddrSeq{
am_addr_t addr;
uint16_t seq;
} AddrSeq;
/********************************************************************************************************************/
/* Routing table which indicate that the packets received for the node "received.addr" with sequence "received.seq" */
/* have to be forwarded to the mote "sent.addr" with sequence "sent.seq". That will form the routes. Each route */
/* has a usage frequence value which indicates how frequently this route is being used(reset every certain interval)*/
/********************************************************************************************************************/
typedef struct RoutingTable{
am_addr_t origin; //Address of the node that creates the packets that are following this route
am_addr_t destination; //Address of the node that finally receives the packets that are following this route
AddrSeq received;
AddrSeq sent;
uint16_t usageFreq;
} RoutingTable;
/********************************************************************************************************************/
/* Reachable Motes (addresses) from the local mote */
/* "targetAddr" = mote address that can be reached from the local mote */
/* "sendRoute" = indicates the address and sequence where the msg has to be sent to reach the target mote */
/********************************************************************************************************************/
typedef struct ReachableMotes{
am_addr_t targetAddr;
AddrSeq sendRoute;
} ReachableMotes;
/********************************************************************************************************************/
/* Memory Filter performs as a LIFO queue to store the most frequent discovery packet routes so to avoid cycles */
/* "originAddr" = it indicates who created the packet */
/* "seqMsg" = indicate seq for this message */
/********************************************************************************************************************/
typedef struct MemoryFilter{
am_addr_t originAddr;
uint16_t seqMsg;
} MemoryFilter;
/********************************************************************************************************************/
/* List of Discovery Packets Acked. That allows to control how many NEW_ROUTE packets are acked with a */
/* NEW_ROUTE_ACK packet. */
/* "originAddr" = it indicates who created the packet */
/* "seqMsg" = it indicates seq for this message */
/********************************************************************************************************************/
typedef struct PacketsAckedFilter{
am_addr_t originAddr;
uint16_t seqMsg;
} PacketsAckedFilter;
/********************************************************************************************************************/
/* Structure of the Message for TinyHop */
/********************************************************************************************************************/
typedef nx_struct TOS_HoppingMsg {
nx_am_addr_t targetAddr; //Final destination address for the msg
nx_am_addr_t originAddr; //Origin address of the msg
nx_am_addr_t senderAddr; //Mote which sends the msg each time (even if it's forwarded)
nx_uint16_t seqMsg; //Seq of the message (generated by the origin mote) (automatically reset at max 2^16)
nx_uint16_t seqRoute; //Seq for each packet being sent to perform routing process
nx_uint8_t type; //Type of msg being sent: NEW_ROUTE,ACK_NEW_ROUTE,FOLLOW_ROUTE,...
nx_uint8_t data[0];
} TOS_HoppingMsg;
#endif /* _TOS_TINYHOP_H */
|
tinyos-io/tinyos-3.x-contrib | sensorscheme/tos/lib/SensorScheme/SensorScheme.h | #ifndef SENSORSCHEME_H
#define SENSORSCHEME_H
#include "Types.h"
#include "Macros.h"
#include "SensorSchemeMsg.h"
enum {
AM_SSCOLLECT_MSG = 8,
CL_SSCOLLECT_MSG = 9,
CL_SSINTERCEPT_MSG = 10,
COLLECTION_ROOTNODE = 0,
};
enum {
POOL_SIZE = 8,
ROOT_QUEUE_SIZE = 8,
SS_TICKS_PER_SECOND = 16,
};
enum entrypoint_t {
SS_INIT,
SS_RECEIVE,
SS_STARTREAD,
SS_SENDDONE,
SS_SENDLAST,
SS_CONTINUE,
SS_TIMER
} entrypoint_t;
/* the possible error values */
enum errorcode_t {
ERROR_NULL,
ERROR_NONE,
ERROR_OUT_OF_MEMORY,
ERROR_ILLEGAL_WRITE,
ERROR_SYMBOL_NOT_FOUND,
ERROR_TOO_FEW_ARGS,
ERROR_TOO_MANY_ARGS,
ERROR_ILLEGAL_CLOSURE,
ERROR_NOT_CALLABLE,
ERROR_UNKNOWN_PRIMTIIVE,
ERROR_SYMBOL_NOT_BOUND,
ERROR_PRIMITIVE_ARGUMENT_COUNT,
ERROR_MESSAGE_FORMAT,
ERROR_ARG_NOT_PAIR,
ERROR_ARG_NOT_SYMBOL,
ERROR_ARG_NOT_NUMBER,
ERROR_MSG_ENDMARKER,
ERROR_MSG_TERMINATION,
ERROR_MSG_CONTENT_END,
} errorcode_t;
char const* error_str[] = {
[ERROR_NULL] = "NULL error, should not occur",
[ERROR_NONE] = "Terminated normally",
[ERROR_OUT_OF_MEMORY] = "Out of memory!",
[ERROR_ILLEGAL_WRITE] = "Illegal write",
[ERROR_SYMBOL_NOT_FOUND] = "Symbol not found",
[ERROR_TOO_FEW_ARGS] = "Too few arguments to closure",
[ERROR_TOO_MANY_ARGS] = "Too many arguments to closure",
[ERROR_ILLEGAL_CLOSURE] = "Illegal closure format",
[ERROR_NOT_CALLABLE] = "calling an object that is not callable",
[ERROR_UNKNOWN_PRIMTIIVE] = "Unknwn primitive",
[ERROR_SYMBOL_NOT_BOUND] = "Symbol not bound",
[ERROR_PRIMITIVE_ARGUMENT_COUNT] = "Wrong number of arguments to primitive",
[ERROR_MESSAGE_FORMAT] = "Message format",
[ERROR_ARG_NOT_PAIR] = "Argument is not a pair",
[ERROR_ARG_NOT_SYMBOL] = "Argument is not a symbol",
[ERROR_ARG_NOT_NUMBER] = "Argument is not a number",
[ERROR_MSG_ENDMARKER] = "Message has no end marker",
[ERROR_MSG_TERMINATION] = "Message not terminated properly",
[ERROR_MSG_CONTENT_END] = "Message content not finished yet",
};
#define LABEL_LIST(_) \
_(OP_EXIT) \
_(OP_HANDLEMSG) \
_(OP_HANDLEINIT) \
_(OP_IF_CONT) \
_(OP_SET_CONT) \
_(OP_DEF_CONT) \
_(OP_ARGEVAL_CONT) \
_(OP_APPLY) \
_(OP_APPLY_CONT) \
_(RD_BITS_CONT) \
_(RD_WORD_CONT1) \
_(RD_WORD_CONT2) \
_(RD_DWORD_CONT1) \
_(RD_DWORD_CONT2) \
_(RD_SEXPR_CONT1) \
_(RD_LIST) \
_(RD_DOT) \
_(RD_SEXPR_SYM) \
_(RD_SYM_NIBBLE1) \
_(RD_SYM_NIBBLE2) \
_(RD_SYM_STRING) \
_(RD_SEXPR_NUM) \
_(RD_SEXPR_NIBBLE1) \
_(RD_SEXPR_NIBBLE2) \
_(RD_SEXPR_BYTE) \
_(WR_NUMBER_NIBBLE1) \
_(WR_NUMBER_NIBBLE2) \
_(WR_NUMBER_BYTE) \
_(WR_NUMBER_WORD) \
_(WR_NUMBER_DWORD) \
_(WR_SEXPR_NIL) \
_(WR_SEXPR_SYM) \
_(WR_NUMBER) \
_(WR_SEXPR_LIST) \
_(WR_LIST) \
_(WR_LIST_DOT) \
_(WR_FINISH) \
/* Symbol definitions */
#define SYM_LIST(_) \
_(_NIL, 0) \
_(_TRUE, 0) \
_(_FALSE, 0) \
/* read symbols */ \
_(STRING, 0) \
_(DOT, 0) \
/* the special forms */ \
_(LAMBDA, 0) \
_(IF, 0) \
_(QUOTE, 0) \
_(DEFINE, 0) \
_(SET, 0) \
_(CLOSURE, 0) \
_(CONTINUATION, 0) \
_(PRIMITIVE, 0) \
/* special case ID */ \
_(ID, 0) \
#define JUMP_SWITCH(name) case name: goto name;
#define SENDER_BOOT(name, pr) call Sender.start[name]();
#define RECEIVER_BOOT(name, pr) call Receiver.start[name]();
#define LABEL_ENUM(name) name,
#define PRIM_ENUM(name, fn) name,
enum jumptarget_t {
LABEL_LIST(LABEL_ENUM)
} jumptarget_t;
enum symbols {
SYM_LIST(PRIM_ENUM)
SIMPLE_PRIM_LIST(PRIM_ENUM)
EVAL_PRIM_LIST(PRIM_ENUM)
APPLY_PRIM_LIST(PRIM_ENUM)
SEND_PRIM_LIST(PRIM_ENUM)
} symbols_t;
enum receivers {
_dummy_receiver,
RECEIVER_LIST(PRIM_ENUM)
} receivers_t;
#define COUNT_ITEMS(name, fn) +1
#define NUM_SYMS (0 SYM_LIST(COUNT_ITEMS))
#define NUM_SIMPLEPRIMS (NUM_SYMS SIMPLE_PRIM_LIST(COUNT_ITEMS))
#define NUM_EVALPRIMS (NUM_SIMPLEPRIMS EVAL_PRIM_LIST(COUNT_ITEMS))
#define NUM_APPLYPRIMS (NUM_EVALPRIMS APPLY_PRIM_LIST(COUNT_ITEMS))
#define NUM_PRIMS (NUM_APPLYPRIMS SEND_PRIM_LIST(COUNT_ITEMS))
#define FIRST_SEND_PRIM (NUM_APPLYPRIMS)
#define LAST_PRIM (NUM_PRIMS - 1)
#define LAST_LOCAL (256-8)
#endif
|
tinyos-io/tinyos-3.x-contrib | tcd/powertossim-z/tinyos_files/tinyos-2.0.2/tos/chips/atm128/pins/Atm128Interrupt.h | <filename>tcd/powertossim-z/tinyos_files/tinyos-2.0.2/tos/chips/atm128/pins/Atm128Interrupt.h
// $Id: Atm128Interrupt.h,v 1.1 2014/11/26 19:31:33 carbajor Exp $
/*
* Copyright (c) 2004-2005 Crossbow Technology, Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS BE LIABLE TO
* ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS.
*/
// @author <NAME> <<EMAIL>>
#ifndef _H_Atm128Interrupt_h
#define _H_Atm128Interrupt_h
//====================== External Interrupts ===============================
/* Sleep modes */
enum {
ATM128_IRQ_ON_LOW = 0,
ATM128_IRQ_ON_CHANGE = 1,
ATM128_IRQ_ON_FALL = 2,
ATM128_IRQ_ON_RISE = 3,
};
/* Interrupt Control Register */
typedef struct
{
uint8_t isc0 : 2; //!< Interrupt Sense Control
uint8_t isc1 : 2; //!< Interrupt Sense Control
uint8_t isc2 : 2; //!< Interrupt Sense Control
uint8_t isc3 : 2; //!< Interrupt Sense Control
} Atm128_InterruptCtrl_t;
typedef Atm128_InterruptCtrl_t Atm128_EICRA_t; //!< Ext Interrupt Control A
typedef Atm128_InterruptCtrl_t Atm128_EICRB_t; //!< Ext Interrupt Control B
typedef uint8_t Atm128_EIMSK_t; //!< External Interrupt Mask Register
typedef uint8_t Atm128_EIFR_t; //!< External Interrupt Flag Register
#endif //_H_Atm128Interrupt_h
|
tinyos-io/tinyos-3.x-contrib | berkeley/blip-2.0/support/sdk/c/blip/lib6lowpan/tests/test_unpack_ipnh.c | <reponame>tinyos-io/tinyos-3.x-contrib<gh_stars>1-10
#include <stdint.h>
#include <stdio.h>
#include "Ieee154.h"
#include "ip.h"
#include "lib6lowpan.h"
#include "nwbyte.h"
#include "6lowpan.h"
uint8_t *unpack_ipnh(uint8_t *dest, uint8_t *nxt_hdr, uint8_t *buf);
struct {
uint8_t nxt_hdr;
uint16_t unpacked_length;
int pack_len;
uint8_t pack[2];
int data_length;
} test_cases[] = {
{IPV6_HOP, 8, 1, {LOWPAN_NHC_IPV6_PATTERN | LOWPAN_NHC_EID_HOP | LOWPAN_NHC_NH}, 8},
{IPV6_MOBILITY, 13, 1, {LOWPAN_NHC_IPV6_PATTERN | LOWPAN_NHC_EID_MOBILE | LOWPAN_NHC_NH}, 13},
{IPV6_IPV6, 120, 1, {LOWPAN_NHC_IPV6_PATTERN | LOWPAN_NHC_EID_IPV6 | LOWPAN_NHC_NH}, 120},
{IPV6_IPV6, 12, 2, {LOWPAN_NHC_IPV6_PATTERN | LOWPAN_NHC_EID_IPV6, IANA_UDP}, 12},
};
int run_tests() {
int i, j;
int success = 0, total = 0;
for (i = 0; i < (sizeof(test_cases) / sizeof(test_cases[0])); i++) {
uint8_t nxt_hdr;
uint8_t buf[512], result[512];
uint8_t *rv, *pack;
total++;
memcpy(buf, test_cases[i].pack, test_cases[i].pack_len);
pack = buf + test_cases[i].pack_len;
*pack++ = test_cases[i].data_length;
for (j = 12; j < 12 + test_cases[i].data_length - 2; j++)
*pack++ = j;
printf("INPUT: ");
for (j = 0; j < test_cases[i].data_length; j++)
printf("0x%x ", buf[j]);
printf("\n");
rv = unpack_ipnh(result, &nxt_hdr, buf);
printf("ip6_ext nxt: %i length: %i\n", nxt_hdr, result[1]);
for (j = 0; j < result[1] ; j++) {
printf("0x%x ", result[j]);
}
printf("\n");
// printf("%i:\n", test_cases[i].unpacked_length);
if (test_cases[i].unpacked_length != result[1]) {
printf("ERROR: wrong length\n");
continue;
}
if (test_cases[i].nxt_hdr != nxt_hdr) {
printf("ERROR: wrong next header: %i %i\n", test_cases[i].nxt_hdr, nxt_hdr);
continue;
}
if (test_cases[i].pack_len == 2 && result[0] != test_cases[i].pack[1]) {
printf("ERROR: wrong inline NH\n");
continue;
}
for (j = 2; j < result[1]; j++) {
if (result[j] != j + 10) {
printf("ERROR: wrong payload\n");
break;
}
}
if (j == result[1])
success++;
}
printf("%s: %i/%i tests succeeded\n", __FILE__, success, total);
if (success == total) return 0;
return 1;
}
int main() {
return run_tests();
}
|
tinyos-io/tinyos-3.x-contrib | tub/apps/PacketSniffer_802_15_4/wiresharkPlugins/t2am/packet-t2am.h | /* packet-t2sam.h
* Definitions for TinyOs2 Serial Active Message
* Copyright 2007, <NAME> <<EMAIL>>
*
* $Id: packet-t2am.h,v 1.1 2007/05/30 15:05:31 phihup Exp $
*
* Wireshark - Network traffic analyzer
* By <NAME> <<EMAIL>>
* Copyright 1998 <NAME>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
#ifndef PACKET_T2AM_H
#define PACKET_T2AM_H
/* standard serial packet type for TOS2 AM */
#define T2_AM_SERIAL_TYPE 0x0
/* serial am header length is 7 bytes */
#define T2_AM_HEADER_LEN 7
#define T2_AM_HEADER_DEST_LEN 2
#define T2_AM_HEADER_SRC_LEN 2
#define T2_AM_HEADER_LENGTH_LEN 1
#define T2_AM_HEADER_GROUP_LEN 1
#define T2_AM_HEADER_TYPE_LEN 1
#define T2_AM_HEADER_DEST_OFFSET 0
#define T2_AM_HEADER_SRC_OFFSET (T2_AM_HEADER_DEST_OFFSET + T2_AM_HEADER_DEST_LEN)
#define T2_AM_HEADER_LENGTH_OFFSET (T2_AM_HEADER_SRC_OFFSET + T2_AM_HEADER_SRC_LEN)
#define T2_AM_HEADER_GROUP_OFFSET (T2_AM_HEADER_LENGTH_OFFSET + T2_AM_HEADER_LENGTH_LEN)
#define T2_AM_HEADER_TYPE_OFFSET (T2_AM_HEADER_GROUP_OFFSET + T2_AM_HEADER_GROUP_LEN)
#define T2_AM_DATA_OFFSET (T2_AM_HEADER_TYPE_OFFSET + T2_AM_HEADER_TYPE_LEN)
static void dissect_t2am(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/eon/src/runtime/tinyos/DS2770.h |
//This code is a modified version of code from the Heliomote project
#ifndef _DS2770_H_
#define _DS2770_H_
unsigned char
ds2770_init (void)
{
unsigned char presence;
//TOSH_SEL_ADC2_IOFUNC ();
TOSH_MAKE_ADC4_OUTPUT ();
//TOSH_SEL_GIO1_IOFUNC ();
//TOSH_MAKE_GIO1_OUTPUT ();
TOSH_CLR_ADC4_PIN ();
TOSH_uwait (300); // Keep low for about 600 us
//TOSH_SET_GIO1_PIN();
//TOSH_uwait(100);
//TOSH_CLR_GIO1_PIN();
TOSH_MAKE_ADC4_INPUT (); // Set pin as input
TOSH_uwait (40); // Wait for presence pulse
presence = TOSH_READ_ADC4_PIN (); // Read the bit on pin for presence
TOSH_uwait (250); // Wait for end of timeslot
return !presence; // 1 = presence, 0 = no presence
}
int
ds2770_readBit ()
// It reads one bit from the one-wire interface */
{
int result;
atomic
{
TOSH_MAKE_ADC4_OUTPUT (); // Set pin as output
TOSH_CLR_ADC4_PIN (); // Set the line low
TOSH_uwait (1); // Hold the line low for at least one us
TOSH_MAKE_ADC4_INPUT (); // Set pin as input
TOSH_uwait (7); // Wait 14 us before reading bit value
result = TOSH_READ_ADC4_PIN (); // Store bit value
TOSH_uwait (50);
}
return result;
}
void
ds2770_writeBit (int bit)
// It writes out a bit
{
atomic
{
if (bit)
{
TOSH_MAKE_ADC4_OUTPUT (); // Set pin as output
TOSH_CLR_ADC4_PIN (); // Set the line low
TOSH_uwait (4); // Hold line low for 2 us
TOSH_MAKE_ADC4_INPUT (); // Set pin as input
TOSH_uwait (50); // Write slot is at least 60 us
}
else
{
TOSH_MAKE_ADC4_OUTPUT (); // Set pin as output
TOSH_CLR_ADC4_PIN (); // Set the line low
TOSH_uwait (50); // Hold line low for at least 60 us
TOSH_MAKE_ADC4_INPUT (); // Release the line
TOSH_uwait (8);
}
} //atomic
}
void
ds2770_writeByte (int hexNum)
// It sends one byte via the one-wire that corresponds to the binary representation
// of hexNum. The variable next is used when the number is broken down into its
// binary code and it holds the current value of the variable. curBit holds the
// value of the bit to be written to the line.
{
int i;
for (i = 0; i < 8; i++) // Convert to binary code
{
ds2770_writeBit (hexNum & 0x01);
// shift the data byte for the next bit
hexNum >>= 1;
}
}
int
ds2770_readByte ()
// It reads a byte from the one-wire and stores it in the array byteArray,
// which will contain the information of the one byte read
{
int loop, result = 0;
for (loop = 0; loop < 8; loop++)
{
// shift the result to get it ready for the next bit
result >>= 1;
// if result is one, then set MS bit
if (ds2770_readBit ())
result |= 0x80;
}
return result;
}
void
ds2770_skipROM ()
// Skip ROM command, when only one DS2438 is being used on the line
{
ds2770_writeByte (0xcc); // Request skip ROM to be executed
}
uint8_t
ds2770_readAddr (uint8_t addr)
{
uint8_t data;
uint8_t p;
p = ds2770_init ();
if (p)
{
ds2770_skipROM ();
ds2770_writeByte (0x69);
ds2770_writeByte (addr);
data = ds2770_readByte ();
}
else
{
data = 0xeb;
}
return data;
}
uint8_t
ds2770_readAddrRange (uint8_t addr, int bytes, uint8_t* buffer)
{
uint8_t p;
int i;
p = ds2770_init ();
if (p)
{
ds2770_skipROM ();
ds2770_writeByte (0x69);
ds2770_writeByte (addr);
for (i=0; i < bytes; i++)
{
*(buffer+i) = ds2770_readByte();
}
}
return p;
}
void
ds2770_writeAddr (uint8_t addr, uint8_t val)
{
ds2770_init ();
ds2770_skipROM ();
ds2770_writeByte (0x6C);
ds2770_writeByte (addr);
ds2770_writeByte (val);
}
void
ds2770_refresh ()
{
ds2770_init ();
ds2770_skipROM ();
ds2770_writeByte (0x63);
}
void
ds2770_copyAddr(uint8_t addr)
{
ds2770_init();
ds2770_skipROM();
ds2770_writeByte(0x48);
ds2770_writeByte(addr);
}
#endif
|
tinyos-io/tinyos-3.x-contrib | intelmote2/support/sdk/c/camera_cmd/bigmsg_frame_part.c | /**
* This file is automatically generated by mig. DO NOT EDIT THIS FILE.
* This file implements the functions for encoding and decoding the
* 'bigmsg_frame_part' message type. See bigmsg_frame_part.h for more details.
*/
#include <message.h>
#include "bigmsg_frame_part.h"
uint16_t bigmsg_frame_part_part_id_get(tmsg_t *msg)
{
return tmsg_read_ube(msg, 0, 16);
}
void bigmsg_frame_part_part_id_set(tmsg_t *msg, uint16_t value)
{
tmsg_write_ube(msg, 0, 16, value);
}
uint16_t bigmsg_frame_part_node_id_get(tmsg_t *msg)
{
return tmsg_read_ube(msg, 16, 16);
}
void bigmsg_frame_part_node_id_set(tmsg_t *msg, uint16_t value)
{
tmsg_write_ube(msg, 16, 16, value);
}
size_t bigmsg_frame_part_buf_offset(size_t index1)
{
return bigmsg_frame_part_buf_offsetbits(index1) / 8;
}
uint8_t bigmsg_frame_part_buf_get(tmsg_t *msg, size_t index1)
{
return tmsg_read_ube(msg, bigmsg_frame_part_buf_offsetbits(index1), 8);
}
void bigmsg_frame_part_buf_set(tmsg_t *msg, size_t index1, uint8_t value)
{
tmsg_write_ube(msg, bigmsg_frame_part_buf_offsetbits(index1), 8, value);
}
size_t bigmsg_frame_part_buf_offsetbits(size_t index1)
{
size_t offset = 32;
if (index1 >= 64) { tmsg_fail(); return (size_t)-1; }
offset += 0 + index1 * 8;
return offset;
}
|
tinyos-io/tinyos-3.x-contrib | pisync/SampleApplication/TSyncApp.h | /*
* Copyright (c) 2014, Ege University, Izmir, Turkey & University of Padova, Padova, Italy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the copyright holders nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author: <NAME> <<EMAIL>>
*/
#ifndef TSYNC_APP_H
#define TSYNC_APP_H
enum AppAmId{
AM_TSYNCAPPMSG_T = 6
};
typedef nx_struct TSyncAppMsg_t {
nx_uint16_t nodeid;
nx_uint32_t clock;
nx_uint32_t skew;
} TSyncAppMsg;
#endif /* TSYNC_APP_H */
|
tinyos-io/tinyos-3.x-contrib | iowa/T2.tsync/IAtsync/Wakker.h | <gh_stars>1-10
typedef struct {
uint8_t id; // id of client application
uint8_t indx; // user's index for the alarm
uint32_t wake_time; // in 1/8 seconds; ffffffff => inactive
} sched_list;
// The following is the maximum number of wakeups scheduled
// initial guess: 4 * the number of clients (on average, each
// client has at most three alarms scheduled)
enum { ALRM_slots = 4*uniqueCount("Wakker") };
|
tinyos-io/tinyos-3.x-contrib | hitdke/support/sdk/c/synsb/DataSource.h | // $Id: DataSource.h,v 1.2 2010/06/22 08:32:17 pineapple_liu Exp $
/*
* Copyright (c) 2010 Data & Knowledge Engineering Research Center,
* Harbin Institute of Technology, P. R. China.
* All rights reserved.
*/
/**
* HITDKE Synthetic DataSource (SDS).
*
* @author <NAME> <<EMAIL>>
* @date Jun 21, 2010
*/
#ifndef __HITDKE_DATA_SOURCE_H__
#define __HITDKE_DATA_SOURCE_H__
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct
{
int __unused__;
} DataSource;
typedef struct
{
unsigned int count;
int __unused__;
} RecordSet;
#ifdef __cplusplus
}
#endif
#endif /* __HITDKE_DATA_SOURCE_H__ */
|
tinyos-io/tinyos-3.x-contrib | dexma/tos/lib/net/blip/IPDispatch.h | <reponame>tinyos-io/tinyos-3.x-contrib<gh_stars>1-10
/*
* "Copyright (c) 2008 The Regents of the University of California.
* All rights reserved."
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/
#ifndef _IPDISPATCH_H_
#define _IPDISPATCH_H_
#include <message.h>
#include <lib6lowpan.h>
#include <Statistics.h>
enum {
N_PARENTS = 3,
N_EPOCHS = 2,
N_EPOCHS_COUNTED = 1,
N_RECONSTRUCTIONS = 2,
N_FORWARD_ENT = IP_NUMBER_FRAGMENTS,
};
enum {
CONF_EVICT_THRESHOLD = 5, // Neighbor is 'mature'
CONF_PROM_THRESHOLD = 5, // Acceptable threshold for promotion
MAX_CONSEC_FAILURES = 11, // Max Failures before reroute is attempted
PATH_COST_DIFF_THRESH = 10, // Threshold for 'similar' path costs
LQI_DIFF_THRESH = 10, // Threshold for 'similar' LQI's
LINK_EVICT_THRESH = 50, // ETX * 10
RANDOM_ROUTE = 20, //Percentage of time to select random default route
#if defined(PLATFORM_Z1)
LQI_ADMIT_THRESH = 0x2000,
#else
LQI_ADMIT_THRESH = 0x200,
#endif
};
/* chip-specific lqi values */
uint16_t adjustLQI(uint8_t val);
enum {
WITHIN_THRESH = 1,
ABOVE_THRESH = 2,
BELOW_THRESH = 3,
};
#ifndef LOW_POWER_LISTENING
enum {
TGEN_BASE_TIME = 512,
TGEN_MAX_INTERVAL = 60L * 1024L * 5L,
};
#else
enum {
TGEN_BASE_TIME = 16384L,
TGEN_MAX_INTERVAL = 60L * 1024L * 5L,
};
#endif
struct epoch_stats {
uint16_t success;
uint16_t total;
uint16_t receptions;
};
struct report_stats {
uint8_t messages;
uint8_t transmissions;
uint8_t successes;
};
enum {
T_PIN_OFFSET = 0,
T_PIN_MASK = 1 << T_PIN_OFFSET,
T_VALID_OFFSET = 2,
T_VALID_MASK = 1 << T_VALID_OFFSET,
T_MARKED_OFFSET = 3,
T_MARKED_MASK = 1 << T_MARKED_OFFSET,
T_MATURE_OFFSET = 4,
T_MATURE_MASK = 1 << T_MATURE_OFFSET,
T_EVICT_OFFSET = 5,
T_EVICT_MASK = 1 << T_EVICT_OFFSET,
};
enum {
// store the top-k neighbors. This could be a poor topology
// formation critera is very dense networks. we may be able to
// really use the fact that the "base" has infinite memory.
N_NEIGH = 8,
N_LOW_NEIGH = 2,
N_FREE_NEIGH = (N_NEIGH - N_LOW_NEIGH),
N_FLOW_ENT = 6,
N_FLOW_CHOICES = 2,
N_PARENT_CHOICES = 3,
T_DEF_PARENT = 0xfffd,
T_DEF_PARENT_SLOT = 0,
};
typedef struct {
// The extra 2 is because one dest could be from source route, other
// from the dest being a direct neighbor
ieee154_saddr_t dest[N_FLOW_CHOICES + N_PARENT_CHOICES + 2];
uint8_t current:4;
uint8_t nchoices:4;
uint8_t retries;
uint8_t actRetries;
uint16_t delay;
} send_policy_t;
typedef struct {
send_policy_t policy;
uint8_t frags_sent;
bool failed;
uint8_t refcount;
uint8_t local_flow_label;
} send_info_t;
typedef struct {
send_info_t *info;
message_t *msg;
} send_entry_t;
typedef struct {
uint8_t timeout;
ieee154_saddr_t l2_src;
uint16_t old_tag;
uint16_t new_tag;
send_info_t *s_info;
} forward_entry_t;
/* typedef struct { */
/* /\* how to dispatch this packet *\/ */
/* union { */
/* struct sockaddr_in6 sock; */
/* ip6_addr_t src; */
/* } address; */
/* /\* packet metadata *\/ */
/* union { */
/* uint16_t udp_port; */
/* } dispatch; */
/* struct ip_metadata metadata; */
/* /\* the lib6lowpan reconstruct structure *\/ */
/* reconstruct_t recon; */
/* } ip_recon_t; */
enum {
F_VALID_MASK = 0x01,
//F_TOTAL_VALID_ENTRY_MASK = 0x80, // For entire entry (not just specific choice)
F_FULL_PATH_OFFSET = 1,
F_FULL_PATH_MASK = 0x02,
MAX_PATH_LENGTH = 10,
N_FULL_PATH_ENTRIES = (N_FLOW_CHOICES * N_FLOW_ENT),
};
struct flow_path {
uint8_t path_len;
cmpr_ip6_addr_t path[MAX_PATH_LENGTH];
};
struct f_entry {
uint8_t flags;
union {
struct flow_path *pathE;
cmpr_ip6_addr_t nextHop;
};
};
// Need to add another entry to avoid useless padding
// Or can make sure that the flow_table has an even
// number of entries.
struct flow_entry {
uint8_t flags;
uint8_t count;
struct flow_match match;
struct f_entry entries[N_FLOW_CHOICES];
};
//#define IS_VALID_SLOT(f) (((f)->entries[0].flags & F_TOTAL_VALID_ENTRY_MASK) == F_TOTAL_VALID_ENTRY_MASK)
#define IS_VALID_SLOT(f) (((f)->flags & F_VALID_MASK) == F_VALID_MASK)
//#define SET_VALID_SLOT(f) (f)->entries[0].flags |= F_TOTAL_VALID_ENTRY_MASK
#define SET_VALID_SLOT(f) (f)->flags |= F_VALID_MASK
//#define SET_INVALID_SLOT(f) (f)->entries[0].flags &= ~F_TOTAL_VALID_ENTRY_MASK
#define SET_INVALID_SLOT(f) (f)->flags &= ~F_VALID_MASK
#define IS_VALID_ENTRY(e) (((e).flags & F_VALID_MASK) == F_VALID_MASK)
#define SET_VALID_ENTRY(e) (e).flags |= F_VALID_MASK
#define SET_INVALID_ENTRY(e) (e).flags &= ~F_VALID_MASK
#define IS_FULL_TYPE(e) (((e).flags & F_FULL_PATH_MASK) == F_FULL_PATH_MASK)
#define IS_HOP_TYPE(e) !IS_FULL_TYPE(e)
#define SET_FULL_TYPE(e) ((e).flags |= F_FULL_PATH_MASK)
#define SET_HOP_TYPE(e) ((e).flags &= ~F_FULL_PATH_MASK)
struct neigh_entry {
uint8_t flags;
uint8_t hops; // Put this before neighbor to remove potential padding issues
ieee154_saddr_t neighbor;
uint16_t costEstimate;
uint16_t linkEstimate;
struct epoch_stats stats[N_EPOCHS];
}
#ifdef MIG
__attribute__((packed));
#else
;
#endif
#define IS_NEIGH_VALID(e) (((e)->flags & T_VALID_MASK) == T_VALID_MASK)
#define SET_NEIGH_VALID(e) ((e)->flags |= T_VALID_MASK)
#define SET_NEIGH_INVALID(e) ((e)->flags &= ~T_VALID_MASK)
#define PINNED(e) (((e)->flags & T_PIN_MASK) == T_PIN_MASK)
#define REMOVABLE(e) (((e)->refCount == 0) && !(PINNED(e)))
#define SET_PIN(e) (((e)->flags |= T_PIN_MASK))
#define UNSET_PIN(e) (((e)->flags &= ~T_PIN_MASK))
#define IS_MARKED(e) (((e)->flags & T_MARKED_MASK) == T_MARKED_MASK)
#define SET_MARK(e) (((e)->flags |= T_MARKED_MASK))
#define UNSET_MARK(e) (((e)->flags &= ~T_MARKED_MASK))
#define IS_MATURE(e) (((e)->flags & T_MATURE_MASK) == T_MATURE_MASK)
#define SET_MATURE(e) ((e)->flags |= T_MATURE_MASK)
#define SET_EVICT(e) ((e).flags |= T_EVICT_MASK)
#define UNSET_EVICT(e) ((e).flags &= ~T_EVICT_MASK)
#define SHOULD_EVICT(e) ((e).flags & T_EVICT_MASK)
typedef enum {
S_FORWARD,
S_REQ,
} send_type_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | blaze/apps/NetworkEnergyAnalysis/Analysis.h |
#ifndef ANALYSIS_H
#define ANALYSIS_H
typedef nx_struct AnalysisMsg {
nx_uint32_t intervalBetweenMessagesMs;
nx_uint16_t worInterval;
nx_uint8_t nodesInSurroundingNetwork;
} AnalysisMsg;
enum {
AM_DUMMYMSG = 0x4,
AM_ANALYSISMSG = 0x5,
};
#endif
|
tinyos-io/tinyos-3.x-contrib | stanford-sing/apps/PowerNetBase/4bitle/LinkEstimator.h | <reponame>tinyos-io/tinyos-3.x-contrib<filename>stanford-sing/apps/PowerNetBase/4bitle/LinkEstimator.h<gh_stars>0
/* $Id: LinkEstimator.h,v 1.1 2011/01/20 19:24:40 thenilly Exp $ */
/*
* "Copyright (c) 2006 University of Southern California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written
* agreement is hereby granted, provided that the above copyright
* notice, the following two paragraphs and the author appear in all
* copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF SOUTHERN CALIFORNIA BE LIABLE TO
* ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
* DOCUMENTATION, EVEN IF THE UNIVERSITY OF SOUTHERN CALIFORNIA HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF SOUTHERN CALIFORNIA SPECIFICALLY DISCLAIMS ANY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
* SOUTHERN CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/
#ifndef LINK_ESITIMATOR_H
#define LINK_ESITIMATOR_H
/*
@ author <NAME>
@ Created: June 08, 2006
*/
// Number of entries in the neighbor table
#define NEIGHBOR_TABLE_SIZE 10
// Masks for the flag field in the link estimation header
enum {
// use last four bits to keep track of
// how many footer entries there are
NUM_ENTRIES_FLAG = 15,
};
// The first byte of each outgoing packet is a control byte
// Bits 4..7 reserved for routing and other protocols
// Bits 0..3 is used by the link estimator to encode the
// number of linkest entries in the packet
// link estimator header added to
// every message passing through the link estimator
typedef nx_struct linkest_header {
nx_uint8_t flags;
nx_uint8_t seq;
} linkest_header_t;
// for outgoing link estimator message
// so that we can compute bi-directional quality
typedef nx_struct neighbor_stat_entry {
nx_am_addr_t ll_addr;
nx_uint8_t inquality;
} neighbor_stat_entry_t;
// we put the above neighbor entry in the footer
typedef nx_struct linkest_footer {
neighbor_stat_entry_t neighborList[1];
} linkest_footer_t;
// Flags for the neighbor table entry
enum {
VALID_ENTRY = 0x1,
// A link becomes mature after BLQ_PKT_WINDOW
// packets are received and an estimate is computed
MATURE_ENTRY = 0x2,
// Flag to indicate that this link has received the
// first sequence number
INIT_ENTRY = 0x4,
// The upper layer has requested that this link be pinned
// Useful if we don't want to lose the root from the table
PINNED_ENTRY = 0x8
};
// neighbor table entry
typedef struct neighbor_table_entry {
// link layer address of the neighbor
am_addr_t ll_addr;
// last beacon sequence number received from this neighbor
uint8_t lastseq;
// number of beacons received after last beacon estimator update
// the update happens every BLQ_PKT_WINDOW beacon packets
uint8_t rcvcnt;
// number of beacon packets missed after last beacon estimator update
uint8_t failcnt;
// flags to describe the state of this entry
uint8_t flags;
// inbound qualities in the range [1..255]
// 1 bad, 255 good
uint8_t inquality;
// ETX for the link to this neighbor. This is the quality returned to
// the users of the link estimator
uint16_t etx;
// Number of data packets successfully sent (ack'd) to this neighbor
// since the last data estimator update round. This update happens
// every DLQ_PKT_WINDOW data packets
uint8_t data_success;
// The total number of data packets transmission attempt to this neighbor
// since the last data estimator update round.
uint8_t data_total;
int8_t rssi;
} neighbor_table_entry_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | ethz/rest-api/tos/lib/net/blip/mdns/MDNS.h | /* Copyright (c) 2009, Distributed Computing Group (DCG), ETH Zurich.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* @author <NAME> <<EMAIL>>
*
*/
#ifndef MDNS_H
#define MDNS_H
#define MDNS_PORT 5353
#define MDNS_ADDRESS "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b"
#define MDNS_RELAYING_ENABLED 1
#define MDNS_DEFAULT_TTL 600
#define MDNS_LOCAL_STRING "local"
#define MDNS_BACKOFF_MASK 0x1000
#define DNS_TYPE_PTR 12
#define DNS_TYPE_SRV 33
#define DNS_TYPE_AAAA 28
#define DNS_CLASS_IN 1
#define MDNS_CACHE_FLUSH_FLAG 0x80
typedef nx_struct DNSHeader {
nx_uint16_t id; /* query identification number */
nx_uint8_t qr: 1; /* response flag */
nx_uint8_t opcode: 4; /* purpose of message */
nx_uint8_t aa: 1; /* authoritive answer */
nx_uint8_t tc: 1; /* truncated message */
nx_uint8_t rd: 1; /* recursion desired */
/* byte boundary */
nx_uint8_t ra: 1; /* recursion available */
nx_uint8_t unused :1; /* unused bits (MBZ as of 4.9.3a3) */
nx_uint8_t ad: 1; /* authentic data from named */
nx_uint8_t cd: 1; /* checking disabled by resolver */
nx_uint8_t rcode :4; /* response code */
/* byte boundary */
nx_uint16_t qdcount; /* number of question entries */
nx_uint16_t ancount; /* number of answer entries */
nx_uint16_t nscount; /* number of authority entries */
nx_uint16_t arcount; /* number of resource entries */
} DNSHeader_t;
typedef nx_struct DNS_Question {
nx_uint16_t type; /* type */
nx_uint8_t flush; /* cache flush */
nx_uint8_t class; /* class */
nx_uint32_t ttl; /* time to live */
nx_uint16_t length; /* rd length */
} DNS_Question_t;
typedef nx_struct DNS_SRV_Description {
nx_uint16_t priority;
nx_uint16_t weight;
nx_uint16_t port;
} DNS_SRV_Description_t;
#endif /* MDNS_H */
|
tinyos-io/tinyos-3.x-contrib | nxtmote/tos/chips/bc4/BT.h | #ifndef BT_H
#define BT_H
typedef uint8_t bt_addr_t[SIZE_OF_BDADDR];
#endif
|
tinyos-io/tinyos-3.x-contrib | cire/support/sdk/c/motenet/motenet.c | /*
* Copyright 2011, <NAME>
* All rights reserved
*
* MoteNet: Provide a sockets interface for TinyOS network traffic.
*
* In server or serial mode, motenet provides a sockets interface to
* traffic using the AM (Active Message) light weight protocol. A gateway
* between IP (either IPv4 or IPv6) and the AM motenet needs to be
* running at the interface between the different networks. This
* transition occurs at the node with the serial network interface
* to the motenet.
*
* In direct mode, the motenet is assumed to be running an IPv6 network
* stack. Interconnect at the WSN/Main network interface needs to be
* running IPv6 gateway software such as a PPP capable bridge. So an
* application using the socket interface can connect to any node in
* the WSN domain handled by the gateway.
*
* The MoteNet interface is intended to allow construction of network
* applications that will work with zero or minimal changes when connecting
* to nodes on an AM network or on a 6lowpan network using standard socket
* network programming methods.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of the copyright holder nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <stdint.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netlib.h>
#include <serialsource.h>
#include <sfsource.h>
#include "am.h"
#include "motenet.h"
int mn_debug = 0;
/* max buffer size for copying strings from a motecom connection string */
#define MCS_MAX_BUF 256
/*
* We need to provide a intervention layer in between data below us
* and the application layer. This allows us to handle normal
* sockets talking directly to the network layer as well as emulating
* the network layer handling AM encapsulated packets.
*
* AM packets are handled either directly (SERIAL) or via a Serial
* Forwarder. A motecomm_connection structure (mcs) is used to
* keep track of information needed to provide the switching needed.
* The MCS is provided by the client and is considered opaque to the
* application. We maintain a table that cross references the file
* descriptor returned by the system to the corresponding MCS.
*/
typedef struct {
int fd;
motecom_conn_t *mcs;
} fd_mcs_t;
#define MAX_FD_MCS 5
static fd_mcs_t mn_fd_mcs[MAX_FD_MCS]; /* init's to NULL */
static char *msgs[] = {
"unknown_packet_type",
"ack_timeout" ,
"sync" ,
"too_long" ,
"too_short" ,
"bad_sync" ,
"bad_crc" ,
"closed" ,
"no_memory" ,
"unix_error"
};
void __mn_serial_msg(serial_source_msg problem) {
fprintf(stderr, "*** Note: %s\n", msgs[problem]);
}
int
mn_debug_set(int val) {
int ret;
ret = mn_debug;
mn_debug = val;
return ret;
}
int
mn_debug_get() {
return mn_debug;
}
/*
* strip in place any white space preceeding or trailing
* the string.
*
* returns: pointer to new start.
*
* any whitespace on the end of the string will be stripped. A
* new eol will be laid down at the end of pertinent bits.
*/
char *
strip_white(char *s) {
char *p;
int len;
p = s;
while(*p && isspace(*p))
p++;
s = p;
len = strlen(s);
if (len > 0) {
p = &s[len-1];
while(*p && isspace(*p))
p--;
*(p+1) = 0;
}
return s;
}
/*
* parse_host_port:
*
* parse out host and port portions of the input string.
* two fields, host and port seperated by : .
*
* WARNING: source string is modified in place.
*
* h,p <- parse(s)
*
* input: h ptr to char ptr, for host resultant
* p ptr to char ptr, for port resultant
* s char ptr to string to parse
*
* output: ret 0 parse complete
* 1 oops. failed. something wrong.
* *h h filled in, points at host part
* *p p filled in, points at port part
*
* Original string is modified to 0 terminate found parts.
* h and p point into original string buffer.
*/
int
parse_host_port(char **h, char **p, char *s) {
char *hp, *pp, *t;
hp = s;
t = strrchr(hp, ':'); /* rev search for port seperator */
if (t == NULL)
return 1; /* must be present. */
pp = t + 1;
*t = 0; /* terminate host str */
hp = strip_white(hp); /* kill any imbedded white space */
pp = strip_white(pp);
/* check for ipv6 explicit address in "[]" */
if (hp[0] == '[')
hp++;
t = &hp[strlen(hp)-1];
if (*t == ']')
*t = 0;
hp = strip_white(hp);
*h = hp;
*p = pp;
return 0;
}
int
lookup_host_port(motecom_conn_t *mcs, char *hp, char *pp, int sock_type) {
int err;
struct addrinfo hints, *res;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = sock_type;
err = getaddrinfo(hp, pp, &hints, &res);
if (err) {
fprintf(stderr, "\n*** motenet: gai: \"%s:%s\": %s (%d)\n", hp, pp,
gai_strerror(err), err);
return 1;
}
mcs->ai = res;
if (mn_debug) {
fprintf(stderr, "\n");
while (res) {
fprintf(stderr, "%s\n", ai2str(res));
res = res->ai_next;
}
}
return 0;
}
/*
* MoteNet Parse MOTECOM.
*
* parse a connection string yielding a connection structure.
*
* input: mcs pointer to a connection structure. Result of the
* parse are stored here.
*
* conn_str provided string to parse. Can be NULL or empty.
*
* returns: 0 parsing succeeded, mcs updated with connection data.
* 1 failed to parse. indicate failure.
*
* Source string can be passed in or can be obtained from the environment
* variable MOTECOM. Passed in string takes priority but only if not empty.
*
* Formats:
*
* <host>:<port>
* server@<host>:<port>
* sf@<host>:<port>
* serial@<dev>:<baud>
*
* <host> can be an IPv4 or IPv6 literal address or host name. Host name
* will be looked up using DNS. AAAA will yield ipv6 addresses, AA will
* yield ipv4 addresses. IPv4 literals should be specified in dotted
* quads. IPv6 literals are specified using IPv6 colon nomenclature and
* must be specified inside of "[]" like ipv6 URLs.
*
* Examples:
*
* zot:9001, localhost:9001, 127.0.0.1:9001
*
* serial@/dev/ttyUSB1:115200, serial@COM1:9600
*
* server@zot:9001, sf@zot:9001, server@localhost:9001,
* server@192.168.1.100:9001, etc.
*
* [fe80::fd41:4242:e88:3]:9001, device.ppp.osian:9001
* server@[fe80::fd41:4242:e88:2]:9001, server@host.ppp.osian:9001
*
* port can also be specified by using service name.
*/
int
mn_parse_motecom(motecom_conn_t *mcs, char *conn_str) {
char cs[MCS_MAX_BUF]; /* conn str copy */
char *ctp; /* conn type pointer */
char *hp, *pp; /* host and port pointer */
char *p;
if (!mcs)
return 1;
p = NULL; /* p is where we are starting. */
memset(mcs, 0, sizeof(motecom_conn_t));
if (conn_str) {
/*
* connection string specified (non-NULL), make sure it says something.
*/
strncpy(cs, conn_str, MCS_MAX_BUF);
p = strip_white(cs);
strncpy(mcs->conn_str, p, MC_CONN_SIZE);
if (strlen(p) == 0)
p = NULL;
}
if (p == NULL) { /* if still NULL, no connection string */
/*
* haven't found something to work on yet. So see if we can
* find something in the environment variable MOTECOM.
*/
p = getenv("MOTECOM");
if (p == NULL) /* MOTECOM not found, bail */
return 1;
strncpy(cs, p, MCS_MAX_BUF); /* make our own copy */
p = strip_white(cs);
strncpy(mcs->conn_str, p, MC_CONN_SIZE);
if (strlen(p) == 0)
p = NULL;
}
if (p == NULL) /* still nothing to work on, bail */
return 1;
/*
* something to work on.
*
* See if we can find a connection type, Look for @
*/
ctp = p;
p = strchr(ctp, '@');
if (p == NULL) {
/*
* @ not found --> must be DIRECT
*/
mcs->mc_src = MCS_DIRECT;
if (parse_host_port(&hp, &pp, ctp))
return 1; /* parse didn't work, bail */
ctp = NULL; /* no connection type */
return lookup_host_port(mcs, hp, pp, SOCK_DGRAM);
}
/*
* @ found. Look for "server", "sf", or "serial".
*/
hp = p+1; /* move beyond the connection type */
*p = 0; /* isolate the connection type */
ctp = strip_white(ctp);
if ((strcmp(ctp, "server") == 0) || (strcmp(ctp, "sf") == 0)) {
mcs->mc_src = MCS_SERVER;
if (parse_host_port(&hp, &pp, hp))
return 1;
return lookup_host_port(mcs, hp, pp, SOCK_STREAM);
} else if (strcmp(ctp, "serial") == 0) {
/*
* serial@/dev/ttyUSB1:115200, use parse_host_port to find
* device (host) and baud (port). Same algorithm.
*/
mcs->mc_src = MCS_SERIAL;
if (parse_host_port(&hp, &pp, hp))
return 1;
strncpy(mcs->dev, hp, MC_DEV_SIZE);
strncpy(mcs->baud, pp, MC_BAUD_SIZE);
return 0;
}
fprintf(stderr, "\n*** motenet: unrecognized connection type: %s\n", ctp);
return 1;
}
char *
mn_mcs2str(motecom_conn_t *mcs, char *str, size_t str_size) {
size_t space_avail, added;
char *cur;
struct addrinfo *ai;
if (!str || str_size == 0)
return NULL;
if (!mcs) {
str[0]=0;
return str;
}
space_avail = str_size;
cur = str;
added = snprintf(cur, space_avail, "(%s) ", mcs->conn_str);
space_avail -= added;
cur += added;
switch (mcs->mc_src) {
case MCS_DIRECT:
case MCS_SERVER:
added = snprintf(cur, space_avail, "%s@",
(mcs->mc_src == MCS_DIRECT ? "direct" : "server"));
space_avail -= added;
cur += added;
ai = mcs->ai;
while (ai) {
added = snprintf(cur, space_avail, "<%s>",
Sock_ntop(ai->ai_addr, ai->ai_addrlen));
space_avail -= added;
cur += added;
ai = ai->ai_next;
}
return str;
case MCS_SERIAL:
added = snprintf(cur, space_avail, "serial@%s:%s",
mcs->dev, mcs->baud);
space_avail -= added;
cur += added;
return str;
default:
added = snprintf(cur, space_avail, "unknown, %d",
mcs->mc_src);
space_avail -= added;
cur += added;
return str;
}
}
static int
open_mn_sf_source(motecom_conn_t *mcs) {
int fd, err;
struct addrinfo *aip;
if (!mcs) {
errno = EINVAL;
return -1;
}
aip = mcs->ai;
fd = socket(aip->ai_family, aip->ai_socktype, 0);
if (fd < 0) {
fprintf(stderr, "motenet: socket (server open): %s (%d) (%s)\n",
strerror(errno), errno, mcs->conn_str);
return fd;
}
mcs->sock_fd = fd;
err = connect(fd, aip->ai_addr, aip->ai_addrlen);
if (err < 0) {
fprintf(stderr, "motenet: %s connect (server) %s (%d) (%s)\n",
Sock_ntop(aip->ai_addr, aip->ai_addrlen),
strerror(errno), errno, mcs->conn_str);
close(fd);
return -1;
}
if (init_sf_source(fd) < 0) {
fprintf(stderr, "motenet: init_sf failed. (%s)\n", mcs->conn_str);
close(fd);
errno = EUNATCH;
return -1;
}
return fd;
}
int
mn_socket(motecom_conn_t *mcs, int domain, int type, int protocol) {
int i, fd;
fd_mcs_t *slot;
struct addrinfo *aip;
if (!mcs) {
errno = EINVAL;
return -1;
}
slot = NULL;
for (i = 0; i < MAX_FD_MCS; i++) {
if (mn_fd_mcs[i].mcs == NULL) {
slot = &mn_fd_mcs[i];
break;
}
}
if (slot == NULL) {
errno = ENOBUFS;
return -1;
}
switch(mcs->mc_src) {
case MCS_DIRECT:
aip = mcs->ai;
fd = socket(aip->ai_family, aip->ai_socktype, 0);
if (fd < 0) {
fprintf(stderr, "motenet: socket (direct): %s (%d) (%s)\n", strerror(errno), errno, mcs->conn_str);
return fd;
}
slot->fd = fd;
break;
case MCS_SERVER:
fd = open_mn_sf_source(mcs);
if (fd < 0) {
fprintf(stderr, "motenet: socket (server): %s (%d) (%s)\n", strerror(errno), errno, mcs->conn_str);
return fd;
}
slot->fd = fd;
mcs->sock_fd = fd;
break;
case MCS_SERIAL:
errno = 0;
mcs->serial_src = open_serial_source(mcs->dev, platform_baud_rate(mcs->baud),
0, __mn_serial_msg);
if (mcs->serial_src == NULL) {
if (errno == 0)
errno = EINVAL;
fprintf(stderr, "motenet: socket (serial open): %s (%d) (%s)\n", strerror(errno), errno, mcs->conn_str);
return -1;
}
fd = serial_source_fd(mcs->serial_src);
slot->fd = fd;
break;
default:
errno = EINVAL;
return -1;
}
slot->mcs = mcs;
mcs->family = domain;
mcs->socktype = type;
return fd;
}
static motecom_conn_t *
find_mcs(int fd) {
int i;
for (i = 0; i < MAX_FD_MCS; i++) {
if (mn_fd_mcs[i].fd == fd)
return mn_fd_mcs[i].mcs;
}
return NULL;
}
int
mn_bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
motecom_conn_t *mcs;
struct sockaddr_am *am_addr;
mcs = find_mcs(sockfd);
if (!mcs) {
errno = EINVAL;
return -1;
}
if (mcs->mc_src == MCS_DIRECT)
return bind(sockfd, addr, addrlen);
if (mcs->mc_src != MCS_SERVER && mcs->mc_src != MCS_SERIAL) {
errno = EINVAL;
return -1;
}
am_addr = (struct sockaddr_am *) addr;
if (am_addr->sam_family != AF_AM) {
errno = EINVAL;
return -1;
}
memcpy(&mcs->am_local, am_addr, sizeof(struct sockaddr_am));
return 0;
}
int
mn_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
motecom_conn_t *mcs;
struct sockaddr_am *am_addr;
mcs = find_mcs(sockfd);
if (!mcs) {
errno = EINVAL;
return -1;
}
if (mcs->mc_src == MCS_DIRECT)
return connect(sockfd, addr, addrlen);
if (mcs->mc_src != MCS_SERVER && mcs->mc_src != MCS_SERIAL) {
errno = EINVAL;
return -1;
}
am_addr = (struct sockaddr_am *) addr;
if (am_addr->sam_family != AF_AM) {
errno = EINVAL;
return -1;
}
memcpy(&mcs->am_remote, am_addr, sizeof(struct sockaddr_am));
return 0;
}
int
mn_close(int sockfd) {
int ret;
motecom_conn_t *mcs;
mcs = find_mcs(sockfd);
if (!mcs) {
errno = EINVAL;
return -1;
}
if (mcs->ai) {
freeaddrinfo(mcs->ai);
mcs->ai = NULL;
}
switch (mcs->mc_src) {
case MCS_DIRECT:
return close(sockfd);
case MCS_SERVER:
ret = close(mcs->sock_fd);
mcs->sock_fd = 0;
return ret;
case MCS_SERIAL:
ret = close_serial_source(mcs->serial_src);
mcs->serial_src = NULL;
return ret;
default:
errno = EINVAL;
return -1;
}
}
static ssize_t
am_send_packet(motecom_conn_t *mcs, struct sockaddr_am *am_dest,
const void *buf, size_t len) {
void *packet;
int out_len, i;
am_hdr_t *amh; /* am header in packet */
struct sockaddr_am *aml; /* our local information */
packet = malloc(len + AM_HDR_LEN);
if (!packet) {
errno = ENOMEM;
return -1;
}
/*
* Add a header if needed.... RAW is assumed to be properly constructed.
* DGRAM needs the header put on the front.
*/
switch(mcs->socktype) {
case SOCK_RAW:
memcpy(packet, buf, len);
out_len = len;
break;
case SOCK_DGRAM:
if (!am_dest || am_dest->sam_family != AF_AM) {
errno = EINVAL;
free(packet);
return -1;
}
amh = packet;
aml = &mcs->am_local;
if (mn_debug && aml->sam_type == 0)
fprintf(stderr, "*** warning: send with local_type set to 0\n");
amh->am_encap = AM_ENCAP_BASIC;
amh->am_dest = am_dest->sam_addr; /* dest, already network order */
amh->am_src = aml->sam_addr; /* src, us, network order */
amh->am_len = len;
amh->am_grp = aml->sam_grp; /* should be the same, local overrides */
amh->am_type = aml->sam_type; /* local remote should be same */
memcpy(packet + AM_HDR_LEN, buf, len);
out_len = len + AM_HDR_LEN;
break;
default:
errno = EINVAL;
free(packet);
return -1;
}
if (mn_debug) {
amh = packet;
fprintf(stderr, "%04x:%d (%02x) (l: %d): ", ntohs(amh->am_dest),
amh->am_type, amh->am_type, out_len);
for (i = 0; i < out_len; i++)
fprintf(stderr, "%02x ", ((uint8_t *) packet)[i]);
fprintf(stderr, "\n");
}
switch(mcs->mc_src) {
case MCS_SERVER: write_sf_packet(mcs->sock_fd, packet, out_len); break;
case MCS_SERIAL: write_serial_packet(mcs->serial_src, packet, out_len); break;
default:
errno = EINVAL;
free(packet);
return -1;
}
free(packet);
return out_len;
}
ssize_t
mn_sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen){
motecom_conn_t *mcs;
int out_len;
struct sockaddr_am *dst;
mcs = find_mcs(sockfd);
if (!mcs || !buf || !len) {
errno = EINVAL;
return -1;
}
if (mcs->mc_src == MCS_DIRECT)
return send(sockfd, buf, len, flags);
if (dest_addr)
dst = (struct sockaddr_am *) dest_addr;
else
dst = &mcs->am_remote;
out_len = am_send_packet(mcs, dst, buf, len);
return out_len;
}
ssize_t
mn_send(int sockfd, const void *buf, size_t len, int flags) {
motecom_conn_t *mcs;
int out_len;
mcs = find_mcs(sockfd);
if (!mcs || !buf || !len) {
errno = EINVAL;
return -1;
}
if (mcs->mc_src == MCS_DIRECT)
return send(sockfd, buf, len, flags);
out_len = am_send_packet(mcs, &mcs->am_remote, buf, len);
return out_len;
}
/*
* receive an AM packet with filtering from AM lower layer
*
* Receive an AM packet from either the server or serial with
* input filtering (dest address, group, type).
*/
static void *
am_recv_packet(motecom_conn_t *mcs, int *len) {
uint8_t *packet;
am_hdr_t *amh; /* am header in packet */
struct sockaddr_am *aml; /* our local information */
if (mcs == NULL || len == NULL)
return NULL;
do {
switch (mcs->mc_src) {
case MCS_SERVER: packet = read_sf_packet(mcs->sock_fd, len); break;
case MCS_SERIAL: packet = read_serial_packet(mcs->serial_src, len); break;
default: return NULL;
}
if (packet == NULL)
return NULL;
/*
* SOCK_RAW returns raw protocol information, which is the
* uninterpreted data. No address checks, or type checks, etc. are
* done.
*/
if (mcs->socktype == SOCK_RAW)
return packet;
amh = (am_hdr_t *) packet;
aml = &mcs->am_local;
/* ignore encaps we don't understand. */
if (amh->am_encap != AM_ENCAP_BASIC &&
amh->am_encap != AM_ENCAP_LEN16) {
free(packet);
continue;
}
/*
* accept bcast, we're set for any, or its pointed at us
* otherwise kick to next packet.
*/
if ((amh->am_dest != AM_ADDR_BCAST) &&
(aml->sam_addr != AM_ADDR_ANY) &&
(aml->sam_addr != amh->am_dest)) {
free(packet);
continue;
}
if ((aml->sam_grp != AM_GRP_ANY) &&
(aml->sam_grp != amh->am_grp)) {
free(packet);
continue;
}
if ((aml->sam_type != AM_TYPE_ANY) &&
(aml->sam_type != amh->am_type)) {
free(packet);
continue;
}
break; /* accept the packet */
} while (1);
return packet;
}
/*
* mn_recv: receive on a socket
*
* input: sockfd socket file descriptor to receive on
* must be registered in the fd_mcs database (via mn_socket)
* buf buffer to receive into.
* len max size of buf
* flags flags for receive (see recvfrom(2)), currently not implemented
*
* Receive a motenet packet into the buffer pointed to by BUF. LEN indicates
* the maximum size of the buffer BUF. If the packet data coming in is too
* large to fit into buf, the receive will still occuur upto the maximum size
* LEN. Any remaining packet data will be lost.
*/
ssize_t
mn_recv(int sockfd, void *buf, size_t len, int flags) {
motecom_conn_t *mcs;
uint8_t *packet;
int in_len;
mcs = find_mcs(sockfd);
if (!mcs || !buf || !len) {
errno = EINVAL;
return -1;
}
/*
* DIRECT uses built in filtering dependent on socktype.
* In other words, let the kernel do it.
*/
if (mcs->mc_src == MCS_DIRECT)
return recv(sockfd, buf, len, flags);
if (mcs->socktype != SOCK_DGRAM && mcs->socktype != SOCK_RAW) {
errno = EINVAL;
return -1;
}
packet = am_recv_packet(mcs, &in_len);
if (packet == NULL)
return 0;
if (mcs->socktype == SOCK_RAW) { /* if RAW, return full packet */
if (len < in_len)
in_len = len;
memcpy(buf, packet, in_len);
free(packet);
return in_len;
}
/*
* strip off the header and just return the data
*/
in_len -= AM_HDR_LEN;
if (len < in_len)
in_len = len;
memcpy(buf, packet + AM_HDR_LEN, in_len);
free(packet);
return in_len;
}
/*
* mn_recvfrom: receive on a socket returning packet source.
*
* input: sockfd socket file descriptor to receive on
* must be registered in the fd_mcs database (via mn_socket)
* buf buffer to receive into.
* len max size of buf
* flags flags for receive (see recvfrom(2)), currently not implemented
* src_addr pointer to a sockaddr structure, used to fill in the
* if provided. NULL says do not use.
* addrlen pointer to the size of the src_addr structure. On input
* indicates maximum size of *src_addr. On output how
* big the data written into *src_addr is.
*
* Receive a motenet packet into the buffer pointed to by BUF. LEN indicates
* the maximum size of the buffer BUF. If the packet data coming in is too
* large to fit into buf, the receive will still occuur upto the maximum size
* LEN. Any remaining packet data will be lost.
*
* If src_addr is non-NULL, then the source address of the incoming AM packet
* will be copied into the structure pointed to by SRC_ADDR. ADDRLEN indicates
* the maximum size of the data area available for SRC_ADDR. If the size of
* data being written into SRC_ADDR is larger than ADDRLEN, only the data that
* will fit will be written. Any additional data will be lost. ADDRLEN will
* be updated on return to indicate the size of the data area needed to contain
* the full address.
*/
ssize_t
mn_recvfrom(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen) {
motecom_conn_t *mcs;
void *packet;
int in_len;
am_hdr_t *amh;
struct sockaddr_am *ama, am_addr;
mcs = find_mcs(sockfd);
if (!mcs || !buf || !len) {
errno = EINVAL;
return -1;
}
/*
* DIRECT uses built in filtering dependent on socktype.
* In other words, let the kernel do it.
*/
if (mcs->mc_src == MCS_DIRECT)
return recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
if (mcs->socktype != SOCK_DGRAM && mcs->socktype != SOCK_RAW) {
errno = EINVAL;
return -1;
}
packet = am_recv_packet(mcs, &in_len); /* has dest filtering */
if (packet == NULL)
return 0;
/*
* if src_addr non-NULL (requested), return the src of this packet.
*/
amh = packet;
ama = &am_addr;
ama->sam_family = AF_AM;
ama->sam_addr = amh->am_src; /* net order */
ama->sam_grp = amh->am_grp;
ama->sam_type = amh->am_type;
if (src_addr != NULL && addrlen != NULL) {
if (*addrlen > sizeof(*ama)) /* see recvfrom(2) */
*addrlen = sizeof(*ama);
memcpy(src_addr, ama, *addrlen); /* copy over as much as we can. */
*addrlen = sizeof(*ama); /* see recvfrom(2) */
}
if (mcs->socktype == SOCK_RAW) { /* if RAW, return full packet */
if (len < in_len)
in_len = len;
memcpy(buf, packet, in_len);
free(packet);
return in_len;
}
/*
* strip off the header and just return the data
*/
in_len -= AM_HDR_LEN;
if (len < in_len)
in_len = len;
memcpy(buf, packet + AM_HDR_LEN, in_len);
free(packet);
return in_len;
}
|
tinyos-io/tinyos-3.x-contrib | gems/ttsp/tinyos/apps/profilers/ProfileTsnDrift/ProfileTsnDrift.h | <gh_stars>1-10
#ifndef PROFILE_TSN_DRIFT_H
#define PROFILE_TSN_DRIFT_H
typedef nx_struct ReportMsg {
nx_uint16_t srcAddr;
nx_uint32_t refId;
nx_uint32_t localTimestamp;
nx_uint32_t refTimestamp;
nx_uint32_t temperature;
} ReportMsg_t;
enum {
AM_REPORTMSG = 181
};
#endif |
tinyos-io/tinyos-3.x-contrib | usc/senzip/SenZip_v1.0/senzip/Compression.h | <reponame>tinyos-io/tinyos-3.x-contrib
/*
* @ author <NAME>
* @ affiliation Autonomous Networks Research Group
* @ institution University of Southern California
*/
#ifndef _COMPRESSION_H
#define _COMPRESSION_H
#include <message.h>
#define COMP_RX_DELAY 1000
#define LOST_PKT_THRESHOLD 2
#define SEND_TASK_DELAY 100
#define NUM_MEASUREMENTS 3
#define MAX_SEQ_NUM 256
#define BIT_WIDTH 16
#define BIT_ALLOCATION 5
#define QUANTIZATION_FACTOR (1<<BIT_ALLOCATION)
enum {
AM_SENZIP_COMP_MSG = 33,
};
/* aggregation */
enum {
UP = 1,
DOWN = 2,
NOT_FOUND = 0xFF,
};
/* initial inputs to routing */
enum {
ETX = 1,
UPSTREAM_HOPS = 1,
DOWNSTREAM_HOPS = 1,
};
/* beacon types */
enum {
ADD = 1,
DELETE = 2,
SEND_PARENT_INFO = 3,
PARENT_INFO = 4,
ALL_INFO = 5,
};
typedef struct {
uint16_t currParent;
uint16_t prevParent;
uint8_t hopCount;
uint8_t numChildren;
} self_info;
/* aggregation table */
typedef struct {
uint16_t id;
uint8_t bitAllocation;
uint8_t currentSeqNo;
uint8_t memoryIndex;
} node_info;
typedef struct {
uint8_t upstrOneHopNbrhoodSize;
uint8_t downstrOneHopNbrhoodSize;
} weight_attr;
struct table_entry {
node_info nodeInfo;
weight_attr weight;
uint8_t upstrFurtherHops;
uint8_t downstrFurtherHops;
struct table_entry *upstrNeighborEntry[MAX_NUM_CHILDREN];
struct table_entry *downstrNeighborEntry[MAX_NUM_CHILDREN];
};
typedef struct table_entry agg_table_entry_t;
typedef struct {
agg_table_entry_t *parent;
uint8_t offset;
} entry_position;
/* compression */
enum {
TEMPORAL_ONLY = 1,
SPATIO_TEMPORAL = 2,
};
enum {
RAW = 10,
FULL = 11,
COEFF_M1 = 1,
};
enum {
PARENT = 1,
ADD_CHILD = 2,
DELETE_CHILD = 3,
};
enum {
CHILD = 1,
GRANDCHILD = 2,
};
typedef struct {
bool parent;
bool child;
} changes;
typedef struct {
int16_t partial[2*(BIT_WIDTH/BIT_ALLOCATION)*NUM_MEASUREMENTS];
int16_t full[2*NUM_MEASUREMENTS];
} buffer_t;
typedef struct {
uint8_t id;
uint8_t count;
uint8_t base;
uint8_t seqNum;
uint8_t lastSeqHeard;
int16_t min;
int16_t max;
bool mark;
buffer_t *store;
} buffer_entry_t;
typedef struct {
message_t msg;
} comp_queue_entry_t;
typedef nx_struct senzip_comp_msg {
nx_int16_t data[NUM_MEASUREMENTS];
nx_uint8_t type;
nx_uint8_t src;
nx_uint8_t parent;
nx_uint8_t seq;
nx_int16_t max;
nx_int16_t min;
} comp_msg_t;
#endif
|
tinyos-io/tinyos-3.x-contrib | eon/apps/blink/impl/tinyos/userstructs.h | #ifndef USERSTRUCTSH_H_INCLUDED
#define USERSTRUCTSH_H_INCLUDED
#endif // NODES_H_INCLUDED
|
tinyos-io/tinyos-3.x-contrib | ethz/tinynode184/tos/chips/msp430/usart/msp430usart.h | /*
* Copyright (c) 2004-2006, Technische Universitaet Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitaet Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author <NAME> <<EMAIL>>
* @author <NAME> <<EMAIL>>
*/
#ifndef _H_Msp430Usart_h
#define _H_Msp430Usart_h
#define MSP430_HPLUSCIA0_RESOURCE "Msp430UsciA0.Resource"
#define MSP430_SPIA0_BUS "Msp430SpiA0.Resource"
#define MSP430_UARTA0_BUS "Msp430UartA0.Resource"
#define MSP430_HPLUSCIB0_RESOURCE "Msp430UsciB0.Resource"
#define MSP430_SPIB0_BUS "Msp430SpiB0.Resource"
#define MSP430_HPLUSCIA1_RESOURCE "Msp430UsciA1.Resource"
#define MSP430_SPIA1_BUS "Msp430SpiA1.Resource"
#define MSP430_UARTA1_BUS "Msp430UartA1.Resource"
#define MSP430_HPLUSCIB1_RESOURCE "Msp430UsciB1.Resource"
#define MSP430_SPIB1_BUS "Msp430SpiB1.Resource"
typedef enum
{
USART_NONE = 0,
USART_UART = 1,
USART_UART_TX = 2,
USART_UART_RX = 3,
USART_SPI = 4,
USART_I2C = 5
} msp430_usartmode_t;
typedef struct {
unsigned int swrst: 1; //Software reset (0=operational; 1=reset)
unsigned int mm: 1; //Multiprocessor mode (0=idle-line protocol; 1=address-bit protocol)
unsigned int sync: 1; //Synchronous mode (0=UART; 1=SPI/I2C)
unsigned int listen: 1; //Listen enable (0=disabled; 1=enabled, feed tx back to receiver)
unsigned int clen: 1; //Character length (0=7-bit data; 1=8-bit data)
unsigned int spb: 1; //Stop bits (0=one stop bit; 1=two stop bits)
unsigned int pev: 1; //Parity select (0=odd; 1=even)
unsigned int pena: 1; //Parity enable (0=disabled; 1=enabled)
} __attribute__ ((packed)) msp430_uctl_t ;
typedef struct {
unsigned int txept:1; //Transmitter empty (0=busy; 1=TX buffer empty or SWRST=1)
unsigned int stc:1; //Slave transmit (0=4-pin SPI && STE enabled; 1=3-pin SPI && STE disabled)
unsigned int txwake: 1; //Transmiter wake (0=next char is data; 1=next char is address)
unsigned int urxse: 1; //Receive start-edge detection (0=disabled; 1=enabled)
unsigned int ssel: 2; //Clock source (00=UCLKI; 01=ACLK; 10=SMCLK; 11=SMCLK)
unsigned int ckpl: 1; //Clock polarity (0=normal; 1=inverted)
unsigned int ckph:1; //Clock phase (0=normal; 1=half-cycle delayed)
} __attribute__ ((packed)) msp430_utctl_t;
typedef struct {
unsigned int rxerr: 1; //Receive error (0=no errors; 1=error detected)
unsigned int rxwake: 1; //Receive wake-up (0=received data; 1=received an address)
unsigned int urxwie: 1; //Wake-up interrupt-enable (0=all characters set URXIFGx; 1=only address sets URXIFGx)
unsigned int urxeie: 1; //Erroneous-character receive (0=rejected; 1=recieved and URXIFGx set)
unsigned int brk:1; //Break detect (0=no break; 1=break occured)
unsigned int oe:1; //Overrun error (0=no error; 1=overrun error)
unsigned int pe:1; //Parity error (0=no error; 1=parity error)
unsigned int fe:1; //Framing error (0=no error; 1=low stop bit)
} __attribute__ ((packed)) msp430_urctl_t;
DEFINE_UNION_CAST(uctl2int,uint8_t,msp430_uctl_t)
DEFINE_UNION_CAST(int2uctl,msp430_uctl_t,uint8_t)
DEFINE_UNION_CAST(utctl2int,uint8_t,msp430_utctl_t)
DEFINE_UNION_CAST(int2utctl,msp430_utctl_t,uint8_t)
DEFINE_UNION_CAST(urctl2int,uint8_t,msp430_urctl_t)
DEFINE_UNION_CAST(int2urctl,msp430_urctl_t,uint8_t)
typedef struct {
unsigned int ubr: 16; //Clock division factor
unsigned int sync :1;
unsigned int mode: 2;
unsigned int mm:1; //Master mode (0=slave; 1=master)
unsigned int clen: 1; //Character length (0=8-bit data; 1=7-bit data)
unsigned int msb: 1; //1=MSB first, 0=LSB first
unsigned int ckpl: 1; //Clock polarity (0=inactive is low && data at rising edge; 1=inverted)
unsigned int ckph: 1; //Clock phase (0=normal; 1=half-cycle delayed)
unsigned int :6;
unsigned int ssel: 2; //Clock source (00=external UCLK [slave]; 01=ACLK [master]; 10=SMCLK [master] 11=SMCLK [master]);
unsigned int :0;
} msp430_spi_config_t;
typedef struct {
uint16_t ubr;
uint8_t uctl0;
uint8_t uctl1;
} msp430_spi_registers_t;
typedef union {
msp430_spi_config_t spiConfig;
msp430_spi_registers_t spiRegisters;
} msp430_spi_union_config_t;
msp430_spi_union_config_t msp430_spi_default_config = {
{
ubr : 0x000d, // /13
clen : 0,
mm : 1,
ckph : 1,
ckpl : 0,
sync : 1,
mode : 0,
msb : 1,
ssel : 0x02, // SMCLK
}
};
/**
The calculations were performed using the msp-uart.pl script:
msp-uart.pl -- calculates the uart registers for MSP430
Copyright (C) 2002 - <NAME> - pzn dot debian dot org
**/
typedef enum {
//32KHZ = 32,768 Hz, 1MHZ = 1,048,576 Hz
UBR_32KHZ_1200=0x001B, UMCTL_32KHZ_1200=0x04,
UBR_32KHZ_2400=0x000D, UMCTL_32KHZ_2400=0x0C,
UBR_32KHZ_4800=0x0006, UMCTL_32KHZ_4800=0x0E,
UBR_32KHZ_9600=0x0003, UMCTL_32KHZ_9600=0x06,
/* UBR_1MHZ_1200=0x0369, UMCTL_1MHZ_1200=0x7B,
UBR_1MHZ_1800=0x0246, UMCTL_1MHZ_1800=0x55,
UBR_1MHZ_2400=0x01B4, UMCTL_1MHZ_2400=0xDF,
UBR_1MHZ_4800=0x00DA, UMCTL_1MHZ_4800=0xAA,
UBR_1MHZ_9600=0x006D, UMCTL_1MHZ_9600=0x44,
UBR_1MHZ_19200=0x0036, UMCTL_1MHZ_19200=0xB5,
UBR_1MHZ_38400=0x001B, UMCTL_1MHZ_38400=0x94,
UBR_1MHZ_57600=0x0012, UMCTL_1MHZ_57600=0x84,
UBR_1MHZ_76800=0x000D, UMCTL_1MHZ_76800=0x6D,
UBR_1MHZ_115200=0x0009, UMCTL_1MHZ_115200=0x10,
UBR_1MHZ_230400=0x0004, UMCTL_1MHZ_230400=0x55,*/
//12MHZ = 12,582,912 Hz
UBR_12MHZ_9600=0x051E, UMCTL_12MHZ_9600=0x0C,
UBR_12MHZ_19200=0x028F, UMCTL_12MHZ_19200=0x06,
UBR_12MHZ_38400=0x0147, UMCTL_12MHZ_38400=0x0A,
UBR_12MHZ_57600=0x00DA, UMCTL_12MHZ_57600=0x08,
UBR_12MHZ_115200=0x006D, UMCTL_12MHZ_115200=0x04,
UBR_12MHZ_230400=0x0036, UMCTL_12MHZ_230400=0x0A, // seems not to work
} msp430_uart_rate_t;
typedef struct {
unsigned int ubr:16; //Baud rate (use enum msp430_uart_rate_t for predefined rates)
unsigned int umctl: 8; //Modulation (use enum msp430_uart_rate_t for predefined rates)
unsigned int :1;
unsigned int mode :2; //Multiprocessor mode (0=uart, 1=idle-line protocol; 2=address-bit protocol, 3=UART automaitc baud rate detect)
unsigned int spb: 1; //Stop bits (0=one stop bit; 1=two stop bits)
unsigned int clen: 1; //Character length (0=8-bit data; 1=7-bit data)
unsigned int msb: 1; //LSB / MSB first
unsigned int pev: 1; //Parity select (0=odd; 1=even)
unsigned int pena: 1; //Parity enable (0=disabled; 1=enabled)
unsigned int :0;
unsigned int :3;
unsigned int dorm:1; //dormant
unsigned int brkeie:1; //rx break interrupt enable
unsigned int rxeie:1; //rx erroneous-character interrupt enable
unsigned int ssel: 2; //Clock source (00=UCLKI; 01=ACLK; 10=SMCLK; 11=SMCLK)
unsigned int :0;
unsigned int utxe:1; // 1:enable tx module
unsigned int urxe:1; // 1:enable rx module
} msp430_uart_config_t;
typedef struct {
uint16_t ubr;
uint8_t umctl;
uint8_t uctl0;
uint8_t uctl1;
uint8_t ume;
} msp430_uart_registers_t;
typedef union {
msp430_uart_config_t uartConfig;
msp430_uart_registers_t uartRegisters;
} msp430_uart_union_config_t;
msp430_uart_union_config_t msp430_uart_default_config = {
{
utxe : 1,
urxe : 1,
ubr : UBR_32KHZ_9600,
umctl : UMCTL_32KHZ_9600,
ssel : 0x01,
pena : 0,
pev : 0,
spb : 0,
clen : 0,
mode :0,
msb: 0,
dorm: 0,
brkeie: 0,
rxeie: 1,
}
};
typedef struct {
unsigned int i2cstt: 1; // I2CSTT Bit 0 START bit. (0=No action; 1=Send START condition)
unsigned int i2cstp: 1; // I2CSTP Bit 1 STOP bit. (0=No action; 1=Send STOP condition)
unsigned int i2cstb: 1; // I2CSTB Bit 2 Start byte. (0=No action; 1=Send START condition and start byte (01h))
unsigned int i2cctrx: 1; //I2CTRX Bit 3 I2C transmit. (0=Receive mode; 1=Transmit mode) pin.
unsigned int i2cssel: 2; // I2C clock source select. (00=No clock; 01=ACLK; 10=SMCLK; 11=SMCLK)
unsigned int i2ccrm: 1; // I2C repeat mode
unsigned int i2cword: 1; // I2C word mode. Selects byte(=0) or word(=1) mode for the I2C data register.
} __attribute__ ((packed)) msp430_i2ctctl_t;
DEFINE_UNION_CAST(i2ctctl2int,uint8_t,msp430_i2ctctl_t)
DEFINE_UNION_CAST(int2i2ctctl,msp430_i2ctctl_t,uint8_t)
typedef struct {
unsigned int :1;
unsigned int mst: 1; //Master mode (0=slave; 1=master)
unsigned int :1;
unsigned int listen: 1; //Listen enable (0=disabled; 1=enabled, feed tx back to receiver)
unsigned int xa: 1; //Extended addressing (0=7-bit addressing; 1=8-bit addressing)
unsigned int :1;
unsigned int txdmaen: 1; //DMA to TX (0=disabled; 1=enabled)
unsigned int rxdmaen: 1; //RX to DMA (0=disabled; 1=enabled)
unsigned int :4;
unsigned int i2cssel: 2; //Clock source (00=disabled; 01=ACLK; 10=SMCLK; 11=SMCLK)
unsigned int i2crm: 1; //Repeat mode (0=use I2CNDAT; 1=count in software)
unsigned int i2cword: 1; //Word mode (0=byte mode; 1=word mode)
unsigned int i2cpsc: 8; //Clock prescaler (values >0x04 not recomended)
unsigned int i2csclh: 8; //High period (high period=[value+2]*i2cpsc; can not be lower than 5*i2cpsc)
unsigned int i2cscll: 8; //Low period (low period=[value+2]*i2cpsc; can not be lower than 5*i2cpsc)
unsigned int i2coa : 10; // Own address register.
unsigned int :6;
} msp430_i2c_config_t;
typedef struct {
uint8_t uctl;
uint8_t i2ctctl;
uint8_t i2cpsc;
uint8_t i2csclh;
uint8_t i2cscll;
uint16_t i2coa;
} msp430_i2c_registers_t;
typedef union {
msp430_i2c_config_t i2cConfig;
msp430_i2c_registers_t i2cRegisters;
} msp430_i2c_union_config_t;
msp430_i2c_union_config_t msp430_i2c_default_config = {
{
rxdmaen : 0,
txdmaen : 0,
xa : 0,
listen : 0,
mst : 1,
i2cword : 0,
i2crm : 1,
i2cssel : 0x2,
i2cpsc : 0,
i2csclh : 0x3,
i2cscll : 0x3,
i2coa : 0,
}
};
#endif//_H_Msp430Usart_h
|
tinyos-io/tinyos-3.x-contrib | rincon/tos/chips/msp430/timer/tseconds.h | <reponame>tinyos-io/tinyos-3.x-contrib
#ifndef TSECONDS_H
#define TSECONDS_H
typedef struct { int notUsed; } TSeconds;
#define UQ_TIMER_SECONDS "HilTimerSecondsC.Timer"
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.