Hi Derek
Here I copied pasted some code, that should help you understand how to do
it.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "sfsource.h"
#include "serialprotocol.h"
#include "serialpacket.h"
#include "scmd.h"
#include "demo_sensor.h"
int main(int argc, char **argv)
{
int fd;
if (argc < 3)
{
fprintf(stderr, "Usage: %s <host> <port> - send cmd to a serial
forwarder\n", argv[0]);
exit(2);
}
fd = open_sf_source(argv[1], atoi(argv[2]));
if (fd < 0)
{
fprintf(stderr, "Couldn't open serial forwarder at %s:%s\n",
argv[1], argv[2]);
exit(1);
}
for(;;){
uint16_t moteId;
uint8_t magnitude;
uint8_t cmd;
uint8_t i;
uint8_t packet_size = 1+ SPACKET_SIZE + SCMD_SIZE;
unsigned char *packet;
tmsg_t* msg;
packet = malloc(packet_size);
if (!packet)
exit(2);
for(i=0;i<packet_size;i++)
packet[i] = 0;
packet[0] == SERIAL_TOS_SERIAL_ACTIVE_MESSAGE_ID;
msg = new_tmsg(packet + 1,packet_size - 1);
printf("Input mote destination address: ");
scanf("%hu",&moteId);
printf("Select the command you want to send:\n");
printf("start -> 0\n");
printf("stop -> 1\n");
printf("send log -> 2\n");
printf("erase log -> 3\n");
scanf("%hhu",&cmd);
spacket_header_dest_set(msg,moteId);
spacket_header_length_set(msg,packet_size - SPACKET_SIZE - 1);
spacket_header_type_set(msg,AM_CMD_MSG);
msg = new_tmsg(packet + 1 + SPACKET_SIZE,packet_size - 1 -
SPACKET_SIZE);
switch(cmd){
case START_CMD:
scmd_cmd_set(msg,START_CMD);
break;
case STOP_CMD:
scmd_cmd_set(msg,STOP_CMD);
break;
case SEND_LOG_CMD:
scmd_cmd_set(msg,SEND_LOG_CMD);
break;
case ERASE_LOG_CMD:
scmd_cmd_set(msg,ERASE_LOG_CMD);
break;
}
write_sf_packet(fd, packet, packet_size);
}
close(fd);
}
Its been a while since I did this form scratch. All my other applications
are copy paste of this one.
But if you need further information I can review this
good luck
-Bill
On Thu, Aug 20, 2009 at 11:10 AM, Derek Jones <[email protected]> wrote:
> Hello all,
>
> I am attempting to send some information from my computer to some Tmote Sky
> sensor nodes (using a program created in C, the program succesfully receives
> information from the network), using the nx_struct below that is contained
> in a header file gatewaySensor.h to store the information.
>
> enum
> {
> AM_AUTOMATIONUPDATEMSG = 6,
> };
>
> typedef nx_struct AutomationUpdateMsg
> {
> nx_uint8_t nodeid;
> nx_uint8_t actionUpdate[5];
> }AutomationUpdateMsg;
>
> I have used MIG to generate the functions needed to set/get the
> information once the struct is created. However I am struggling to
> understand exactly how to create the an instantiation of the struct in the C
> program so that I can send it over the network. I have looked at the
> TestSerial.java file in the /apps/test/ directory to see if it helped but
> either due to my lack of understanding of Java or that the process to do the
> same thing in C is very different it hasn't helped much.
>
> Amongst other things I have tried:
>
> 1) Creating a tmsg_t* to and then assigning the values as follows:
>
>
> tmsg_t updateMsg;
>
> AutomationUpdateMsg_actionUpdate_set(updateMsg, 0, 5);
> AutomationUpdateMsg_actionUpdate_set(updateMsg, 1, 10);
> .
> .
> .
> etc where AutomationUpdateMsg_actionUpdate_set is the function created by
> MIG for setting the values of the array nx_uint8_t actionUpdate[5];. This
> perhaps understandably didn't work very well as program has no idea how big
> updateMsg should is and so when trying to set anything but the first value
> of the array an error occurs and the program exits.
>
> 2) Including the gatewaySensor.h header file into the program that will be
> doing the sending so that I can create a version of the struct and then
> assign the values manually before sending it over the serial forwarder, but
> this doesn't work as the compiler gives me an error along the lines of:
>
> In file gatewaySensor.h error: expected '=', ',', ';', 'asm', or
> __attribute__ before 'Automation' as soon as I include the header file.
>
> So my questions are:
>
> 1) Are either of the methods I have tried even remotly correct? If so what
> am I doing wrong?
> 2) If they aren't correct could anyone suggest what should be done, or
> point me towards an example that may help?
>
> I have Googled until my fingers fell off to no avail, so any
> advice/suggestions would be appreciated.
>
> Thanks Derek
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
--
Ing. Guillermo De Cesco
Invenio Ingenieria srl.
tel: (54)2944 442119
web: www.invenioing.com
Av. Pioneros 4163 Dpto 6. CP(R8402AMH)
San Carlos de Bariloche.
Rio Negro, Argentina.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help