Linux: how to interpret data coming from enviromon?

 
Post new topic   Reply to topic    Pico Technology Forum Index -> General Software Discussions
Author Message
organtin
Newbie


Joined: 07 Nov 2006
Posts: 1
Location: Roma, Italy

PostPosted: Fri Dec 08, 2006 1:19 pm    Post subject: Linux: how to interpret data coming from enviromon? Reply with quote

Hi. I'm trying to read data from an enviromon system connected to a humidiprobe sensor on a linux system. I tried to figure out how to get the data from the general documentation, that in fact, is quite poor.

I then wrote a function that reads the last data set as:
Code:

typedef struct {
  SKT_HEADER header;
  unsigned char message [250];
} em_message;

void header(em_message *m, int sequence) {
  m->header.function = SF_FORWARD;
  m->header.sequence = sequence;
  m->header.timeout = 500;
}

int getLastValue(int channel, int s, int sequence, struct sockaddr_in *addr) {
  em_message m;
  if (verbose) {
    printf("(EXEC) getting last reading\n");
  }
  header(&m, sequence);
  m.message[0] = 6; // the length of the message
  m.message[1] = EM_ADDR; // the enviromon address
  m.message[2] = LF_GET_BLOCK; //the function
  m.message[3] = LB_CURRENT; // function parameter (current reading)
  m.message[4] = 0; // unused
  m.message[5] = chksm(&m);
  execcmd(&m, s, addr);
  int data = (m.message[3+2*channel] << 8) + m.message[4+2*channel];
  return data;
}


Here execcmd is a function that "inject" the em_message structure on the s socket, as an UDP message.

I put sequence=0 (by the way, what is intended for?). Executing this function returns something like:

index: 0 value: 124
index: 1 value: 1
index: 2 value: 0
index: 3 value: 8
index: 4 value: 158
index: 5 value: 6
index: 6 value: 6
index: 7 value: 6
index: 8 value: 6
...
and so on, all other lines are equal to the last one, expect the last, who is:
index: 123 value: 247

As far as I understand: 124 in the 0-th component of the buffer is the length of the buffer (that in fact has 124 bytes). The following two values are the address of the sensor (1) and the function (0, I guess this is the return code, in fact). Then I interpret the data as follows: 8 and 158 should interpreted as 8*256+158, corresponding to the reading of channel 1 (the data returned by my function for channel=0; it seems to be the temperature), then what about the list of 6? What about the humidity?

Thank you.

Of course, if I can manage to read data correctly, I'll publish my source code, so anyone can use the system on linux (at least to read last data read).
Back to top
ziko
Site Admin
Site Admin


Joined: 01 Dec 2006
Posts: 658
Location: St Neots

PostPosted: Thu Dec 28, 2006 2:01 pm    Post subject: Reply with quote

Hi and thank you for your post.

Currently we are running a limited service over the Christmas period and as such I cannot answer any programming questions. However we will be operating fully from next week.

Sorry for any inconvenience.

Kind regards
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Pico Technology Forum Index -> General Software Discussions
All times are GMT
Page 1 of 1

 


Pico Technology topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group